processorMeshes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "processorMeshes.H"
27 #include "Time.H"
28 #include "primitiveMesh.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::processorMeshes::read()
33 {
34  // Make sure to clear (and hence unregister) any previously loaded meshes
35  // and fields
36  forAll(databases_, proci)
37  {
38  boundaryProcAddressing_.set(proci, nullptr);
39  cellProcAddressing_.set(proci, nullptr);
40  faceProcAddressing_.set(proci, nullptr);
41  pointProcAddressing_.set(proci, nullptr);
42  meshes_.set(proci, nullptr);
43  }
44 
45  forAll(databases_, proci)
46  {
47  meshes_.set
48  (
49  proci,
50  new fvMesh
51  (
52  IOobject
53  (
54  meshName_,
55  databases_[proci].timeName(),
56  databases_[proci]
57  )
58  )
59  );
60 
61  pointProcAddressing_.set
62  (
63  proci,
64  new labelIOList
65  (
66  IOobject
67  (
68  "pointProcAddressing",
69  meshes_[proci].facesInstance(),
70  meshes_[proci].meshSubDir,
71  meshes_[proci],
74  )
75  )
76  );
77 
78  faceProcAddressing_.set
79  (
80  proci,
81  new labelIOList
82  (
83  IOobject
84  (
85  "faceProcAddressing",
86  meshes_[proci].facesInstance(),
87  meshes_[proci].meshSubDir,
88  meshes_[proci],
91  )
92  )
93  );
94 
95  cellProcAddressing_.set
96  (
97  proci,
98  new labelIOList
99  (
100  IOobject
101  (
102  "cellProcAddressing",
103  meshes_[proci].facesInstance(),
104  meshes_[proci].meshSubDir,
105  meshes_[proci],
108  )
109  )
110  );
111 
112  boundaryProcAddressing_.set
113  (
114  proci,
115  new labelIOList
116  (
117  IOobject
118  (
119  "boundaryProcAddressing",
120  meshes_[proci].facesInstance(),
121  meshes_[proci].meshSubDir,
122  meshes_[proci],
125  )
126  )
127  );
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
135 (
136  PtrList<Time>& databases,
137  const word& meshName
138 )
139 :
140  meshName_(meshName),
141  databases_(databases),
142  meshes_(databases.size()),
143  pointProcAddressing_(databases.size()),
144  faceProcAddressing_(databases.size()),
145  cellProcAddressing_(databases.size()),
146  boundaryProcAddressing_(databases.size())
147 {
148  read();
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 {
157 
158  forAll(databases_, proci)
159  {
160  // Check if any new meshes need to be read.
161  fvMesh::readUpdateState procStat = meshes_[proci].readUpdate();
162 
163  /*
164  if (procStat != fvMesh::UNCHANGED)
165  {
166  Info<< "Processor " << proci
167  << " at time " << databases_[proci].timeName()
168  << " detected mesh change " << procStat
169  << endl;
170  }
171  */
172 
173  // Combine into overall mesh change status
174  if (stat == fvMesh::UNCHANGED)
175  {
176  stat = procStat;
177  }
178  else if (stat != procStat)
179  {
181  << "Processor " << proci
182  << " has a different polyMesh at time "
183  << databases_[proci].timeName()
184  << " compared to any previous processors." << nl
185  << "Please check time " << databases_[proci].timeName()
186  << " directories on all processors for consistent"
187  << " mesh files."
188  << exit(FatalError);
189  }
190  }
191 
192  if
193  (
194  stat == fvMesh::TOPO_CHANGE
195  || stat == fvMesh::TOPO_PATCH_CHANGE
196  )
197  {
198  // Reread all meshes and addressing
199  read();
200  }
201  return stat;
202 }
203 
204 
206 {
207  // Read the field for all the processors
208  PtrList<pointIOField> procsPoints(meshes_.size());
209 
210  forAll(meshes_, proci)
211  {
212  procsPoints.set
213  (
214  proci,
215  new pointIOField
216  (
217  IOobject
218  (
219  "points",
220  meshes_[proci].time().timeName(),
222  meshes_[proci],
225  false
226  )
227  )
228  );
229  }
230 
231  // Create the new points
232  vectorField newPoints(mesh.nPoints());
233 
234  forAll(meshes_, proci)
235  {
236  const vectorField& procPoints = procsPoints[proci];
237 
238  // Set the cell values in the reconstructed field
239 
240  const labelList& pointProcAddressingI = pointProcAddressing_[proci];
241 
242  if (pointProcAddressingI.size() != procPoints.size())
243  {
245  << "problem :"
246  << " pointProcAddressingI:" << pointProcAddressingI.size()
247  << " procPoints:" << procPoints.size()
248  << abort(FatalError);
249  }
250 
251  forAll(pointProcAddressingI, pointi)
252  {
253  newPoints[pointProcAddressingI[pointi]] = procPoints[pointi];
254  }
255  }
256 
257  mesh.movePoints(newPoints);
258  mesh.moving(false);
259  mesh.write();
260 }
261 
262 
263 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool moving() const
Is mesh moving.
Definition: polyMesh.H:512
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:312
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1093
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
word timeName
Definition: getTimeIndex.H:3
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
static const char nl
Definition: Ostream.H:260
processorMeshes(PtrList< Time > &databases, const word &meshName)
Construct from components.
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:716
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
label nPoints() const
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42