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-2023 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 labelList& zoneIDs
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  if (!isNull<labelList>(zoneIDs))
93  {
94  forAll(zoneIDs, i)
95  {
96  forAll(mesh.cellZones()[zoneIDs[i]], zoneCelli)
97  {
98  cutCell(mesh.cellZones()[zoneIDs[i]][zoneCelli]);
99  }
100  }
101  }
102  else
103  {
104  forAll(mesh.cells(), celli)
105  {
106  cutCell(celli);
107  }
108  }
109 
110  // Generate the cell cut polygons
111  const label nAllocate = nCutCells + nCutCells/10;
112  EdgeMap<label> meshEdgePoint(nAllocate*4);
113  DynamicList<point> pointsDyn(nAllocate);
114  DynamicList<edge> pointEdgesDyn(nAllocate);
115  DynamicList<scalar> pointEdgeLambdasDyn(nAllocate);
116  DynamicList<face> facesDyn(nAllocate);
117  DynamicList<label> faceCellsDyn(nAllocate);
118  forAll(mesh.cells(), celli)
119  {
120  forAll(cellCuts[celli], cellCuti)
121  {
122  if (cellCuts[celli][cellCuti].size() < 3) continue;
123 
124  facesDyn.append(face(cellCuts[celli][cellCuti].size()));
125 
126  forAll(cellCuts[celli][cellCuti], i)
127  {
128  const label cei = cellCuts[celli][cellCuti][i];
129  const label cfi = cAddrs[celli].ceiToCfiAndFei()[cei][0][0];
130  const label fei = cAddrs[celli].ceiToCfiAndFei()[cei][0][1];
131 
132  const edge e =
133  mesh.faces()[mesh.cells()[celli][cfi]].faceEdge(fei);
134 
135  EdgeMap<label>::iterator iter = meshEdgePoint.find(e);
136 
137  const label surfacePointi =
138  iter != meshEdgePoint.end() ? *iter : pointsDyn.size();
139 
140  if (surfacePointi == pointsDyn.size())
141  {
142  meshEdgePoint.insert(e, surfacePointi);
143 
144  const scalar lambda =
145  cutPoly::edgeCutLambda(e, pAlphas, isoAlpha);
146 
147  pointsDyn.append
148  (
150  );
151  pointEdgesDyn.append(e);
152  pointEdgeLambdasDyn.append(lambda);
153  }
154 
155  facesDyn.last()[i] = surfacePointi;
156  }
157 
158  faceCellsDyn.append(celli);
159  }
160  }
161 
162  // Transfer to non-dynamic storage
163  points_.transfer(pointsDyn);
164  pointEdges_.transfer(pointEdgesDyn);
165  pointEdgeLambdas_.transfer(pointEdgeLambdasDyn);
166  faces_.transfer(facesDyn);
167  faceCells_.transfer(faceCellsDyn);
168 
169  if (debug)
170  {
171  const label nLabels =
173 
174  Pout<< typeName << " : constructed surface of size "
175  << points().size()*sizeof(point) + nLabels*sizeof(label)
176  << " in " << cpuTime.cpuTimeIncrement() << "s" << nl << endl;
177  }
178 }
179 
180 
182 (
183  const PtrList<cutPolyIsoSurface>& isos
184 )
185 :
186  points_(),
187  pointEdges_(),
188  pointEdgeLambdas_(),
189  faces_(),
190  faceCells_()
191 {
192  label nPoints = 0, nFaces = 0;
193  forAll(isos, i)
194  {
195  nPoints += isos[i].points_.size();
196  nFaces += isos[i].faces_.size();
197  }
198 
199  points_.resize(nPoints);
200  pointEdges_.resize(nPoints);
201  pointEdgeLambdas_.resize(nPoints);
202  faces_.resize(nFaces);
203  faceCells_.resize(nFaces);
204 
205  label pointi0 = 0, facei0 = 0;
206  forAll(isos, i)
207  {
208  const label nPs = isos[i].points_.size();
209  const label nFs = isos[i].faces_.size();
210 
211  SubList<point>(points_, nPs, pointi0) = isos[i].points_;
212  SubList<edge>(pointEdges_, nPs, pointi0) = isos[i].pointEdges_;
213  SubList<scalar>(pointEdgeLambdas_, nPs, pointi0) =
214  isos[i].pointEdgeLambdas_;
215  SubList<face>(faces_, nFs, facei0) = isos[i].faces_;
216  SubList<label>(faceCells_, nFs, facei0) = isos[i].faceCells_;
217 
218  forAll(isos[i].faces_, fi)
219  {
220  forAll(faces_[facei0 + fi], fpi)
221  {
222  faces_[facei0 + fi][fpi] += pointi0;
223  }
224  }
225 
226  pointi0 += nPs;
227  facei0 += nFs;
228  }
229 }
230 
231 
232 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
233 
235 {}
236 
237 
238 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:142
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.
cutPolyIsoSurface(const polyMesh &mesh, const scalarField &pAlphas, const scalar isoAlpha, const labelList &zoneIDs=NullObjectRef< labelList >())
Construct from a mesh, point values and an iso-value.
const faceList & faces() const
Faces of the iso-surface.
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:80
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1374
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1361
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:451
const cellList & cells() const
label nPoints
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:105
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:251
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
vector point
Point is a vector.
Definition: point.H:41
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
static const char nl
Definition: Ostream.H:260
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112