CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

UDF Posting Value Twice in File

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 13, 2020, 19:05
Default UDF Posting Value Twice in File
  #1
New Member
 
David
Join Date: Aug 2020
Posts: 5
Rep Power: 5
David12 is on a distinguished road
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;
}
David12 is offline   Reply With Quote

Old   August 14, 2020, 00:32
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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;
}
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 03:30
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch gschaider OpenFOAM Installation 225 August 25, 2015 19:43
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 10:57
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 11:44
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


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