MPLIC.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) 2020 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 "MPLIC.H"
27 #include "MPLICcell.H"
28 #include "volPointInterpolation.H"
29 #include "syncTools.H"
30 #include "slicedSurfaceFields.H"
31 #include "upwind.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(MPLIC, 0);
38 
39  surfaceInterpolationScheme<scalar>::addMeshFluxConstructorToTable<MPLIC>
41 }
42 
43 
44 // * * * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * //
45 
47 (
48  const label celli,
49  const scalarField& phi,
50  scalarField& alphaf,
51  boolList& correctedFaces,
52  const DynamicList<scalar>& cellAlphaf,
53  const fvMesh& mesh
54 ) const
55 {
56  // Face owners reference
57  const labelList& own = mesh.faceOwner();
58 
59  // The cell face labels
60  const labelList& cFaces = mesh.cells()[celli];
61 
62  // Fill the alphaf with surface interpolation in direction of the flow
63  forAll(cFaces, i)
64  {
65  const label facei = cFaces[i];
66  const scalar phiSigni = sign(phi[facei]);
67 
68  if
69  (
70  (own[facei] == celli && phiSigni == 1)
71  || (own[facei] != celli && phiSigni == -1)
72  )
73  {
74  alphaf[facei] = cellAlphaf[i];
75  correctedFaces[facei] = true;
76  }
77  }
78 }
79 
80 
82 (
83  const volScalarField& alpha,
84  const surfaceScalarField& phi,
85  scalarField& initAlphaf,
86  const bool unweighted,
87  const scalar tol,
88  const bool isMPLIC
89 ) const
90 {
91  // Finite volume mesh reference
92  const fvMesh& mesh = alpha.mesh();
93 
94  // Reference to primitive mesh
95  const primitiveMesh& primMesh = mesh;
96 
97  // Velocity field reference
98  const volVectorField& U
99  (
100  mesh.lookupObject<const volVectorField>
101  (
102  IOobject::groupName("U", phi.group())
103  )
104  );
105 
106  // Interpolate alpha from volume to the points of the mesh
107  const scalarField alphap
108  (
110  );
111 
112  // Interpolate U from cell centres to the points of the mesh
113  vectorField Up;
114 
115  if (!unweighted)
116  {
118  }
119 
120  // Flatten down phi flux field
121  const scalarField spicedPhi
122  (
124  (
125  IOobject
126  (
127  "splicedPhi",
128  mesh.time().timeName(),
129  mesh
130  ),
131  phi,
132  false
133  ).splice()
134  );
135 
136  scalarField alphaf(mesh.nFaces(), 0);
137 
138  // Mark which faces are corrected by MPLIC
139  boolList correctedFaces(mesh.nFaces(), false);
140 
141  // Construct class for cell cut
142  MPLICcell cutCell(unweighted, isMPLIC);
143 
144  // Loop through all the cells
145  forAll(mesh.cells(), celli)
146  {
147  if (alpha[celli] < (1 - tol) && alpha[celli] > tol)
148  {
149  // Store cell information
151  (
152  primMesh,
153  alphap,
154  Up,
155  alpha[celli],
156  U[celli],
157  celli
158  );
159 
160  // Volume ratio matching algorithm
161  if (cutCell.matchAlpha(cellInfo))
162  {
163  // Fill cutCell.alphaf() with face values from this cell
164  setCellAlphaf
165  (
166  celli,
167  spicedPhi,
168  alphaf,
169  correctedFaces,
170  cutCell.alphaf(),
171  mesh
172  );
173  }
174  }
175  }
176 
177  // Synchronise across the processor and cyclic patches
178  syncTools::syncFaceList(mesh, alphaf, plusEqOp<scalar>());
179  syncTools::syncFaceList(mesh, correctedFaces, plusEqOp<bool>());
180 
181  // Correct selected faces
182  forAll(correctedFaces, facei)
183  {
184  if (correctedFaces[facei])
185  {
186  initAlphaf[facei] = alphaf[facei];
187  }
188  }
189 
190  // Convert the alphaPhi spliced field into a surfaceScalarField
191  tmp<surfaceScalarField> tslicedAlpha
192  (
194  (
195  "alphaf",
197  (
198  IOobject
199  (
200  "alphaf",
201  mesh.time().timeName(),
202  mesh
203  ),
204  mesh,
205  dimless,
206  initAlphaf,
207  false
208  ),
210  )
211  );
212  surfaceScalarField& slicedAlpha = tslicedAlpha.ref();
213 
214  forAll(mesh.boundary(), patchi)
215  {
216  if (alpha.boundaryField()[patchi].fixesValue())
217  {
218  slicedAlpha.boundaryFieldRef()[patchi] =
219  alpha.boundaryField()[patchi];
220  }
221  }
222 
223  return tslicedAlpha;
224 }
225 
226 
227 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
228 
230 (
232 ) const
233 {
235 
236  scalarField spicedTvff
237  (
239  (
240  IOobject
241  (
242  "spicedTvff",
243  mesh().time().timeName(),
244  mesh()
245  ),
246  tvff,
247  false
248  ).splice()
249  );
250 
251  return surfaceAlpha(vf, phi_, spicedTvff, true, 1e-6);
252 }
253 
254 
255 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
static word group(const word &name)
Return group (extension part of name)
Definition: IOobject.C:144
tmp< GeometricField< Type, pointPatchField, pointMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate volField using inverse distance weighting.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
label nFaces() const
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
static tmp< GeometricField< scalar, fvsPatchField, surfaceMesh > > New(const word &name, const Internal &, const PtrList< fvsPatchField< scalar >> &)
Return a temporary field constructed from name,.
void setCellAlphaf(const label celli, const scalarField &phi, scalarField &alphaf, boolList &correctedFaces, const DynamicList< scalar > &cellAlphaf, const fvMesh &mesh) const
Set alphaPhi for the faces of the given cell.
Definition: MPLIC.C:47
const cellList & cells() const
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:622
Holds information regarding type of cell. Used in inside/outside determination in cellClassification...
Definition: cellInfo.H:63
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
Provides local cell addressing for geometry and data for MPLIC class.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
tmp< surfaceScalarField > surfaceAlpha(const volScalarField &alpha, const surfaceScalarField &phi, scalarField &spicedTvff, const bool unweighted, const scalar tol, const bool isMPLIC=true) const
Return alpha interpolation.
Definition: MPLIC.C:82
static const volPointInterpolation & New(const fvMesh &mesh)
Definition: MeshObject.C:44
Class performs geometric matching of volume fraction and calculates surface interpolation of volume f...
Definition: MPLICcell.H:55
virtual tmp< surfaceScalarField > interpolate(const GeometricField< scalar, fvPatchField, volMesh > &vf) const
Return the face-interpolate of the given cell field.
Definition: MPLIC.C:230
dynamicFvMesh & mesh
surfaceInterpolationScheme< scalar >::addMeshFluxConstructorToTable< MPLIC > addMPLICScalarMeshFluxConstructorToTable_
Definition: MPLIC.C:40
static word groupName(Name name, const word &group)
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1169
word timeName
Definition: getTimeIndex.H:3
const Mesh & mesh() const
Return mesh.
defineTypeNameAndDebug(combustionModel, 0)
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:381
label patchi
U
Definition: pEqn.H:72
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
Upwind differencing scheme class.
Definition: upwind.H:51
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
tmp< Field< Type > > splice() const
Splice the sliced field and return the complete field.
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
A class for managing temporary objects.
Definition: PtrList.H:53
static const word & calculatedType()
Return the type of the calculated for of fvsPatchField.
Specialization of GeometricField which holds slices of given complete fields in a form that they act ...
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:540