All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gaussLaplacianScheme.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-2018 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 "gaussLaplacianScheme.H"
27 #include "surfaceInterpolate.H"
28 #include "fvcDiv.H"
29 #include "fvcGrad.H"
30 #include "fvMatrices.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace fv
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 template<class Type, class GType>
45 tmp<fvMatrix<Type>>
47 (
48  const surfaceScalarField& gammaMagSf,
49  const surfaceScalarField& deltaCoeffs,
51 )
52 {
53  tmp<fvMatrix<Type>> tfvm
54  (
55  new fvMatrix<Type>
56  (
57  vf,
58  deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions()
59  )
60  );
61  fvMatrix<Type>& fvm = tfvm.ref();
62 
63  fvm.upper() = deltaCoeffs.primitiveField()*gammaMagSf.primitiveField();
64  fvm.negSumDiag();
65 
67  {
68  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
69  const fvsPatchScalarField& pGamma = gammaMagSf.boundaryField()[patchi];
70  const fvsPatchScalarField& pDeltaCoeffs =
71  deltaCoeffs.boundaryField()[patchi];
72 
73  if (pvf.coupled())
74  {
75  fvm.internalCoeffs()[patchi] =
76  pGamma*pvf.gradientInternalCoeffs(pDeltaCoeffs);
77  fvm.boundaryCoeffs()[patchi] =
78  -pGamma*pvf.gradientBoundaryCoeffs(pDeltaCoeffs);
79  }
80  else
81  {
82  fvm.internalCoeffs()[patchi] = pGamma*pvf.gradientInternalCoeffs();
83  fvm.boundaryCoeffs()[patchi] = -pGamma*pvf.gradientBoundaryCoeffs();
84  }
85  }
86 
87  return tfvm;
88 }
89 
90 
91 template<class Type, class GType>
94 (
95  const surfaceVectorField& SfGammaCorr,
97 )
98 {
99  const fvMesh& mesh = this->mesh();
100 
102  (
104  (
105  IOobject
106  (
107  "gammaSnGradCorr("+vf.name()+')',
108  vf.instance(),
109  mesh,
112  ),
113  mesh,
114  SfGammaCorr.dimensions()
115  *vf.dimensions()*mesh.deltaCoeffs().dimensions()
116  )
117  );
118 
119  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
120  {
121  tgammaSnGradCorr.ref().replace
122  (
123  cmpt,
124  fvc::dotInterpolate(SfGammaCorr, fvc::grad(vf.component(cmpt)))
125  );
126  }
127 
128  return tgammaSnGradCorr;
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 template<class Type, class GType>
137 (
139 )
140 {
141  const fvMesh& mesh = this->mesh();
142 
144  (
145  fvc::div(this->tsnGradScheme_().snGrad(vf)*mesh.magSf())
146  );
147 
148  tLaplacian.ref().rename("laplacian(" + vf.name() + ')');
149 
150  return tLaplacian;
151 }
152 
153 
154 template<class Type, class GType>
157 (
160 )
161 {
162  const fvMesh& mesh = this->mesh();
163 
164  const surfaceVectorField Sn(mesh.Sf()/mesh.magSf());
165 
166  const surfaceVectorField SfGamma(mesh.Sf() & gamma);
168  (
169  SfGamma & Sn
170  );
171  const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn);
172 
173  tmp<fvMatrix<Type>> tfvm = fvmLaplacianUncorrected
174  (
175  SfGammaSn,
176  this->tsnGradScheme_().deltaCoeffs(vf),
177  vf
178  );
179  fvMatrix<Type>& fvm = tfvm.ref();
180 
182  = gammaSnGradCorr(SfGammaCorr, vf);
183 
184  if (this->tsnGradScheme_().corrected())
185  {
186  tfaceFluxCorrection.ref() +=
187  SfGammaSn*this->tsnGradScheme_().correction(vf);
188  }
189 
190  fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().primitiveField();
191 
192  if (mesh.fluxRequired(vf.name()))
193  {
194  fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
195  }
196 
197  return tfvm;
198 }
199 
200 
201 template<class Type, class GType>
204 (
207 )
208 {
209  const fvMesh& mesh = this->mesh();
210 
211  const surfaceVectorField Sn(mesh.Sf()/mesh.magSf());
212  const surfaceVectorField SfGamma(mesh.Sf() & gamma);
214  (
215  SfGamma & Sn
216  );
217  const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn);
218 
220  (
221  fvc::div
222  (
223  SfGammaSn*this->tsnGradScheme_().snGrad(vf)
224  + gammaSnGradCorr(SfGammaCorr, vf)
225  )
226  );
227 
228  tLaplacian.ref().rename
229  (
230  "laplacian(" + gamma.name() + ',' + vf.name() + ')'
231  );
232 
233  return tLaplacian;
234 }
235 
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 } // End namespace fv
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // ************************************************************************* //
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
const surfaceVectorField & Sf() const
Return cell face area vectors.
const word & name() const
Return name.
Definition: IOobject.H:297
static scalar Sn(const scalar a, const scalar x)
Definition: invIncGamma.C:81
FieldField< Field, Type > & internalCoeffs()
fvBoundary scalar field containing pseudo-matrix coeffs
Definition: fvMatrix.H:306
const Boundary & boundaryField() const
Return const-reference to the boundary field.
static tmp< fvMatrix< Type > > fvmLaplacianUncorrected(const surfaceScalarField &gammaMagSf, const surfaceScalarField &deltaCoeffs, const GeometricField< Type, fvPatchField, volMesh > &)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
uint8_t direction
Definition: direction.H:45
static tmp< GeometricField< typename innerProduct< vector, Type >::type, fvsPatchField, surfaceMesh > > dotInterpolate(const surfaceVectorField &Sf, const GeometricField< Type, fvPatchField, volMesh > &tvf)
Interpolate field onto faces.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
scalarField & upper()
Definition: lduMatrix.C:197
surfaceTypeFieldPtr & faceFluxCorrectionPtr()
Return pointer to face-flux non-orthogonal correction field.
Definition: fvMatrix.H:324
const dimensionSet & dimensions() const
Return dimensions.
dynamicFvMesh & mesh
Calculate the gradient of the given field.
labelList fv(nPoints)
Basic second-order laplacian using face-gradients and Gauss&#39; theorem.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:478
FieldField< Field, Type > & boundaryCoeffs()
fvBoundary scalar field containing pseudo-matrix coeffs
Definition: fvMatrix.H:313
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:328
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
Calculate the divergence of the given field.
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
Field< Type > & source()
Definition: fvMatrix.H:294
tmp< GeometricField< Type, fvPatchField, volMesh > > fvcLaplacian(const GeometricField< Type, fvPatchField, volMesh > &)
const fileName & instance() const
Definition: IOobject.H:392
label patchi
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:498
bool fluxRequired(const word &name) const
Definition: fvSchemes.C:508
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A special matrix type and solver, designed for finite volume solutions of scalar equations.
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
A class for managing temporary objects.
Definition: PtrList.H:53
tmp< fvMatrix< Type > > fvmLaplacian(const GeometricField< GType, fvsPatchField, surfaceMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
const surfaceScalarField & deltaCoeffs() const
Return reference to cell-centre difference coefficients.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Namespace for OpenFOAM.