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>
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 
141  auto& ssfb = ssf.boundaryFieldRef();
142 
143  forAll(vf.boundaryField(), patchI)
144  {
145  ssfb[patchI] = vf.boundaryField()[patchI].snGrad();
146  }
147 
148  return tssf;
149 }
150 
151 
152 template<class Type>
155 (
157 ) const
158 {
160  lnGrad(vf, deltaCoeffs(vf));
161 
162  if (corrected())
163  {
164  tsf.ref() += correction(vf);
165  }
166 
167  return tsf;
168 }
169 
170 
171 template<class Type>
174 (
176 ) const
177 {
179  lnGrad(tvf());
180  tvf.clear();
181  return tinterpVf;
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace fa
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
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.
Definition: areaFieldsFwd.H:50
Ignore writing from objectRegistry::writeObject()
virtual ~lnGradScheme()
Destructor.
Definition: lnGradScheme.C:85
#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:42
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:94
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:627
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:172
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
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.