lnGradScheme.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) 2016-2017 Wikki Ltd
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 "fa.H"
30 #include "lnGradScheme.H"
31 #include "areaFields.H"
32 #include "edgeFields.H"
33 #include "HashTable.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace fa
43 {
44 
45 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
46 
47 template<class Type>
48 tmp<lnGradScheme<Type>> lnGradScheme<Type>::New
49 (
50  const faMesh& mesh,
51  Istream& schemeData
52 )
53 {
54  if (fa::debug)
55  {
57  << "constructing lnGradScheme<Type>"
58  << endl;
59  }
60 
61  if (schemeData.eof())
62  {
63  FatalIOErrorInFunction(schemeData)
64  << "Grad scheme not specified" << nl << nl
65  << "Valid schemes are :" << endl
66  << MeshConstructorTablePtr_->sortedToc()
67  << exit(FatalIOError);
68  }
69 
70  const word schemeName(schemeData);
71 
72  auto* ctorPtr = MeshConstructorTable(schemeName);
73 
74  if (!ctorPtr)
75  {
77  (
78  schemeData,
79  "grad",
80  schemeName,
81  *MeshConstructorTablePtr_
82  ) << exit(FatalIOError);
83  }
84 
85  return ctorPtr(mesh, schemeData);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90 
91 template<class Type>
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
98 template<class Type>
101 (
103  const tmp<edgeScalarField>& tdeltaCoeffs,
104  const word& lnGradName
105 )
106 {
107  const faMesh& mesh = vf.mesh();
108 
109  // construct GeometricField<Type, faePatchField, edgeMesh>
111  (
113  (
114  IOobject
115  (
116  lnGradName + "("+vf.name()+')',
117  vf.instance(),
118  vf.db(),
121  ),
122  mesh,
123  vf.dimensions()*tdeltaCoeffs().dimensions()
124  )
125  );
127 
128  // set reference to difference factors array
129  const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
130 
131  // owner/neighbour addressing
132  const labelUList& owner = mesh.owner();
133  const labelUList& neighbour = mesh.neighbour();
134 
135  forAll(owner, faceI)
136  {
137  ssf[faceI] =
138  deltaCoeffs[faceI]*(vf[neighbour[faceI]] - vf[owner[faceI]]);
139  }
140 
142  ssf.boundaryFieldRef();
143 
144  forAll(vf.boundaryField(), patchI)
145  {
146  ssfb[patchI] = vf.boundaryField()[patchI].snGrad();
147  }
148 
149  return tssf;
150 }
151 
152 
153 template<class Type>
156 (
158 ) const
159 {
161  lnGrad(vf, deltaCoeffs(vf));
162 
163  if (corrected())
164  {
165  tsf.ref() += correction(vf);
166  }
167 
168  return tsf;
169 }
170 
171 
172 template<class Type>
175 (
177 ) const
178 {
180  lnGrad(tvf());
181  tvf.clear();
182  return tinterpVf;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 } // End namespace fa
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::fa::lnGradScheme::lnGrad
static tmp< GeometricField< Type, faePatchField, edgeMesh > > lnGrad(const GeometricField< Type, faPatchField, areaMesh > &, const tmp< edgeScalarField > &, const word &snGradName="lnGrad")
Return the lnGrad of the given cell field.
Definition: lnGradScheme.C:101
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
HashTable.H
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
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::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
edgeFields.H
Foam::IOstream::eof
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:239
Foam::fac::lnGrad
tmp< GeometricField< Type, faePatchField, edgeMesh > > lnGrad(const GeometricField< Type, faPatchField, areaMesh > &vf, const word &name)
Definition: facLnGrad.C:47
areaFields.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fa::lnGradScheme::~lnGradScheme
virtual ~lnGradScheme()
Destructor.
Definition: lnGradScheme.C:92
fa.H
Foam::fa::lnGradScheme::New
static tmp< lnGradScheme< Type > > New(const faMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: lnGradScheme.C:49
Foam::GeometricField::Boundary
The boundary fields.
Definition: GeometricField.H:115
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::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:82
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
lnGradScheme.H
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
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