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 -------------------------------------------------------------------------------
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 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(processorMeshes, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void 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 
107 Foam::processorMeshes::processorMeshes
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  (
167  stat == polyMesh::TOPO_CHANGE
168  || stat == polyMesh::TOPO_PATCH_CHANGE
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  (
190  IOobject
191  (
192  "points",
193  meshes_[proci].time().timeName(),
195  meshes_[proci].thisDb(),
198  false // not registered
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 
231 void Foam::processorMeshes::removeFiles(const polyMesh& mesh)
232 {
233  IOobject io
234  (
235  "procAddressing",
238  mesh.thisDb()
239  );
240 
241  // procAddressing
242  fileHandler().rm(fileHandler().filePath(io.objectPath()));
243 
244  // pointProcAddressing
245  io.rename("pointProcAddressing");
246  fileHandler().rm(fileHandler().filePath(io.objectPath()));
247 
248  // faceProcAddressing
249  io.rename("faceProcAddressing");
250  fileHandler().rm(fileHandler().filePath(io.objectPath()));
251 
252  // cellProcAddressing
253  io.rename("cellProcAddressing");
254  fileHandler().rm(fileHandler().filePath(io.objectPath()));
255 
256  // boundaryProcAddressing
257  io.rename("boundaryProcAddressing");
258  fileHandler().rm(fileHandler().filePath(io.objectPath()));
259 }
260 
261 
262 // ************************************************************************* //
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:853
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:578
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1072
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:626
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:402
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:888
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file 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:239
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:125
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:377
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word timeName
Definition: getTimeIndex.H:3
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
dynamicFvMesh & mesh
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
defineTypeNameAndDebug(combustionModel, 0)
Field< vector > vectorField
Specialisation of Field<T> for vector.
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:89
List< label > labelList
A List of labels.
Definition: List.H:62
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:38
Namespace for OpenFOAM.