Loading...
Searching...
No Matches
advectionDiffusionPatchDistMethod.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) 2015-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2020 OpenCFD Ltd.
10 Copyright (C) 2020-2023 PCOpt/NTUA
11 Copyright (C) 2020-2023 FOSS GP
12-------------------------------------------------------------------------------
13License
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\*---------------------------------------------------------------------------*/
30
32#include "surfaceInterpolate.H"
33#include "fvcGrad.H"
34#include "fvcDiv.H"
35#include "fvmDiv.H"
36#include "fvmLaplacian.H"
37#include "fvmSup.H"
38#include "fvOptions.H"
40
44// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45
46namespace Foam
47{
48namespace patchDistMethods
49{
50 defineTypeNameAndDebug(advectionDiffusion, 0);
52}
53}
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
57Foam::patchDistMethods::advectionDiffusion::advectionDiffusion
58(
59 const dictionary& dict,
60 const fvMesh& mesh,
62)
63:
65 //- We do not want to recurse into 'advectionDiffusion' again so
66 // make sure we pick up 'method' always from the subdictionary.
67 //coeffs_(dict.optionalSubDict(type() + "Coeffs")),
68 coeffs_(dict.subDict(type() + "Coeffs")),
69 pdmPredictor_
70 (
72 (
73 coeffs_,
74 mesh,
76 )
77 ),
78 epsilon_(coeffs_.getOrDefault<scalar>("epsilon", 0.1)),
79 tolerance_(coeffs_.getOrDefault<scalar>("tolerance", 1e-3)),
80 maxIter_(coeffs_.getOrDefault<int>("maxIter", 10)),
81 predicted_(false),
82 checkAndWriteMesh_(coeffs_.getOrDefault("checkAndWriteMesh", false))
83{}
85
86// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87
89{
90 return correct(y, volVectorField::null().constCast());
91}
92
93
95(
98)
99{
100 if (!predicted_)
101 {
102 pdmPredictor_->correct(y);
103 predicted_ = true;
104 }
105
106 // If the mesh has become invalid, trying to solve the eikonal equation
107 // might lead to crashing and we wont get a chance to see the failed mesh.
108 // Write the mesh points here
109 if (checkAndWriteMesh_)
110 {
112 << "Checking mesh in advectionDiffusion " << endl;
113 if (mesh_.checkMesh(true))
114 {
116 (
118 (
119 "points",
120 mesh_.pointsInstance(),
122 mesh_,
126 ),
127 mesh_.points()
128 );
129 points.write();
130 }
131 }
132
134 (
135 IOobject
136 (
137 "ny",
138 mesh_.time().timeName(),
139 mesh_,
143 ),
144 mesh_,
146 patchTypes<vector>(mesh_, patchIDs_)
147 );
148
149 const fvPatchList& patches = mesh_.boundary();
150 volVectorField::Boundary& nybf = ny.boundaryFieldRef();
151
152 for (const label patchi : patchIDs_)
153 {
154 nybf[patchi] == -patches[patchi].nf();
155 }
156
157 // Scaling dimensions, to be used with fvOptions
158 volScalarField scaleDims
159 (
160 IOobject
161 (
162 "scaleDims",
163 mesh_.time().timeName(),
164 mesh_,
168 ),
169 mesh_,
170 dimensionedScalar("scaleDims", dimTime/dimLength, scalar(1))
171 );
172
173 fv::options& fvOptions(fv::options::New(this->mesh_));
174 int iter = 0;
175 scalar initialResidual = 0;
176
177 do
178 {
179 ny = fvc::grad(y);
180 ny /= (mag(ny) + SMALL);
181
183 nf /= (mag(nf) + SMALL);
184
185 surfaceScalarField yPhi("yPhi", mesh_.Sf() & nf);
186
187 fvScalarMatrix yEqn
188 (
189 fvm::div(yPhi, y)
190 + fvm::SuSp(-fvc::div(yPhi), y)
191 - epsilon_*y*fvm::laplacian(y)
192 ==
193 dimensionedScalar("1", dimless, 1.0)
194 + fvOptions(scaleDims, y)
195 );
196
197 yEqn.relax();
198 fvOptions.constrain(yEqn);
199 initialResidual = yEqn.solve().initialResidual();
200 fvOptions.correct(y);
201
202 } while (initialResidual > tolerance_ && ++iter < maxIter_);
203
204 // Need to stabilise the y for overset meshes since the holed cells
205 // keep the initial value (0.0) so the gradient of that will be
206 // zero as well. Turbulence models do not like zero wall distance.
207 y.clamp_min(SMALL);
208
209 // Only calculate n if the field is defined
210 if (notNull(n))
211 {
212 n = -ny;
213 }
214
215 return true;
216}
217
218
219// ************************************************************************* //
scalar y
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
labelList patchIDs
fv::options & fvOptions
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
GeometricBoundaryField< vector, fvPatchField, volMesh > Boundary
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Type & initialResidual() const noexcept
Return initial residual.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
Definition fvMatrix.C:1094
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Finite-volume options, which is an IOdictionary of values and a fv::optionList.
Definition fvOptions.H:69
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present otherwise lookup and return.
Definition fvOptions.C:116
Specialisation of patchDist for wall distance calculation.
static autoPtr< patchDistMethod > New(const dictionary &dict, const fvMesh &mesh, const labelHashSet &patchIDs, const word &defaultPatchDistMethod=word::null)
const fvMesh & mesh_
Reference to the mesh.
patchDistMethod(const patchDistMethod &)=delete
No copy construct.
const labelHashSet patchIDs_
Set of patch IDs.
static wordList patchTypes(const fvMesh &mesh, const labelHashSet &patchIDs)
Return the patch types for y and n.
const labelHashSet & patchIDs() const
Return the patchIDs.
Calculation of approximate distance to nearest patch for all cells and boundary by solving the Eikona...
virtual bool correct(volScalarField &y)
Correct the given distance-to-patch field.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
Definition polyMesh.H:411
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
thermo correct()
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
Calculate the divergence of the given field.
Calculate the gradient of the given field.
Calculate the matrix for the divergence of the given field and flux.
Calculate the matrix for the laplacian of the field.
Calculate the finiteVolume matrix for implicit and explicit sources.
const pointField & points
#define DebugInfo
Report an information message using Foam::Info.
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.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcGrad.C:47
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcDiv.C:42
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition fvmDiv.C:41
zeroField SuSp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimless
Dimensionless.
PtrList< fvPatch > fvPatchList
Store lists of fvPatch as a PtrList.
Definition fvPatch.H:64
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
fvMatrix< scalar > fvScalarMatrix
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
vectorIOField pointIOField
pointIOField is a vectorIOField.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
Definition nullObject.H:267
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
wordList patchTypes(nPatches)
dictionary dict
volScalarField & e