Ansys Products

Ansys Products

UDF Compilation and Interpretation Error

    • ehkh
      Subscriber

      Hi,


      I am facing errors while trying to do interpretation or compilation for a UDF in fluent.


      I am simulating a 2D rectangular cavity with the following boundary conditions: adiabatic top layer, periodic side walls and rigid bottom with thermal heat flux and small random perturbations following this equation: dT/dy= -exp(-h)+ epsilon*[rand(x)-0.5] , where rand is a one dimensional array of random numbers uniformly distributed in the range of [0,1].


      I used a UDF to assign the heat flux and perturbation to the bottom layer. When I used interpretation of UDF, I get an error notifying that: srand: undeclared variable.


      When trying to compile it, I get an error notifying that: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).nnThe system cannot find the file specified. however, the UDF source files are in the directory that contains my case and data files.


       


      Following the UDF I am using to set up the boundary condition at the bottom layer:


       


       


      #include "udf.h"


      #include "stdlib.h"            /* srand and rand */


      #include "time.h"


      #include "random.h"


       


      #define RAND_MAX 32767


       


       


      DEFINE_PROFILE(Temp_rand_pertubation_bottom,thread,index)


      {


       


      real x[ND_ND]; /* this will hold the position vector */


       


      face_t f;


       


      real time= CURRENT_TIME;


       


       


      float h,E,r;


       


      srand((unsigned)time(NULL));        /*  this to specify a different random number at each cell */


      k=0.6                /* thermal conductivity */


      T=300               /* Temp in Kelvin */


      h = 0.5; /* cavity height  */


      E= 0.01; /* epsilon constant value */


       


       


        begin_f_loop_all(f,thread)


      {


      r= rand()/float(RAND_MAX);       /* r is a 1D array of random numbers uniformly distributed in the range of [0,1] */


        


      F_CENTROID (x,f,thread);


       


      F_PROFILE(f,thread,index) = k*T*(- exp(-h)+E*(r-0.5))/h;         /* apply random perturbation */


      }


        end_f_loop_all(f,thread);


       


      void srand(unsighned int seed);


      }


       


       


       


      To avoid these errors, please advice me whether my UDF need to be corrected or modified, or its something to do with fluent itself.


       


      Many thanks


      Esra'a

    • Rob
      Ansys Employee

      Check on the compiled error: is there something about "nmake" not being recognised?

    • ehkh
      Subscriber

      Can you please give me more clarification what you meant by "nmake"?


      If I understood you, I get nothing about "nmake", the error that I get is as follows: 


      The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).nnThe system cannot find the file specified.


      However, even I am getting this error, I found a libudt file in the directory but  the UDF does not come out in the drop down menu in heat flux boundary condition dialog box.


       

    • DrAmine
      Ansys Employee

      Do you have compiler installed? Can you check with a dummy Hello World dummy DEFINE_ON_DEMAND UDF.?

    • Rob
      Ansys Employee

      UDFs can fail to compile due to coding errors and/or lack of a compiler. The former usually gives a string of errors, the latter complains about nmake not being present/recognised. As there is then no libudf to load you get the error you're seeing. 

    • ehkh
      Subscriber

      Hi,


       


      Thanks for your reply.


      In order to solve the problem, I have installed the latest version of visual studio, restarted the machine, set up the Path in the environment variable correctly as below:


      C:Program Files (x86)Microsoft Visual Studio2019CommunityCommon7Tools;


      C:Program Files (x86)Microsoft Visual Studio2019CommunityVC;


      C:Program FilesANSYS Incv192fluent;  


      BUT still facing the same problem !  


      Could you please guide me how to get this error solved.  


      Thanks

    • Rob
      Ansys Employee

      Which means it's not compiling. Are you getting the "nmake" not recognised or a list of errors on the code? Check in the Installation section for the former (I think we're still using Visual Studio 2017). 

    • ehkh
      Subscriber

      Thanks for your reply.


      I don't get anything related to "nmake" or error in the code. the only error error I get exactly copied from the TUI:


      Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).nnThe system cannot find the file specified.


      nnF:esraworked simulations2Drayleigh benard convectionRectCavityHeatfluxPatterson2015RecyCavityHeatflux_filesdp0FFFMECHlibudfwin642ddp_hostlibudf.dll


      Error Object: #f


      Regarding Visual studio, I have installed v2019, do I need to install v2017 to be compatible with Fluent 19.2 ??


       


       


       

    • Rob
      Ansys Employee

      Which just means the UDF isn't compiled. I'll move to installation, but please review the various threads on compilers as I suspect that'll resolve this problem. 

    • tsiriaks
      Ansys Employee

      Please use Visual Studio 2017, the current ANSYS versions won't work with 2019 without certain modifications in the script.


      Try VS 2017 and make sure that you don't have space anywhere in path, folder names, case and data files (I see you have plenty of them)

    • ehkh
      Subscriber

      Thanks for your reply.


      Do you recommend to use ANSYS 19.2 or 18.2 to be compatible with VS 2017 ??


       


      Thanks

    • tsiriaks
      Ansys Employee

      ANSYS 2019 R# is ok, no need for older versions.


      Thanks,


      Win

    • ehkh
      Subscriber

      It works!! Thanks.

    • tsiriaks
      Ansys Employee

      Perfect ! Thank you for the update.


      Win

    • ehkh
      Subscriber

      Hi,


      When using the UDF at the bottom layer, I supposed to see plumes or rolls on the temperature contour profile.


      BUT I didn't, what I get is a simple diffusion problem.


      I wrote the UDF so that each cell on the bottom layer has different random number of heat flux, I used the srand function.


      Here is my UDF:


      #include "udf.h"


       


      #include "stdlib.h"            


      /* srand and rand */


       


      #include "random.h"


       


      #include "time.h"


       


      /*#define RAND_MAX 32767*/


       


      #define k 0.6                


      /* thermal conductivity */


       


      #define T 300               


      /* Temp in Kelvin */


       


      DEFINE_PROFILE(Temp_rand_pertubation_bottom,thread,index)


       


      {


       


      real x[ND_ND]; 


      /* this will hold the position vector */


       


      face_t f;


       


      real time = CURRENT_TIME;


       


      float h = 0.5;


      float E = 0.01;


       


      srand((unsigned int) time);        


      /*this to specify a different random number at each cell*/


       


      begin_f_loop_all(f,thread)


       


      {


       


      float r = (rand() / RAND_MAX);      


      /* r is a 1D array of random numbers uniformly distributed in the range of [0,1] */


       


      F_CENTROID (x,f,thread);


       


      F_PROFILE(f,thread,index) = k*T*(- exp(-h)+E*(r-0.5))/h;         


      /* apply random perturbation */


       


      }


       


      end_f_loop_all(f,thread);


       


       


      void srand(unsigned int seed);


       


      }


       


      please advice me whether I need to modify the code.


       


      Many thanks for your valuable help.


      Esra'a


       


       


       


       


       

    • Rob
      Ansys Employee

      What is the material density?

    • ehkh
      Subscriber

      I am using water as a fluid at 300K , so the density is 997 Kg/m3.


      please not that I am using a laminar unsteady model.


      Thanks

    • ehkh
      Subscriber

       


       


      Hi  
      I am still struggling with this... 
       
      I modified My UDF so that each face on the bottom layer has different random number of heat flux, using the uniform_random() function and included this in the profile equation. Compiled successfully and hooked as a thermal boundary condition for heat flux. My UDF returns the correct value I am looking for.
       

      BUT still not getting plumes or rolls on the temperature contour profile, as I am using a laminar transient simulation with Rayleigh number equals to 10^9. I am expecting to see something similar to previous work done using SNS code. Please refer to Figure 6 in the Journal article (Hattori et. at, 2015)
      https://doi.org/10.1016/j.ijheatmasstransfer.2015.03.060
       
      could you please advice me what is the correct setup for heat flux boundary condition. I went through the boundary conditions section in the manual but could not figure out an answer to my question.
       
      Thanks
      Esra'a
    • tsiriaks
      Ansys Employee

      You may have to create a new thread in Physics Simulation  ->  Fluid Dynamics section , then include the url of this thread for reference. You should get more responses in that section.


      Thanks,


      Win

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