faGradScheme.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-2023 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 "HashTable.H"
31 #include "objectRegistry.H"
32 #include "solution.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 gradScheme<Type>"
57  << endl;
58  }
59 
60  if (schemeData.eof())
61  {
62  FatalIOErrorInFunction(schemeData)
63  << "Grad scheme not specified" << nl << nl
64  << "Valid grad schemes are :" << nl
65  << IstreamConstructorTablePtr_->sortedToc()
66  << exit(FatalIOError);
67  }
68 
69  const word schemeName(schemeData);
70 
71  auto* ctorPtr = IstreamConstructorTable(schemeName);
72 
73  if (!ctorPtr)
74  {
76  (
77  schemeData,
78  "grad",
79  schemeName,
80  *IstreamConstructorTablePtr_
81  ) << exit(FatalIOError);
82  }
83 
84  return ctorPtr(mesh, schemeData);
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 template<class Type>
91 tmp
92 <
94  <
97  areaMesh
98  >
99 >
101 (
103  const word& name
104 ) const
105 {
106  typedef typename outerProduct<vector, Type>::type GradType;
108 
109  GradFieldType* pgGrad =
110  mesh().thisDb().template getObjectPtr<GradFieldType>(name);
111 
112  if (!this->mesh().cache(name)) // || this->mesh().changing()
113  {
114  // Delete any old occurrences to avoid double registration
115  if (pgGrad && pgGrad->ownedByRegistry())
116  {
117  solution::cachePrintMessage("Deleting", name, vsf);
118  delete pgGrad;
119  }
120 
121  solution::cachePrintMessage("Calculating", name, vsf);
122  return calcGrad(vsf, name);
123  }
124 
125 
126  if (!pgGrad)
127  {
128  solution::cachePrintMessage("Calculating and caching", name, vsf);
129 
130  pgGrad = calcGrad(vsf, name).ptr();
131  regIOobject::store(pgGrad);
132  }
133  else
134  {
135  if (pgGrad->upToDate(vsf))
136  {
137  solution::cachePrintMessage("Reusing", name, vsf);
138  }
139  else
140  {
141  solution::cachePrintMessage("Updating", name, vsf);
142  delete pgGrad;
143 
144  pgGrad = calcGrad(vsf, name).ptr();
145  regIOobject::store(pgGrad);
146  }
147  }
148 
149  return *pgGrad;
150 }
151 
152 
153 template<class Type>
154 tmp
155 <
157  <
159  faPatchField,
160  areaMesh
161  >
162 >
164 (
166 ) const
167 {
168  return grad(vsf, "grad(" + vsf.name() + ')');
169 }
170 
171 
172 template<class Type>
173 tmp
174 <
176  <
178  faPatchField,
179  areaMesh
180  >
181 >
183 (
185 ) const
186 {
187  typedef typename outerProduct<vector, Type>::type GradType;
189 
190  tmp<GradFieldType> tgrad = grad(tvsf());
191  tvsf.clear();
192  return tgrad;
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace fa
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace Foam
203 
204 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
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
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
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > grad(const GeometricField< Type, faPatchField, areaMesh > &, const word &name) const
Calculate and return the grad of the given field which may have been cached.
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
static void cachePrintMessage(const char *message, const word &name, const FieldType &fld)
Helper for printing cache message.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
int debug
Static debugging option.
static tmp< gradScheme< Type > > New(const faMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: faGradScheme.C:41
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Mesh data needed to do the Finite Area discretisation.
Definition: areaFaMesh.H:47
A class for managing temporary objects.
Definition: HashPtrTable.H:50
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:289
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:51
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.