TAGGED: fluent, read-input, udf
-
-
September 3, 2020 at 2:08 pm
mardott
SubscriberI need to write an UDF that reads data from a .dat file (first line is just a number that represent the total number of the remaining lines of the file, from the second line and until the end the file becomes 4 columns).nA piece of my code:n#include udf.hn/* Defining global variables */n#define n_array 1000 /* Hypotetical dimension of the following arrays */ndouble x_coord[n_array], y_coord[n_array],u[n_array],v[n_array];ndouble y_vector, position[ND_ND], val;nint N_tot, j;nFILE *fp;nn/* x-velocity */nDEFINE_PROFILE(x_velocity,t,i)n{n if((fp = fopen(FILENAME.datr)) == NULL)nttprintf(ERROR in opening DataFile );nntfscanf(fp,%d, &N_tot);ntprintf(N_tot is %d,N_tot);nn for (j=0; j>N_tot; j++)nttfscanf(fp,%lf %lf %lf %lf, &x_coord[j], &y_coord[j], &u[j] ,&v[j]);ntfclose(fp);ntprintf(x is %lf,x_coord);nntbegin_f_loop(f,t)nt{ntt[... code that interpolates u long y]nttF_PROFILE(f,t,i) = val;nt}ntend_f_loop(f,t)n}/* y-velocity */nnDEFINE_PROFILE(y_velocity,t,i)n{nt/* variable declarations */ntface_t f;ntbegin_f_loop(f,t)nt{ntt[... code that interpolates v along y]nttF_PROFILE(f,t,i) = val;nt}ntend_f_loop(f,t)n}nnAm I doing something wrong in the file reading? Because when I try to print in the console, N_tot is printed correctly, but x_coord is always zero.nI guess I also have to parallelize my functions, but it doesn't seem to work in any way.nCould anyone help me?nThanks!n -
September 3, 2020 at 2:57 pm
Rob
Forum ModeratorAssuming you're reading the files into Fluent why don't you just write out a profile using the tools in Fluent? n -
September 3, 2020 at 4:17 pm
mardott
SubscriberBecause I have to manipulate the data I extrapolate from this file. And in general it would be useful, for the future, to know how I can store variables that I read from these files. n -
September 3, 2020 at 4:40 pm
Amine Ben Hadj Ali
Ansys EmployeeIt is not an easy step as you need to allocate memory dynamically and chose a reliable interpolation method. I will rather put the part of reading outside of the profiles. n -
September 4, 2020 at 11:17 am
mardott
SubscriberYeah I will consider to allocate the memory dynamically for a general case, once I managed to make the code work for this specific case (here an array of 1000 is more than enough). If I put the reading part outside the profiles, FLUENT doesn't build the library and complains about the arrays and asks me to insert brackets where they are not supposed to be inserted / I really cannot see the error.n -
September 4, 2020 at 2:43 pm
-
Viewing 5 reply threads
- The topic ‘UDF for reading .dat file and then sending values as profile’ is closed to new replies.
Ansys Innovation Space
Trending discussions
- air flow in and out of computer case
- Varying Bond model parameters to mimic soil particle cohesion/stiction
- Eroded Mass due to Erosion of Soil Particles by Fluids
- I am doing a corona simulation. But particles are not spreading.
- Guidance needed for Conjugate Heat Transfer Analysis for a 3s3p Li-ion Battery
- Centrifugal Fan Analysis for Determination of Characteristic Curve
- Issue to compile a UDF in ANSYS Fluent
- JACOBI Convergence Issue in ANSYS AQWA
- affinity not set
- Resuming SAG Mill Simulation with New Particle Batch in Rocky
Top Contributors
-
3967
-
1431
-
1272
-
1119
-
1015
Top Rated Tags
© 2025 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.