hexRef8Data.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) 2015-2026 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 "IOobject.H"
27 #include "UList.H"
28 
29 #include "hexRef8Data.H"
30 #include "polyTopoChangeMap.H"
31 #include "polyDistributionMap.H"
32 #include "polyMesh.H"
33 #include "syncTools.H"
34 #include "refinementHistory.H"
35 #include "fvMesh.H"
36 #include "polyTopoChange.H"
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 {
42  {
44  rio.rename("cellLevel");
45  bool haveFile = returnReduce
46  (
47  rio.headerOk(),
48  orOp<bool>()
49  );
50  if (haveFile)
51  {
52  if (polyTopoChange::debug)
53  {
54  Info<< "Reading hexRef8 data : " << rio.name() << endl;
55  }
56 
57  cellLevelPtr_.reset(new labelIOList(rio));
58  }
59  }
60  {
62  rio.rename("pointLevel");
63  bool haveFile = returnReduce
64  (
65  rio.headerOk(),
66  orOp<bool>()
67  );
68  if (haveFile)
69  {
70  if (polyTopoChange::debug)
71  {
72  Info<< "Reading hexRef8 data : " << rio.name() << endl;
73  }
74 
75  pointLevelPtr_.reset(new labelIOList(rio));
76  }
77  }
78  {
80  rio.rename("level0Edge");
81  bool haveFile = returnReduce
82  (
83  rio.headerOk(),
84  orOp<bool>()
85  );
86  if (haveFile)
87  {
88  if (polyTopoChange::debug)
89  {
90  Info<< "Reading hexRef8 data : " << rio.name() << endl;
91  }
92 
93  level0EdgePtr_.reset
94  (
95  new localUniformDimensionedScalarField(rio, dimLength)
96  );
97  }
98  }
99  {
101  rio.rename("refinementHistory");
102  bool haveFile = returnReduce
103  (
104  rio.headerOk(),
105  orOp<bool>()
106  );
107  if (haveFile)
108  {
109  if (polyTopoChange::debug)
110  {
111  Info<< "Reading hexRef8 data : " << rio.name() << endl;
112  }
113 
114  refHistoryPtr_.reset(new refinementHistory(rio));
115  }
116  }
117 }
118 
119 
121 (
122  const IOobject& io,
123  const hexRef8Data& data,
124  const labelList& cellMap,
125  const labelList& pointMap
126 )
127 {
128  if (data.cellLevelPtr_.valid())
129  {
130  IOobject rio(io);
131  rio.rename(data.cellLevelPtr_().name());
132 
133  cellLevelPtr_.reset
134  (
135  new labelIOList
136  (
137  rio,
138  UIndirectList<label>(data.cellLevelPtr_(), cellMap)()
139  )
140  );
141  }
142  if (data.pointLevelPtr_.valid())
143  {
144  IOobject rio(io);
145  rio.rename(data.pointLevelPtr_().name());
146 
147  pointLevelPtr_.reset
148  (
149  new labelIOList
150  (
151  rio,
152  UIndirectList<label>(data.pointLevelPtr_(), pointMap)()
153  )
154  );
155  }
156  if (data.level0EdgePtr_.valid())
157  {
158  IOobject rio(io);
159  rio.rename(data.level0EdgePtr_().name());
160 
161  level0EdgePtr_.reset
162  (
163  new localUniformDimensionedScalarField(rio, data.level0EdgePtr_())
164  );
165  }
166  if (data.refHistoryPtr_.valid())
167  {
168  IOobject rio(io);
169  rio.rename(data.refHistoryPtr_().name());
170 
171  refHistoryPtr_ = data.refHistoryPtr_().clone(rio, cellMap);
172  }
173 }
174 
175 
177 (
178  const IOobject& io,
179  const UPtrList<const labelList>& cellMaps,
180  const UPtrList<const labelList>& pointMaps,
181  const UPtrList<const hexRef8Data>& procDatas
182 )
183 {
184  const polyMesh& mesh = dynamic_cast<const polyMesh&>(io.db());
185 
186  // cellLevel
187 
188  if (procDatas[0].cellLevelPtr_.valid())
189  {
190  IOobject rio(io);
191  rio.rename(procDatas[0].cellLevelPtr_().name());
192 
193  cellLevelPtr_.reset(new labelIOList(rio, mesh.nCells()));
194  labelList& cellLevel = cellLevelPtr_();
195 
196  forAll(procDatas, procI)
197  {
198  const labelList& procCellLevel = procDatas[procI].cellLevelPtr_();
199  UIndirectList<label>(cellLevel, cellMaps[procI]) = procCellLevel;
200  }
201  }
202 
203 
204  // pointLevel
205 
206  if (procDatas[0].pointLevelPtr_.valid())
207  {
208  IOobject rio(io);
209  rio.rename(procDatas[0].pointLevelPtr_().name());
210 
211  pointLevelPtr_.reset(new labelIOList(rio, mesh.nPoints()));
212  labelList& pointLevel = pointLevelPtr_();
213 
214  forAll(procDatas, procI)
215  {
216  const labelList& procPointLevel = procDatas[procI].pointLevelPtr_();
217  UIndirectList<label>(pointLevel, pointMaps[procI]) = procPointLevel;
218  }
219  }
220 
221 
222  // level0Edge
223 
224  if (procDatas[0].level0EdgePtr_.valid())
225  {
226  IOobject rio(io);
227  rio.rename(procDatas[0].level0EdgePtr_().name());
228 
229  level0EdgePtr_.reset
230  (
231  new localUniformDimensionedScalarField
232  (
233  rio,
234  procDatas[0].level0EdgePtr_()
235  )
236  );
237  }
238 
239 
240  // refinementHistory
241 
242  if (procDatas[0].refHistoryPtr_.valid())
243  {
244  IOobject rio(io);
245  rio.rename(procDatas[0].refHistoryPtr_().name());
246 
247  UPtrList<const refinementHistory> procRefs(procDatas.size());
248  forAll(procDatas, i)
249  {
250  procRefs.set(i, &procDatas[i].refHistoryPtr_());
251  }
252 
253  refHistoryPtr_.reset
254  (
256  (
257  rio,
258  cellMaps,
259  procRefs
260  )
261  );
262  }
263 }
264 
265 
266 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
267 
269 {}
270 
271 
272 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
273 
275 {
276  const polyMesh& mesh = dynamic_cast<const polyMesh&>(io.db());
277 
278  bool hasCellLevel = returnReduce(cellLevelPtr_.valid(), orOp<bool>());
279  if (hasCellLevel && !cellLevelPtr_.valid())
280  {
281  IOobject rio(io);
282  rio.rename("cellLevel");
283  rio.readOpt() = IOobject::NO_READ;
284  cellLevelPtr_.reset(new labelIOList(rio, labelList(mesh.nCells(), 0)));
285  }
286 
287  bool hasPointLevel = returnReduce(pointLevelPtr_.valid(), orOp<bool>());
288  if (hasPointLevel && !pointLevelPtr_.valid())
289  {
290  IOobject rio(io);
291  rio.rename("pointLevel");
292  rio.readOpt() = IOobject::NO_READ;
293  pointLevelPtr_.reset
294  (
295  new labelIOList(rio, labelList(mesh.nPoints(), 0))
296  );
297  }
298 
299  bool hasLevel0Edge = returnReduce(level0EdgePtr_.valid(), orOp<bool>());
300  if (hasLevel0Edge)
301  {
302  // Get master length
303  scalar masterLen = level0EdgePtr_().value();
304  Pstream::scatter(masterLen);
305  if (!level0EdgePtr_.valid())
306  {
307  IOobject rio(io);
308  rio.rename("level0Edge");
309  rio.readOpt() = IOobject::NO_READ;
310  level0EdgePtr_.reset
311  (
312  new localUniformDimensionedScalarField
313  (
314  rio,
315  dimensionedScalar(dimLength, masterLen)
316  )
317  );
318  }
319  }
320 
321  bool hasHistory = returnReduce(refHistoryPtr_.valid(), orOp<bool>());
322  if (hasHistory && !refHistoryPtr_.valid())
323  {
324  IOobject rio(io);
325  rio.rename("refinementHistory");
326  rio.readOpt() = IOobject::NO_READ;
327  refHistoryPtr_.reset(new refinementHistory(rio, mesh.nCells(), true));
328  }
329 }
330 
331 
333 {
334  if (cellLevelPtr_.valid())
335  {
336  cellLevelPtr_() = labelList(cellLevelPtr_(), map.cellMap());
337  cellLevelPtr_().instance() = map.mesh().facesInstance();
338  }
339  if (pointLevelPtr_.valid())
340  {
341  pointLevelPtr_() = labelList(pointLevelPtr_(), map.pointMap());
342  pointLevelPtr_().instance() = map.mesh().facesInstance();
343  }
344 
345  // No need to distribute the level0Edge
346 
347  if (refHistoryPtr_.valid() && refHistoryPtr_().active())
348  {
349  refHistoryPtr_().topoChange(map);
350  refHistoryPtr_().instance() = map.mesh().facesInstance();
351  }
352 }
353 
354 
356 {
357  if (cellLevelPtr_.valid())
358  {
359  map.cellMap().distribute(cellLevelPtr_());
360  }
361  if (pointLevelPtr_.valid())
362  {
363  map.pointMap().distribute(pointLevelPtr_());
364  }
365 
366  // No need to distribute the level0Edge
367 
368  if (refHistoryPtr_.valid() && refHistoryPtr_().active())
369  {
370  refHistoryPtr_().distribute(map);
371  }
372 }
373 
374 
376 {
377  bool ok = true;
378  if (cellLevelPtr_.valid())
379  {
380  ok = ok && cellLevelPtr_().write();
381  }
382  if (pointLevelPtr_.valid())
383  {
384  ok = ok && pointLevelPtr_().write();
385  }
386  if (level0EdgePtr_.valid())
387  {
388  ok = ok && level0EdgePtr_().write();
389  }
390  if (refHistoryPtr_.valid())
391  {
392  ok = ok && refHistoryPtr_().write();
393  }
394  return ok;
395 }
396 
397 
398 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:309
readOption readOpt() const
Definition: IOobject.H:357
virtual void rename(const word &newName)
Rename.
Definition: IOobject.H:337
const word & name() const
Return name.
Definition: IOobject.H:307
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
A List with indirect addressing.
Definition: UIndirectList.H:61
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
bool set(const label) const
Is element set.
Definition: UPtrListI.H:87
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Various for reading/decomposing/reconstructing/distributing refinement data.
Definition: hexRef8Data.H:58
void topoChange(const polyTopoChangeMap &)
In-place update for topology changes.
Definition: hexRef8Data.C:332
void distribute(const polyDistributionMap &)
In-place distribute.
Definition: hexRef8Data.C:355
void sync(const IOobject &io)
Parallel synchronise. This enforces valid objects on all processors.
Definition: hexRef8Data.C:274
~hexRef8Data()
Destructor.
Definition: hexRef8Data.C:268
hexRef8Data(const IOobject &io)
Construct read. Has special provision for only some processors.
Definition: hexRef8Data.C:40
bool write() const
Write.
Definition: hexRef8Data.C:375
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const distributionMap & cellMap() const
Cell distribute map.
const distributionMap & pointMap() const
Point distribute map.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:1012
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & cellMap() const
Old cell map.
const labelList & pointMap() const
Old point map.
const polyMesh & mesh() const
Return polyMesh.
label nCells() const
label nPoints() const
All refinement history. Used in unrefinement.
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:545
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
List< label > labelList
A List of labels.
Definition: labelList.H:56
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
const dimensionSet & dimLength
Definition: dimensions.C:276
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
IOList< label > labelIOList
Label container classes.
Definition: labelIOList.H:42
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.