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 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 "primitiveMesh.H"
32 #include "topoSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(processorMeshes, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::processorMeshes::read()
45 {
46  // Make sure to clear (and hence unregister) any previously loaded meshes
47  // and fields
48  forAll(databases_, proci)
49  {
50  boundaryProcAddressing_.set(proci, nullptr);
51  cellProcAddressing_.set(proci, nullptr);
52  faceProcAddressing_.set(proci, nullptr);
53  pointProcAddressing_.set(proci, nullptr);
54  meshes_.set(proci, nullptr);
55  }
56 
57  forAll(databases_, proci)
58  {
59  meshes_.set
60  (
61  proci,
62  new fvMesh
63  (
64  IOobject
65  (
66  meshName_,
67  databases_[proci].timeName(),
68  databases_[proci]
69  )
70  )
71  );
72 
73  pointProcAddressing_.set
74  (
75  proci,
76  new labelIOList
77  (
78  IOobject
79  (
80  "pointProcAddressing",
81  meshes_[proci].facesInstance(),
82  meshes_[proci].meshSubDir,
83  meshes_[proci],
86  )
87  )
88  );
89 
90  faceProcAddressing_.set
91  (
92  proci,
93  new labelIOList
94  (
95  IOobject
96  (
97  "faceProcAddressing",
98  meshes_[proci].facesInstance(),
99  meshes_[proci].meshSubDir,
100  meshes_[proci],
103  )
104  )
105  );
106 
107  cellProcAddressing_.set
108  (
109  proci,
110  new labelIOList
111  (
112  IOobject
113  (
114  "cellProcAddressing",
115  meshes_[proci].facesInstance(),
116  meshes_[proci].meshSubDir,
117  meshes_[proci],
120  )
121  )
122  );
123 
124  boundaryProcAddressing_.set
125  (
126  proci,
127  new labelIOList
128  (
129  IOobject
130  (
131  "boundaryProcAddressing",
132  meshes_[proci].facesInstance(),
133  meshes_[proci].meshSubDir,
134  meshes_[proci],
137  )
138  )
139  );
140  }
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
146 Foam::processorMeshes::processorMeshes
147 (
148  PtrList<Time>& databases,
149  const word& meshName
150 )
151 :
152  meshName_(meshName),
153  databases_(databases),
154  meshes_(databases.size()),
155  pointProcAddressing_(databases.size()),
156  faceProcAddressing_(databases.size()),
157  cellProcAddressing_(databases.size()),
158  boundaryProcAddressing_(databases.size())
159 {
160  read();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
167 {
169 
170  forAll(databases_, proci)
171  {
172  // Check if any new meshes need to be read.
173  fvMesh::readUpdateState procStat = meshes_[proci].readUpdate();
174 
175  /*
176  if (procStat != fvMesh::UNCHANGED)
177  {
178  Info<< "Processor " << proci
179  << " at time " << databases_[proci].timeName()
180  << " detected mesh change " << procStat
181  << endl;
182  }
183  */
184 
185  // Combine into overall mesh change status
186  if (stat == fvMesh::UNCHANGED)
187  {
188  stat = procStat;
189  }
190  else if (stat != procStat)
191  {
193  << "Processor " << proci
194  << " has a different polyMesh at time "
195  << databases_[proci].timeName()
196  << " compared to any previous processors." << nl
197  << "Please check time " << databases_[proci].timeName()
198  << " directories on all processors for consistent"
199  << " mesh files."
200  << exit(FatalError);
201  }
202  }
203 
204  if
205  (
206  stat == fvMesh::TOPO_CHANGE
207  || stat == fvMesh::TOPO_PATCH_CHANGE
208  )
209  {
210  // Reread all meshes and addressing
211  read();
212  }
213  return stat;
214 }
215 
216 
218 {
219  // Read the field for all the processors
220  PtrList<pointIOField> procsPoints(meshes_.size());
221 
222  forAll(meshes_, proci)
223  {
224  procsPoints.set
225  (
226  proci,
227  new pointIOField
228  (
229  IOobject
230  (
231  "points",
232  meshes_[proci].time().timeName(),
234  meshes_[proci],
237  false
238  )
239  )
240  );
241  }
242 
243  // Create the new points
244  vectorField newPoints(mesh.nPoints());
245 
246  forAll(meshes_, proci)
247  {
248  const vectorField& procPoints = procsPoints[proci];
249 
250  // Set the cell values in the reconstructed field
251 
252  const labelList& pointProcAddressingI = pointProcAddressing_[proci];
253 
254  if (pointProcAddressingI.size() != procPoints.size())
255  {
257  << "problem :"
258  << " pointProcAddressingI:" << pointProcAddressingI.size()
259  << " procPoints:" << procPoints.size()
260  << abort(FatalError);
261  }
262 
263  forAll(pointProcAddressingI, pointi)
264  {
265  newPoints[pointProcAddressingI[pointi]] = procPoints[pointi];
266  }
267  }
268 
269  mesh.movePoints(newPoints);
270  mesh.write();
271 }
272 
273 
275 {
276  fileName pointPath
277  (
278  IOobject
279  (
280  "pointProcAddressing",
283  mesh
284  ).objectPath()
285  );
286  if (topoSet::debug) DebugVar(pointPath);
287  rm(pointPath);
288 
289  rm
290  (
291  IOobject
292  (
293  "faceProcAddressing",
296  mesh
297  ).objectPath()
298  );
299  rm
300  (
301  IOobject
302  (
303  "cellProcAddressing",
306  mesh
307  ).objectPath()
308  );
309  rm
310  (
311  IOobject
312  (
313  "boundaryProcAddressing",
316  mesh
317  ).objectPath()
318  );
319  rm
320  (
321  IOobject
322  (
323  "procAddressing",
326  mesh
327  ).objectPath()
328  );
329 }
330 
331 
332 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1041
topoSet.H
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:852
Foam::rm
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: MSwindows.C:1004
Foam::fvMesh::movePoints
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:865
primitiveMesh.H
Foam::labelIOList
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:44
processorMeshes.H
Foam::processorMeshes::reconstructPoints
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
Definition: processorMeshes.C:217
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::polyMesh::TOPO_PATCH_CHANGE
Definition: polyMesh.H:95
Foam::Field< vector >
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:92
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:94
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::processorMeshes::readUpdate
fvMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
Definition: processorMeshes.C:166
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::processorMeshes::removeFiles
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
Definition: processorMeshes.C:274
DebugVar
#define DebugVar(var)
Report a variable name and value.
Definition: messageStream.H:404
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:185