Loading...
Searching...
No Matches
primitiveMesh.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-2016 OpenFOAM Foundation
9 Copyright (C) 2021-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
29#include "primitiveMesh.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
35 defineTypeNameAndDebug(primitiveMesh, 0);
36}
37
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42:
43 nInternalPoints_(0), // note: points are considered ordered on empty mesh
44 nPoints_(0),
45 nInternal0Edges_(-1),
46 nInternal1Edges_(-1),
47 nInternalEdges_(-1),
48 nEdges_(-1),
49 nInternalFaces_(0),
50 nFaces_(0),
51 nCells_(0)
52{}
53
54
56(
57 const label nPoints,
58 const label nInternalFaces,
59 const label nFaces,
60 const label nCells
61)
62:
63 nInternalPoints_(-1),
64 nPoints_(nPoints),
65 nEdges_(-1),
66 nInternalFaces_(nInternalFaces),
67 nFaces_(nFaces),
68 nCells_(nCells)
69{}
70
71
72// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73
76 clearOut();
77}
78
79
80// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81
83(
84 label& nInternalPoints,
85 labelList& oldToNew,
86 const faceList& faces,
87 const label nInternalFaces,
88 const label nPoints
89)
90{
91 // Internal points are points that are not used by a boundary face.
92
93 // Map from old to new position
94 oldToNew.resize_nocopy(nPoints);
95 oldToNew = -1;
96
97
98 // 1. Create compact addressing for boundary points. Start off by indexing
99 // from 0 inside oldToNew. (shifted up later on)
100
101 label nBoundaryPoints = 0;
102 for (label facei = nInternalFaces; facei < faces.size(); ++facei)
103 {
104 const face& f = faces[facei];
105
106 for (label pointi : f)
107 {
108 if (oldToNew[pointi] == -1)
109 {
110 oldToNew[pointi] = nBoundaryPoints++;
111 }
112 }
113 }
114
115 // Now we know the number of boundary and internal points
116
117 nInternalPoints = nPoints - nBoundaryPoints;
118
119 // Move the boundary addressing up
120 forAll(oldToNew, pointi)
121 {
122 if (oldToNew[pointi] != -1)
123 {
124 oldToNew[pointi] += nInternalPoints;
125 }
126 }
127
128
129 // 2. Compact the internal points. Detect whether internal and boundary
130 // points are mixed.
131
132 label internalPointi = 0;
133
134 bool ordered = true;
135
136 for (label facei = 0; facei < nInternalFaces; facei++)
137 {
138 const face& f = faces[facei];
139
140 for (label pointi : f)
141 {
142 if (oldToNew[pointi] == -1)
143 {
144 if (pointi >= nInternalPoints)
145 {
146 ordered = false;
147 }
148 oldToNew[pointi] = internalPointi++;
149 }
151 }
152
153 return ordered;
154}
155
156
158(
159 const label nPoints,
160 const label nInternalFaces,
161 const label nFaces,
162 const label nCells
163)
164{
165 clearOut();
166
167 nPoints_ = nPoints;
168 nEdges_ = -1;
169 nInternal0Edges_ = -1;
170 nInternal1Edges_ = -1;
171 nInternalEdges_ = -1;
172
173 nInternalFaces_ = nInternalFaces;
174 nFaces_ = nFaces;
175 nCells_ = nCells;
176
177 // Check if points are ordered
178 label nInternalPoints;
179 labelList pointMap;
180
181 bool isOrdered = calcPointOrder
182 (
183 nInternalPoints,
184 pointMap,
185 faces(),
186 nInternalFaces_,
187 nPoints_
188 );
189
190 if (isOrdered)
191 {
192 nInternalPoints_ = nInternalPoints;
193 }
194 else
195 {
196 nInternalPoints_ = -1;
197 }
198
199 if (debug)
200 {
201 Pout<< "primitiveMesh::reset : mesh reset to"
202 << " nInternalPoints:" << nInternalPoints_
203 << " nPoints:" << nPoints_
204 << " nEdges:" << nEdges_
205 << " nInternalFaces:" << nInternalFaces_
206 << " nFaces:" << nFaces_
207 << " nCells:" << nCells_
208 << endl;
209 }
210}
211
212
214(
215 const label nPoints,
216 const label nInternalFaces,
217 const label nFaces,
218 const label nCells,
219 cellList& clst
220)
221{
222 reset
223 (
224 nPoints,
225 nInternalFaces,
226 nFaces,
228 );
229
230 cfPtr_ = std::make_unique<cellList>(std::move(clst));
231}
232
233
235(
236 pointField&& faceCentres,
237 pointField&& faceAreas,
238 pointField&& cellCentres,
239 scalarField&& cellVolumes
240)
241{
242 if
243 (
244 faceCentres.size() != nFaces_
245 || faceAreas.size() != nFaces_
246 || cellCentres.size() != nCells_
247 || cellVolumes.size() != nCells_
248 )
249 {
251 << "Wrong sizes of passed in face/cell data"
252 << abort(FatalError);
253 }
254
255 // Remove old geometry
256 clearGeom();
257
258 faceCentresPtr_ = std::make_unique<pointField>(std::move(faceCentres));
259 faceAreasPtr_ = std::make_unique<pointField>(std::move(faceAreas));
260 cellCentresPtr_ = std::make_unique<pointField>(std::move(cellCentres));
261 cellVolumesPtr_ = std::make_unique<scalarField>(std::move(cellVolumes));
262
263 if (debug)
264 {
265 Pout<< "primitiveMesh::resetGeometry : geometry reset for"
266 << " nFaces:" << faceCentresPtr_->size()
267 << " nCells:" << cellCentresPtr_->size() << endl;
268 }
269}
270
271
273(
274 const pointField& newPoints,
275 const pointField& oldPoints
276)
277{
278 // Note: the following clearout is now handled by the fvGeometryScheme
279 // triggered by the call to updateGeom() in polyMesh::movePoints
280
281 // Force recalculation of all geometric data with new points
282 //clearGeom();
283}
284
285
287{
288 if (!cellShapesPtr_)
289 {
290 calcCellShapes();
291 }
292
293 return *cellShapesPtr_;
294}
295
296
298{
299 if (!faceCentresPtr_ || !faceAreasPtr_)
300 {
301 // These are always calculated in tandem, but only once
302 calcFaceCentresAndAreas();
303 }
304
305 if (!cellCentresPtr_ || !cellVolumesPtr_)
306 {
307 // These are always calculated in tandem, but only once
308 calcCellCentresAndVols();
309 }
310}
311
312
313// ************************************************************************* //
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
Cell-face mesh analysis engine.
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
primitiveMesh()
Construct null.
const vectorField & faceCentres() const
virtual const pointField & oldPoints() const =0
Return old points for mesh motion.
const scalarField & cellVolumes() const
virtual const faceList & faces() const =0
Return faces.
void clearGeom()
Clear geometry.
label nInternalFaces() const noexcept
Number of internal faces.
const vectorField & cellCentres() const
virtual ~primitiveMesh()
Destructor.
const cellShapeList & cellShapes() const
Return cell shapes.
void calcCellCentresAndVols() const
Calculate cell centres and volumes.
label nPoints() const noexcept
Number of mesh points.
label nInternalPoints() const noexcept
Points not on boundary.
label nCells() const noexcept
Number of mesh cells.
label nFaces() const noexcept
Number of mesh faces.
void movePoints(const pointField &p, const pointField &oldP)
Move points.
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
const vectorField & faceAreas() const
void calcFaceCentresAndAreas() const
Calculate face centres and areas.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
virtual void updateGeom()
Update all geometric data.
void resetGeometry(pointField &&faceCentres, pointField &&faceAreas, pointField &&cellCentres, scalarField &&cellVolumes)
Reset the local geometry.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
label nPoints
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
List< face > faceList
List of faces.
Definition faceListFwd.H:41
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
List< cell > cellList
List of cell.
Definition cellListFwd.H:41
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
List< cellShape > cellShapeList
List of cellShape.
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299