Fluids

Fluids

    • engineer72
      Subscriber

      Hello there


      i have problems in using fprintf in my compiled udf. i used it in a simple udf as below, but still not working:


       

    • Rob
      Ansys Employee

      Listing the problems will help, as will putting the source code in the post: staff are not permitted to open/download attachments. 

    • engineer72
      Subscriber

    • rachels1001
      Subscriber

      It's hard to tell without the console errors, but as an initial guess, the DEFINE_RW_FILE command can't be used in UDFs that are executed on Windows systems, according to the Ansys documentation. 

    • engineer72
      Subscriber

      thank U for answering. there is no error at all, the solution is done but no data is written.


      so how can i export a variable's magnitudes into an external file? in simple above example,  for compiled udf and using windows system?

    • Rob
      Ansys Employee

      If you just need a number from a point/surface use the reports and write to a file: much easier too! 

    • engineer72
      Subscriber

      i need the number calculated in udf, so i cant find it in reports.

    • SK95
      Subscriber

      fp in the function header is a pointer to a file which is already open, therefore using fopen can lead to undefined behaviour. Try to use this code:

      DEFINE_RW_FILE(writer, fp)


      {


         fprintf(fp, %d, kount);


      }

    • SK95
      Subscriber

      If you want to print to your own file you don't need the DEFINE_RW_FILE function. You can just write your 3 lines fopen, fprintf, fclose anywhere you want (e.g. in your DEFINE_ADJUST function). But keep in mind opening and closing a file each time, takes "a lot of time" and therefore your runtime will be longer.

    • engineer72
      Subscriber

      thank U for your attention! i tried below udf, but it shows error as i want to load the udf after building that. is the problem about using compiled udf or windows system or something?


    • DrAmine
      Ansys Employee

      Talking about errors: share wuth us the error? I guess your forgot to define the File you want to open.

    • SK95
      Subscriber

      Sorry I forgot to mention...you have to define the variable fp first, before using it.


      FILE *fp;
      fp = fopen...

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