Fluids

Fluids

UDF for reading .dat file and then sending values as profile

Tagged: , ,

    • mardott
      Subscriber
      I 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
    • Rob
      Ansys Employee
      Assuming you're reading the files into Fluent why don't you just write out a profile using the tools in Fluent? n
    • mardott
      Subscriber
      Because 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
    • DrAmine
      Ansys Employee
      It 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
    • mardott
      Subscriber
      Yeah 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
    • Rob
      Ansys Employee
      Data is stored in UDMs for the most part when using UDFs. If you need to modify the data use Custom Field Functions and write those out. You can alter them for the import if needed.n
Viewing 5 reply threads
  • You must be logged in to reply to this topic.