polyMeshClear.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-2017 OpenFOAM Foundation
9  Copyright (C) 2020 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 "polyMesh.H"
30 #include "primitiveMesh.H"
31 #include "globalMeshData.H"
32 #include "MeshObject.H"
33 #include "indexedOctree.H"
34 #include "treeDataCell.H"
35 #include "pointMesh.H"
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
40 {
41  DebugInFunction << "Removing boundary patches." << endl;
42 
43  boundary_.clear();
44 
45  clearOut();
46 }
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
52 {
53  DebugInFunction << "Clearing geometric data" << endl;
54 
55  // Clear all geometric mesh objects
56  meshObject::clear<pointMesh, GeometricMeshObject>(*this);
57  meshObject::clear<polyMesh, GeometricMeshObject>(*this);
58 
60 
61  boundary_.clearGeom();
62 
63  // Reset valid directions (could change with rotation)
64  geometricD_ = Zero;
65  solutionD_ = Zero;
66 
67  // Remove the cell tree
68  cellTreePtr_.clear();
69 }
70 
71 
73 (
74  pointIOField&& newPoints,
75  autoPtr<labelIOList>& newTetBasePtIsPtr
76 )
77 {
79  << "Updating geometric data with newPoints:"
80  << newPoints.size() << " newTetBasePtIs:"
81  << bool(newTetBasePtIsPtr) << endl;
82 
83  if (points_.size() != 0 && points_.size() != newPoints.size())
84  {
86  << "Point motion detected but number of points "
87  << newPoints.size() << " in "
88  << newPoints.objectPath() << " does not correspond to "
89  << " current " << points_.size()
90  << exit(FatalError);
91  }
92 
93  // Clear all geometric mesh objects that are not 'movable'
95  <
96  pointMesh,
97  TopologicalMeshObject,
98  MoveableMeshObject
99  >
100  (
101  *this
102  );
104  <
105  polyMesh,
106  TopologicalMeshObject,
107  MoveableMeshObject
108  >
109  (
110  *this
111  );
112 
114 
115  boundary_.clearGeom();
116 
117  // Reset valid directions (could change with rotation)
118  geometricD_ = Zero;
119  solutionD_ = Zero;
120 
121  // Remove the cell tree
122  cellTreePtr_.clear();
123 
124  // Update local data
125  points_.instance() = newPoints.instance();
126  points_.transfer(newPoints);
127 
128  // Optional new tet base points
129  if (newTetBasePtIsPtr)
130  {
131  tetBasePtIsPtr_ = std::move(newTetBasePtIsPtr);
132  }
133 
134  // Calculate the geometry for the patches (transformation tensors etc.)
135  boundary_.calcGeometry();
136 
137  // Derived info
138  bounds_ = boundBox(points_);
139 
140  // Rotation can cause direction vector to change
141  geometricD_ = Zero;
142  solutionD_ = Zero;
144  // Update all 'movable' objects
145  meshObject::movePoints<polyMesh>(*this);
146  meshObject::movePoints<pointMesh>(*this);
147 }
148 
149 
150 void Foam::polyMesh::clearAddressing(const bool isMeshUpdate)
151 {
153  << "Clearing topology isMeshUpdate:" << isMeshUpdate << endl;
154 
155  if (isMeshUpdate)
156  {
157  // Part of a mesh update. Keep meshObjects that have an updateMesh
158  // callback
160  <
161  pointMesh,
164  >
165  (
166  *this
167  );
169  <
170  polyMesh,
173  >
174  (
175  *this
176  );
177  }
178  else
179  {
180  meshObject::clear<pointMesh, TopologicalMeshObject>(*this);
181  meshObject::clear<polyMesh, TopologicalMeshObject>(*this);
182  }
183 
185 
186  // parallelData depends on the processorPatch ordering so force
187  // recalculation
188  globalMeshDataPtr_.reset(nullptr);
189 
190  // Reset valid directions
191  geometricD_ = Zero;
192  solutionD_ = Zero;
193 
194  // Update zones
195  pointZones_.clearAddressing();
196  faceZones_.clearAddressing();
197  cellZones_.clearAddressing();
198 
199  // Remove the stored tet base points
200  tetBasePtIsPtr_.clear();
201 
202  // Remove the cell tree
203  cellTreePtr_.clear();
204 }
205 
206 
208 {
209  resetMotion();
210 
211  points_.clear();
212  faces_.clear();
213  owner_.clear();
214  neighbour_.clear();
215 
216  clearedPrimitives_ = true;
217 }
218 
219 
221 {
222  clearGeom();
223  clearAddressing();
224 }
225 
226 
228 {
229  DebugInFunction << "Clearing tet base points" << endl;
230 
231  tetBasePtIsPtr_.clear();
232 }
233 
234 
236 {
237  DebugInFunction << "Clearing cell tree" << endl;
238 
239  cellTreePtr_.clear();
240 }
241 
242 
243 // ************************************************************************* //
void clearAddressing()
Clear topological data.
void updateGeomPoints(pointIOField &&newPoints, autoPtr< labelIOList > &newTetBasePtIsPtr)
Update geometry points; keep topology. Optionally with new face decomposition.
Definition: polyMeshClear.C:66
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
static void clearUpto(objectRegistry &obr)
Clear all meshObject derived from FromType up to (but not including) ToType.
Definition: MeshObject.C:257
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
void clearGeom()
Clear geometry.
void clearPrimitives()
Clear primitive data (points, faces and cells)
#define DebugInFunction
Report an information message using Foam::Info.
void clearGeom()
Clear geometry.
Definition: polyMeshClear.C:44
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:32
void clear()
Clear the patch list and all demand-driven data.
void clearTetBasePtIs()
Clear tet base points.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A primitive field of type <T> with automated input and output.
void clearCellTree()
Clear cell tree data.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127