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 | Copyright (C) 2011-2016 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().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 = const_cast<GradFieldType&>
113  (
114  mesh().objectRegistry::template lookupObject<GradFieldType>(name)
115  );
116 
117  if (gGrad.upToDate(vsf))
118  {
119  return gGrad;
120  }
121  else
122  {
123  solution::cachePrintMessage("Deleting", name, vsf);
124  gGrad.release();
125  delete &gGrad;
126 
127  solution::cachePrintMessage("Recalculating", name, vsf);
128  tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
129 
130  solution::cachePrintMessage("Storing", name, vsf);
131  regIOobject::store(tgGrad.ptr());
132  GradFieldType& gGrad = const_cast<GradFieldType&>
133  (
134  mesh().objectRegistry::template lookupObject<GradFieldType>
135  (
136  name
137  )
138  );
139 
140  return gGrad;
141  }
142  }
143  else
144  {
145  if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
146  {
147  GradFieldType& gGrad = const_cast<GradFieldType&>
148  (
149  mesh().objectRegistry::template lookupObject<GradFieldType>
150  (
151  name
152  )
153  );
154 
155  if (gGrad.ownedByRegistry())
156  {
157  solution::cachePrintMessage("Deleting", name, vsf);
158  gGrad.release();
159  delete &gGrad;
160  }
161  }
162 
163  solution::cachePrintMessage("Calculating", name, vsf);
164  return calcGrad(vsf, name);
165  }
166 }
167 
168 
169 template<class Type>
170 Foam::tmp
171 <
173  <
174  typename Foam::outerProduct<Foam::vector, Type>::type,
175  Foam::fvPatchField,
177  >
178 >
180 (
182 ) const
183 {
184  return grad(vsf, "grad(" + vsf.name() + ')');
185 }
186 
187 
188 template<class Type>
189 Foam::tmp
190 <
192  <
193  typename Foam::outerProduct<Foam::vector, Type>::type,
194  Foam::fvPatchField,
196  >
197 >
199 (
201 ) const
202 {
203  typedef typename outerProduct<vector, Type>::type GradType;
205 
206  tmp<GradFieldType> tgrad = grad(tvsf());
207  tvsf.clear();
208  return tgrad;
209 }
210 
211 
212 // ************************************************************************* //
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
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:253
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Generic GeometricField class.
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:53
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
virtual ~gradScheme()
Destructor.
Definition: gradScheme.C:78
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
static const char nl
Definition: Ostream.H:262
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.
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:331
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:34
A class for managing temporary objects.
Definition: PtrList.H:54
const word & name() const
Return name.
Definition: IOobject.H:260
IOerror FatalIOError
#define InfoInFunction
Report an information message using Foam::Info.