syncObjects.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "syncObjects.H"
29 #include "Time.H"
30 #include "polyMesh.H"
32 #include "objectRegistry.H"
33 #include "mappedPatchBase.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace functionObjects
40 {
41  defineTypeNameAndDebug(syncObjects, 0);
42 
44  (
45  functionObject,
46  syncObjects,
47  dictionary
48  );
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
58 Foam::functionObjects::syncObjects::syncObjects
59 (
60  const word& name,
61  const Time& runTime,
62  const dictionary& dict
63 )
64 :
66  obr_
67  (
68  //runTime.lookupObject<objectRegistry>
69  //(
70  // dict.lookupOrDefault("region", polyMesh::defaultRegion)
71  //)
72  runTime
73  )
74 {
75  read(dict);
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (debug)
84  {
85  Pout<< type() << " : sync()"
86  << " root:" << root_ << endl;
87  }
88 
89  const label oldWarnComm = UPstream::warnComm;
91 
92  if (!Pstream::parRun())
93  {
94  return;
95  }
96 
97 
98  // Send my data to all other processors
99  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 
101  // Note provision of explicit all-world communicator
102  PstreamBuffers pBufs
103  (
106  0
107  );
108 
109 
110  const label nProcs = Pstream::nProcs(pBufs.comm());
111  for (label proci = 0; proci < nProcs; proci++)
112  {
113  // Get database to send
115  (
116  obr_,
117  mappedPatchBase::sendPath(root_, proci)
118  );
119 
120  // Pack into dictionary
121  dictionary sendDataDict;
122  mappedPatchBase::writeDict(sendObr, sendDataDict);
123 
124  //Pout<< "** to processor " << proci
125  // << " sendObr:" << sendObr.objectPath()
126  // << " sending dictionary:" << sendDataDict << endl;
127  UOPstream os(proci, pBufs);
128  os << sendDataDict;
129  }
130 
131  // Start sending and receiving and block
132  pBufs.finishedSends();
133 
134  for (label proci = 0; proci < nProcs; proci++)
135  {
136  // Get database to receive data into
137  const objectRegistry& receiveObr = mappedPatchBase::subRegistry
138  (
139  obr_,
140  mappedPatchBase::receivePath(root_, proci)
141  );
142  //Pout<< "** from processor " << proci
143  // << " receiveObr:" << receiveObr.objectPath()
144  // << " receiving dictionary" << endl;
145  UIPstream is(proci, pBufs);
146  const dictionary fromProcDict(is);
147  //Pout<< "** from processor " << proci
148  // << " received dictionary:" << fromProcDict << endl;
149 
151  (
152  fromProcDict,
153  const_cast<objectRegistry&>(receiveObr)
154  );
155  }
156 
157  //if (debug)
158  //{
159  // dictionary allDict;
160  // // Add send subdictionary
161  // dictionary& sendDict = allDict.subDictOrAdd("send");
162  // mappedPatchBase::writeDict
163  // (
164  // mappedPatchBase::subRegistry(obr_, "send"),
165  // sendDict
166  // );
167  // // Add receive subdictionary
168  // dictionary& receiveDict = allDict.subDictOrAdd("receive");
169  // mappedPatchBase::writeDict
170  // (
171  // mappedPatchBase::subRegistry(obr_, "receive"),
172  // receiveDict
173  // );
174  // Pout<< type() << " : after synchronisation:" << allDict << endl;
175  //}
176 
177  UPstream::warnComm = oldWarnComm;
178 }
179 
180 
182 {
183  if (debug)
184  {
185  Pout<< type() << " : read(const dictionary&)" << endl;
186  }
187 
189  root_ = dict.getOrDefault<fileName>("root", fileName::null);
190 
191  if (debug)
192  {
193  Pout<< type() << " : root:" << root_ << endl;
194  }
195 
196  // Make sure that at startup we're doing a sync (execute below only gets
197  // called at end of timeloop)
198  sync();
199 
200  return true;
201 }
202 
203 
205 {
206  if (debug)
207  {
208  Pout<< type() << " : execute()" << endl;
209  }
210 
211  sync();
212 
213  return true;
214 }
215 
216 
218 {
219  if (debug)
220  {
221  Pout<< type() << " : write()" << endl;
222  }
223 
224  return true;
225 }
226 
227 
228 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::functionObjects::syncObjects::read
virtual bool read(const dictionary &)
Read the syncObjects data.
Definition: syncObjects.C:181
Foam::UPstream::warnComm
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:298
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::UPstream::commsTypes::nonBlocking
Foam::mappedPatchBase::sendPath
static fileName sendPath(const fileName &root, const label proci)
Helper: return path to store data to be sent to processor i.
Definition: mappedPatchBase.C:1784
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::mappedPatchBase::readDict
static void readDict(const dictionary &d, objectRegistry &obr)
(recursively) construct and register IOFields from dictionary
Definition: mappedPatchBase.C:1857
Foam::mappedPatchBase::subRegistry
static const objectRegistry & subRegistry(const objectRegistry &obr, const wordList &names, const label index)
Definition: mappedPatchBase.C:1183
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::UOPstream
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:57
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:87
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
objectRegistry.H
Foam::mappedPatchBase::writeDict
static void writeDict(const objectRegistry &obr, dictionary &dict)
Convert objectRegistry contents into dictionary.
Definition: mappedPatchBase.C:1818
Foam::functionObjects::syncObjects::sync
void sync()
Do all: synchronise all IOFields and objectRegistry.
Definition: syncObjects.C:81
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
polyMesh.H
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:321
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
syncObjects.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:137
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:80
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::mappedPatchBase::receivePath
static fileName receivePath(const fileName &root, const label proci)
Definition: mappedPatchBase.C:1801
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Time.H
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:541
Foam::functionObject::debug
static int debug
Flag to execute debug content.
Definition: functionObject.H:346
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:56
Foam::functionObjects::syncObjects::execute
virtual bool execute()
Do nothing.
Definition: syncObjects.C:204
Foam::PstreamBuffers::comm
label comm() const
Definition: PstreamBuffers.H:147
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:446
Foam::functionObjects::syncObjects::write
virtual bool write()
Write the registered objects.
Definition: syncObjects.C:217
mappedPatchBase.H