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-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 #include "pointMesh.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(processorMeshes, 0);
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::processorMeshes::read()
47 {
48  // Make sure to clear (and hence unregister) any previously loaded meshes
49  // and fields
50  pBoundaryProcAddressing_.free();
51  pMeshes_.free();
52 
53  boundaryProcAddressing_.free();
54  cellProcAddressing_.free();
55  faceProcAddressing_.free();
56  pointProcAddressing_.free();
57  meshes_.free();
58 
59  forAll(databases_, proci)
60  {
61  meshes_.emplace_set
62  (
63  proci,
64  IOobject
65  (
66  meshName_,
67  databases_[proci].timeName(),
68  databases_[proci]
69  )
70  );
71 
72  // Read the addressing information
73 
74  IOobject ioAddr
75  (
76  "procAddressing",
77  meshes_[proci].facesInstance(),
79  meshes_[proci].thisDb(),
82  );
83 
84  // pointProcAddressing (polyMesh)
85  ioAddr.rename("pointProcAddressing");
86  pointProcAddressing_.emplace_set(proci, ioAddr);
87 
88  // faceProcAddressing (polyMesh)
89  ioAddr.rename("faceProcAddressing");
90  faceProcAddressing_.emplace_set(proci, ioAddr);
91 
92  // cellProcAddressing (polyMesh)
93  ioAddr.rename("cellProcAddressing");
94  cellProcAddressing_.emplace_set(proci, ioAddr);
95 
96  // boundaryProcAddressing (polyMesh)
97  ioAddr.rename("boundaryProcAddressing");
98  boundaryProcAddressing_.emplace_set(proci, ioAddr);
99 
100 
101  // pointMesh
102  // ~~~~~~~~~
103 
104  pMeshes_.set
105  (
106  proci,
107  new pointMesh
108  (
109  meshes_[proci],
111  )
112  );
113 
114  pBoundaryProcAddressing_.set
115  (
116  proci,
118  (
119  IOobject
120  (
121  "boundaryProcAddressing",
122  meshes_[proci].facesInstance(),
124  pMeshes_[proci].thisDb(),
128  ),
129  boundaryProcAddressing_[proci]
130  )
131  );
132  }
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
137 
138 Foam::processorMeshes::processorMeshes
139 (
140  PtrList<Time>& databases,
141  const word& meshName
142 )
143 :
144  meshName_(meshName),
145  databases_(databases),
146  meshes_(databases.size()),
147  pointProcAddressing_(databases.size()),
148  faceProcAddressing_(databases.size()),
149  cellProcAddressing_(databases.size()),
150  boundaryProcAddressing_(databases.size()),
151  pMeshes_(databases.size()),
152  pBoundaryProcAddressing_(databases.size())
153 {
154  read();
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
163 
164  forAll(databases_, proci)
165  {
166  // Check if any new meshes need to be read.
167  polyMesh::readUpdateState procStat = meshes_[proci].readUpdate();
168 
169  /*
170  if (procStat != polyMesh::UNCHANGED)
171  {
172  Info<< "Processor " << proci
173  << " at time " << databases_[proci].timeName()
174  << " detected mesh change " << procStat
175  << endl;
176  }
177  */
178 
179  // Combine into overall mesh change status
180  if (stat == polyMesh::UNCHANGED)
181  {
182  stat = procStat;
183  }
184  else if (stat != procStat)
185  {
187  << "Processor " << proci
188  << " has a different polyMesh at time "
189  << databases_[proci].timeName()
190  << " compared to any previous processors." << nl
191  << "Please check time " << databases_[proci].timeName()
192  << " directories on all processors for consistent"
193  << " mesh files."
194  << exit(FatalError);
195  }
196  }
197 
198  if
199  (
200  stat == polyMesh::TOPO_CHANGE
201  || stat == polyMesh::TOPO_PATCH_CHANGE
202  )
203  {
204  // Reread all meshes and addressing
205  read();
206  }
207  return stat;
208 }
209 
210 
212 {
213  // Read the field for all the processors
214  PtrList<pointIOField> procsPoints(meshes_.size());
215 
216  forAll(meshes_, proci)
217  {
218  procsPoints.set
219  (
220  proci,
221  new pointIOField
222  (
223  IOobject
224  (
225  "points",
226  meshes_[proci].time().timeName(),
228  meshes_[proci].thisDb(),
232  )
233  )
234  );
235  }
236 
237  // Create the new points
238  vectorField newPoints(mesh.nPoints());
239 
240  forAll(meshes_, proci)
241  {
242  const vectorField& procPoints = procsPoints[proci];
243 
244  const labelList& pointProcAddr = pointProcAddressing_[proci];
245 
246  if (pointProcAddr.size() != procPoints.size())
247  {
249  << "problem :"
250  << " pointProcAddr:" << pointProcAddr.size()
251  << " procPoints:" << procPoints.size()
252  << abort(FatalError);
253  }
254 
255  UIndirectList<point>(newPoints, pointProcAddr) = procPoints;
256  // or: newPoints.rmap(procPoints, pointProcAddr)
257  }
258 
259  mesh.movePoints(newPoints);
260  mesh.write();
261 }
262 
263 
264 void Foam::processorMeshes::removeFiles(const polyMesh& mesh)
265 {
266  IOobject io
267  (
268  "procAddressing",
271  mesh.thisDb()
272  );
273 
274  // procAddressing
275  fileHandler().rm(fileHandler().filePath(io.objectPath()));
276 
277  // pointProcAddressing
278  io.rename("pointProcAddressing");
279  fileHandler().rm(fileHandler().filePath(io.objectPath()));
280 
281  // faceProcAddressing
282  io.rename("faceProcAddressing");
283  fileHandler().rm(fileHandler().filePath(io.objectPath()));
284 
285  // cellProcAddressing
286  io.rename("cellProcAddressing");
287  fileHandler().rm(fileHandler().filePath(io.objectPath()));
288 
289  // boundaryProcAddressing
290  io.rename("boundaryProcAddressing");
291  fileHandler().rm(fileHandler().filePath(io.objectPath()));
292 
293 
294 
295  // pointMesh
296  // ~~~~~~~~~
297 
298  IOobject pointIO
299  (
300  "boundary",
303  mesh.thisDb()
304  );
305 
306  // pointMesh/boundary
307  fileHandler().rm(fileHandler().filePath(pointIO.objectPath()));
308 
309  // boundaryProcAddressing
310  io.rename("boundaryProcAddressing");
311  fileHandler().rm(fileHandler().filePath(pointIO.objectPath()));
312 }
313 
314 
315 // ************************************************************************* //
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:844
label nPoints() const noexcept
Number of mesh points.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:685
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:411
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:884
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
Ignore writing from objectRegistry::writeObject()
polyMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:284
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
Reading is optional [identical to LAZY_READ].
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1068
defineTypeNameAndDebug(combustionModel, 0)
static word meshSubDir
Return the mesh sub-directory name (usually "pointMesh")
Definition: pointMesh.H:107
Field< vector > vectorField
Specialisation of Field<T> for vector.
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
List< label > labelList
A List of labels.
Definition: List.H:61
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
Do not request registration (bool: false)
Namespace for OpenFOAM.