curvatureSeparation.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) 2011-2018 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 "curvatureSeparation.H"
28 #include "fvMesh.H"
29 #include "Time.H"
30 #include "volFields.H"
31 #include "kinematicSingleLayer.H"
32 #include "surfaceInterpolate.H"
33 #include "fvcDiv.H"
34 #include "fvcGrad.H"
35 #include "stringListOps.H"
36 #include "cyclicPolyPatch.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace regionModels
43 {
44 namespace surfaceFilmModels
45 {
46 
47 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
48 
49 defineTypeNameAndDebug(curvatureSeparation, 0);
51 (
52  injectionModel,
53  curvatureSeparation,
54  dictionary
55 );
56 
57 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
58 
59 tmp<volScalarField> curvatureSeparation::calcInvR1
60 (
61  const volVectorField& U
62 ) const
63 {
64  // method 1
65 /*
66  tmp<volScalarField> tinvR1
67  (
68  new volScalarField("invR1", fvc::div(film().nHat()))
69  );
70 */
71 
72  // method 2
73  dimensionedScalar smallU("smallU", dimVelocity, rootVSmall);
74  volVectorField UHat(U/(mag(U) + smallU));
75  tmp<volScalarField> tinvR1
76  (
77  new volScalarField("invR1", UHat & (UHat & gradNHat_))
78  );
79 
80 
81  scalarField& invR1 = tinvR1.ref().primitiveFieldRef();
82 
83  // apply defined patch radii
84  const scalar rMin = 1e-6;
85  const fvMesh& mesh = film().regionMesh();
86  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
87  forAll(definedPatchRadii_, i)
88  {
89  label patchi = definedPatchRadii_[i].first();
90  scalar definedInvR1 = 1.0/max(rMin, definedPatchRadii_[i].second());
91  UIndirectList<scalar>(invR1, pbm[patchi].faceCells()) = definedInvR1;
92  }
93 
94  // filter out large radii
95  const scalar rMax = 1e6;
96  forAll(invR1, i)
97  {
98  if (mag(invR1[i]) < 1/rMax)
99  {
100  invR1[i] = -1.0;
101  }
102  }
103 
104  if (debug && mesh.time().writeTime())
105  {
106  tinvR1().write();
107  }
108 
109  return tinvR1;
110 }
111 
112 
114 (
115  const surfaceScalarField& phi
116 ) const
117 {
118  const fvMesh& mesh = film().regionMesh();
119  const vectorField nf(mesh.Sf()/mesh.magSf());
120  const unallocLabelList& own = mesh.owner();
121  const unallocLabelList& nbr = mesh.neighbour();
122 
123  scalarField phiMax(mesh.nCells(), -great);
124  scalarField cosAngle(mesh.nCells(), 0.0);
125  forAll(nbr, facei)
126  {
127  label cellO = own[facei];
128  label cellN = nbr[facei];
129 
130  if (phi[facei] > phiMax[cellO])
131  {
132  phiMax[cellO] = phi[facei];
133  cosAngle[cellO] = -gHat_ & nf[facei];
134  }
135  if (-phi[facei] > phiMax[cellN])
136  {
137  phiMax[cellN] = -phi[facei];
138  cosAngle[cellN] = -gHat_ & -nf[facei];
139  }
140  }
141 
142  forAll(phi.boundaryField(), patchi)
143  {
144  const fvsPatchScalarField& phip = phi.boundaryField()[patchi];
145  const fvPatch& pp = phip.patch();
146  const labelList& faceCells = pp.faceCells();
147  const vectorField nf(pp.nf());
148  forAll(phip, i)
149  {
150  label celli = faceCells[i];
151  if (phip[i] > phiMax[celli])
152  {
153  phiMax[celli] = phip[i];
154  cosAngle[celli] = -gHat_ & nf[i];
155  }
156  }
157  }
158 /*
159  // correction for cyclics - use cyclic pairs' face normal instead of
160  // local face normal
161  const fvBoundaryMesh& pbm = mesh.boundary();
162  forAll(phi.boundaryField(), patchi)
163  {
164  if (isA<cyclicPolyPatch>(pbm[patchi]))
165  {
166  const scalarField& phip = phi.boundaryField()[patchi];
167  const vectorField nf(pbm[patchi].nf());
168  const labelList& faceCells = pbm[patchi].faceCells();
169  const label sizeBy2 = pbm[patchi].size()/2;
170 
171  for (label face0=0; face0<sizeBy2; face0++)
172  {
173  label face1 = face0 + sizeBy2;
174  label cell0 = faceCells[face0];
175  label cell1 = faceCells[face1];
176 
177  // flux leaving half 0, entering half 1
178  if (phip[face0] > phiMax[cell0])
179  {
180  phiMax[cell0] = phip[face0];
181  cosAngle[cell0] = -gHat_ & -nf[face1];
182  }
183 
184  // flux leaving half 1, entering half 0
185  if (-phip[face1] > phiMax[cell1])
186  {
187  phiMax[cell1] = -phip[face1];
188  cosAngle[cell1] = -gHat_ & nf[face0];
189  }
190  }
191  }
192  }
193 */
194  // checks
195  if (debug && mesh.time().writeTime())
196  {
197  volScalarField volCosAngle
198  (
199  IOobject
200  (
201  "cosAngle",
202  mesh.time().timeName(),
203  mesh,
205  ),
206  mesh,
207  dimensionedScalar("zero", dimless, 0.0),
208  zeroGradientFvPatchScalarField::typeName
209  );
210  volCosAngle.primitiveFieldRef() = cosAngle;
211  volCosAngle.correctBoundaryConditions();
212  volCosAngle.write();
213  }
214 
215  return max(min(cosAngle, scalar(1)), scalar(-1));
216 }
217 
218 
219 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
220 
221 curvatureSeparation::curvatureSeparation
222 (
224  const dictionary& dict
225 )
226 :
227  injectionModel(type(), film, dict),
228  gradNHat_(fvc::grad(film.nHat())),
229  deltaByR1Min_(coeffDict_.lookupOrDefault<scalar>("deltaByR1Min", 0.0)),
230  definedPatchRadii_(),
231  magG_(mag(film.g().value())),
232  gHat_(Zero)
233 {
234  if (magG_ < rootVSmall)
235  {
237  << "Acceleration due to gravity must be non-zero"
238  << exit(FatalError);
239  }
240 
241  gHat_ = film.g().value()/magG_;
242 
243  List<Tuple2<word, scalar>> prIn(coeffDict_.lookup("definedPatchRadii"));
244  const wordList& allPatchNames = film.regionMesh().boundaryMesh().names();
245 
246  DynamicList<Tuple2<label, scalar>> prData(allPatchNames.size());
247 
248  labelHashSet uniquePatchIDs;
249 
250  forAllReverse(prIn, i)
251  {
252  labelList patchIDs = findStrings(prIn[i].first(), allPatchNames);
253  forAll(patchIDs, j)
254  {
255  const label patchi = patchIDs[j];
256 
257  if (!uniquePatchIDs.found(patchi))
258  {
259  const scalar radius = prIn[i].second();
260  prData.append(Tuple2<label, scalar>(patchi, radius));
261 
262  uniquePatchIDs.insert(patchi);
263  }
264  }
265  }
266 
267  definedPatchRadii_.transfer(prData);
268 }
269 
270 
271 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
272 
274 {}
275 
276 
277 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
278 
280 (
281  scalarField& availableMass,
282  scalarField& massToInject,
283  scalarField& diameterToInject
284 )
285 {
286  const kinematicSingleLayer& film =
287  refCast<const kinematicSingleLayer>(this->film());
288  const fvMesh& mesh = film.regionMesh();
289 
290  const volScalarField& delta = film.delta();
291  const volVectorField& U = film.U();
292  const surfaceScalarField& phi = film.phi();
293  const volScalarField& rho = film.rho();
294  const scalarField magSqrU(magSqr(film.U()));
295  const volScalarField& sigma = film.sigma();
296 
297  const scalarField invR1(calcInvR1(U));
298  const scalarField cosAngle(calcCosAngle(phi));
299 
300  // calculate force balance
301  const scalar Fthreshold = 1e-10;
302  scalarField Fnet(mesh.nCells(), 0.0);
303  scalarField separated(mesh.nCells(), 0.0);
304  forAll(invR1, i)
305  {
306  if ((invR1[i] > 0) && (delta[i]*invR1[i] > deltaByR1Min_))
307  {
308  scalar R1 = 1.0/(invR1[i] + rootVSmall);
309  scalar R2 = R1 + delta[i];
310 
311  // inertial force
312  scalar Fi = -delta[i]*rho[i]*magSqrU[i]*72.0/60.0*invR1[i];
313 
314  // body force
315  scalar Fb =
316  - 0.5*rho[i]*magG_*invR1[i]*(sqr(R1) - sqr(R2))*cosAngle[i];
317 
318  // surface force
319  scalar Fs = sigma[i]/R2;
320 
321  Fnet[i] = Fi + Fb + Fs;
322 
323  if (Fnet[i] + Fthreshold < 0)
324  {
325  separated[i] = 1.0;
326  }
327  }
328  }
329 
330  // inject all available mass
331  massToInject = separated*availableMass;
332  diameterToInject = separated*delta;
333  availableMass -= separated*availableMass;
334 
335  addToInjectedMass(sum(separated*availableMass));
336 
337  if (debug && mesh.time().writeTime())
338  {
339  volScalarField volFnet
340  (
341  IOobject
342  (
343  "Fnet",
344  mesh.time().timeName(),
345  mesh,
347  ),
348  mesh,
349  dimensionedScalar("zero", dimForce, 0.0),
350  zeroGradientFvPatchScalarField::typeName
351  );
352  volFnet.primitiveFieldRef() = Fnet;
353  volFnet.correctBoundaryConditions();
354  volFnet.write();
355  }
356 
358 }
359 
360 
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
362 
363 } // End namespace surfaceFilmModels
364 } // End namespace regionModels
365 } // End namespace Foam
366 
367 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
scalar delta
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
virtual const volVectorField & U() const
Return the film velocity [m/s].
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
const surfaceVectorField & Sf() const
Return cell face area vectors.
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
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:124
Kinematic form of single-cell layer surface film model.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:66
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
tmp< vectorField > nf() const
Return face normals.
Definition: fvPatch.C:124
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
label nCells() const
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
const dimensionedScalar sigma
Stefan-Boltzmann constant: default SI units: [W/m2/K4].
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:440
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Operations on lists of strings.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
tmp< volScalarField > calcInvR1(const volVectorField &U) const
Calculate local (inverse) radius of curvature.
addToRunTimeSelectionTable(surfaceFilmRegionModel, kinematicSingleLayer, mesh)
Macros for easy insertion into run-time selection tables.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
const surfaceFilmRegionModel & film() const
Return const access to the film surface film model.
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:288
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
dynamicFvMesh & mesh
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
Calculate the gradient of the given field.
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:93
wordList names() const
Return a list of patch names.
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
const Type & value() const
Return const reference to value.
virtual const volVectorField & nHat() const
Return the patch normal vectors.
virtual const surfaceScalarField & phi() const
Return the film flux [kg.m/s].
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:61
static const zero Zero
Definition: zero.H:97
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
Foam::polyBoundaryMesh.
Calculate the divergence of the given field.
void addToInjectedMass(const scalar dMass)
Add to injected mass.
const dimensionedVector & g() const
Return the accleration due to gravity.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
const dimensionSet dimForce
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
Base class for film injection models, handling mass transfer from the film.
const volScalarField & delta() const
Return const access to the film thickness [m].
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:282
const fvPatch & patch() const
Return patch.
label patchi
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const volScalarField & sigma() const
Return const access to the surface tension [kg/s2].
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A List with indirect addressing.
Definition: fvMatrix.H:106
dimensioned< scalar > mag(const dimensioned< Type > &)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
virtual const volScalarField & rho() const
Return the film density [kg/m3].
A class for managing temporary objects.
Definition: PtrList.H:53
An indexed form of CGAL::Triangulation_face_base_2<K> used to keep track of the vertices in the trian...
Definition: indexedFace.H:48
void transfer(List< T > &)
Transfer contents of the argument List into this.
Definition: DynamicListI.H:259
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
defineTypeNameAndDebug(kinematicSingleLayer, 0)
scalar deltaByR1Min_
Minimum gravity driven film thickness (non-dimensionalised delta/R1)
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
Namespace for OpenFOAM.
const dimensionSet dimVelocity