LimitedScheme.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 | Copyright (C) 2011-2016 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 =
172  const_cast<surfaceScalarField&>
173  (
175  (
176  limiterFieldName
177  )
178  );
179 
180  calcLimiter(phi, limiterField);
181 
182  return limiterField;
183  }
184  else
185  {
186  tmp<surfaceScalarField> tlimiterField
187  (
189  (
190  IOobject
191  (
192  limiterFieldName,
193  mesh.time().timeName(),
194  mesh
195  ),
196  mesh,
197  dimless
198  )
199  );
200 
201  calcLimiter(phi, tlimiterField.ref());
202 
203  return tlimiterField;
204  }
205 }
206 
207 
208 // ************************************************************************* //
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:428
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
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 scalar psiMax, const scalar psiMin)
bool foundObject(const word &name) const
Is the named Type found?
Class to create NVD/TVD limited weighting-factors.
Definition: LimitedScheme.H:63
virtual tmp< surfaceScalarField > limiter(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the interpolation weighting factors.
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:715
UList< label > labelUList
Definition: UList.H:64
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
dynamicFvMesh & mesh
Calculate the gradient of the given field.
A class for handling words, derived from string.
Definition: word.H:59
volScalarField scalarField(fieldObject, mesh)
Internal & ref()
Return a reference to the dimensioned internal field.
label patchi
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A class for managing temporary objects.
Definition: PtrList.H:54
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const word & name() const
Return name.
Definition: IOobject.H:260
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243