Fluids

Fluids

EXECUTE_AT_END UDF

    • kfouladi
      Subscriber

      Hello All,


      I have problem using a DEFINE_EXECUTE_AT_END UDF. It seems not to do anything or at least it does not create the output file (edata.txt). I originally had this UDF as a DEFINE_ON_DEMAND, which worked fine. Any help would be appreciated. 


      This is what fluent writes at the end:


      Registering UdfSource, ("Users/kfoul_000/Documents/…../gen.c")


      Registering Udflib, ("Users/kfoul_000/Documents/…./dp0/FFF-1/Fluent/libudfxaa1")


       Writing data to C:Userskfoul_000Documents....dp0FFF-1FluentFFF-1.1.ip ...


      (1) I have defined 3 User-Defined Memory. (2) Please disregard the accuracy of the equation.


      My UDF file is attached to the next post.


       


      Kamran

    • kfouladi
      Subscriber

      #include "udf.h"


      DEFINE_EXECUTE_AT_END(gen)


      {


        Domain *d; /* declare domain pointer since it is not passed as an  


                       argument to the DEFINE macro  */


         real temp = 293.15;


         real dudx, dudy;


         real rho = 1000.0;


         real sum_e;


         sum_e=0.;


         Thread *t;


         cell_t c;


         d = Get_Domain(1);     /* Get the domain using Fluent utility */


           /*(location index 0)                                            */


          /* Loop over all cell threads in the domain */


         thread_loop_c(t,d)


           {


           begin_c_loop(c,t)


             {


      dudx = C_U_G(c,t)[0];


      dudy = C_U_G(c,t)[1];


               C_UDMI(c,t,0) = 1.0/temp*(2*(pow(dudx,2) + pow(dvdy,2) ));


      C_UDMI(c,t,1) = rho;


      C_UDMI(c,t,2) = C_UDMI(c,t,0) + C_UDMI(c,t,1);


             sum_e += C_UDMI(c,t,2) * C_VOLUME(c,t);


             }


           end_c_loop(c,t)


              }


      printf("Volume integral e: %gn", sum_e);


      FILE *fp;    


        fp = fopen("edata.txt","w+"); 


       fprintf(fp, "Volume integral e: %gn", sum_e);


      fclose(fp); 


      fflush(stdout);


      }

    • Konstantine Kourbatski
      Ansys Employee

      1) is the DEFINE_EXECUTE_AT_END executed? You have printf, is this message been printed?


      2) since you are not specifying explicit path to the file, fluent is expected to open file in project_filesdp0FLUFluent, but if it's not there, do a quick search of your folders to check if it's been written in a different place

    • kfouladi
      Subscriber

      I am not sure DEFINE_EXECUTE_AT_END is executed. printf is not printed and I checked my computer and there is no "edata.txt" in any directory.

    • Konstantine Kourbatski
      Ansys Employee

      is it properly hooked: User-Defined - Functions - Hooks

    • Konstantine Kourbatski
      Ansys Employee

      Is DEFINE_EXECUTE_AT_END executed at every iteration? Do you see printf outputs after each iteration? What may happen is the file is not overwritten at a subsequent execution, but this is a basic C programming question not related to ANSYS products

Viewing 5 reply threads
  • You must be logged in to reply to this topic.