All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LimitedScheme.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-2019 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 "volFields.H"
27 #include "surfaceFields.H"
28 #include "fvcGrad.H"
29 #include "coupledFvPatchFields.H"
30 
31 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
32 
33 template<class Type, class Limiter, template<class> class LimitFunc>
35 (
36  const GeometricField<Type, fvPatchField, volMesh>& phi,
37  surfaceScalarField& limiterField
38 ) const
39 {
40  const fvMesh& mesh = this->mesh();
41 
42  tmp<GeometricField<typename Limiter::phiType, fvPatchField, volMesh>>
43  tlPhi = LimitFunc<Type>()(phi);
44 
45  const GeometricField<typename Limiter::phiType, fvPatchField, volMesh>&
46  lPhi = tlPhi();
47 
48  tmp<GeometricField<typename Limiter::gradPhiType, fvPatchField, volMesh>>
49  tgradc(fvc::grad(lPhi));
50  const GeometricField<typename Limiter::gradPhiType, fvPatchField, volMesh>&
51  gradc = tgradc();
52 
53  const surfaceScalarField& CDweights = mesh.surfaceInterpolation::weights();
54 
55  const labelUList& owner = mesh.owner();
56  const labelUList& neighbour = mesh.neighbour();
57 
58  const vectorField& C = mesh.C();
59 
60  scalarField& pLim = limiterField.primitiveFieldRef();
61 
62  forAll(pLim, face)
63  {
64  label own = owner[face];
65  label nei = neighbour[face];
66 
67  pLim[face] = Limiter::limiter
68  (
69  CDweights[face],
70  this->faceFlux_[face],
71  lPhi[own],
72  lPhi[nei],
73  gradc[own],
74  gradc[nei],
75  C[nei] - C[own]
76  );
77  }
78 
79  surfaceScalarField::Boundary& bLim =
80  limiterField.boundaryFieldRef();
81 
82  forAll(bLim, patchi)
83  {
84  scalarField& pLim = bLim[patchi];
85 
86  if (bLim[patchi].coupled())
87  {
88  const scalarField& pCDweights = CDweights.boundaryField()[patchi];
89  const scalarField& pFaceFlux =
90  this->faceFlux_.boundaryField()[patchi];
91 
92  const Field<typename Limiter::phiType> plPhiP
93  (
94  lPhi.boundaryField()[patchi].patchInternalField()
95  );
96  const Field<typename Limiter::phiType> plPhiN
97  (
98  lPhi.boundaryField()[patchi].patchNeighbourField()
99  );
100  const Field<typename Limiter::gradPhiType> pGradcP
101  (
102  gradc.boundaryField()[patchi].patchInternalField()
103  );
104  const Field<typename Limiter::gradPhiType> pGradcN
105  (
106  gradc.boundaryField()[patchi].patchNeighbourField()
107  );
108 
109  // Build the d-vectors
110  vectorField pd(CDweights.boundaryField()[patchi].patch().delta());
111 
112  forAll(pLim, face)
113  {
114  pLim[face] = Limiter::limiter
115  (
116  pCDweights[face],
117  pFaceFlux[face],
118  plPhiP[face],
119  plPhiN[face],
120  pGradcP[face],
121  pGradcN[face],
122  pd[face]
123  );
124  }
125  }
126  else
127  {
128  pLim = 1.0;
129  }
130  }
131 }
132 
133 
134 // * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * //
135 
136 template<class Type, class Limiter, template<class> class LimitFunc>
139 (
141 ) const
142 {
143  const fvMesh& mesh = this->mesh();
144 
145  const word limiterFieldName(type() + "Limiter(" + phi.name() + ')');
146 
147  if (this->mesh().cache("limiter"))
148  {
149  if (!mesh.foundObject<surfaceScalarField>(limiterFieldName))
150  {
151  surfaceScalarField* limiterField
152  (
154  (
155  IOobject
156  (
157  limiterFieldName,
158  mesh.time().timeName(),
159  mesh,
160  IOobject::NO_READ,
161  IOobject::NO_WRITE
162  ),
163  mesh,
164  dimless
165  )
166  );
167 
168  mesh.objectRegistry::store(limiterField);
169  }
170 
171  surfaceScalarField& limiterField =
173  (
174  limiterFieldName
175  );
176 
177  calcLimiter(phi, limiterField);
178 
179  return limiterField;
180  }
181  else
182  {
183  tmp<surfaceScalarField> tlimiterField
184  (
186  (
187  limiterFieldName,
188  mesh,
189  dimless
190  )
191  );
192 
193  calcLimiter(phi, tlimiterField.ref());
194 
195  return tlimiterField;
196  }
197 }
198 
199 
200 // ************************************************************************* //
Foam::surfaceFields.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const word & name() const
Return name.
Definition: IOobject.H:303
Class to create NVD/TVD limited weighting-factors.
Definition: LimitedScheme.H:63
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
Type & lookupObjectRef(const word &name) const
Lookup and return the object reference of the given Type.
bool foundObject(const word &name) const
Is the named Type found?
volVectorField vectorField(fieldObject, mesh)
Generic GeometricField class.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:622
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
UList< label > labelUList
Definition: UList.H:65
dynamicFvMesh & mesh
Calculate the gradient of the given field.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
void limiter(scalarField &allLambda, const RdeltaTType &rDeltaT, const RhoType &rho, const volScalarField &psi, const surfaceScalarField &phiBD, const surfaceScalarField &phiCorr, const SpType &Sp, const SuType &Su, const PsiMaxType &psiMax, const PsiMinType &psiMin)
A class for handling words, derived from string.
Definition: word.H:59
virtual tmp< surfaceScalarField > limiter(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the interpolation weighting factors.
volScalarField scalarField(fieldObject, mesh)
label patchi
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
A class for managing temporary objects.
Definition: PtrList.H:53
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92