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-2013 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  Info<< "gradScheme<Type>::New"
42  "(const fvMesh& mesh, Istream& schemeData) : "
43  "constructing gradScheme<Type>"
44  << endl;
45  }
46 
47  if (schemeData.eof())
48  {
50  (
51  "gradScheme<Type>::New"
52  "(const fvMesh& mesh, Istream& schemeData)",
53  schemeData
54  ) << "Grad scheme not specified" << endl << endl
55  << "Valid grad schemes are :" << endl
56  << IstreamConstructorTablePtr_->sortedToc()
57  << exit(FatalIOError);
58  }
59 
60  const word schemeName(schemeData);
61 
62  typename IstreamConstructorTable::iterator cstrIter =
63  IstreamConstructorTablePtr_->find(schemeName);
64 
65  if (cstrIter == IstreamConstructorTablePtr_->end())
66  {
68  (
69  "gradScheme<Type>::New"
70  "(const fvMesh& mesh, Istream& schemeData)",
71  schemeData
72  ) << "Unknown grad scheme " << schemeName << nl << nl
73  << "Valid grad schemes are :" << endl
74  << IstreamConstructorTablePtr_->sortedToc()
75  << exit(FatalIOError);
76  }
77 
78  return cstrIter()(mesh, schemeData);
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
83 
84 template<class Type>
86 {}
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 template<class Type>
92 <
94  <
95  typename Foam::outerProduct<Foam::vector, Type>::type,
96  Foam::fvPatchField,
98  >
99 >
101 (
103  const word& name
104 ) const
105 {
106  typedef typename outerProduct<vector, Type>::type GradType;
108 
109  if (!this->mesh().changing() && this->mesh().cache(name))
110  {
111  if (!mesh().objectRegistry::template foundObject<GradFieldType>(name))
112  {
113  solution::cachePrintMessage("Calculating and caching", name, vsf);
114  tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
115  regIOobject::store(tgGrad.ptr());
116  }
117 
118  solution::cachePrintMessage("Retrieving", name, vsf);
119  GradFieldType& gGrad = const_cast<GradFieldType&>
120  (
121  mesh().objectRegistry::template lookupObject<GradFieldType>(name)
122  );
123 
124  if (gGrad.upToDate(vsf))
125  {
126  return gGrad;
127  }
128  else
129  {
130  solution::cachePrintMessage("Deleting", name, vsf);
131  gGrad.release();
132  delete &gGrad;
133 
134  solution::cachePrintMessage("Recalculating", name, vsf);
135  tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
136 
137  solution::cachePrintMessage("Storing", name, vsf);
138  regIOobject::store(tgGrad.ptr());
139  GradFieldType& gGrad = const_cast<GradFieldType&>
140  (
141  mesh().objectRegistry::template lookupObject<GradFieldType>
142  (
143  name
144  )
145  );
146 
147  return gGrad;
148  }
149  }
150  else
151  {
152  if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
153  {
154  GradFieldType& gGrad = const_cast<GradFieldType&>
155  (
156  mesh().objectRegistry::template lookupObject<GradFieldType>
157  (
158  name
159  )
160  );
161 
162  if (gGrad.ownedByRegistry())
163  {
164  solution::cachePrintMessage("Deleting", name, vsf);
165  gGrad.release();
166  delete &gGrad;
167  }
168  }
169 
170  solution::cachePrintMessage("Calculating", name, vsf);
171  return calcGrad(vsf, name);
172  }
173 }
174 
175 
176 template<class Type>
177 Foam::tmp
178 <
180  <
181  typename Foam::outerProduct<Foam::vector, Type>::type,
182  Foam::fvPatchField,
184  >
185 >
187 (
189 ) const
190 {
191  return grad(vsf, "grad(" + vsf.name() + ')');
192 }
193 
194 
195 template<class Type>
196 Foam::tmp
197 <
199  <
200  typename Foam::outerProduct<Foam::vector, Type>::type,
201  Foam::fvPatchField,
203  >
204 >
206 (
208 ) const
209 {
210  typedef typename outerProduct<vector, Type>::type GradType;
212 
213  tmp<GradFieldType> tgrad = grad(tvsf());
214  tvsf.clear();
215  return tgrad;
216 }
217 
218 
219 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
virtual ~gradScheme()
Destructor.
Definition: gradScheme.C:85
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:148
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
dynamicFvMesh & mesh
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
const word & name() const
Return name.
Definition: IOobject.H:260
Generic GeometricField class.
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.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
A class for managing temporary objects.
Definition: PtrList.H:118
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition: gradScheme.C:34