PoissonPatchDistMethod.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2017 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 "PoissonPatchDistMethod.H"
30 #include "fvcGrad.H"
31 #include "fvmLaplacian.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace patchDistMethods
39 {
40  defineTypeNameAndDebug(Poisson, 0);
41  addToRunTimeSelectionTable(patchDistMethod, Poisson, dictionary);
42 }
43 }
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 Foam::patchDistMethods::Poisson::Poisson
48 (
49  const dictionary& dict,
50  const fvMesh& mesh,
51  const labelHashSet& patchIDs
52 )
53 :
54  patchDistMethod(mesh, patchIDs)
55 {}
56 
57 
58 Foam::patchDistMethods::Poisson::Poisson
59 (
60  const fvMesh& mesh,
61  const labelHashSet& patchIDs
62 )
63 :
64  patchDistMethod(mesh, patchIDs)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  return correct(y, const_cast<volVectorField&>(volVectorField::null()));
73 }
74 
75 
77 (
80 )
81 {
82  if (!tyPsi_.valid())
83  {
84  tyPsi_ = tmp<volScalarField>
85  (
86  new volScalarField
87  (
88  IOobject
89  (
90  "yPsi",
91  mesh_.time().timeName(),
92  mesh_
93  ),
94  mesh_,
96  y.boundaryFieldRef().types()
97  )
98  );
99  }
100  volScalarField& yPsi = tyPsi_.ref();
101 
102  solve(fvm::laplacian(yPsi) == dimensionedScalar("1", dimless, -1.0));
103 
104  volVectorField gradyPsi(fvc::grad(yPsi));
105  volScalarField magGradyPsi(mag(gradyPsi));
106 
107  // Need to stabilise the y for overset meshes since the holed cells
108  // keep the initial value (0.0) so the gradient of that will be
109  // zero as well. Turbulence models do not like zero wall distance.
110  y = max
111  (
112  sqrt(magSqr(gradyPsi) + 2*yPsi) - magGradyPsi,
113  dimensionedScalar("smallY", dimLength, SMALL)
114  );
115 
116  // For overset: enforce smooth y field (yPsi is smooth, magGradyPsi is
117  // not)
118  mesh_.interpolate(y);
119 
120  // Need to stabilise the y for overset meshes since the holed cells
121  // keep the initial value (0.0) so the gradient of that will be
122  // zero as well. Turbulence models do not like zero wall distance.
123  y.max(SMALL);
124 
125  // For overset: enforce smooth y field (yPsi is smooth, magGradyPsi is
126  // not)
127  mesh_.interpolate(y);
128 
129  // Cache yPsi if the mesh is moving otherwise delete
130  if (!mesh_.changing())
131  {
132  tyPsi_.clear();
133  }
134 
135  // Only calculate n if the field is defined
136  if (notNull(n))
137  {
138  n =
139  -gradyPsi
140  /max
141  (
142  magGradyPsi,
143  dimensionedScalar("smallMagGradyPsi", dimLength, SMALL)
144 
145  );
146 
147  // For overset: enforce smooth field
148  mesh_.interpolate(n);
149  }
150 
151  return true;
152 }
153 
154 
155 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::patchDistMethods::Poisson::correct
virtual bool correct(volScalarField &y)
Correct the given distance-to-patch field.
Definition: PoissonPatchDistMethod.C:70
Foam::HashSet< label, Hash< label > >
Foam::patchDistMethods::defineTypeNameAndDebug
defineTypeNameAndDebug(advectionDiffusion, 0)
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::fvm::laplacian
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:48
fvmLaplacian.H
Calculate the matrix for the laplacian of the field.
Foam::solve
SolverPerformance< Type > solve(faMatrix< Type > &, Istream &)
Solve returning the solution statistics given convergence tolerance.
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::notNull
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:207
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::patchDistMethod
Specialisation of patchDist for wall distance calculation.
Definition: patchDistMethod.H:59
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
PoissonPatchDistMethod.H
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::patchDistMethods::addToRunTimeSelectionTable
addToRunTimeSelectionTable(patchDistMethod, advectionDiffusion, dictionary)
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:749
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
fvcGrad.H
Calculate the gradient of the given field.
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::GeometricField< vector, fvPatchField, volMesh >::null
static const GeometricField< vector, fvPatchField, volMesh > & null()
Return a null geometric field.
Definition: GeometricFieldI.H:32
Foam::GeometricField< scalar, fvPatchField, volMesh >
y
scalar y
Definition: LISASMDCalcMethod1.H:14