|
[Sponsors] |
August 15, 2017, 04:53 |
Using fwrite in FLUENT
|
#1 |
Senior Member
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0 |
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); } } } } |
|
August 23, 2017, 05:53 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
One thing I notice: you open the file once, and close it many times! Your fclose should be two braces out!
|
|
August 23, 2017, 06:38 |
|
#3 |
Senior Member
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0 |
Hi Pakk,
Correct, found that one |
|
February 5, 2018, 10:07 |
|
#4 |
New Member
sowmi
Join Date: Mar 2017
Posts: 14
Rep Power: 9 |
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. |
|
|
|
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 |