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

Using fwrite in FLUENT

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 15, 2017, 04:53
Default Using fwrite in FLUENT
  #1
Senior Member
 
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0
CeesH is on a distinguished road
Hi all,

To store my DPM data, I wrote a script that writes scalar values to the disk every N timesteps. I previously did this with ASCII files without issues, but as they started getting quite sizeable, I am seeking to replace them with binary files.

For testing, I just wrote a serial version of the code, but I already run into some problems: the outputted file size is always some power of 2, and it doesn't store data for all particles. For example, if track 2500 particles and write 1 integer (4 bytes), it only stores data for the first 2048 particles (such that the file size is 8192 bytes). Since it doesn't always store data for the same 2048 particles, this makes it impossible to create timetracks.

Any idea why this might be happening?
And a second question, in case this is fixed, any idea on whether fwrite needs specific parallelization considerations? With ASCII data, using par_fopen and par_fprintf did the trick, but I can't find any specific details for fwrite.

Best,
Cees


Code:
DEFINE_EXECUTE_AT_END(particle_data)
{
Injection *I;
Injection *dpm_injections = Get_dpm_injections();
Particle *p;
int j = 1;
int temp;

if (N_TIME % 5 == 0)
{
FILE *fyle;
char whoru[80];
sprintf(whoru,"D:/ECUST_SD_SIM/P_TRACK/DATA_%.8d.bin%",N_TIME);
fyle = fopen(whoru,"ab");


loop(I,dpm_injections)
{
loop(p,I->p)
{
	
// initialize id values
if (P_USER_REAL(p,0) < 1)
{
P_USER_REAL(p,0) = j;
j++;
}

// write file

temp = P_USER_REAL(p,0)
fwrite(&temp,sizeof(temp),1,fyle)
par_fclose(fyle);
}
}
}
}
CeesH is offline   Reply With Quote

Old   August 23, 2017, 05:53
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
One thing I notice: you open the file once, and close it many times! Your fclose should be two braces out!
pakk is offline   Reply With Quote

Old   August 23, 2017, 06:38
Default
  #3
Senior Member
 
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0
CeesH is on a distinguished road
Hi Pakk,

Correct, found that one
CeesH is offline   Reply With Quote

Old   February 5, 2018, 10:07
Default
  #4
New Member
 
sowmi
Join Date: Mar 2017
Posts: 14
Rep Power: 9
Sowmi is on a distinguished road
Hello Ceesh
Can you suggest me to how to write coding for inert heating law in DPM. Am using DPM for plasma spray coating and am new to it. I want to check law through code using UDF .
It would be better to get reply as early as possible as it is very urgent.
Thanks in advance.
Sowmi 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
CFX vs. FLUENT turbo CFX 4 April 13, 2021 09:08
How to solve UDF compilation problems in Fluent. pakk Fluent UDF and Scheme Programming 16 September 10, 2018 03:48
Two questions on Fluent UDF Steven Fluent UDF and Scheme Programming 7 March 23, 2018 04:22
heat transfer with RANS wall function, over a flat plate (validation with fluent) bruce OpenFOAM Running, Solving & CFD 6 January 20, 2017 07:22
Problems in lauching FLUENT Lourival FLUENT 3 January 16, 2008 17:48


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