CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

UDF with output text file

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   December 13, 2007, 07:17
Default UDF with output text file
  #1
manu
Guest
 
Posts: n/a
I'm writind a UDF Macro (interpreted) where I define the new boundary conditions for each time-step of the simulation. I would like also to write in a txt file the variables I used to compute this boundary condition. So I use the commands: FILE *fp, fopen, fprintf, fclose. The problem is that I don't know how to close the file only at the end of the simulation, because otherwise, my txt file will be overwritten after each timestep if I include the "fclose" in the brackets of my UDF Macro. So is there a way to say to my Macro that the iteration is over, and so with a if-condition I could close my file rightly? I mean something like

if ("!!!iteration finished!!!") {fclose(fp) }

?????????????????????????????????????????????????? ???????????????????????????????????????? Here is a simplified version of my code:

#include "udf.h"

FILE *fp;

#define p_atm 1e5

DEFINE_PROFILE(pressure_outlet,t,i) { face_t f; real p = 1e5; real A[ND_ND]; real B[ND_ND]; int n = RP_Get_Integer("time-step");

A[n]= n+2; B[n]= 2*n; p= (3*A[n]+B[n])/(n+1)*p_atm;

begin_f_loop(f,t) { F_PROFILE(f,t,i) = p; /*new boundary condition */ } end_f_loop(f,t)

/*write column titles*/ if (n==0) { fp = fopen("output.txt","w"); fprintf(fp,"A \t B \t p\n"); }

fprintf(fp,"%f \t %f \t %f\n",A[n],B[n],p); /* fclose(fp); */ }
  Reply With Quote

Old   December 13, 2007, 08:42
Default Re: UDF with output text file
  #2
al_c
Guest
 
Posts: n/a
You can use "a" option instead of "w" option in fopen() function. For example fopen("output.txt","a"). In this case all new data will be append to the existing data.
  Reply With Quote

Old   March 23, 2011, 14:24
Default
  #3
Member
 
Join Date: Apr 2010
Location: Pisa / Italy
Posts: 57
Rep Power: 7
Atze is on a distinguished road
hi,

i've used fprintf to write .txt file .... but the output is written twice.... why?

example:
0.000900 1.148102e-006
0.000900 1.148102e-006
0.001000 1.513927e-006
0.001000 1.513927e-006
0.001100 1.872173e-006
0.001100 1.872173e-006
0.001200 2.222938e-006
0.001200 2.222938e-006
Atze is offline   Reply With Quote

Old   March 24, 2011, 09:55
Default
  #4
New Member
 
Join Date: Mar 2009
Posts: 4
Rep Power: 8
e0125583 is on a distinguished road
@Atze: are you simulating in parallel?
e0125583 is offline   Reply With Quote

Old   March 24, 2011, 11:22
Default
  #5
Member
 
Join Date: Apr 2010
Location: Pisa / Italy
Posts: 57
Rep Power: 7
Atze is on a distinguished road
@e0125583

no, i'm not.... my code is simply

data=fopen("data.txt","a");
fprintf(data,"%f %e\n",time,domega);
fclose(data);

as reported on udf-manual..... it's strange. Now i'm importing data.txt in excel and removing odd (or pair) lines...
Atze is offline   Reply With Quote

Old   May 31, 2012, 07:16
Default do you find the reason ?
  #6
New Member
 
Join Date: Mar 2012
Posts: 26
Rep Power: 5
tsi07 is on a distinguished road
Hello,

I have the same problem, but for me the value is repeted 3 times.
Have you found the solution of that strange thing ?

Thanks!!
tsi07 is offline   Reply With Quote

Old   April 24, 2013, 02:46
Default
  #7
New Member
 
Daan de Boer
Join Date: Jun 2012
Posts: 6
Rep Power: 0
daandb is on a distinguished road
same issue (5 times in my case)
daandb is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pisoFoam compiling error with OF 1.7.1 on MAC OSX Greg Givogue OpenFOAM Programming & Development 3 March 4, 2011 18:18
ParaView 33 canbt open OpenFoam file hariya03 OpenFOAM Paraview & paraFoam 7 September 25, 2008 17:33
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24
error while compiling the USER Sub routine CFD user CFX 3 November 25, 2002 16:16
PHI file structure Eugene Phoenics 9 November 2, 2001 23:00


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