snGradScheme.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  Copyright (C) 2019-2021 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 "fv.H"
30 #include "snGradScheme.H"
31 #include "volFields.H"
32 #include "surfaceFields.H"
33 #include "HashTable.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace fv
43 {
44 
45 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
46 
47 template<class Type>
48 tmp<snGradScheme<Type>> snGradScheme<Type>::New
49 (
50  const fvMesh& mesh,
51  Istream& schemeData
52 )
53 {
54  if (fv::debug)
55  {
56  InfoInFunction << "Constructing snGradScheme<Type>" << endl;
57  }
58 
59  if (schemeData.eof())
60  {
61  FatalIOErrorInFunction(schemeData)
62  << "Discretisation scheme not specified"
63  << nl << nl
64  << "Valid schemes are :" << nl
65  << MeshConstructorTablePtr_->sortedToc()
66  << exit(FatalIOError);
67  }
68 
69  const word schemeName(schemeData);
70 
71  auto* ctorPtr = MeshConstructorTable(schemeName);
72 
73  if (!ctorPtr)
74  {
76  (
77  schemeData,
78  "discretisation",
79  schemeName,
80  *MeshConstructorTablePtr_
81  ) << exit(FatalIOError);
82  }
83 
84  return ctorPtr(mesh, schemeData);
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 template<class Type>
93 (
95  const tmp<surfaceScalarField>& tdeltaCoeffs,
96  const word& snGradName
97 )
98 {
99  const fvMesh& mesh = vf.mesh();
100 
101  // construct GeometricField<Type, fvsPatchField, surfaceMesh>
103  (
105  (
106  IOobject
107  (
108  snGradName + "("+vf.name()+')',
109  vf.instance(),
110  vf.mesh(),
113  ),
114  mesh,
115  vf.dimensions()*tdeltaCoeffs().dimensions()
116  )
117  );
119  ssf.setOriented();
120 
121  // set reference to difference factors array
122  const scalarField& deltaCoeffs = tdeltaCoeffs();
123 
124  // owner/neighbour addressing
125  const labelUList& owner = mesh.owner();
126  const labelUList& neighbour = mesh.neighbour();
127 
128  forAll(owner, facei)
129  {
130  ssf[facei] =
131  deltaCoeffs[facei]*(vf[neighbour[facei]] - vf[owner[facei]]);
132  }
133 
135  Boundary& ssfbf = ssf.boundaryFieldRef();
136 
137  forAll(vf.boundaryField(), patchi)
138  {
139  const fvPatchField<Type>& pvf = vf.boundaryField()[patchi];
140 
141  if (pvf.coupled())
142  {
143  ssfbf[patchi] = pvf.snGrad(tdeltaCoeffs().boundaryField()[patchi]);
144  }
145  else
146  {
147  ssfbf[patchi] = pvf.snGrad();
148  }
149  }
150 
151  return tsf;
152 }
153 
154 
155 template<class Type>
158 (
160  const word& sndGradName
161 )
162 {
163  return snGrad(vf, vf.mesh().nonOrthDeltaCoeffs(), sndGradName);
164 }
165 
166 
167 template<class Type>
170 (
172 ) const
173 {
175  (
176  snGrad(vf, deltaCoeffs(vf))
177  );
178 
179  if (corrected())
180  {
181  tsf.ref() += correction(vf);
182  }
183 
184  return tsf;
185 }
186 
187 
188 template<class Type>
191 (
193 ) const
194 {
196  (
197  snGrad(tvf())
198  );
199 
200  tsf.clear();
201  return tsf;
202 }
203 
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 } // End namespace fv
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace Foam
212 
213 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
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
volFields.H
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:47
Foam::fvPatchField::snGrad
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:225
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
fv.H
HashTable.H
Foam::tmp::clear
void clear() const noexcept
Definition: tmpI.H:287
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Field< scalar >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::eof
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:239
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::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:783
Foam::UList< label >
Foam::fv::snGradScheme::New
static tmp< snGradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: snGradScheme.C:49
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::fv::snGradScheme::snGrad
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &, const tmp< surfaceScalarField > &, const word &snGradName="snGrad")
Definition: snGradScheme.C:93
snGradScheme.H
Foam::GeometricField< Type, fvPatchField, volMesh >
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
Foam::fv::snGradScheme::sndGrad
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > sndGrad(const GeometricField< Type, fvPatchField, volMesh > &, const word &snGradName="sndGrad")
Return the sndGrad of the given cell field.
Definition: snGradScheme.C:158