curvatureSeparation.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "curvatureSeparation.H"
31 #include "fvMesh.H"
32 #include "Time.H"
33 #include "volFields.H"
34 #include "kinematicSingleLayer.H"
35 #include "surfaceInterpolate.H"
36 #include "fvcDiv.H"
37 #include "fvcGrad.H"
38 #include "stringListOps.H"
39 #include "cyclicPolyPatch.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 namespace regionModels
46 {
47 namespace surfaceFilmModels
48 {
49 
50 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
51 
52 defineTypeNameAndDebug(curvatureSeparation, 0);
54 (
55  injectionModel,
58 );
59 
60 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
61 
63 (
64  const volVectorField& U
65 ) const
66 {
67  // method 1
68 /*
69  tmp<volScalarField> tinvR1
70  (
71  new volScalarField("invR1", fvc::div(film().nHat()))
72  );
73 */
74 
75  // method 2
76  dimensionedScalar smallU("smallU", dimVelocity, ROOTVSMALL);
77  volVectorField UHat(U/(mag(U) + smallU));
78  tmp<volScalarField> tinvR1
79  (
80  new volScalarField("invR1", UHat & (UHat & gradNHat_))
81  );
82 
83 
84  scalarField& invR1 = tinvR1.ref().primitiveFieldRef();
85 
86  // apply defined patch radii
87  const scalar rMin = 1e-6;
88  const fvMesh& mesh = film().regionMesh();
89  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
91  {
92  label patchi = definedPatchRadii_[i].first();
93  scalar definedInvR1 = 1.0/max(rMin, definedPatchRadii_[i].second());
94  UIndirectList<scalar>(invR1, pbm[patchi].faceCells()) = definedInvR1;
95  }
96 
97  // filter out large radii
98  const scalar rMax = 1e6;
99  forAll(invR1, i)
100  {
101  if (mag(invR1[i]) < 1/rMax)
102  {
103  invR1[i] = -1.0;
104  }
105  }
106 
107  if (debug && mesh.time().writeTime())
108  {
109  tinvR1().write();
110  }
111 
112  return tinvR1;
113 }
114 
115 
117 (
118  const surfaceScalarField& phi
119 ) const
120 {
121  const fvMesh& mesh = film().regionMesh();
122  const vectorField nf(mesh.Sf()/mesh.magSf());
123  const labelUList& own = mesh.owner();
124  const labelUList& nbr = mesh.neighbour();
125 
126  scalarField phiMax(mesh.nCells(), -GREAT);
127  scalarField cosAngle(mesh.nCells(), Zero);
128  forAll(nbr, facei)
129  {
130  label cellO = own[facei];
131  label cellN = nbr[facei];
132 
133  if (phi[facei] > phiMax[cellO])
134  {
135  phiMax[cellO] = phi[facei];
136  cosAngle[cellO] = -gHat_ & nf[facei];
137  }
138  if (-phi[facei] > phiMax[cellN])
139  {
140  phiMax[cellN] = -phi[facei];
141  cosAngle[cellN] = -gHat_ & -nf[facei];
142  }
143  }
144 
145  forAll(phi.boundaryField(), patchi)
146  {
147  const fvsPatchScalarField& phip = phi.boundaryField()[patchi];
148  const fvPatch& pp = phip.patch();
149  const labelList& faceCells = pp.faceCells();
150  const vectorField nf(pp.nf());
151  forAll(phip, i)
152  {
153  label celli = faceCells[i];
154  if (phip[i] > phiMax[celli])
155  {
156  phiMax[celli] = phip[i];
157  cosAngle[celli] = -gHat_ & nf[i];
158  }
159  }
160  }
161 /*
162  // correction for cyclics - use cyclic pairs' face normal instead of
163  // local face normal
164  const fvBoundaryMesh& pbm = mesh.boundary();
165  forAll(phi.boundaryField(), patchi)
166  {
167  if (isA<cyclicPolyPatch>(pbm[patchi]))
168  {
169  const scalarField& phip = phi.boundaryField()[patchi];
170  const vectorField nf(pbm[patchi].nf());
171  const labelList& faceCells = pbm[patchi].faceCells();
172  const label sizeBy2 = pbm[patchi].size()/2;
173 
174  for (label face0=0; face0<sizeBy2; face0++)
175  {
176  label face1 = face0 + sizeBy2;
177  label cell0 = faceCells[face0];
178  label cell1 = faceCells[face1];
179 
180  // flux leaving half 0, entering half 1
181  if (phip[face0] > phiMax[cell0])
182  {
183  phiMax[cell0] = phip[face0];
184  cosAngle[cell0] = -gHat_ & -nf[face1];
185  }
186 
187  // flux leaving half 1, entering half 0
188  if (-phip[face1] > phiMax[cell1])
189  {
190  phiMax[cell1] = -phip[face1];
191  cosAngle[cell1] = -gHat_ & nf[face0];
192  }
193  }
194  }
195  }
196 */
197  // checks
198  if (debug && mesh.time().writeTime())
199  {
200  volScalarField volCosAngle
201  (
202  IOobject
203  (
204  "cosAngle",
205  mesh.time().timeName(),
206  mesh,
210  ),
211  mesh,
214  );
215  volCosAngle.primitiveFieldRef() = cosAngle;
216  volCosAngle.correctBoundaryConditions();
217  volCosAngle.write();
218  }
219 
220  return clamp(cosAngle, scalarMinMax(-1, 1));
221 }
222 
223 
224 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
225 
226 curvatureSeparation::curvatureSeparation
227 (
229  const dictionary& dict
230 )
231 :
232  injectionModel(type(), film, dict),
233  gradNHat_(fvc::grad(film.nHat())),
234  deltaByR1Min_(coeffDict_.getOrDefault<scalar>("deltaByR1Min", 0)),
235  definedPatchRadii_(),
236  magG_(mag(film.g().value())),
237  gHat_(Zero)
238 {
239  if (magG_ < ROOTVSMALL)
240  {
242  << "Acceleration due to gravity must be non-zero"
243  << exit(FatalError);
244  }
245 
246  gHat_ = film.g().value()/magG_;
247 
248  List<Tuple2<word, scalar>> prIn(coeffDict_.lookup("definedPatchRadii"));
249  const wordList& allPatchNames = film.regionMesh().boundaryMesh().names();
250 
251  DynamicList<Tuple2<label, scalar>> prData(allPatchNames.size());
252 
253  labelHashSet uniquePatchIDs;
254 
255  forAllReverse(prIn, i)
256  {
257  labelList patchIDs = findIndices(allPatchNames, prIn[i].first());
258  forAll(patchIDs, j)
259  {
260  const label patchi = patchIDs[j];
261 
262  if (!uniquePatchIDs.found(patchi))
263  {
264  const scalar radius = prIn[i].second();
265  prData.append(Tuple2<label, scalar>(patchi, radius));
266 
267  uniquePatchIDs.insert(patchi);
268  }
269  }
270  }
272  definedPatchRadii_.transfer(prData);
273 }
274 
275 
276 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
277 
279 {}
280 
281 
282 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
283 
285 (
286  scalarField& availableMass,
287  scalarField& massToInject,
288  scalarField& diameterToInject
289 )
290 {
291  const kinematicSingleLayer& film =
292  refCast<const kinematicSingleLayer>(this->film());
293  const fvMesh& mesh = film.regionMesh();
294 
295  const volScalarField& delta = film.delta();
296  const volVectorField& U = film.U();
297  const surfaceScalarField& phi = film.phi();
298  const volScalarField& rho = film.rho();
299  const scalarField magSqrU(magSqr(film.U()));
300  const volScalarField& sigma = film.sigma();
301 
302  const scalarField invR1(calcInvR1(U));
303  const scalarField cosAngle(calcCosAngle(phi));
304 
305  // calculate force balance
306  const scalar Fthreshold = 1e-10;
307  scalarField Fnet(mesh.nCells(), Zero);
308  scalarField separated(mesh.nCells(), Zero);
309  forAll(invR1, i)
310  {
311  if ((invR1[i] > 0) && (delta[i]*invR1[i] > deltaByR1Min_))
312  {
313  scalar R1 = 1.0/(invR1[i] + ROOTVSMALL);
314  scalar R2 = R1 + delta[i];
315 
316  // inertial force
317  scalar Fi = -delta[i]*rho[i]*magSqrU[i]*72.0/60.0*invR1[i];
318 
319  // body force
320  scalar Fb =
321  - 0.5*rho[i]*magG_*invR1[i]*(sqr(R1) - sqr(R2))*cosAngle[i];
322 
323  // surface force
324  scalar Fs = sigma[i]/R2;
325 
326  Fnet[i] = Fi + Fb + Fs;
327 
328  if (Fnet[i] + Fthreshold < 0)
329  {
330  separated[i] = 1.0;
331  }
332  }
333  }
334 
335  // inject all available mass
336  massToInject = separated*availableMass;
337  diameterToInject = separated*delta;
338  availableMass -= separated*availableMass;
339 
340  addToInjectedMass(sum(separated*availableMass));
341 
342  if (debug && mesh.time().writeTime())
343  {
344  volScalarField volFnet
345  (
346  IOobject
347  (
348  "Fnet",
349  mesh.time().timeName(),
350  mesh,
354  ),
355  mesh,
358  );
359  volFnet.primitiveFieldRef() = Fnet;
360  volFnet.correctBoundaryConditions();
361  volFnet.write();
362  }
363 
365 }
366 
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 } // End namespace surfaceFilmModels
371 } // End namespace regionModels
372 } // End namespace Foam
373 
374 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
List< Tuple2< label, scalar > > definedPatchRadii_
List of radii for patches - if patch not defined, radius.
scalar delta
const labelList patchIDs(pbm.indices(polyPatchNames, true))
fvsPatchField< scalar > fvsPatchScalarField
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
Definition: dictionary.C:367
const polyBoundaryMesh & pbm
const Type & value() const noexcept
Return const reference to value.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:97
tmp< scalarField > calcCosAngle(const surfaceScalarField &phi) const
Calculate the cosine of the angle between gravity vector and.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Kinematic form of single-cell layer surface film model.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool found(const T &val, label pos=0) const
Same as contains()
Definition: UList.H:879
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
Operations on lists of strings.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
tmp< volScalarField > calcInvR1(const volVectorField &U) const
Calculate local (inverse) radius of curvature.
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:92
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
virtual const volScalarField & rho() const =0
Return the film density [kg/m3].
addToRunTimeSelectionTable(surfaceFilmRegionModel, kinematicSingleLayer, mesh)
Macros for easy insertion into run-time selection tables.
const surfaceFilmRegionModel & film() const
Return const access to the film surface film model.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dynamicFvMesh & mesh
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
Calculate the gradient of the given field.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
wordList names() const
Return a list of patch names.
virtual const volScalarField & delta() const =0
Return the film thickness [m].
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:26
virtual const volVectorField & U() const =0
Return the film velocity [m/s].
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
Calculate the divergence of the given field.
void addToInjectedMass(const scalar dMass)
Add to injected mass.
const dimensionedVector & g() const
Return the acceleration due to gravity.
const uniformDimensionedVectorField & g
const dimensionSet dimForce
int debug
Static debugging option.
Base class for film injection models, handling mass transfer from the film.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
U
Definition: pEqn.H:72
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
Nothing to be read.
Field< vector > vectorField
Specialisation of Field<T> for vector.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:437
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
An indexed form of CGAL::Triangulation_face_base_2<K> used to keep track of the vertices in the trian...
Definition: indexedFace.H:43
volTensorField gradNHat_
Gradient of surface normals.
virtual const volScalarField & sigma() const =0
Return the film surface tension [N/m].
defineTypeNameAndDebug(kinematicSingleLayer, 0)
scalar deltaByR1Min_
Minimum gravity driven film thickness (non-dimensionalised delta/R1)
Do not request registration (bool: false)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:51
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
Definition: dimensionSet.C:271
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
const dimensionSet dimVelocity