|
[Sponsors] |
udf for spatial and temporal profile - linking error |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 6, 2020, 18:08 |
udf for spatial and temporal profile - linking error
|
#1 |
Member
Alexandre M S Costa
Join Date: Apr 2009
Posts: 31
Rep Power: 17 |
Hi All,
Hopefully some udf guru can tell what is wrong. The udf is pretty useful. I am trying to compile the UDF below but I am facing the following link error message: kernel32.lib(KERNEL32.dll) : error LNK2005: ReadFile already defined in temporalprof.obj Creating library libudf.lib and object libudf.exp libudf.dll : fatal error LNK1169: one or more multiply defined symbols found The UDF below reads in a text file that contains data for both spatial and temporal variation of a scalar quantity. The format of text file: ----------------------------------------------------------- - The first line contains the NPtsTm (number of time steps points) and NPtsData (number of data points) - Next line is a blank - Next NPtsTm lines contain the time data - Next line is a blank - Next NPtsData lines contain the x-coordinates data - Next line is a blank - Next NPtsData lines contain the y-coordinates data - Next line is a blank - Next NPtsData lines contain the z-coordinates data - Next line is a blank - Next NptsData lines contain the first scalar data at time#0 - Next line is a blank - Next NptsData lines contain the first scalar data at time#1 - ... so on ... until the last time data is given The UDF code : #include "udf.h" int NPtsTm,NPtsData; int DataIsRead = 0; real *tmarr,*xarr,*yarr,*zarr,**Tarr; DEFINE_ON_DEMAND(ReadFile) { int n,i; float data; FILE* fp; fp = fopen("DataFile","r"); if ( fp!=NULL ) Message("Reading file \n"); else Message("Error in opening file \n"); fscanf(fp,"%d %d\n",&NPtsTm,&NPtsData); Message("\n"); Message("There are %d time entries and %d spatial entries\n",NPtsTm,NPtsData); /* Dynamic allocation for 1D array */ tmarr = (real *) malloc(NPtsTm*sizeof(real)); xarr = (real *) malloc(NPtsData*sizeof(real)); yarr = (real *) malloc(NPtsData*sizeof(real)); zarr = (real *) malloc(NPtsData*sizeof(real)); /* Dynamic allocation for 2D array */ { real *temp; temp = (real * ) malloc(NPtsTm*NPtsData*sizeof(real)); Tarr = (real **) malloc(NPtsTm*sizeof(real *)); for(n=0;n<NPtsTm;n++) Tarr[n] = temp + n*NPtsData; } if ( (tmarr==NULL)||(xarr==NULL)||(yarr==NULL)||(zarr== NULL)||(Tarr==NULL) ) Message("Memory allocation error \n"); fscanf(fp,"\n"); Message("\n"); Message("The following is the %d time entries\n",NPtsTm); for ( n=0;n<NPtsTm;n++ ) { fscanf(fp,"%f \n",&data); tmarr[n] = (real)data; Message(" %f\n",data); } fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); xarr[i] = (real)data; } fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); yarr[i] = (real)data; } fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); zarr[i] = (real)data; } for ( n=0;n<NPtsTm;n++ ) { fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); Tarr[n][i] = (real)data; } } DataIsRead = 1; fclose(fp); /* Output check */ Message("\n"); Message("The following is the %d coordinate entries\n",NPtsData); for ( i=0;i<NPtsData;i++ ) { Message(" %f %f %f\n",xarr[i],yarr[i],zarr[i]); } for ( n=0;n<NPtsTm;n++ ) { Message("\n"); Message("The following is scalar data for time entry # %d\n",n); for ( i=0;i<NPtsData;i++ ) { Message(" %f\n",Tarr[n][i]); } } } /*----------------------------------------------------------------------------*/ real GetData(real xf, real yf, real zf, real tm) { int n,nL,nU,i; real tmL,tmU,data,dataL,dataU,sf,smin; tm += 1.0e-7; /* Find the time bracket */ nL = 0; nU = 1; tmL = tmarr[nL]; tmU = tmarr[nU]; for ( n=0;n<NPtsTm;n++ ) { if ( (tm>=tmarr[n])&&(tm<=tmarr[n+1]) ) { nL = n; nU = n+1; tmL = tmarr[nL]; tmU = tmarr[nU]; break; } } /* Find data at the lower and upper time bound */ smin = 1.0e30; dataL = 0.0; dataU = 0.0; for ( i=0;i<NPtsData;i++ ) { sf = sqrt( pow((xarr[i]-xf),2) + pow((yarr[i]-yf),2) + pow((zarr[i]-zf),2) ); if ( sf<=smin ) { smin = sf; dataL = Tarr[nL][i]; dataU = Tarr[nU][i]; } } /* Interpolate between lower and upper time values */ data = dataL + ( tm - tmL )/( tmU - tmL )*( dataU - dataL ); return data; } /*----------------------------------------------------------------------------*/ DEFINE_PROFILE(Tspec,tf,pos) { face_t f; real tm,xf[ND_ND]; tm = RP_Get_Real("flow-time"); begin_f_loop(f,tf) { F_CENTROID(xf,f,tf); F_PROFILE(f,tf,pos) = GetData(xf[0],xf[1],xf[2],tm); } end_f_loop(f,tf) } |
|
August 7, 2020, 06:11 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
change in
Code:
DEFINE_ON_DEMAND(ReadFile)
__________________
best regards ****************************** press LIKE if this message was helpful |
|
August 7, 2020, 12:45 |
|
#3 |
Member
Alexandre M S Costa
Join Date: Apr 2009
Posts: 31
Rep Power: 17 |
Great . Thank you very much.
|
|
July 6, 2021, 05:11 |
Problem with using the code
|
#4 | |
New Member
Farshad Taj
Join Date: Jul 2021
Posts: 1
Rep Power: 0 |
Quote:
Hi amscosta, I hope you are doing well. I am trying to use the UDF you have provided to have a Spatio-temporal velocity profile. I could successfully compile this code in Fluent, but when I try to initialize my solution, the following error appears on my screen and then, fluent is crashed. Error: MPI Application rank 0 exited before MPI finalization() with status 2 I would be thankful if you could let me know whether you had this error or not, and the potential way you used to deal with that. Also, I would be thankful if you could provide me with a sample of the text file that is being used for this UDF. Using the sample, I would understand whether I have written my text file in the correct format or not. Best, Farshad |
||
Tags |
spatial temporal profile |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Unsteady Boundary Profile with data file | Arianna | FLUENT | 34 | July 29, 2019 17:35 |
Using a Mass Flow Rate profile with a Temporal field as a Boundary Condition | Jotheman | Main CFD Forum | 0 | October 18, 2015 10:25 |
Temporal and spatially varying temperature udf | avi@lpsc | Fluent UDF and Scheme Programming | 0 | August 24, 2013 06:43 |
Ubuntu 12.10 + openfoam2.2.0 ==> paraview error message | peteryuan | OpenFOAM Installation | 6 | August 18, 2013 19:00 |
temporal error for unsteady flow | hawk | Main CFD Forum | 8 | August 25, 2006 07:58 |