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-2023 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  boundaryProcAddressing_.free();
50  cellProcAddressing_.free();
51  faceProcAddressing_.free();
52  pointProcAddressing_.free();
53  meshes_.free();
54 
55  forAll(databases_, proci)
56  {
57  meshes_.emplace_set
58  (
59  proci,
60  IOobject
61  (
62  meshName_,
63  databases_[proci].timeName(),
64  databases_[proci]
65  )
66  );
67 
68  // Read the addressing information
69 
70  IOobject ioAddr
71  (
72  "procAddressing",
73  meshes_[proci].facesInstance(),
75  meshes_[proci].thisDb(),
78  );
79 
80  // pointProcAddressing (polyMesh)
81  ioAddr.rename("pointProcAddressing");
82  pointProcAddressing_.emplace_set(proci, ioAddr);
83 
84  // faceProcAddressing (polyMesh)
85  ioAddr.rename("faceProcAddressing");
86  faceProcAddressing_.emplace_set(proci, ioAddr);
87 
88  // cellProcAddressing (polyMesh)
89  ioAddr.rename("cellProcAddressing");
90  cellProcAddressing_.emplace_set(proci, ioAddr);
91 
92  // boundaryProcAddressing (polyMesh)
93  ioAddr.rename("boundaryProcAddressing");
94  boundaryProcAddressing_.emplace_set(proci, ioAddr);
95  }
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
101 Foam::processorMeshes::processorMeshes
102 (
103  PtrList<Time>& databases,
104  const word& meshName
105 )
106 :
107  meshName_(meshName),
108  databases_(databases),
109  meshes_(databases.size()),
110  pointProcAddressing_(databases.size()),
111  faceProcAddressing_(databases.size()),
112  cellProcAddressing_(databases.size()),
113  boundaryProcAddressing_(databases.size())
114 {
115  read();
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
124 
125  forAll(databases_, proci)
126  {
127  // Check if any new meshes need to be read.
128  polyMesh::readUpdateState procStat = meshes_[proci].readUpdate();
129 
130  /*
131  if (procStat != polyMesh::UNCHANGED)
132  {
133  Info<< "Processor " << proci
134  << " at time " << databases_[proci].timeName()
135  << " detected mesh change " << procStat
136  << endl;
137  }
138  */
139 
140  // Combine into overall mesh change status
141  if (stat == polyMesh::UNCHANGED)
142  {
143  stat = procStat;
144  }
145  else if (stat != procStat)
146  {
148  << "Processor " << proci
149  << " has a different polyMesh at time "
150  << databases_[proci].timeName()
151  << " compared to any previous processors." << nl
152  << "Please check time " << databases_[proci].timeName()
153  << " directories on all processors for consistent"
154  << " mesh files."
155  << exit(FatalError);
156  }
157  }
158 
159  if
160  (
161  stat == polyMesh::TOPO_CHANGE
162  || stat == polyMesh::TOPO_PATCH_CHANGE
163  )
164  {
165  // Reread all meshes and addressing
166  read();
167  }
168  return stat;
169 }
170 
171 
173 {
174  // Read the field for all the processors
175  PtrList<pointIOField> procsPoints(meshes_.size());
176 
177  forAll(meshes_, proci)
178  {
179  procsPoints.set
180  (
181  proci,
182  new pointIOField
183  (
184  IOobject
185  (
186  "points",
187  meshes_[proci].time().timeName(),
189  meshes_[proci].thisDb(),
193  )
194  )
195  );
196  }
197 
198  // Create the new points
199  vectorField newPoints(mesh.nPoints());
200 
201  forAll(meshes_, proci)
202  {
203  const vectorField& procPoints = procsPoints[proci];
204 
205  const labelList& pointProcAddr = pointProcAddressing_[proci];
206 
207  if (pointProcAddr.size() != procPoints.size())
208  {
210  << "problem :"
211  << " pointProcAddr:" << pointProcAddr.size()
212  << " procPoints:" << procPoints.size()
213  << abort(FatalError);
214  }
215 
216  UIndirectList<point>(newPoints, pointProcAddr) = procPoints;
217  // or: newPoints.rmap(procPoints, pointProcAddr)
218  }
219 
220  mesh.movePoints(newPoints);
221  mesh.write();
222 }
223 
224 
225 void Foam::processorMeshes::removeFiles(const polyMesh& mesh)
226 {
227  IOobject io
228  (
229  "procAddressing",
232  mesh.thisDb()
233  );
234 
235  // procAddressing
236  fileHandler().rm(fileHandler().filePath(io.objectPath()));
237 
238  // pointProcAddressing
239  io.rename("pointProcAddressing");
240  fileHandler().rm(fileHandler().filePath(io.objectPath()));
241 
242  // faceProcAddressing
243  io.rename("faceProcAddressing");
244  fileHandler().rm(fileHandler().filePath(io.objectPath()));
245 
246  // cellProcAddressing
247  io.rename("cellProcAddressing");
248  fileHandler().rm(fileHandler().filePath(io.objectPath()));
249 
250  // boundaryProcAddressing
251  io.rename("boundaryProcAddressing");
252  fileHandler().rm(fileHandler().filePath(io.objectPath()));
253 }
254 
255 
256 // ************************************************************************* //
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:859
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:598
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:677
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:410
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:918
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:421
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
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:1102
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:90
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Do not request registration (bool: false)
Namespace for OpenFOAM.