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