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 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace fa
42 {
43 
44 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
45 
46 template<class Type>
48 (
49  const faMesh& mesh,
50  Istream& schemeData
51 )
52 {
53  if (fa::debug)
54  {
56  << "constructing lnGradScheme<Type>"
57  << endl;
58  }
59 
60  if (schemeData.eof())
61  {
62  FatalIOErrorInFunction(schemeData)
63  << "Grad scheme not specified" << nl << nl
64  << "Valid schemes are :" << endl
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  "grad",
79  schemeName,
80  *MeshConstructorTablePtr_
81  ) << exit(FatalIOError);
82  }
83 
84  return ctorPtr(mesh, schemeData);
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
90 template<class Type>
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
97 template<class Type>
100 (
102  const tmp<edgeScalarField>& tdeltaCoeffs,
103  const word& lnGradName
104 )
105 {
106  const faMesh& mesh = vf.mesh();
107 
108  // construct GeometricField<Type, faePatchField, edgeMesh>
110  (
112  (
113  IOobject
114  (
115  lnGradName + "("+vf.name()+')',
116  vf.instance(),
117  vf.db(),
120  ),
121  mesh,
122  vf.dimensions()*tdeltaCoeffs().dimensions()
123  )
124  );
126 
127  // set reference to difference factors array
128  const scalarField& deltaCoeffs = tdeltaCoeffs().internalField();
129 
130  // owner/neighbour addressing
131  const labelUList& owner = mesh.owner();
132  const labelUList& neighbour = mesh.neighbour();
133 
134  forAll(owner, faceI)
135  {
136  ssf[faceI] =
137  deltaCoeffs[faceI]*(vf[neighbour[faceI]] - vf[owner[faceI]]);
138  }
139 
140  auto& ssfb = ssf.boundaryFieldRef();
141 
142  forAll(vf.boundaryField(), patchI)
143  {
144  ssfb[patchI] = vf.boundaryField()[patchI].snGrad();
145  }
146 
147  return tssf;
148 }
149 
150 
151 template<class Type>
154 (
156 ) const
157 {
159  lnGrad(vf, deltaCoeffs(vf));
160 
161  if (corrected())
162  {
163  tsf.ref() += correction(vf);
164  }
165 
166  return tsf;
167 }
168 
169 
170 template<class Type>
173 (
175 ) const
176 {
178  lnGrad(tvf());
179  tvf.clear();
180  return tinterpVf;
181 }
182 
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace fa
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace Foam
191 
192 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:133
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Generic GeometricField class.
Ignore writing from objectRegistry::writeObject()
virtual ~lnGradScheme()
Destructor.
Definition: lnGradScheme.C:84
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
static tmp< lnGradScheme< Type > > New(const faMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
Definition: lnGradScheme.C:41
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:93
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
const Mesh & mesh() const noexcept
Return mesh.
int debug
Static debugging option.
tmp< GeometricField< Type, faePatchField, edgeMesh > > lnGrad(const GeometricField< Type, faPatchField, areaMesh > &vf, const word &name)
Definition: facLnGrad.C:40
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:637
Nothing to be read.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:645
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:289
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
#define InfoInFunction
Report an information message using Foam::Info.