gradScheme.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "fv.H"
27 #include "objectRegistry.H"
28 #include "solution.H"
29 
30 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const fvMesh& mesh,
36  Istream& schemeData
37 )
38 {
39  if (fv::debug)
40  {
41  InfoInFunction << "Constructing gradScheme<Type>" << endl;
42  }
43 
44  if (schemeData.eof())
45  {
47  (
48  schemeData
49  ) << "Grad scheme not specified" << endl << endl
50  << "Valid grad schemes are :" << endl
51  << IstreamConstructorTablePtr_->sortedToc()
52  << exit(FatalIOError);
53  }
54 
55  const word schemeName(schemeData);
56 
57  typename IstreamConstructorTable::iterator cstrIter =
58  IstreamConstructorTablePtr_->find(schemeName);
59 
60  if (cstrIter == IstreamConstructorTablePtr_->end())
61  {
63  (
64  schemeData
65  ) << "Unknown grad scheme " << schemeName << nl << nl
66  << "Valid grad schemes are :" << endl
67  << IstreamConstructorTablePtr_->sortedToc()
68  << exit(FatalIOError);
69  }
70 
71  return cstrIter()(mesh, schemeData);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
77 template<class Type>
79 {}
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 template<class Type>
85 <
87  <
88  typename Foam::outerProduct<Foam::vector, Type>::type,
89  Foam::fvPatchField,
91  >
92 >
94 (
96  const word& name
97 ) const
98 {
99  typedef typename outerProduct<vector, Type>::type GradType;
101 
102  if (!this->mesh().changing() && this->mesh().solution().cache(name))
103  {
104  if (!mesh().objectRegistry::template foundObject<GradFieldType>(name))
105  {
106  solution::cachePrintMessage("Calculating and caching", name, vsf);
107  tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
108  regIOobject::store(tgGrad.ptr());
109  }
110 
111  solution::cachePrintMessage("Retrieving", name, vsf);
112  GradFieldType& gGrad =
113  mesh().objectRegistry::template lookupObjectRef<GradFieldType>
114  (
115  name
116  );
117 
118  if (gGrad.upToDate(vsf))
119  {
120  return gGrad;
121  }
122  else
123  {
124  solution::cachePrintMessage("Deleting", name, vsf);
125  gGrad.release();
126  delete &gGrad;
127 
128  solution::cachePrintMessage("Recalculating", name, vsf);
129  tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
130 
131  solution::cachePrintMessage("Storing", name, vsf);
132  regIOobject::store(tgGrad.ptr());
133  GradFieldType& gGrad =
134  mesh().objectRegistry::template lookupObjectRef<GradFieldType>
135  (
136  name
137  );
138 
139  return gGrad;
140  }
141  }
142  else
143  {
144  if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
145  {
146  GradFieldType& gGrad =
147  mesh().objectRegistry::template lookupObjectRef<GradFieldType>
148  (
149  name
150  );
151 
152  if (gGrad.ownedByRegistry())
153  {
154  solution::cachePrintMessage("Deleting", name, vsf);
155  gGrad.release();
156  delete &gGrad;
157  }
158  }
159 
160  solution::cachePrintMessage("Calculating", name, vsf);
161  return calcGrad(vsf, name);
162  }
163 }
164 
165 
166 template<class Type>
167 Foam::tmp
168 <
170  <
171  typename Foam::outerProduct<Foam::vector, Type>::type,
172  Foam::fvPatchField,
174  >
175 >
177 (
179 ) const
180 {
181  return grad(vsf, "grad(" + vsf.name() + ')');
182 }
183 
184 
185 template<class Type>
186 Foam::tmp
187 <
189  <
190  typename Foam::outerProduct<Foam::vector, Type>::type,
191  Foam::fvPatchField,
193  >
194 >
196 (
198 ) const
199 {
200  typedef typename outerProduct<vector, Type>::type GradType;
202 
203  tmp<GradFieldType> tgrad = grad(tvsf());
204  tvsf.clear();
205  return tgrad;
206 }
207 
208 
209 // ************************************************************************* //
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
const word & name() const
Return name.
Definition: IOobject.H:315
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Generic GeometricField class.
fvMesh & mesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:53
A class for handling words, derived from string.
Definition: word.H:59
virtual ~gradScheme()
Destructor.
Definition: gradScheme.C:78
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:336
static const char nl
Definition: Ostream.H:260
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:34
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:48
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
A class for managing temporary objects.
Definition: PtrList.H:53
IOerror FatalIOError
#define InfoInFunction
Report an information message using Foam::Info.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvPatchField, volMesh > &, const word &name) const
Calculate and return the grad of the given field.