isoAdvection.H
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 Johan Roenby
10  Copyright (C) 2016-2017, 2019 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
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 Class
29  Foam::isoAdvection
30 
31 Description
32  Calculates the new VOF (alpha) field after time step dt given the initial
33  VOF field and a velocity field U and face fluxes phi. The fluid transport
34  calculation is based on an idea of using isosurfaces to estimate the
35  internal distribution of fluid in cells and advecting such isosurfaces
36  across the mesh faces with the velocity field interpolated to the
37  isosurfaces.
38 
39  Reference:
40  \verbatim
41  Roenby, J., Bredmose, H. and Jasak, H. (2016).
42  A computational method for sharp interface advection
43  Royal Society Open Science, 3
44  doi 10.1098/rsos.160405
45  \endverbatim
46 
47  Original code supplied by Johan Roenby, DHI (2016)
48 
49 SourceFiles
50  isoAdvection.C
51  isoAdvectionTemplates.C
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #ifndef isoAdvection_H
56 #define isoAdvection_H
57 
58 #include "fvMesh.H"
59 #include "volFieldsFwd.H"
60 #include "surfaceFields.H"
61 #include "className.H"
62 #include "isoCutCell.H"
63 #include "isoCutFace.H"
64 #include "bitSet.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 
71 /*---------------------------------------------------------------------------*\
72  Class isoAdvection Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class isoAdvection
76 {
77  // Private data types
78 
83 
84 
85  // Private data
86 
87  //- Reference to mesh
88  const fvMesh& mesh_;
89 
90  //- Dictionary for isoAdvection controls
91  const dictionary dict_;
92 
93  //- VOF field
94  volScalarField& alpha1_;
95 
96  //- Often used reference to alpha1 internal field
97  scalarField& alpha1In_;
98 
99  //- Reference to flux field
100  const surfaceScalarField& phi_;
101 
102  //- Reference to velocity field
103  const volVectorField& U_;
104 
105  //- Face volumetric water transport
106  surfaceScalarField dVf_;
107 
108  //- Time spent performing interface advection
109  scalar advectionTime_;
110 
111 
112  // Point interpolation data
113 
114  //- VOF field interpolated to mesh points
115  scalarField ap_;
116 
117 
118  // Switches and tolerances. Tolerances need to go into toleranceSwitches
119 
120  //- Number of alpha bounding steps
121  label nAlphaBounds_;
122 
123  //- Tolerance for search of isoFace giving specified VOF value
124  scalar isoFaceTol_;
125 
126  //- Tolerance for marking of surface cells:
127  // Those with surfCellTol_ < alpha1 < 1 - surfCellTol_
128  scalar surfCellTol_;
129 
130  //- Switch controlling whether to use isoface normals for interface
131  // orientation (default corresponding to false) to base it on
132  // a smoothed gradient of alpha calculation (giving better results
133  // on tri on tet meshes).
134  bool gradAlphaBasedNormal_;
135 
136  //- Print isofaces in a <case>/isoFaces/isoFaces_#N.vtk files.
137  // Intended for debugging
138  bool writeIsoFacesToFile_;
139 
140  // Cell and face cutting
141 
142  //- List of surface cells
143  DynamicLabelList surfCells_;
144 
145  //- Cell cutting object
146  isoCutCell isoCutCell_;
147 
148  //- Face cutting object
149  isoCutFace isoCutFace_;
150 
151  //- Cells that have been touched by the bounding step
152  bitSet cellIsBounded_;
153 
154  //- True for all surface cells and their neighbours
155  bitSet checkBounding_;
156 
157  //- Storage for boundary faces downwind to a surface cell
158  DynamicLabelList bsFaces_;
159 
160  //- Storage for boundary surface iso face centre
161  DynamicVectorList bsx0_;
162 
163  //- Storage for boundary surface iso face normal
164  DynamicVectorList bsn0_;
165 
166  //- Storage for boundary surface iso face speed
167  DynamicScalarList bsUn0_;
168 
169  //- Storage for boundary surface iso value
170  DynamicScalarList bsf0_;
171 
172 
173  // Additional data for parallel runs
174 
175  //- List of processor patch labels
176  DynamicLabelList procPatchLabels_;
177 
178  //- For each patch if it is a processor patch this is a list of the
179  // face labels on this patch that are downwind to a surface cell.
180  // For non-processor patches the list will be empty.
181  List<DynamicLabelList> surfaceCellFacesOnProcPatches_;
182 
183 
184  // Private Member Functions
185 
186  //- No copy construct
187  isoAdvection(const isoAdvection&) = delete;
188 
189  //- No copy assignment
190  void operator=(const isoAdvection&) = delete;
191 
192 
193  // Advection functions
194 
195  //- For each face calculate volumetric face transport during dt
196  void timeIntegratedFlux();
197 
198  //- Set ap_ values of celli's vertices in accordance with the
199  // unit normal of celli as obtained from cellNoramlsIn.
200  void setCellVertexValues
201  (
202  const label celli,
203  const vectorField& cellNormalsIn
204  );
205 
206  //- Function used to normalise and smoothen grad(alpha) in case
207  // gradAlphaBasedNormal_ is true.
208  void normaliseAndSmooth
209  (
210  volVectorField& cellN
211  );
212 
213  //- For a given cell return labels of faces fluxing out of this cell
214  // (based on sign of phi)
215  void setDownwindFaces
216  (
217  const label celli,
218  DynamicLabelList& downwindFaces
219  ) const;
220 
221  // Limit fluxes
222  void limitFluxes();
223 
224  // Bound fluxes
225  void boundFromAbove
226  (
227  const scalarField& alpha1,
228  surfaceScalarField& dVfcorrected,
229  DynamicLabelList& correctedFaces
230  );
231 
232  //- Given the face volume transport dVf calculates the total volume
233  // leaving a given cell. Note: cannot use dVf member because
234  // netFlux is called also for corrected dVf
235  scalar netFlux
236  (
237  const surfaceScalarField& dVf,
238  const label celli
239  ) const;
240 
241  //- Determine if a cell is a surface cell
242  bool isASurfaceCell(const label celli) const
243  {
244  return
245  (
246  surfCellTol_ < alpha1In_[celli]
247  && alpha1In_[celli] < 1 - surfCellTol_
248  );
249  }
250 
251  //- Clear out isoFace data
252  void clearIsoFaceData()
253  {
254  surfCells_.clear();
255  bsFaces_.clear();
256  bsx0_.clear();
257  bsn0_.clear();
258  bsUn0_.clear();
259  bsf0_.clear();
260 
261  if (mesh_.topoChanging())
262  {
263  // Introduced resizing to cope with changing meshes
264  checkBounding_.resize(mesh_.nCells());
265  cellIsBounded_.resize(mesh_.nCells());
266  ap_.resize(mesh_.nPoints());
267  }
268  checkBounding_ = false;
269  cellIsBounded_ = false;
270 
271  }
272 
273  // Face value functions needed for random face access where the face
274  // can be either internal or boundary face
275 
276  //- Return face value for a given Geometric surface field
277  template<typename Type>
278  Type faceValue
279  (
281  const label facei
282  ) const;
283 
284  //- Set face value for a given Geometric surface field
285  template<typename Type>
286  void setFaceValue
287  (
289  const label facei,
290  const Type& value
291  ) const;
292 
293 
294  // Parallel run handling functions
295 
296  //- Synchronize dVf across processor boundaries using upwind value
297  void syncProcPatches
298  (
299  surfaceScalarField& dVf,
300  const surfaceScalarField& phi
301  );
302 
303  //- Check if the face is on processor patch and append it to the
304  // list of surface cell faces on processor patches
305  void checkIfOnProcPatch(const label facei);
306 
307 
308 public:
309 
310  //- Runtime type information
311  TypeName("isoAdvection");
312 
313  //- Constructors
314 
315  //- Construct given alpha, phi and velocity field. Note: phi should be
316  // divergence free up to a sufficient tolerance
318  (
320  const surfaceScalarField& phi,
321  const volVectorField& U
322  );
323 
324 
325  //- Destructor
326  virtual ~isoAdvection() = default;
327 
328 
329  // Member functions
330 
331  //- Advect the free surface. Updates alpha field, taking into account
332  // multiple calls within a single time step.
333  void advect();
334 
335  //- Apply the bounding based on user inputs
337 
338  // Access functions
339 
340  //- Return alpha field
341  const volScalarField& alpha() const
342  {
343  return alpha1_;
344  }
345 
346  //- Return the controls dictionary
347  const dictionary& dict() const
348  {
349  return dict_;
350  }
351 
352  //- Return cellSet of surface cells
353  void writeSurfaceCells() const;
354 
355  //- Return cellSet of bounded cells
356  void writeBoundedCells() const;
357 
358  //- Return mass flux
360  (
361  const dimensionedScalar rho1,
362  const dimensionedScalar rho2
363  ) const
364  {
366  (
368  (
369  "rhoPhi",
370  (rho1 - rho2)*dVf_/mesh_.time().deltaT() + rho2*phi_
371  )
372  );
373  }
374 
375  scalar advectionTime() const
376  {
377  return advectionTime_;
378  }
379 
380  //- Write isoface points to .obj file
381  void writeIsoFaces
382  (
383  const DynamicList<List<point>>& isoFacePts
384  ) const;
385 };
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 } // End namespace Foam
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 #ifdef NoRepository
394 # include "isoAdvectionTemplates.C"
395 #endif
396 
397 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
398 
399 #endif
400 
401 // ************************************************************************* //
Foam::isoAdvection::~isoAdvection
virtual ~isoAdvection()=default
Destructor.
volFieldsFwd.H
Foam::polyMesh::topoChanging
bool topoChanging() const
Is mesh topology changing.
Definition: polyMesh.H:527
Foam::isoAdvection::TypeName
TypeName("isoAdvection")
Runtime type information.
Foam::isoAdvection::writeSurfaceCells
void writeSurfaceCells() const
Return cellSet of surface cells.
Definition: isoAdvection.C:917
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::TimeState::deltaT
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:54
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::DynamicList< label >
Foam::isoAdvection
Calculates the new VOF (alpha) field after time step dt given the initial VOF field and a velocity fi...
Definition: isoAdvection.H:74
Foam::isoAdvection::applyBruteForceBounding
void applyBruteForceBounding()
Apply the bounding based on user inputs.
Definition: isoAdvection.C:888
surfaceFields.H
Foam::surfaceFields.
alpha1
const volScalarField & alpha1
Definition: setRegionFluidFields.H:8
Foam::isoAdvection::getRhoPhi
tmp< surfaceScalarField > getRhoPhi(const dimensionedScalar rho1, const dimensionedScalar rho2) const
Return mass flux.
Definition: isoAdvection.H:359
isoAdvectionTemplates.C
bitSet.H
Foam::PackedList::resize
void resize(const label nElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:388
Foam::isoAdvection::writeIsoFaces
void writeIsoFaces(const DynamicList< List< point >> &isoFacePts) const
Write isoface points to .obj file.
Definition: isoAdvection.C:969
Foam::isoCutCell
Class for cutting a cell, celli, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Definition: isoCutCell.H:66
Foam::isoAdvection::advectionTime
scalar advectionTime() const
Definition: isoAdvection.H:374
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::label
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:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::DynamicList::clear
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:348
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
rho2
volScalarField & rho2
Definition: setRegionFluidFields.H:30
rho1
volScalarField & rho1
Definition: setRegionFluidFields.H:27
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::dimensioned< scalar >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::isoAdvection::dict
const dictionary & dict() const
Return the controls dictionary.
Definition: isoAdvection.H:346
U
U
Definition: pEqn.H:72
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::isoCutFace
Class for cutting a face, faceI, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Definition: isoCutFace.H:64
Foam::primitiveMesh::nPoints
label nPoints() const
Number of mesh points.
Definition: primitiveMeshI.H:37
Foam::isoAdvection::alpha
const volScalarField & alpha() const
Return alpha field.
Definition: isoAdvection.H:340
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
isoCutCell.H
Foam::isoAdvection::advect
void advect()
Advect the free surface. Updates alpha field, taking into account.
Definition: isoAdvection.C:842
Foam::GeometricField< scalar, fvPatchField, volMesh >
isoCutFace.H
Foam::isoAdvection::writeBoundedCells
void writeBoundedCells() const
Return cellSet of bounded cells.
Definition: isoAdvection.C:941