cutPolyIsoSurface.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) 2022-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 "cutPolyIsoSurface.H"
27 #include "cellEdgeAddressing.H"
28 #include "cutPolyValue.H"
29 #include "EdgeMap.H"
30 #include "cpuTime.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const polyMesh& mesh,
45  const scalarField& pAlphas,
46  const scalar isoAlpha,
47  const labelUList& cells
48 )
49 :
50  points_(),
51  pointEdges_(),
52  pointEdgeLambdas_(),
53  faces_(),
54  faceCells_()
55 {
57 
58  // Cut the faces
60  forAll(mesh.faces(), facei)
61  {
62  faceCuts[facei] =
64  (
65  mesh.faces()[facei],
66  pAlphas,
67  isoAlpha
68  );
69  }
70 
71  // Request the cell-edge addressing engine
73 
74  // Cut the cells
76  label nCutCells = 0;
77  auto cutCell = [&](const label celli)
78  {
79  cellCuts[celli] =
81  (
82  mesh.cells()[celli],
83  cAddrs[celli],
84  mesh.faces(),
85  faceCuts,
86  pAlphas,
87  isoAlpha
88  );
89 
90  nCutCells += !cellCuts[celli].empty();
91  };
92 
93  if (notNull(cells))
94  {
95  forAll(cells, i)
96  {
97  cutCell(cells[i]);
98  }
99  }
100  else
101  {
102  forAll(mesh.cells(), celli)
103  {
104  cutCell(celli);
105  }
106  }
107 
108  // Generate the cell cut polygons
109  const label nAllocate = nCutCells + nCutCells/10;
110  EdgeMap<label> meshEdgePoint(nAllocate*4);
111  DynamicList<point> pointsDyn(nAllocate);
112  DynamicList<edge> pointEdgesDyn(nAllocate);
113  DynamicList<scalar> pointEdgeLambdasDyn(nAllocate);
114  DynamicList<face> facesDyn(nAllocate);
115  DynamicList<label> faceCellsDyn(nAllocate);
116  forAll(mesh.cells(), celli)
117  {
118  forAll(cellCuts[celli], cellCuti)
119  {
120  if (cellCuts[celli][cellCuti].size() < 3) continue;
121 
122  facesDyn.append(face(cellCuts[celli][cellCuti].size()));
123 
124  forAll(cellCuts[celli][cellCuti], i)
125  {
126  const label cei = cellCuts[celli][cellCuti][i];
127  const label cfi = cAddrs[celli].ceiToCfiAndFei()[cei][0][0];
128  const label fei = cAddrs[celli].ceiToCfiAndFei()[cei][0][1];
129 
130  const edge e =
131  mesh.faces()[mesh.cells()[celli][cfi]].faceEdge(fei);
132 
133  EdgeMap<label>::iterator iter = meshEdgePoint.find(e);
134 
135  const label surfacePointi =
136  iter != meshEdgePoint.end() ? *iter : pointsDyn.size();
137 
138  if (surfacePointi == pointsDyn.size())
139  {
140  meshEdgePoint.insert(e, surfacePointi);
141 
142  const scalar lambda =
143  cutPoly::edgeCutLambda(e, pAlphas, isoAlpha);
144 
145  pointsDyn.append
146  (
148  );
149  pointEdgesDyn.append(e);
150  pointEdgeLambdasDyn.append(lambda);
151  }
152 
153  facesDyn.last()[i] = surfacePointi;
154  }
155 
156  faceCellsDyn.append(celli);
157  }
158  }
159 
160  // Transfer to non-dynamic storage
161  points_.transfer(pointsDyn);
162  pointEdges_.transfer(pointEdgesDyn);
163  pointEdgeLambdas_.transfer(pointEdgeLambdasDyn);
164  faces_.transfer(facesDyn);
165  faceCells_.transfer(faceCellsDyn);
166 
167  if (debug)
168  {
169  const label nLabels =
171 
172  Pout<< typeName << " : constructed surface of size "
173  << points().size()*sizeof(point) + nLabels*sizeof(label)
174  << " in " << cpuTime.cpuTimeIncrement() << "s" << nl << endl;
175  }
176 }
177 
178 
180 (
181  const PtrList<cutPolyIsoSurface>& isos
182 )
183 :
184  points_(),
185  pointEdges_(),
186  pointEdgeLambdas_(),
187  faces_(),
188  faceCells_()
189 {
190  label nPoints = 0, nFaces = 0;
191  forAll(isos, i)
192  {
193  nPoints += isos[i].points_.size();
194  nFaces += isos[i].faces_.size();
195  }
196 
197  points_.resize(nPoints);
198  pointEdges_.resize(nPoints);
199  pointEdgeLambdas_.resize(nPoints);
200  faces_.resize(nFaces);
201  faceCells_.resize(nFaces);
202 
203  label pointi0 = 0, facei0 = 0;
204  forAll(isos, i)
205  {
206  const label nPs = isos[i].points_.size();
207  const label nFs = isos[i].faces_.size();
208 
209  SubList<point>(points_, nPs, pointi0) = isos[i].points_;
210  SubList<edge>(pointEdges_, nPs, pointi0) = isos[i].pointEdges_;
211  SubList<scalar>(pointEdgeLambdas_, nPs, pointi0) =
212  isos[i].pointEdgeLambdas_;
213  SubList<face>(faces_, nFs, facei0) = isos[i].faces_;
214  SubList<label>(faceCells_, nFs, facei0) = isos[i].faceCells_;
215 
216  forAll(isos[i].faces_, fi)
217  {
218  forAll(faces_[facei0 + fi], fpi)
219  {
220  faces_[facei0 + fi][fpi] += pointi0;
221  }
222  }
223 
224  pointi0 += nPs;
225  facei0 += nFs;
226  }
227 }
228 
229 
230 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
231 
233 {}
234 
235 
236 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
static cellEdgeAddressingList & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A List obtained as a section of another List.
Definition: SubList.H:56
T & last()
Return the last element of the list.
Definition: UListI.H:128
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
Description of cuts across cells.
Definition: cellCuts.H:111
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:55
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTime.C:60
Iso-surface class based on the cutPoly cutting routines.
virtual ~cutPolyIsoSurface()
Destructor.
const faceList & faces() const
Faces of the iso-surface.
cutPolyIsoSurface(const polyMesh &mesh, const scalarField &pAlphas, const scalar isoAlpha, const labelUList &cells=NullObjectRef< labelUList >())
Construct from a mesh, point values and an iso-value.
const pointField & points() const
Points of the iso-surface.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1295
const cellList & cells() const
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label nPoints
const cellShapeList & cells
dimensionedScalar lambda(viscosity->lookup("lambda"))
labelList subSizes(const List< T > &, AccessOp aop=accessOp< T >())
Gets sizes of sublists.
Definition: ListListOps.C:61
scalar edgeCutLambda(const edge &e, const scalarField &pAlphas, const scalar isoAlpha)
Get the local coordinate within an edge, given end point values and an.
Definition: cutPolyValueI.H:31
Type edgeCutValue(const edge &e, const scalar lambda, const Field< Type > &pPsis)
Linearly interpolate a value from the end points to the cut point of an.
List< labelPair > faceCuts(const face &f, const scalarField &pAlphas, const scalar isoAlpha)
Return the cuts for a given face. This returns a list of pairs of.
Definition: cutPoly.C:61
labelListList cellCuts(const cell &c, const cellEdgeAddressing &cAddr, const faceUList &fs, const List< List< labelPair >> &fCuts, const scalarField &pAlphas, const scalar isoAlpha)
Return the cuts for a given cell. This returns a list of lists of cell-edge.
Definition: cutPoly.C:121
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
vector point
Point is a vector.
Definition: point.H:41
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112