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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
37namespace Foam
38{
39namespace functionObjects
40{
43 (
47 );
48}
49}
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
55(
56 const word& name,
57 const Time& runTime,
58 const dictionary& dict
59)
60:
62 obr_(runTime)
63{
64 read(dict);
65}
66
67
68// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69
71{
72 if (debug)
73 {
74 Pout<< type() << " : sync()"
75 << " root:" << root_ << endl;
76 }
77
78 const label oldWarnComm = UPstream::warnComm;
80
81 if (!Pstream::parRun())
82 {
83 return;
84 }
85
86
87 // Send my data to all other processors
88 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90 // Note provision of explicit all-world communicator
91 PstreamBuffers pBufs
92 (
95 0
96 );
97
98
99 for (const int proci : pBufs.allProcs())
100 {
101 // Get database to send
103 (
104 obr_,
105 mappedPatchBase::sendPath(root_, proci)
106 );
107
108 // Pack into dictionary
109 dictionary sendDataDict;
110 mappedPatchBase::writeDict(sendObr, sendDataDict);
111
112 if (debug & 2)
113 {
114 Pout<< "** to processor " << proci
115 << " sendObr:" << sendObr.objectPath()
116 << " sending dictionary:" << sendDataDict << endl;
117 }
118 UOPstream os(proci, pBufs);
119 os << sendDataDict;
120 }
121
122 // Start sending and receiving and block
123 pBufs.finishedSends();
124
125 for (const int proci : pBufs.allProcs())
126 {
127 // Get database to receive data into
129 (
130 obr_,
131 mappedPatchBase::receivePath(root_, proci)
132 );
133 UIPstream is(proci, pBufs);
134 const dictionary fromProcDict(is);
135 if (debug & 2)
136 {
137 Pout<< "** from processor " << proci
138 << " receiveObr:" << receiveObr.objectPath()
139 << " received dictionary:" << fromProcDict << endl;
140 }
141 mappedPatchBase::readDict
142 (
143 fromProcDict,
144 const_cast<objectRegistry&>(receiveObr)
145 );
146 }
147
148 //if (debug)
149 //{
150 // dictionary allDict;
151 // // Add send subdictionary
152 // dictionary& sendDict = allDict.subDictOrAdd("send");
153 // mappedPatchBase::writeDict
154 // (
155 // mappedPatchBase::subRegistry(obr_, "send"),
156 // sendDict
157 // );
158 // // Add receive subdictionary
159 // dictionary& receiveDict = allDict.subDictOrAdd("receive");
160 // mappedPatchBase::writeDict
161 // (
162 // mappedPatchBase::subRegistry(obr_, "receive"),
163 // receiveDict
164 // );
165 // Pout<< type() << " : after synchronisation:" << allDict << endl;
166 //}
167
168 UPstream::warnComm = oldWarnComm;
169}
170
171
173{
174 if (debug)
175 {
176 Pout<< type() << " : read(const dictionary&)" << endl;
177 }
178
180 root_ = dict.getOrDefault<fileName>("root", fileName::null);
181
182 if (debug)
183 {
184 Pout<< type() << " : root:" << root_ << endl;
185 }
186
187 // Make sure that at startup we're doing a sync (execute below only gets
188 // called at end of timeloop)
189 sync();
190
191 return true;
192}
193
194
196{
197 if (debug)
198 {
199 Pout<< type() << " : execute()" << endl;
200 }
201
202 sync();
203
204 return true;
205}
206
207
209{
210 if (debug)
211 {
212 Pout<< type() << " : write()" << endl;
213 }
214
215 return true;
216}
217
218
219// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:214
Buffers for inter-processor communications streams (UOPstream, UIPstream).
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
void finishedSends(const bool wait=true)
Mark sends as done.
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
@ nonBlocking
"nonBlocking"
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Definition: UPstream.H:296
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
static const fileName null
An empty fileName.
Definition: fileName.H:102
Abstract base-class for Time/database function objects.
Foam::dictionary writeDict() const
Write to dictionary.
Copies content of local objectRegistry to all processors.
Definition: syncObjects.H:112
void sync()
Do all: synchronise all IOFields and objectRegistry.
Definition: syncObjects.C:70
virtual bool execute()
Do nothing.
Definition: syncObjects.C:195
virtual bool write()
Write the registered objects.
Definition: syncObjects.C:208
virtual bool read(const dictionary &)
Read the syncObjects data.
Definition: syncObjects.C:172
static const objectRegistry & subRegistry(const objectRegistry &obr, const wordList &names, const label index)
static fileName sendPath(const fileName &root, const label proci)
Helper: return path to store data to be sent to processor i.
static fileName receivePath(const fileName &root, const label proci)
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
dictionary dict