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