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  Modified code Copyright (C) 2016-2019 OpenCFD Ltd.
10  Modified code Copyright (C) 2019 DLR
11  Modified code Copyright (C) 2018, 2021 Johan Roenby
12 -------------------------------------------------------------------------------
13 License
14  This file is part of OpenFOAM.
15 
16  OpenFOAM is free software: you can redistribute it and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 
29 Class
30  Foam::isoAdvection
31 
32 Description
33  An implementation of the isoAdvector geometric Volume-of-Fluid method
34  advancing the provided volume fraction field (alpha1) in time using the
35  given velocity field, U, and corresponding face fluxes, phi.
36 
37  References:
38 
39  Main isoAdvector idea:
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  Calculation of rhoPhi:
48  \verbatim
49  Roenby, J., Bredmose, H., & Jasak, H. (2019).
50  IsoAdvector: Geometric VOF on general meshes.
51  OpenFOAMĀ® (pp. 281-296). Springer, Cham.
52  \endverbatim
53 
54  Extension to porous media flows:
55  \verbatim
56  Missios, K., Jacobsen, N. G., Moeller, K., & Roenby, J.
57  Using the isoAdvector Geometric VOF Method for Interfacial Flows
58  Through Porous Media. MARINE 2021.
59  \endverbatim
60 
61  Original code supplied by Johan Roenby, DHI (2016)
62  Modified Henning Scheufler, DLR
63 
64 SourceFiles
65  isoAdvection.C
66  isoAdvectionTemplates.C
67 
68 \*---------------------------------------------------------------------------*/
69 
70 #ifndef isoAdvection_H
71 #define isoAdvection_H
72 
73 #include "fvMesh.H"
74 #include "volFieldsFwd.H"
75 #include "surfaceFields.H"
76 #include "fvc.H"
77 #include "className.H"
78 #include "reconstructionSchemes.H"
79 #include "cutFaceAdvect.H"
80 #include "bitSet.H"
81 #include "zeroField.H"
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 namespace Foam
86 {
87 
88 /*---------------------------------------------------------------------------*\
89  Class isoAdvection Declaration
90 \*---------------------------------------------------------------------------*/
91 
92 class isoAdvection
93 {
94  // Private data types
95 
100 
101 
102  // Private data
103 
104  //- Reference to mesh
105  const fvMesh& mesh_;
106 
107  //- Dictionary for isoAdvection controls
108  const dictionary dict_;
109 
110  //- VOF field
111  volScalarField& alpha1_;
112 
113  //- Often used reference to alpha1 internal field
114  scalarField& alpha1In_;
115 
116  //- Reference to flux field
117  const surfaceScalarField& phi_;
118 
119  //- Reference to velocity field
120  const volVectorField& U_;
121 
122  //- Face volumetric water transport
123  surfaceScalarField dVf_;
124 
125  //- Face volumetric transport
126  surfaceScalarField alphaPhi_;
127 
128  //- Time spent performing interface advection
129  scalar advectionTime_;
130 
131  //- store timeIndex
132  label timeIndex_;
133 
134  // Switches and tolerances. Tolerances need to go into toleranceSwitches
135 
136  //- Number of alpha bounding steps
137  label nAlphaBounds_;
138 
139  //- Tolerance for search of isoFace giving specified VOF value
140  scalar isoFaceTol_;
141 
142  //- Tolerance for marking of surface cells:
143  // Those with surfCellTol_ < alpha1 < 1 - surfCellTol_
144  scalar surfCellTol_;
145 
146  //- Print isofaces in a <case>/isoFaces/isoFaces_#N.vtk files.
147  // Intended for debugging
148  bool writeIsoFacesToFile_;
149 
150  // Cell and face cutting
151 
152  //- List of surface cells
153  DynamicLabelList surfCells_;
154 
155  //- Pointer to reconstruction scheme
157 
158  //- An isoCutFace object to get access to its face cutting functionality
159  cutFaceAdvect advectFace_;
160 
161  //- Storage for boundary faces downwind to a surface cell
162  DynamicLabelList bsFaces_;
163 
164  //- Storage for boundary surface iso face centre
165  DynamicVectorList bsx0_;
166 
167  //- Storage for boundary surface iso face normal
168  DynamicVectorList bsn0_;
169 
170  //- Storage for boundary surface iso face speed
171  DynamicScalarList bsUn0_;
172 
173  //- Switch telling if porosity is enabled
174  bool porosityEnabled_;
175 
176  //- Pointer to porosity field (read from objectRegistry if exists)
177  volScalarField* porosityPtr_;
178 
179  // Additional data for parallel runs
180 
181  //- List of processor patch labels
182  DynamicLabelList procPatchLabels_;
183 
184  //- For each patch if it is a processor patch this is a list of the
185  // face labels on this patch that are downwind to a surface cell.
186  // For non-processor patches the list will be empty.
187  List<DynamicLabelList> surfaceCellFacesOnProcPatches_;
188 
189 
190  // Private Member Functions
191 
192  //- No copy construct
193  isoAdvection(const isoAdvection&) = delete;
194 
195  //- No copy assignment
196  void operator=(const isoAdvection&) = delete;
197 
198 
199  // Advection functions
200 
201  //- Extend markedCell with cell-face-cell.
202  void extendMarkedCells(bitSet& markedCell) const;
203 
204  void setProcessorPatches();
205 
206  //- For each face calculate volumetric face transport during dt
207  void timeIntegratedFlux();
208 
209  //- For a given cell return labels of faces fluxing out of this cell
210  // (based on sign of phi)
211  void setDownwindFaces
212  (
213  const label celli,
214  DynamicLabelList& downwindFaces
215  ) const;
216 
217  // LimitFluxes
218  template < class SpType, class SuType >
219  void limitFluxes
220  (
221  const SpType& Sp,
222  const SuType& Su
223  );
224 
225  // Bound fluxes
226  template < class SpType, class SuType >
227  void boundFlux
228  (
229  const bitSet& nextToInterface,
230  surfaceScalarField& dVfcorrectionValues,
231  DynamicLabelList& correctedFaces,
232  const SpType& Sp,
233  const SuType& Su
234  );
235 
236  //- Given the face volume transport dVf calculates the total volume
237  // leaving a given cell. Note: cannot use dVf member because
238  // netFlux is called also for corrected dVf
239  scalar netFlux
240  (
241  const surfaceScalarField& dVf,
242  const label celli
243  ) const;
244 
245  //- Determine if a cell is a surface cell
246  bool isASurfaceCell(const label celli) const
247  {
248  return
249  (
250  surfCellTol_ < alpha1In_[celli]
251  && alpha1In_[celli] < 1 - surfCellTol_
252  );
253  }
254 
255  //- Clear out isoFace data
256  void clearIsoFaceData()
257  {
258  surfCells_.clear();
259  bsFaces_.clear();
260  bsx0_.clear();
261  bsn0_.clear();
262  bsUn0_.clear();
263 
264  }
265 
266  // Face value functions needed for random face access where the face
267  // can be either internal or boundary face
268 
269  //- Return face value for a given Geometric surface field
270  template<typename Type>
271  Type faceValue
272  (
274  const label facei
275  ) const;
276 
277  //- Set face value for a given Geometric surface field
278  template<typename Type>
279  void setFaceValue
280  (
282  const label facei,
283  const Type& value
284  ) const;
285 
286 
287  // Parallel run handling functions
288 
289  //- Synchronize dVf across processor boundaries using upwind value
290  DynamicList<label> syncProcPatches
291  (
292  surfaceScalarField& dVf,
293  const surfaceScalarField& phi,
294  bool returnSyncedFaces=false
295  );
296 
297  //- Check if the face is on processor patch and append it to the
298  // list of surface cell faces on processor patches
299  void checkIfOnProcPatch(const label facei);
300 
301  //- Apply the bounding based on user inputs
302  void applyBruteForceBounding();
303 
304 public:
305 
306  //- Runtime type information
307  TypeName("isoAdvection");
308 
309  //- Constructors
310 
311  //- Construct given alpha, phi and velocity field. Note: phi should be
312  // divergence free up to a sufficient tolerance
314  (
316  const surfaceScalarField& phi,
317  const volVectorField& U
318  );
319 
320 
321  //- Destructor
322  virtual ~isoAdvection() = default;
323 
324 
325  // Member functions
326 
327  //- Advect the free surface. Updates alpha field, taking into account
328  // multiple calls within a single time step.
329  template < class SpType, class SuType >
330  void advect(const SpType& Sp, const SuType& Su);
331 
332  // Access functions
333 
334  //- Return reconstructionSchemes
335  reconstructionSchemes& surf() noexcept
336  {
337  return surf_();
338  }
339 
340  //- Return alpha field
341  const volScalarField& alpha() const noexcept
342  {
343  return alpha1_;
344  }
345 
346  //- Return the controls dictionary
347  const dictionary& dict() const noexcept
348  {
349  return dict_;
350  }
351 
352  //- Return cellSet of surface cells
353  void writeSurfaceCells() const;
354 
355  //- Return mass flux
357  (
358  const dimensionedScalar rho1,
359  const dimensionedScalar rho2
360  ) const
361  {
363  (
365  (
366  "rhoPhi",
367  (rho1 - rho2)*dVf_/mesh_.time().deltaT() + rho2*phi_
368  )
369  );
370  }
371 
372  //- Return mass flux
374  (
375  const volScalarField& rho1,
376  const volScalarField& rho2
377  )
378  {
380  (
382  (
383  "rhoPhi",
384  fvc::interpolate(rho1 - rho2)*alphaPhi_
385  + fvc::interpolate(rho2)*phi_
386  )
387  );
388  }
389 
390  //- reference to alphaPhi
391  const surfaceScalarField& alphaPhi() const noexcept
392  {
393  return alphaPhi_;
394  }
395 
396  //- time spend in the advection step
397  scalar advectionTime() const noexcept
398  {
399  return advectionTime_;
400  }
401 
402  //- Write isoface points to .obj file
403  void writeIsoFaces
404  (
405  const DynamicList<List<point>>& isoFacePts
406  ) const;
407 };
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 } // End namespace Foam
412 
413 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
414 
415 #ifdef NoRepository
416 # include "isoAdvectionTemplates.C"
417 #endif
418 
419 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 
421 #endif
422 
423 // ************************************************************************* //
cutFaceAdvect.H
Foam::isoAdvection::~isoAdvection
virtual ~isoAdvection()=default
Destructor.
volFieldsFwd.H
Foam::isoAdvection::TypeName
TypeName("isoAdvection")
Runtime type information.
Foam::isoAdvection::writeSurfaceCells
void writeSurfaceCells() const
Return cellSet of surface cells.
Definition: isoAdvection.C:640
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::TimeState::deltaT
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:55
reconstructionSchemes.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
Foam::isoAdvection
An implementation of the isoAdvector geometric Volume-of-Fluid method advancing the provided volume f...
Definition: isoAdvection.H:91
Sp
zeroField Sp
Definition: alphaSuSp.H:2
Foam::isoAdvection::advect
void advect(const SpType &Sp, const SuType &Su)
Advect the free surface. Updates alpha field, taking into account.
Definition: isoAdvectionTemplates.C:392
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:356
Foam::isoAdvection::alpha
const volScalarField & alpha() const noexcept
Return alpha field.
Definition: isoAdvection.H:340
isoAdvectionTemplates.C
bitSet.H
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::isoAdvection::writeIsoFaces
void writeIsoFaces(const DynamicList< List< point >> &isoFacePts) const
Write isoface points to .obj file.
Definition: isoAdvection.C:665
zeroField.H
Su
zeroField Su
Definition: alphaSuSp.H:1
Foam::Field< scalar >
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
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:123
Foam::dimensioned< scalar >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fvc::interpolate
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Foam::cutFaceAdvect
Calculates the face fluxes.
Definition: cutFaceAdvect.H:66
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
U
U
Definition: pEqn.H:72
Foam::isoAdvection::dict
const dictionary & dict() const noexcept
Return the controls dictionary.
Definition: isoAdvection.H:346
Foam::isoAdvection::surf
reconstructionSchemes & surf() noexcept
Return reconstructionSchemes.
Definition: isoAdvection.H:334
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: BitOps.H:63
Foam::isoAdvection::alphaPhi
const surfaceScalarField & alphaPhi() const noexcept
reference to alphaPhi
Definition: isoAdvection.H:390
fvc.H
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::reconstructionSchemes
Original code supplied by Henning Scheufler, DLR (2019)
Definition: reconstructionSchemes.H:58
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::isoAdvection::advectionTime
scalar advectionTime() const noexcept
time spend in the advection step
Definition: isoAdvection.H:396