contactAngleForce.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) 2018-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "contactAngleForce.H"
31#include "fvcGrad.H"
32#include "unitConversion.H"
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace regionModels
40{
41namespace surfaceFilmModels
42{
43
44// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45
47
48// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
49
50void contactAngleForce::initialise()
51{
52 const wordRes zeroForcePatches
53 (
54 coeffDict_.getOrDefault<wordRes>("zeroForcePatches", wordRes())
55 );
56
57 if (zeroForcePatches.size())
58 {
60 const scalar dLim = coeffDict_.get<scalar>("zeroForceDistance");
61
62 Info<< " Assigning zero contact force within " << dLim
63 << " of patches:" << endl;
64
65 labelHashSet patchIDs = pbm.patchSet(zeroForcePatches);
66
67 for (const label patchi : patchIDs)
68 {
69 Info<< " " << pbm[patchi].name() << endl;
70 }
71
72 // Temporary implementation until run-time selection covers this case
75 (
77 (
78 "y",
83 false
84 ),
86 dimensionedScalar("y", dimLength, GREAT)
87 );
88 dist.correct(y);
89
90 mask_ = pos0(y - dimensionedScalar("dLim", dimLength, dLim));
91 }
92}
93
94
95// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96
98(
99 const word& typeName,
101 const dictionary& dict
102)
103:
104 force(typeName, film, dict),
105 Ccf_(coeffDict_.get<scalar>("Ccf")),
106 mask_
107 (
109 (
110 typeName + ":contactForceMask",
111 filmModel_.time().timeName(),
112 filmModel_.regionMesh(),
113 IOobject::NO_READ,
114 IOobject::NO_WRITE
115 ),
116 filmModel_.regionMesh(),
117 dimensionedScalar("mask", dimless, 1.0)
118 )
119{
120 initialise();
121}
122
123
124// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125
127{}
128
129
130// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
131
133{
135 (
137 (
139 (
140 typeName + ":contactForce",
145 ),
148 )
149 );
150
151 vectorField& force = tForce.ref().primitiveFieldRef();
152
153 const labelUList& own = filmModel_.regionMesh().owner();
154 const labelUList& nbr = filmModel_.regionMesh().neighbour();
155
156 const scalarField& magSf = filmModel_.magSf();
157
159 const volScalarField& sigma = filmModel_.sigma();
160
161 const tmp<volScalarField> ttheta = theta();
162 const volScalarField& theta = ttheta();
163
164 const volVectorField gradAlpha(fvc::grad(alpha));
165
166 forAll(nbr, facei)
167 {
168 const label cellO = own[facei];
169 const label cellN = nbr[facei];
170
171 label celli = -1;
172 if ((alpha[cellO] > 0.5) && (alpha[cellN] < 0.5))
173 {
174 celli = cellO;
175 }
176 else if ((alpha[cellO] < 0.5) && (alpha[cellN] > 0.5))
177 {
178 celli = cellN;
179 }
180
181 if (celli != -1 && mask_[celli] > 0.5)
182 {
183 const scalar invDx = filmModel_.regionMesh().deltaCoeffs()[facei];
184 const vector n =
185 gradAlpha[celli]/(mag(gradAlpha[celli]) + ROOTVSMALL);
186 const scalar cosTheta = cos(degToRad(theta[celli]));
187 force[celli] += Ccf_*n*sigma[celli]*(1 - cosTheta)/invDx;
188 }
189 }
190
191 forAll(alpha.boundaryField(), patchi)
192 {
193 if (!filmModel_.isCoupledPatch(patchi))
194 {
195 const fvPatchField<scalar>& alphaPf = alpha.boundaryField()[patchi];
196 const fvPatchField<scalar>& maskPf = mask_.boundaryField()[patchi];
197 const fvPatchField<scalar>& sigmaPf = sigma.boundaryField()[patchi];
198 const fvPatchField<scalar>& thetaPf = theta.boundaryField()[patchi];
199 const scalarField& invDx = alphaPf.patch().deltaCoeffs();
200 const labelUList& faceCells = alphaPf.patch().faceCells();
201
202 forAll(alphaPf, facei)
203 {
204 if (maskPf[facei] > 0.5)
205 {
206 label cellO = faceCells[facei];
207
208 if ((alpha[cellO] > 0.5) && (alphaPf[facei] < 0.5))
209 {
210 const vector n =
211 gradAlpha[cellO]
212 /(mag(gradAlpha[cellO]) + ROOTVSMALL);
213 const scalar cosTheta = cos(degToRad(thetaPf[facei]));
214 force[cellO] +=
215 Ccf_*n*sigmaPf[facei]*(1 - cosTheta)/invDx[facei];
216 }
217 }
218 }
219 }
220 }
221
222 force /= magSf;
223
225 {
226 tForce().write();
227 }
228
230 (
232 );
233
234 tfvm.ref() += tForce;
235
236 return tfvm;
237}
238
239
240// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241
242} // End namespace surfaceFilmModels
243} // End namespace regionModels
244} // End namespace Foam
245
246// ************************************************************************* //
scalar y
label n
Macros for easy insertion into run-time selection tables.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
virtual void correct()
Solve the turbulence equations and correct the turbulence viscosity.
bool writeTime() const noexcept
True if this is a write time.
Definition: TimeStateI.H:67
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition: fvMesh.H:417
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:423
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:362
const scalarField & deltaCoeffs() const
Definition: fvPatch.C:196
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:113
Fast topological mesh-wave method for calculating the distance to nearest patch for all cells and bou...
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
Base-class for film contact angle force models.
const Time & time() const
Return the reference to the time database.
Definition: regionModelI.H:40
bool isCoupledPatch(const label regionPatchi) const
Return true if patchi on the local region is a coupled.
Definition: regionModelI.H:134
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:64
virtual const volScalarField & magSf() const
Return the face area magnitudes / [m2].
Base-class for film contact angle force models.
virtual tmp< volScalarField > theta() const =0
Return the contact angle field.
surfaceFilmRegionModel & filmModel_
Reference to the film surface film model.
Base class for film (stress-based) force models.
Definition: force.H:60
virtual const volScalarField & sigma() const =0
Return the film surface tension [N/m].
virtual const volScalarField & alpha() const =0
Return the film coverage, 1 = covered, 0 = uncovered / [].
const dictionary coeffDict_
Coefficients dictionary.
Definition: subModelBase.H:82
virtual const surfaceScalarField & deltaCoeffs() const
Return reference to cell-centre difference coefficients.
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
U
Definition: pEqn.H:72
Calculate the gradient of the given field.
word timeName
Definition: getTimeIndex.H:3
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Namespace for OpenFOAM.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet dimless
Dimensionless.
dimensionedScalar pos0(const dimensionedScalar &ds)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:59
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fvMatrix< vector > fvVectorMatrix
Definition: fvMatricesFwd.H:46
const dimensionSet dimForce
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:60
dimensionedScalar cos(const dimensionedScalar &ds)
volScalarField & alpha
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Unit conversion functions.