Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
35template<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()
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
77template<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().topoChanging())
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) && this->mesh().upToDatePoints(*pgGrad))
123 {
124 solution::cachePrintMessage("Reusing", name, vsf);
125 }
126 else
127 {
128 solution::cachePrintMessage("Updating", name, vsf);
129 calcGrad(*pgGrad, vsf);
130 }
131 }
132
133 return *pgGrad;
134}
135
136
137template<class Type>
139<
148(
150) const
151{
152 return grad(vsf, "grad(" + vsf.name() + ')');
153}
154
155
156template<class Type>
158<
171 typedef typename outerProduct<vector, Type>::type GradType;
173
174 tmp<GradFieldType> tgrad = grad(tvsf());
175 tvsf.clear();
176 return tgrad;
177}
178
179
180template<class Type>
182(
184 <
187 volMesh
188 >& result,
190) const
191{
192 DebugPout<< "gradScheme<Type>::calcGrad on " << vsf.name()
193 << " into " << result.name() << endl;
194
195 result = calcGrad(vsf, result.name());
196}
197
198
199// ************************************************************************* //
Generic GeometricField class.
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
bool eof() const noexcept
True if end of input seen.
Definition IOstream.H:289
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &, const word &name) const =0
Calculate and return the grad of the given field.
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 which may have been cached.
Definition gradScheme.C:81
const fvMesh & mesh() const
Return const reference to mesh.
Definition gradScheme.H:138
static tmp< gradScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return a pointer to a new gradScheme created on freestore.
Definition gradScheme.C:30
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
bool store()
Register object with its registry and transfer ownership to the registry.
static void cachePrintMessage(const char *message, const word &name, const FieldType &fld)
Helper for printing cache message.
A class for managing temporary objects.
Definition tmp.H:75
Mesh data needed to do the Finite Volume discretisation.
Definition volMesh.H:47
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition error.H:637
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define InfoInFunction
Report an information message using Foam::Info.
#define DebugPout
Report an information message using Foam::Pout.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125