cutCellIso.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) 2016-2017 DHI
9 Copyright (C) 2018-2019 Johan Roenby
10 Copyright (C) 2020 DLR
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
30#include "cutCellIso.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
35:
37 mesh_(mesh),
38 cellI_(-1),
39 f_(f),
40 cutValue_(0),
41 cutFace_(cutFaceIso(mesh_, f_)),
42 cutFaceCentres_(10),
43 cutFaceAreas_(10),
44 isoFaceEdges_(10),
45 facePoints_(10),
46 faceCentre_(Zero),
47 faceArea_(Zero),
48 subCellCentre_(Zero),
49 subCellVolume_(-10),
50 VOF_(-10),
51 cellStatus_(-1)
52{
54}
55
56
57// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58
60(
61 const label cellI,
62 const scalar cutValue
63)
64{
65 // resets data members
66 clearStorage();
67 cellI_ = cellI;
68 cutValue_ = cutValue;
69 const cell& c = mesh_.cells()[cellI_];
70
71 bool fullyBelow = true;
72 bool fullyAbove = true;
73
74 label nFaceBelowInterface = 0;
75
76 // loop over cell faces
77 for (const label facei : c)
78 {
79 const label faceStatus = cutFace_.calcSubFace(facei, cutValue_);
80
81 if (faceStatus == 0) // face is cut
82 {
83 cutFaceCentres_.append(cutFace_.subFaceCentre());
84 cutFaceAreas_.append(cutFace_.subFaceArea());
85 isoFaceEdges_.append(cutFace_.surfacePoints());
86 fullyBelow = false;
87 fullyAbove = false;
88 }
89 else if (faceStatus == -1) // face fully below
90 {
91 cutFaceCentres_.append(cutFace_.subFaceCentre());
92 cutFaceAreas_.append(cutFace_.subFaceArea());
93 fullyAbove = false;
94 nFaceBelowInterface++;
95 }
96 else
97 {
98 fullyBelow = false;
99 }
100 }
101
102 if (!fullyBelow && !fullyAbove) // cell cut at least at one face
103 {
104 cellStatus_ = 0;
105
106 // calc faceArea and faceCentre
107 calcGeomDataCutFace
108 (
109 isoFaceEdges_,
110 average(cutFaceCentres_),
111 faceArea_,
112 faceCentre_
113 );
114
115 // In the rare but occuring cases where a cell is only touched at a
116 // point or a line the isoFaceArea_ will have zero length and here the
117 // cell should be treated as either completely empty or full.
118 if (mag(faceArea_) < ROOTVSMALL)
119 {
120 if (nFaceBelowInterface == 0)
121 {
122 // Cell fully above isosurface
123 cellStatus_ = 1;
124 subCellCentre_ = Zero;
125 subCellVolume_ = 0;
126 VOF_ = 0;
127 return cellStatus_;
128 }
129 else
130 {
131 // Cell fully below isosurface
132 cellStatus_ = -1;
133 subCellCentre_ = mesh_.C()[cellI_];
134 subCellVolume_ = mesh_.V()[cellI_];
135 VOF_ = 1;
136 return cellStatus_;
137 }
138 }
139
140 cutFaceCentres_.append(faceCentre_);
141 cutFaceAreas_.append(faceArea_);
142
143 // calc volume and sub cell centre
144 calcCellData
145 (
146 cutFaceCentres_,
147 cutFaceAreas_,
148 subCellCentre_,
149 subCellVolume_
150 );
151
152 VOF_ = subCellVolume_ / mesh_.V()[cellI_];
153 }
154 else if (fullyAbove) // cell fully above isosurface
155 {
156 cellStatus_ = 1;
157 subCellCentre_ = Zero;
158 subCellVolume_ = 0;
159 VOF_ = 0;
160 }
161 else if (fullyBelow) // cell fully below isosurface
162 {
163 cellStatus_ = -1;
164 subCellCentre_ = mesh_.C()[cellI_];
165 subCellVolume_ = mesh_.V()[cellI_];
166 VOF_ = 1;
167 }
168
169 return cellStatus_;
170}
171
172
174{
175 if (facePoints_.empty())
176 {
177 // get face points in sorted order
178 calcIsoFacePointsFromEdges
179 (
180 faceArea_,
181 faceCentre_,
182 isoFaceEdges_,
183 facePoints_
184 );
185 }
186
187 return facePoints_;
188}
189
190
192{
193 cellI_ = -1;
194 cutValue_ = 0;
195 cutFaceCentres_.clear();
196 cutFaceAreas_.clear();
197 isoFaceEdges_.clear();
198 facePoints_.clear();
199 faceCentre_ = Zero;
200 faceArea_ = Zero;
201 subCellCentre_ = Zero;
202 subCellVolume_ = -10;
203 VOF_ = -10;
204 cellStatus_ = -1;
205}
206
207
208// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
Class for cutting a cell, celli, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Definition: cutCellIso.H:79
label calcSubCell(const label cellI, const scalar cutValue)
Sets internal values and returns face status.
Definition: cutCellIso.C:60
const DynamicList< point > & facePoints()
Returns the points of the cutting PLICface.
Definition: cutCellIso.C:173
void clearStorage()
Resets internal values.
Definition: cutCellIso.C:191
Service routines for cutting a cell, celli, of an fvMesh, mesh_, at its intersection with a surface.
Definition: cutCell.H:60
Class for cutting a face, faceI, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Definition: cutFaceIso.H:71
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
dynamicFvMesh & mesh
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
labelList f(nPoints)