|
[Sponsors] |
October 28, 2013, 06:21 |
OFstream for parallel processing
|
#1 |
New Member
Laurien Vandewalle
Join Date: Jun 2013
Location: Ghent, Belgium
Posts: 29
Rep Power: 13 |
Hi everyone!
I wrote a code in which several useful numbers and calculated values are written to one single file during runtime. The file is constructed like this: fileName heatData(runTime.path()/"postProcessing"); OFstream heatFile("heatData"); In the solver code, the following lines are included in order to write the average temperature at the wall, the average Nusselt number, the heat flux etc. to the "heatData" file. heatFile<< runTime.timeName() << tab << average(Twall.boundaryField()[wallPatch]) << tab << Tbulk.value() << tab << gradTwallAv.value() << tab << heatFlux.value() <<tab << gamma.value() << tab << average(nusseltNumber.boundaryField()[wallPatch]) << ";" << endl; heatFile.flush(); This works perfectly when I work on 1 processor. All values are written to the "heatData"-file in separate columns, just as I want. However, when I run my case in parallel on different processors (using decomposePar), the "heatData"-file looks totally useless. Data is written randomly, line breaks are randomly added and zeros are outputted instead of the real values. Can anyone explain what's going on here? Or give me some help? |
|
October 28, 2013, 15:56 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
Hi Laurien,
Yes, it is basically, because all of your processors try to write the information to the same file. Since not all of the processors have faces on all patches, this probably explains the zeros. The random input of values will be due to the fact that the processors are not synchronised all of the time. Let me try to sketch something, which should probably (not compiled): IN CONSTRUCTOR: Code:
autoPtr<OFstream> file_; if (Pstream::master()) { file_.reset( new OFstream(<path + name>)); } Code:
// Get reference to the boundary fields label patchI = <some patch index> const scalarField& tw = T.boundaryField()[patchI]; const scalarField& magsf = mesh.magSf().boundaryField()[patchI]; // Get the sum of areas and T*area on that processor scalar sarea = Foam::sum(magsf); scalar sT = Foam::sum(tw*magsf); // Collect across the processors reduce(sarea, sumOp<scalar>()); reduce(sT, sumOp<scalar>()); // Alternatively, there might be a function called gAverage, but // I have not checked. // Only if the processor is the master, write to the file if (Pstream::master()) { // Perform the patch averaging here. file_() << sT/sarea << endl; } Kind regards, Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request. |
|
October 28, 2013, 16:59 |
|
#3 |
Senior Member
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 23 |
You might also want to use a small function to get the output directory:
Code:
const fileName pollutant::getOutputDir() const { // Create the output folder if it doesn't exist yet fileName outputDir; if (Pstream::parRun()) { outputDir = mesh_.time().path()/".."/"postProcessing"; } else { outputDir = mesh_.time().path()/"postProcessing"; } if (!isDir(outputDir)) { mkDir(outputDir); } return outputDir; } Cheers, L |
|
May 7, 2014, 14:20 |
|
#4 |
Senior Member
Join Date: Dec 2011
Posts: 121
Rep Power: 15 |
Hey FOAMers,
At the end of my parallel solver, i filled a vectorField with some values and i'd like to print them into a file : Code:
Ub= ... ; reduce(Ub, sumOp<vectorField>() ); if (Pstream::master()){ fileName outputFile(mesh.time().path()/".."/("test.csv"); OFstream test(outputFile); test <<"First line to test" << endl ; test << mag(gAverage(Ub)) << endl;} If i don't use 'Pstream::master()' , simulation keeps going without any problem. Tnx in advance for any idea about the reason. |
|
December 1, 2015, 12:06 |
|
#5 | |
New Member
Max Gaedtke
Join Date: Nov 2015
Posts: 1
Rep Power: 0 |
Quote:
Greetings, Max |
||
May 3, 2018, 11:45 |
|
#6 |
Member
Join Date: Oct 2015
Posts: 63
Rep Power: 11 |
Has anyone managed to figure out what the problem is? Even I'm stuck with the same problem.
Best, Scram_1 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
parallel processing time+reconstruct time<serial processing?! | immortality | OpenFOAM | 8 | August 13, 2013 10:15 |
[OpenFOAM] is parallel processing available in parafoam for post processing? | sachinlb | ParaView | 1 | August 14, 2012 10:52 |
How does one initialise an OFstream in the constructor? | bigphil | OpenFOAM Programming & Development | 2 | August 18, 2011 09:48 |
NO model vs post processing in coal combustion,CFX | sakalido | CFX | 1 | April 15, 2011 15:07 |
Post Processing in FEM | Abhijit Tilak | Main CFD Forum | 0 | April 26, 2004 12:59 |