gradScheme.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 "objectRegistry.H"
31 #include "solution.H"
32 
33 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const fvMesh& mesh,
39  Istream& schemeData
40 )
41 {
42  if (fv::debug)
43  {
44  InfoInFunction << "Constructing gradScheme<Type>" << endl;
45  }
46 
47  if (schemeData.eof())
48  {
49  FatalIOErrorInFunction(schemeData)
50  << "Grad scheme not specified" << endl << endl
51  << "Valid grad schemes are :" << endl
52  << IstreamConstructorTablePtr_->sortedToc()
53  << exit(FatalIOError);
54  }
55 
56  const word schemeName(schemeData);
57 
58  auto* ctorPtr = IstreamConstructorTable(schemeName);
59 
60  if (!ctorPtr)
61  {
63  (
64  schemeData,
65  "grad",
66  schemeName,
67  *IstreamConstructorTablePtr_
68  ) << exit(FatalIOError);
69  }
70 
71  return ctorPtr(mesh, schemeData);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 template<class Type>
79 <
81  <
85  >
86 >
88 (
90  const word& name
91 ) const
92 {
93  typedef typename outerProduct<vector, Type>::type GradType;
95 
96  GradFieldType* pgGrad =
97  mesh().objectRegistry::template getObjectPtr<GradFieldType>(name);
98 
99  if (!this->mesh().cache(name) || this->mesh().changing())
100  {
101  // Delete any old occurrences to avoid double registration
102  if (pgGrad && pgGrad->ownedByRegistry())
103  {
104  solution::cachePrintMessage("Deleting", name, vsf);
105  delete pgGrad;
106  }
107 
108  solution::cachePrintMessage("Calculating", name, vsf);
109  return calcGrad(vsf, name);
110  }
111 
112 
113  if (!pgGrad)
114  {
115  solution::cachePrintMessage("Calculating and caching", name, vsf);
116 
117  pgGrad = calcGrad(vsf, name).ptr();
118  regIOobject::store(pgGrad);
119  }
120  else
121  {
122  if (pgGrad->upToDate(vsf))
123  {
124  solution::cachePrintMessage("Reusing", name, vsf);
125  }
126  else
127  {
128  solution::cachePrintMessage("Updating", name, vsf);
129  delete pgGrad;
130 
131  pgGrad = calcGrad(vsf, name).ptr();
132  regIOobject::store(pgGrad);
133  }
134  }
135 
136  return *pgGrad;
137 }
138 
139 
140 template<class Type>
141 Foam::tmp
142 <
144  <
148  >
149 >
151 (
152  const GeometricField<Type, fvPatchField, volMesh>& vsf
153 ) const
154 {
155  return grad(vsf, "grad(" + vsf.name() + ')');
156 }
157 
158 
159 template<class Type>
160 Foam::tmp
161 <
163  <
167  >
168 >
170 (
171  const tmp<GeometricField<Type, fvPatchField, volMesh>>& tvsf
172 ) const
173 {
174  typedef typename outerProduct<vector, Type>::type GradType;
175  typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
176 
177  tmp<GradFieldType> tgrad = grad(tvsf());
178  tvsf.clear();
179  return tgrad;
180 }
181 
182 
183 // ************************************************************************* //
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
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
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:51
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
objectRegistry.H
Foam::fac::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:56
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fv::gradScheme::New
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:37
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
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
solution.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::fv::gradScheme::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvPatchField, volMesh > &, const word &name) const