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().changing())
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))
123 {
124 solution::cachePrintMessage("Reusing", name, vsf);
125 }
126 else
127 {
128 solution::cachePrintMessage("Updating", name, vsf);
129 delete pgGrad;
130
131 pgGrad = calcGrad(vsf, name).ptr();
132 regIOobject::store(pgGrad);
133 }
134 }
135
136 return *pgGrad;
137}
138
139
140template<class Type>
142<
144 <
148 >
149>
151(
153) const
154{
155 return grad(vsf, "grad(" + vsf.name() + ')');
156}
157
158
159template<class Type>
161<
163 <
167 >
168>
170(
172) const
173{
174 typedef typename outerProduct<vector, Type>::type GradType;
176
177 tmp<GradFieldType> tgrad = grad(tvsf());
178 tvsf.clear();
179 return tgrad;
180}
181
182
183// ************************************************************************* //
Generic GeometricField class.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:239
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Computes the gradient of an input field.
Definition: grad.H:157
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
A class for managing temporary objects.
Definition: tmp.H:65
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:54
type
Volume classification types.
Definition: volumeType.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define InfoInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130