processorMeshes.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "processorMeshes.H"
30#include "Time.H"
31#include "IndirectList.H"
32#include "primitiveMesh.H"
33#include "OSspecific.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
40}
41
42
43// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44
45void Foam::processorMeshes::read()
46{
47 // Make sure to clear (and hence unregister) any previously loaded meshes
48 // and fields
49 forAll(databases_, proci)
50 {
51 boundaryProcAddressing_.set(proci, nullptr);
52 cellProcAddressing_.set(proci, nullptr);
53 faceProcAddressing_.set(proci, nullptr);
54 pointProcAddressing_.set(proci, nullptr);
55 meshes_.set(proci, nullptr);
56 }
57
58 forAll(databases_, proci)
59 {
60 meshes_.set
61 (
62 proci,
63 new fvMesh
64 (
65 IOobject
66 (
67 meshName_,
68 databases_[proci].timeName(),
69 databases_[proci]
70 )
71 )
72 );
73
74 // Read the addressing information
75
76 IOobject ioAddr
77 (
78 "procAddressing",
79 meshes_[proci].facesInstance(),
81 meshes_[proci].thisDb(),
84 );
85
86 // pointProcAddressing (polyMesh)
87 ioAddr.rename("pointProcAddressing");
88 pointProcAddressing_.set(proci, new labelIOList(ioAddr));
89
90 // faceProcAddressing (polyMesh)
91 ioAddr.rename("faceProcAddressing");
92 faceProcAddressing_.set(proci, new labelIOList(ioAddr));
93
94 // cellProcAddressing (polyMesh)
95 ioAddr.rename("cellProcAddressing");
96 cellProcAddressing_.set(proci, new labelIOList(ioAddr));
97
98 // boundaryProcAddressing (polyMesh)
99 ioAddr.rename("boundaryProcAddressing");
100 boundaryProcAddressing_.set(proci, new labelIOList(ioAddr));
101 }
102}
103
104
105// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106
108(
109 PtrList<Time>& databases,
110 const word& meshName
111)
112:
113 meshName_(meshName),
114 databases_(databases),
115 meshes_(databases.size()),
116 pointProcAddressing_(databases.size()),
117 faceProcAddressing_(databases.size()),
118 cellProcAddressing_(databases.size()),
119 boundaryProcAddressing_(databases.size())
120{
121 read();
122}
123
124
125// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126
128{
130
131 forAll(databases_, proci)
132 {
133 // Check if any new meshes need to be read.
134 polyMesh::readUpdateState procStat = meshes_[proci].readUpdate();
135
136 /*
137 if (procStat != polyMesh::UNCHANGED)
138 {
139 Info<< "Processor " << proci
140 << " at time " << databases_[proci].timeName()
141 << " detected mesh change " << procStat
142 << endl;
143 }
144 */
145
146 // Combine into overall mesh change status
147 if (stat == polyMesh::UNCHANGED)
148 {
149 stat = procStat;
150 }
151 else if (stat != procStat)
152 {
154 << "Processor " << proci
155 << " has a different polyMesh at time "
156 << databases_[proci].timeName()
157 << " compared to any previous processors." << nl
158 << "Please check time " << databases_[proci].timeName()
159 << " directories on all processors for consistent"
160 << " mesh files."
161 << exit(FatalError);
162 }
163 }
164
165 if
166 (
169 )
170 {
171 // Reread all meshes and addressing
172 read();
173 }
174 return stat;
175}
176
177
179{
180 // Read the field for all the processors
181 PtrList<pointIOField> procsPoints(meshes_.size());
182
183 forAll(meshes_, proci)
184 {
185 procsPoints.set
186 (
187 proci,
188 new pointIOField
189 (
191 (
192 "points",
193 meshes_[proci].time().timeName(),
195 meshes_[proci].thisDb(),
198 false
199 )
200 )
201 );
202 }
203
204 // Create the new points
205 vectorField newPoints(mesh.nPoints());
206
207 forAll(meshes_, proci)
208 {
209 const vectorField& procPoints = procsPoints[proci];
210
211 const labelList& pointProcAddr = pointProcAddressing_[proci];
212
213 if (pointProcAddr.size() != procPoints.size())
214 {
216 << "problem :"
217 << " pointProcAddr:" << pointProcAddr.size()
218 << " procPoints:" << procPoints.size()
219 << abort(FatalError);
220 }
221
222 UIndirectList<point>(newPoints, pointProcAddr) = procPoints;
223 // or: newPoints.rmap(procPoints, pointProcAddr)
224 }
225
226 mesh.movePoints(newPoints);
227 mesh.write();
228}
229
230
232{
233 IOobject ioAddr
234 (
235 "procAddressing",
238 mesh.thisDb(),
241 false // not registered
242 );
243
244 // procAddressing
245 rm(ioAddr.objectPath());
246
247 // pointProcAddressing
248 ioAddr.rename("pointProcAddressing");
249 rm(ioAddr.objectPath());
250
251 // faceProcAddressing
252 ioAddr.rename("faceProcAddressing");
253 rm(ioAddr.objectPath());
254
255 // cellProcAddressing
256 ioAddr.rename("cellProcAddressing");
257 rm(ioAddr.objectPath());
258
259 // boundaryProcAddressing
260 ioAddr.rename("boundaryProcAddressing");
261 rm(ioAddr.objectPath());
262}
263
264
265// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:497
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:214
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
const T * set(const label i) const
Definition: PtrList.H:138
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
void removeFiles() const
Remove all files from mesh instance()
Definition: faMesh.C:718
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:302
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1079
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:895
void reconstructPoints()
Helper: reconstruct and write mesh points.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:866
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:324
label nPoints() const noexcept
Number of mesh points.
Container for processor mesh addressing.
polyMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
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
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
word timeName
Definition: getTimeIndex.H:3
Namespace for OpenFOAM.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: MSwindows.C:1012
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
errorManip< error > abort(error &err)
Definition: errorManip.H:144
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:44
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333