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) 2018 Johan Roenby
11  Modified code Copyright (C) 2019 DLR
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  Calculates the new VOF (alpha) field after time step dt given the initial
34  VOF field and a velocity field U and face fluxes phi. The fluid transport
35  calculation is based on an idea of using isosurfaces to estimate the
36  internal distribution of fluid in cells and advecting such isosurfaces
37  across the mesh faces with the velocity field interpolated to the
38  isosurfaces.
39 
40  Reference:
41  \verbatim
42  Roenby, J., Bredmose, H. and Jasak, H. (2016).
43  A computational method for sharp interface advection
44  Royal Society Open Science, 3
45  doi 10.1098/rsos.160405
46  \endverbatim
47 
48  Original code supplied by Johan Roenby, DHI (2016)
49  Modified Henning Scheufler, DLR
50 
51 SourceFiles
52  isoAdvection.C
53  isoAdvectionTemplates.C
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #ifndef isoAdvection_H
58 #define isoAdvection_H
59 
60 #include "fvMesh.H"
61 #include "volFieldsFwd.H"
62 #include "surfaceFields.H"
63 #include "fvc.H"
64 #include "className.H"
65 #include "reconstructionSchemes.H"
66 #include "cutFaceAdvect.H"
67 #include "bitSet.H"
68 #include "zeroField.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class isoAdvection Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 class isoAdvection
80 {
81  // Private data types
82 
87 
88 
89  // Private data
90 
91  //- Reference to mesh
92  const fvMesh& mesh_;
93 
94  //- Dictionary for isoAdvection controls
95  const dictionary dict_;
96 
97  //- VOF field
98  volScalarField& alpha1_;
99 
100  //- Often used reference to alpha1 internal field
101  scalarField& alpha1In_;
102 
103  //- Reference to flux field
104  const surfaceScalarField& phi_;
105 
106  //- Reference to velocity field
107  const volVectorField& U_;
108 
109  //- Face volumetric water transport
110  surfaceScalarField dVf_;
111 
112  //- Face volumetric transport
113  surfaceScalarField alphaPhi_;
114 
115  //- Time spent performing interface advection
116  scalar advectionTime_;
117 
118 
119  // Switches and tolerances. Tolerances need to go into toleranceSwitches
120 
121  //- Number of alpha bounding steps
122  label nAlphaBounds_;
123 
124  //- Tolerance for search of isoFace giving specified VOF value
125  scalar isoFaceTol_;
126 
127  //- Tolerance for marking of surface cells:
128  // Those with surfCellTol_ < alpha1 < 1 - surfCellTol_
129  scalar surfCellTol_;
130 
131  //- Print isofaces in a <case>/isoFaces/isoFaces_#N.vtk files.
132  // Intended for debugging
133  bool writeIsoFacesToFile_;
134 
135  // Cell and face cutting
136 
137  //- List of surface cells
138  DynamicLabelList surfCells_;
139 
140  //- Pointer to reconstruction scheme
142 
143  //- An isoCutFace object to get access to its face cutting functionality
144  cutFaceAdvect advectFace_;
145 
146  //- Storage for boundary faces downwind to a surface cell
147  DynamicLabelList bsFaces_;
148 
149  //- Storage for boundary surface iso face centre
150  DynamicVectorList bsx0_;
151 
152  //- Storage for boundary surface iso face normal
153  DynamicVectorList bsn0_;
154 
155  //- Storage for boundary surface iso face speed
156  DynamicScalarList bsUn0_;
157 
158 
159 
160  // Additional data for parallel runs
161 
162  //- List of processor patch labels
163  DynamicLabelList procPatchLabels_;
164 
165  //- For each patch if it is a processor patch this is a list of the
166  // face labels on this patch that are downwind to a surface cell.
167  // For non-processor patches the list will be empty.
168  List<DynamicLabelList> surfaceCellFacesOnProcPatches_;
169 
170 
171  // Private Member Functions
172 
173  //- No copy construct
174  isoAdvection(const isoAdvection&) = delete;
175 
176  //- No copy assignment
177  void operator=(const isoAdvection&) = delete;
178 
179 
180  // Advection functions
181 
182  //- For each face calculate volumetric face transport during dt
183  void timeIntegratedFlux();
184 
185  //- For a given cell return labels of faces fluxing out of this cell
186  // (based on sign of phi)
187  void setDownwindFaces
188  (
189  const label celli,
190  DynamicLabelList& downwindFaces
191  ) const;
192 
193  // LimitFluxes
194  template < class SpType, class SuType >
195  void limitFluxes
196  (
197  const SpType& Sp,
198  const SuType& Su
199  );
200 
201  // Bound fluxes
202  template < class SpType, class SuType >
203  void boundFlux
204  (
205  const scalarField& alpha1,
206  surfaceScalarField& dVfcorrectionValues,
207  DynamicLabelList& correctedFaces,
208  const SpType& Sp,
209  const SuType& Su
210  );
211 
212  //- Given the face volume transport dVf calculates the total volume
213  // leaving a given cell. Note: cannot use dVf member because
214  // netFlux is called also for corrected dVf
215  scalar netFlux
216  (
217  const surfaceScalarField& dVf,
218  const label celli
219  ) const;
220 
221  //- Determine if a cell is a surface cell
222  bool isASurfaceCell(const label celli) const
223  {
224  return
225  (
226  surfCellTol_ < alpha1In_[celli]
227  && alpha1In_[celli] < 1 - surfCellTol_
228  );
229  }
230 
231  //- Clear out isoFace data
232  void clearIsoFaceData()
233  {
234  surfCells_.clear();
235  bsFaces_.clear();
236  bsx0_.clear();
237  bsn0_.clear();
238  bsUn0_.clear();
239 
240  }
241 
242  // Face value functions needed for random face access where the face
243  // can be either internal or boundary face
244 
245  //- Return face value for a given Geometric surface field
246  template<typename Type>
247  Type faceValue
248  (
250  const label facei
251  ) const;
252 
253  //- Set face value for a given Geometric surface field
254  template<typename Type>
255  void setFaceValue
256  (
258  const label facei,
259  const Type& value
260  ) const;
261 
262 
263  // Parallel run handling functions
264 
265  //- Synchronize dVf across processor boundaries using upwind value
266  DynamicList<label> syncProcPatches
267  (
268  surfaceScalarField& dVf,
269  const surfaceScalarField& phi,
270  bool returnSyncedFaces=false
271  );
272 
273  //- Check if the face is on processor patch and append it to the
274  // list of surface cell faces on processor patches
275  void checkIfOnProcPatch(const label facei);
276 
277 
278 public:
279 
280  //- Runtime type information
281  TypeName("isoAdvection");
282 
283  //- Constructors
284 
285  //- Construct given alpha, phi and velocity field. Note: phi should be
286  // divergence free up to a sufficient tolerance
288  (
290  const surfaceScalarField& phi,
291  const volVectorField& U
292  );
293 
294 
295  //- Destructor
296  virtual ~isoAdvection() = default;
297 
298 
299  // Member functions
300 
301  //- Advect the free surface. Updates alpha field, taking into account
302  // multiple calls within a single time step.
303  template < class SpType, class SuType >
304  void advect(const SpType& Sp, const SuType& Su);
305 
306  //- Apply the bounding based on user inputs
308 
309  // Access functions
310 
311  //- Return reconstructionSchemes
313  {
314  return surf_();
315  }
316 
317  //- Return alpha field
318  const volScalarField& alpha() const
319  {
320  return alpha1_;
321  }
322 
323  //- Return the controls dictionary
324  const dictionary& dict() const
325  {
326  return dict_;
327  }
328 
329  //- Return cellSet of surface cells
330  void writeSurfaceCells() const;
331 
332  //- Return mass flux
334  (
335  const dimensionedScalar rho1,
336  const dimensionedScalar rho2
337  ) const
338  {
340  (
342  (
343  "rhoPhi",
344  (rho1 - rho2)*dVf_/mesh_.time().deltaT() + rho2*phi_
345  )
346  );
347  }
348 
349  //- Return mass flux
351  (
352  const volScalarField& rho1,
353  const volScalarField& rho2
354  )
355  {
357  (
359  (
360  "rhoPhi",
361  fvc::interpolate(rho1 - rho2)*alphaPhi_
362  + fvc::interpolate(rho2)*phi_
363  )
364  );
365  }
366 
367  //- reference to alphaPhi
368  const surfaceScalarField& alphaPhi() const
369  {
370  return alphaPhi_;
371  }
372 
373  //- time spend in the advection step
374  scalar advectionTime() const
375  {
376  return advectionTime_;
377  }
378 
379  //- Write isoface points to .obj file
380  void writeIsoFaces
381  (
382  const DynamicList<List<point>>& isoFacePts
383  ) const;
384 };
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #ifdef NoRepository
393 # include "isoAdvectionTemplates.C"
394 #endif
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #endif
399 
400 // ************************************************************************* //
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:548
Foam::TimeState::deltaT
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:54
reconstructionSchemes.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
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:78
Sp
zeroField Sp
Definition: alphaSuSp.H:2
Foam::isoAdvection::alphaPhi
const surfaceScalarField & alphaPhi() const
reference to alphaPhi
Definition: isoAdvection.H:367
Foam::isoAdvection::applyBruteForceBounding
void applyBruteForceBounding()
Apply the bounding based on user inputs.
Definition: isoAdvection.C:519
Foam::isoAdvection::advect
void advect(const SpType &Sp, const SuType &Su)
Advect the free surface. Updates alpha field, taking into account.
Definition: isoAdvectionTemplates.C:366
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:333
isoAdvectionTemplates.C
bitSet.H
Foam::isoAdvection::writeIsoFaces
void writeIsoFaces(const DynamicList< List< point >> &isoFacePts) const
Write isoface points to .obj file.
Definition: isoAdvection.C:572
zeroField.H
Su
zeroField Su
Definition: alphaSuSp.H:1
Foam::isoAdvection::advectionTime
scalar advectionTime() const
time spend in the advection step
Definition: isoAdvection.H:373
Foam::Field< scalar >
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:83
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::isoAdvection::surf
reconstructionSchemes & surf()
Return reconstructionSchemes.
Definition: isoAdvection.H:311
Foam::cutFaceAdvect
Calculates the face fluxes.
Definition: cutFaceAdvect.H:66
Foam::isoAdvection::dict
const dictionary & dict() const
Return the controls dictionary.
Definition: isoAdvection.H:323
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
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::alpha
const volScalarField & alpha() const
Return alpha field.
Definition: isoAdvection.H:317
fvc.H
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
Foam::reconstructionSchemes
Original code supplied by Henning Scheufler, DLR (2019)
Definition: reconstructionSchemes.H:58
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53