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 | Copyright (C) 2011-2015 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  meshes_.set(procI, NULL);
39  pointProcAddressing_.set(procI, NULL);
40  faceProcAddressing_.set(procI, NULL);
41  cellProcAddressing_.set(procI, NULL);
42  boundaryProcAddressing_.set(procI, NULL);
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 
134 Foam::processorMeshes::processorMeshes
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  {
180  FatalErrorIn("processorMeshes::readUpdate()")
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 addresssing
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  {
244  FatalErrorIn("processorMeshes")
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.write();
259 }
260 
261 
262 // ************************************************************************* //
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
virtual bool write() const
Write mesh using IO settings from time.
Definition: fvMesh.C:875
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:728
A class for handling words, derived from string.
Definition: word.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
dynamicFvMesh & mesh
fvMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
static const char nl
Definition: Ostream.H:260
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42
label nPoints() const
word timeName
Definition: getTimeIndex.H:3