fixedGradientFaPatchField.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const dictionary& dict,
39 )
40 {
41  if (!IOobjectOption::isAnyRead(readOpt)) return false;
42  const auto& p = faPatchFieldBase::patch();
43 
44 
45  const auto* eptr = dict.findEntry("gradient", keyType::LITERAL);
46 
47  if (eptr)
48  {
49  gradient_.assign(*eptr, p.size());
50  return true;
51  }
52 
53  if (IOobjectOption::isReadRequired(readOpt))
54  {
56  << "Required entry 'gradient' : missing for patch " << p.name()
57  << " in dictionary " << dict.relativeName() << nl
58  << exit(FatalIOError);
59  }
60 
61  return false;
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
67 template<class Type>
69 (
70  const faPatch& p,
72 )
73 :
74  faPatchField<Type>(p, iF),
75  gradient_(p.size(), Zero)
76 {}
77 
78 
79 template<class Type>
81 (
82  const faPatch& p,
84  const dictionary& dict,
85  IOobjectOption::readOption requireGrad
86 )
87 :
88  faPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
89  gradient_(p.size())
90 {
91  if (readGradientEntry(dict, requireGrad))
92  {
93  evaluate();
94  }
95  else
96  {
97  // Not read (eg, optional and missing):
98  // - treat as zero-gradient, do not evaluate
100  gradient_ = Zero;
101  }
102 }
103 
104 
105 template<class Type>
107 (
108  const fixedGradientFaPatchField<Type>& ptf,
109  const faPatch& p,
110  const DimensionedField<Type, areaMesh>& iF,
111  const faPatchFieldMapper& mapper
112 )
113 :
114  faPatchField<Type>(ptf, p, iF, mapper),
115  gradient_(ptf.gradient_, mapper)
116 {}
117 
118 
119 template<class Type>
121 (
123 )
124 :
125  faPatchField<Type>(ptf),
126  gradient_(ptf.gradient_)
127 {}
128 
129 
130 template<class Type>
132 (
135 )
136 :
137  faPatchField<Type>(ptf, iF),
138  gradient_(ptf.gradient_)
139 {}
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
144 template<class Type>
146 (
147  const faPatchFieldMapper& m
148 )
149 {
151  gradient_.autoMap(m);
152 }
153 
154 
155 template<class Type>
157 (
158  const faPatchField<Type>& ptf,
159  const labelList& addr
160 )
161 {
162  faPatchField<Type>::rmap(ptf, addr);
163 
164  const fixedGradientFaPatchField<Type>& fgptf =
165  refCast<const fixedGradientFaPatchField<Type>>(ptf);
166 
167  gradient_.rmap(fgptf.gradient_, addr);
168 }
169 
170 
171 template<class Type>
173 {
174  if (!this->updated())
175  {
176  this->updateCoeffs();
177  }
178 
180  (
181  this->patchInternalField() + gradient_/this->patch().deltaCoeffs()
182  );
183 
185 }
186 
187 
188 template<class Type>
191 (
192  const tmp<scalarField>&
193 ) const
194 {
195  return tmp<Field<Type>>::New(this->size(), pTraits<Type>::one);
196 }
197 
198 
199 template<class Type>
202 (
203  const tmp<scalarField>&
204 ) const
205 {
206  return gradient()/this->patch().deltaCoeffs();
207 }
208 
209 
210 template<class Type>
213 {
214  return tmp<Field<Type>>::New(this->size(), Zero);
215 }
216 
217 
218 template<class Type>
221 {
222  return gradient();
223 }
224 
225 
226 template<class Type>
228 {
230  gradient_.writeEntry("gradient", os);
231 }
232 
233 
234 // ************************************************************************* //
bool readGradientEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "gradient" entry into corresponding member.
dictionary dict
virtual void write(Ostream &os) const
Write.
Definition: faPatchField.C:253
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
commsTypes
Communications types.
Definition: UPstream.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
This boundary condition supplies a fixed gradient condition, such that the patch values are calculate...
void extrapolateInternal()
Assign the patch field from the internal field.
Definition: faPatchField.C:60
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
friend Ostream & operator(Ostream &, const Field< Type > &)
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
fixedGradientFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:466
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
Definition: faPatchField.C:224
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
Definition: faPatchField.C:241
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A FieldMapper for finite-area patch fields.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
readOption
Enumeration defining read preferences.