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 
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 
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 
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 
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 
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 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  {
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 // ************************************************************************* //
Foam::processorMeshes::cellProcAddressing_
PtrList< labelIOList > cellProcAddressing_
List of processor cell addressing lists.
Definition: processorMeshes.H:71
Foam::processorMeshes::pointProcAddressing_
PtrList< labelIOList > pointProcAddressing_
List of processor point addressing lists.
Definition: processorMeshes.H:65
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::processorMeshes::meshName_
const word meshName_
Definition: processorMeshes.H:56
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOField< vector >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::processorMeshes::databases_
PtrList< Time > & databases_
Processor databases.
Definition: processorMeshes.H:59
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::fvMesh::movePoints
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition: fvMesh.C:726
processorMeshes.H
Foam::processorMeshes::reconstructPoints
void reconstructPoints(fvMesh &)
Reconstruct point position after motion in parallel.
Definition: processorMeshes.C:205
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::fvMesh::write
virtual bool write() const
Write mesh using IO settings from time.
Definition: fvMesh.C:873
Foam::polyMesh::TOPO_PATCH_CHANGE
@ TOPO_PATCH_CHANGE
Definition: polyMesh.H:93
Foam::processorMeshes::boundaryProcAddressing_
PtrList< labelIOList > boundaryProcAddressing_
List of processor boundary addressing lists.
Definition: processorMeshes.H:74
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::processorMeshes::meshes_
PtrList< fvMesh > meshes_
List of processor meshes.
Definition: processorMeshes.H:62
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
Foam::PtrList
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
Foam::polyMesh::TOPO_CHANGE
@ TOPO_CHANGE
Definition: polyMesh.H:92
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::processorMeshes::readUpdate
fvMesh::readUpdateState readUpdate()
Update the meshes based on the mesh files saved in time directories.
Definition: processorMeshes.C:154
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::processorMeshes::faceProcAddressing_
PtrList< labelIOList > faceProcAddressing_
List of processor face addressing lists.
Definition: processorMeshes.H:68
Foam::processorMeshes::processorMeshes
processorMeshes(const processorMeshes &)
Disallow default bitwise copy construct.
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::processorMeshes::read
void read()
Read all meshes.
Definition: processorMeshes.C:32
Foam::IOList< label >
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
timeName
word timeName
Definition: getTimeIndex.H:3
meshName
static char meshName[]
Definition: globalFoam.H:7
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.