|
[Sponsors] |
April 3, 2015, 09:42 |
Global variable in parallel code
|
#1 |
Member
|
Greetings, dear foamers!
What is the easiest way to implement global variable in OF code, which is synchronized between the processes on request and which is written to file same as all other vector/scalar fields? I would be grateful for any ideas. |
|
April 3, 2015, 09:52 |
|
#2 |
Senior Member
|
Hi,
Little clarification, what is the type of this variable? In general "all other vector/scalar fields" can be considered as global variables. |
|
April 3, 2015, 09:56 |
|
#3 |
Member
|
Hello and thank you for reply.
I mean that I need not a field, but only 1 floating point value, which is synchronized over all processes. I suppose that it could be uniformDimensionedScalarField, and synchronization can be done by means of OPstream and IPstream, but I don't know how to make reconstructPar "reconstruct" this field. |
|
April 3, 2015, 11:14 |
|
#4 |
Senior Member
|
Hi,
Curiouser and curiouser How the scalar should be synchronized? Maximum of all processors, sum of all processors? Any way there is reduce that can perform binary operation on the scalar from different processors. Concerning output. Take OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C as an example. When I needed to calculate energy and mass balances in the simulations and write them into file, I've used this code in the constructor of the balances calculation class: Code:
if (active_) { fileName balancesSubDir = "balances"/mesh_.time().timeName(); if (Pstream::parRun()) { balancesSubDir = mesh_.time().path()/".."/balancesSubDir; } else { balancesSubDir = mesh_.time().path()/balancesSubDir; } mkDir(balancesSubDir); // Writing file headers if (mass_) { Info<< "Creating mass balances ... " << endl; mPtr_ = new OFstream(balancesSubDir/"mass.dat"); *mPtr_ << "# 1_t(s) 2_Mass(kg) 3_dM(kg) 4_dMest(kg)" << endl; } ... |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
simpleFoam parallel | AndrewMortimer | OpenFOAM Running, Solving & CFD | 12 | August 7, 2015 18:45 |
parallel issue: global face zone/patch ... | matteoL | OpenFOAM Running, Solving & CFD | 2 | June 16, 2010 06:22 |
Problems with MFIX code and Parallel Processing. | Fernando Pio | Main CFD Forum | 4 | August 29, 2006 14:33 |
Could anybody help me see this error and give help | liugx212 | OpenFOAM Running, Solving & CFD | 3 | January 4, 2006 18:07 |
Design Integration with CFD? | John C. Chien | Main CFD Forum | 19 | May 17, 2001 15:56 |