CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

simple UDF doesn't read input from external file. interprets/compiles without errors

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 22, 2018, 03:44
Unhappy simple UDF doesn't read input from external file. interprets/compiles without errors
  #1
New Member
 
ahmad
Join Date: Mar 2018
Posts: 21
Rep Power: 8
ahmad_xjtu is on a distinguished road
HI, I am trying to write a UDF, which reads data(temperature values) from an external (.dat) file. (saved in the same location as the UDF). It also needs to write the data in another file in the same folder. UDF interprets/compiles without any error. But doesn't store or reads data from/into the input/output files. UDF is written below.
#include "udf.h"
DEFINE_PROFILE(wall_2, thread, index)
{
real x[ND_ND];
face_t f;
int count,i;
real w,a,b;
FILE *fpp;
FILE *fp;
fpp=fopen("MianT2.dat","w+");
fp=fopen("MianT.dat","r+");
count=0;
begin_f_loop(f,thread)
{
count=count+1;
fscanf(fp,"%d %f %f %f",&i,&a,&b,&w);
F_CENTROID(x,f,thread);
F_PROFILE(f,thread,index)=w;
fprintf(fpp,"%d %f %f %f/n",count,x[0],x[1],w);
}
end_f_loop(f,thread)
fclose(fpp);
fclose(fp);
}

read file(mianT.dat) has 4 coloumns.

any help would be highly appreciated, I have already spent days trying to resolve these issues, but in vain.

Last edited by ahmad_xjtu; March 22, 2018 at 03:46. Reason: missing line
ahmad_xjtu is offline   Reply With Quote

Old   March 22, 2018, 05:08
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Add checks to see if the files open:

Code:
fpp=fopen("MianT2.dat","w+");
fp=fopen("MianT.dat","r+"); 
if (!fpp) {Message("Can not open MianT2.dat for writing!");exit(1);}
if (!fp) {Message("Can not open MianT.dat for reading!");exit(1);}
And see what you get.
pakk is offline   Reply With Quote

Old   March 22, 2018, 05:25
Default
  #3
New Member
 
ahmad
Join Date: Mar 2018
Posts: 21
Rep Power: 8
ahmad_xjtu is on a distinguished road
Thank you so much for the response.
I am new to UDF's and never tried C language either. though I can handle fortran.
Did you mean to add these lines in code and interpret the udf?
I tried interpreting in fluent and it gave the following error.
Error: I:\\fluent_external_reciever\\external_files\\dp0\ \FFF\\Fluent\\source.c: line 12: invalid type for negation: pointer to void.

attached herewith are data from read and write files. It creates and writes something in the output file, but not what I am expecting.

first 20 entries of the write file

1 60.764812 81.775528 0.000000
2 60.764812 77.975975 0.000000
3 60.764812 81.175499 0.000000
4 60.764812 81.375465 0.000000
5 60.764812 80.975525 0.000000
6 60.764812 76.975876 0.000000
7 60.764812 81.775528 0.000000
8 60.764812 81.575439 0.000000
9 60.764812 81.775520 0.000000
10 60.764812 81.775513 0.000000
11 60.764812 80.775558 0.000000
12 60.764812 77.975975 0.000000
13 60.764812 81.775513 0.000000
14 60.764812 80.575584 0.000000
15 60.764812 81.175491 0.000000
16 60.764812 81.375458 0.000000
17 60.764812 76.975868 0.000000
18 60.764812 81.775505 0.000000
19 60.764812 81.575432 0.000000
20 60.764812 80.375618 0.000000


and similarly for the read file,
1 0.1 4.9 594.124
2 0.1 4.7 596.741
3 0.1 4.5 600.5
4 0.1 4.3 604.18
5 0.1 4.1 607.712
6 0.1 3.9 610.96
7 0.1 3.7 613.945
8 0.1 3.5 616.58
9 0.1 3.3 618.823
10 0.1 3.1 620.638
11 0.1 2.9 621.967
12 0.1 2.7 622.792
13 0.1 2.5 623.153
14 0.1 2.3 622.964
15 0.1 2.1 622.281
16 0.1 1.9 621.086
17 0.1 1.7 619.423
18 0.1 1.5 617.32
19 0.1 1.3 614.779
20 0.1 1.1 611.87


thank you.
ahmad_xjtu is offline   Reply With Quote

Old   March 22, 2018, 06:36
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
No, I meant compile.

By the way: your original post said "But doesn't store or reads data from/into the input/output files.". The most recent post said "It creates and writes something in the output file, but not what I am expecting." These are two different outcomes than point to different solutions.
ahmad_xjtu likes this.
pakk is offline   Reply With Quote

Old   March 22, 2018, 09:22
Default
  #5
New Member
 
ahmad
Join Date: Mar 2018
Posts: 21
Rep Power: 8
ahmad_xjtu is on a distinguished road
yeah, my apologies for making it confusing. Please consider the most recent post, i.e. not having the desired output.

I compiled the code as you suggested.Everything remains the same. The same output as in my last post.
This appears as UDF compiles.
Copied I:\fluent_external_reciever\external_files\dp0\FFF \Fluent\source.c to libudf\src
Creating user_nt.udf file for 3ddp ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v150\fluent"\fluent15.0.0\sr c\makefile_nt.udf "libudf\win64\3ddp\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\3ddp")# Generating ud_io1.h
source.c
# Generating udf_names.c because of makefile source.obj
udf_names.c
udf_names.c(8) : warning C4113: 'void (*)()' differs in parameter lists from 'void (*)(void)'
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj source.obj
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp

Done.

Thank you again for taking time to review my problem.
ahmad_xjtu is offline   Reply With Quote

Old   March 23, 2018, 03:03
Default
  #6
New Member
 
ahmad
Join Date: Mar 2018
Posts: 21
Rep Power: 8
ahmad_xjtu is on a distinguished road
I kept playing with it and here's an update.
I created another file, put all the values of the input file into that new file and loaded this new file. its really strange and weird but I am now getting the right values for temperature.

Last edited by ahmad_xjtu; March 24, 2018 at 08:52. Reason: update
ahmad_xjtu is offline   Reply With Quote

Reply

Tags
udf input file, udf read


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 09:46
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation 136 October 10, 2017 18:25
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 18:18
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 06:18


All times are GMT -4. The time now is 15:53.