CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF Posting Value Twice in File (https://www.cfd-online.com/Forums/fluent/229554-udf-posting-value-twice-file.html)

David12 August 13, 2020 19:05

UDF Posting Value Twice in File
 
Hello everyone,

As said in the title, my UDF is currently outputting the data I want twice into a data file, and I only want it to post it once. For example it would look something like this:

Time RPM
0 0
0 0
1 1
1 1

I looked around on different forums, and it seems my problem might be because I need to Parallelize my UDF? I'm a newbie when it comes to writing UDF so I'm confused on the whole Parallelization issue. If anyone knows anything about my output problem, I'd very much appreciate the help.


Code:

#include "udf.h"

FILE *fp;    /* local pointer fp to FILE */

DEFINE_ZONE_MOTION(fmotion,omega,axis,origin,velocity,time,dtime)
{
 time = CURRENT_TIME;
 if (time < 0.1)
 {
 *omega = 2500.0 * time;
 }
 else
 {
 *omega = 250.0;
 }
 N3V_D (velocity,=,0.0,0.0,0.0);
 N3V_S(origin,=,0.0); /* default values, line could be omitted */
 N3V_D(axis,=,0.0,1.0,0.0); /* default values, line could be omitted */
 fp = fopen("data.txt","a+");
 fprintf(fp,"Time: %f RPM: %f\n",time,*omega);
 fclose(fp);    /* close the file pointed to by fp */
 return;
}


AlexanderZ August 14, 2020 00:32

try this, compile code
Code:

#include "udf.h"

FILE *fp;    /* local pointer fp to FILE */

DEFINE_ZONE_MOTION(fmotion,omega,axis,origin,velocity,time,dtime)
{
 time = CURRENT_TIME;
 if (time < 0.1)
 {
 *omega = 2500.0 * time;
 }
 else
 {
 *omega = 250.0;
 }
 N3V_D (velocity,=,0.0,0.0,0.0);
 N3V_S(origin,=,0.0); /* default values, line could be omitted */
 N3V_D(axis,=,0.0,1.0,0.0); /* default values, line could be omitted */
 #if RP_HOST
 fp = fopen("data.txt","a+");
 fprintf(fp,"Time: %f RPM: %f\n",time,*omega);
 fclose(fp);    /* close the file pointed to by fp */
 #endif
 return;
}



All times are GMT -4. The time now is 08:47.