CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Global variable in parallel code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 3, 2015, 09:42
Default Global variable in parallel code
  #1
Member
 
Aleksey Rukhlenko
Join Date: Nov 2009
Location: Moscow
Posts: 55
Rep Power: 16
Aleksey_R is on a distinguished road
Send a message via ICQ to Aleksey_R
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.
Aleksey_R is offline   Reply With Quote

Old   April 3, 2015, 09:52
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Little clarification, what is the type of this variable? In general "all other vector/scalar fields" can be considered as global variables.
alexeym is offline   Reply With Quote

Old   April 3, 2015, 09:56
Default
  #3
Member
 
Aleksey Rukhlenko
Join Date: Nov 2009
Location: Moscow
Posts: 55
Rep Power: 16
Aleksey_R is on a distinguished road
Send a message via ICQ to Aleksey_R
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.
Aleksey_R is offline   Reply With Quote

Old   April 3, 2015, 11:14
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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;
        }
...
Though maybe there is another, more idiomatic, way to do it.
alexeym 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
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


All times are GMT -4. The time now is 19:06.