gaussLaplacianScheme.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) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "gaussLaplacianScheme.H"
29 #include "surfaceInterpolate.H"
30 #include "fvcDiv.H"
31 #include "fvcGrad.H"
32 #include "fvMatrices.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace fv
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 template<class Type, class GType>
47 tmp<fvMatrix<Type>>
49 (
50  const surfaceScalarField& gammaMagSf,
51  const surfaceScalarField& deltaCoeffs,
53 )
54 {
55  tmp<fvMatrix<Type>> tfvm
56  (
57  new fvMatrix<Type>
58  (
59  vf,
60  deltaCoeffs.dimensions()*gammaMagSf.dimensions()*vf.dimensions()
61  )
62  );
63  fvMatrix<Type>& fvm = tfvm.ref();
64 
65  fvm.upper() = deltaCoeffs.primitiveField()*gammaMagSf.primitiveField();
66  fvm.negSumDiag();
67 
68  forAll(vf.boundaryField(), patchi)
69  {
70  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
71  const fvsPatchScalarField& pGamma = gammaMagSf.boundaryField()[patchi];
72  const fvsPatchScalarField& pDeltaCoeffs =
73  deltaCoeffs.boundaryField()[patchi];
74 
75  if (pvf.coupled())
76  {
77  fvm.internalCoeffs()[patchi] =
78  pGamma*pvf.gradientInternalCoeffs(pDeltaCoeffs);
79  fvm.boundaryCoeffs()[patchi] =
80  -pGamma*pvf.gradientBoundaryCoeffs(pDeltaCoeffs);
81  }
82  else
83  {
84  fvm.internalCoeffs()[patchi] = pGamma*pvf.gradientInternalCoeffs();
85  fvm.boundaryCoeffs()[patchi] = -pGamma*pvf.gradientBoundaryCoeffs();
86  }
87  }
88 
89  return tfvm;
90 }
91 
92 
93 template<class Type, class GType>
96 (
97  const surfaceVectorField& SfGammaCorr,
99 )
100 {
101  const fvMesh& mesh = this->mesh();
102 
104  (
106  (
107  IOobject
108  (
109  "gammaSnGradCorr("+vf.name()+')',
110  vf.instance(),
111  mesh,
114  ),
115  mesh,
116  SfGammaCorr.dimensions()
117  *vf.dimensions()*mesh.deltaCoeffs().dimensions()
118  )
119  );
120  tgammaSnGradCorr.ref().oriented() = SfGammaCorr.oriented();
121 
122  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
123  {
124  tgammaSnGradCorr.ref().replace
125  (
126  cmpt,
127  fvc::dotInterpolate(SfGammaCorr, fvc::grad(vf.component(cmpt)))
128  );
129  }
130 
131  return tgammaSnGradCorr;
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 template<class Type, class GType>
138 tmp<GeometricField<Type, fvPatchField, volMesh>>
140 (
142 )
143 {
144  const fvMesh& mesh = this->mesh();
145 
147  (
148  fvc::div(this->tsnGradScheme_().snGrad(vf)*mesh.magSf())
149  );
150 
151  tLaplacian.ref().rename("laplacian(" + vf.name() + ')');
152 
153  return tLaplacian;
154 }
155 
156 
157 template<class Type, class GType>
160 (
163 )
164 {
165  const fvMesh& mesh = this->mesh();
166 
167  const surfaceVectorField Sn(mesh.Sf()/mesh.magSf());
168 
169  const surfaceVectorField SfGamma(mesh.Sf() & gamma);
171  (
172  SfGamma & Sn
173  );
174  const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn);
175 
176  tmp<fvMatrix<Type>> tfvm = fvmLaplacianUncorrected
177  (
178  SfGammaSn,
179  this->tsnGradScheme_().deltaCoeffs(vf),
180  vf
181  );
182  fvMatrix<Type>& fvm = tfvm.ref();
183 
185  = gammaSnGradCorr(SfGammaCorr, vf);
186 
187  if (this->tsnGradScheme_().corrected())
188  {
189  tfaceFluxCorrection.ref() +=
190  SfGammaSn*this->tsnGradScheme_().correction(vf);
191  }
192 
193  fvm.source() -= mesh.V()*fvc::div(tfaceFluxCorrection())().primitiveField();
194 
195  if (mesh.fluxRequired(vf.name()))
196  {
197  fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
198  }
199 
200  return tfvm;
201 }
202 
203 
204 template<class Type, class GType>
207 (
210 )
211 {
212  const fvMesh& mesh = this->mesh();
213 
214  const surfaceVectorField Sn(mesh.Sf()/mesh.magSf());
215  const surfaceVectorField SfGamma(mesh.Sf() & gamma);
217  (
218  SfGamma & Sn
219  );
220  const surfaceVectorField SfGammaCorr(SfGamma - SfGammaSn*Sn);
221 
223  (
224  fvc::div
225  (
226  SfGammaSn*this->tsnGradScheme_().snGrad(vf)
227  + gammaSnGradCorr(SfGammaCorr, vf)
228  )
229  );
230 
231  tLaplacian.ref().rename
232  (
233  "laplacian(" + gamma.name() + ',' + vf.name() + ')'
234  );
235 
236  return tLaplacian;
237 }
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace fv
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 } // End namespace Foam
247 
248 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:47
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::GeometricField::component
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::fvc::dotInterpolate
static tmp< GeometricField< typename innerProduct< vector, Type >::type, fvsPatchField, surfaceMesh > > dotInterpolate(const surfaceVectorField &Sf, const GeometricField< Type, fvPatchField, volMesh > &tvf)
Interpolate field onto faces.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::GeometricField::primitiveField
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Definition: GeometricFieldI.H:53
Foam::fv::gaussLaplacianScheme::fvcLaplacian
tmp< GeometricField< Type, fvPatchField, volMesh > > fvcLaplacian(const GeometricField< Type, fvPatchField, volMesh > &)
Definition: gaussLaplacianScheme.C:140
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
Foam::DimensionedField::replace
void replace(const direction d, const DimensionedField< cmptType, GeoMesh > &df)
Replace a component field of the field.
fvcDiv.H
Calculate the divergence of the given field.
Foam::fvc::div
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:49
Foam::fvMatrix::boundaryCoeffs
const FieldField< Field, Type > & boundaryCoeffs() const
Definition: fvMatrix.H:471
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::fvPatchField::coupled
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:345
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::fv::gaussLaplacianScheme
Basic second-order laplacian using face-gradients and Gauss' theorem.
Definition: gaussLaplacianScheme.H:60
Foam::fvPatchField::gradientInternalCoeffs
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: fvPatchField.H:494
Foam::fv::gaussLaplacianScheme::fvmLaplacian
tmp< fvMatrix< Type > > fvmLaplacian(const GeometricField< GType, fvsPatchField, surfaceMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)
Definition: gaussLaplacianScheme.C:160
Foam::fv::gaussLaplacianScheme::fvmLaplacianUncorrected
static tmp< fvMatrix< Type > > fvmLaplacianUncorrected(const surfaceScalarField &gammaMagSf, const surfaceScalarField &deltaCoeffs, const GeometricField< Type, fvPatchField, volMesh > &)
Definition: gaussLaplacianScheme.C:49
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::tmp::ptr
T * ptr() const
Return managed pointer for reuse, or clone() the object reference.
Definition: tmpI.H:255
fv
labelList fv(nPoints)
Foam::fvPatchField::gradientBoundaryCoeffs
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: fvPatchField.H:514
Foam::Sn
static scalar Sn(const scalar a, const scalar x)
Definition: invIncGamma.C:68
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:749
fvcGrad.H
Calculate the gradient of the given field.
Foam::fvMatrix::source
Field< Type > & source()
Definition: fvMatrix.H:445
gamma
const scalar gamma
Definition: EEqn.H:9
gaussLaplacianScheme.H
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::fvMatrix::faceFluxCorrectionPtr
faceFluxFieldPtrType & faceFluxCorrectionPtr()
Return pointer to face-flux non-orthogonal correction field.
Definition: fvMatrix.H:488
Foam::fvMatrix::internalCoeffs
const FieldField< Field, Type > & internalCoeffs() const
Definition: fvMatrix.H:457
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62