freestreamFvPatchField.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-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2020 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 
29 #include "freestreamFvPatchField.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const fvPatch& p,
38 )
39 :
41  freestreamBCPtr_(nullptr)
42 {}
43 
44 
45 template<class Type>
47 (
48  const fvPatch& p,
50  const dictionary& dict
51 )
52 :
53  inletOutletFvPatchField<Type>(p, iF),
54  freestreamBCPtr_(nullptr)
55 {
57 
58  this->phiName_ = dict.getOrDefault<word>("phi", "phi");
59 
60  if
61  (
62  freestreamValue().assign
63  (
64  "freestreamValue", dict, p.size(), IOobjectOption::LAZY_READ
65  )
66  )
67  {
68  if (!this->readValueEntry(dict))
69  {
71  }
72  }
73  else
74  {
75  // Freestream value provided by another patch
76  freestreamBCPtr_ =
77  fvPatchField<Type>::New(p, iF, dict.subDict("freestreamBC"));
78 
79  // Force user to supply an initial value
80  // - we do not know if the supplied BC has all dependencies available
82  }
83 }
84 
85 
86 template<class Type>
88 (
89  const freestreamFvPatchField<Type>& ptf,
90  const fvPatch& p,
91  const DimensionedField<Type, volMesh>& iF,
92  const fvPatchFieldMapper& mapper
93 )
94 :
95  inletOutletFvPatchField<Type>(ptf, p, iF, mapper),
96  freestreamBCPtr_(nullptr)
97 {
98  if (ptf.freestreamBCPtr_)
99  {
100  freestreamBCPtr_ =
101  fvPatchField<Type>::New(ptf.freestreamBCPtr_(), p, iF, mapper);
102  }
103 }
104 
105 
106 template<class Type>
108 (
109  const freestreamFvPatchField<Type>& ptf
110 )
111 :
112  inletOutletFvPatchField<Type>(ptf),
113  freestreamBCPtr_(nullptr)
114 {
115  if (ptf.freestreamBCPtr_)
116  {
117  freestreamBCPtr_ = ptf.freestreamBCPtr_->clone();
118  }
119 }
120 
121 
122 template<class Type>
124 (
125  const freestreamFvPatchField<Type>& ptf,
126  const DimensionedField<Type, volMesh>& iF
127 )
128 :
129  inletOutletFvPatchField<Type>(ptf, iF),
130  freestreamBCPtr_(nullptr)
131 {
132  if (ptf.freestreamBCPtr_)
133  {
134  freestreamBCPtr_ = ptf.freestreamBCPtr_->clone();
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
141 template<class Type>
142 void Foam::freestreamFvPatchField<Type>::autoMap(const fvPatchFieldMapper& m)
143 {
145  if (freestreamBCPtr_)
146  {
147  freestreamBCPtr_->autoMap(m);
148  }
149 }
150 
151 
152 template<class Type>
154 (
155  const fvPatchField<Type>& ptf,
156  const labelList& addr
157 )
158 {
160 
161  const auto& fsptf = refCast<const freestreamFvPatchField<Type>>(ptf);
162 
163  if (freestreamBCPtr_ && fsptf.freestreamBCPtr_)
164  {
165  freestreamBCPtr_->rmap(fsptf.freestreamBCPtr_(), addr);
166  }
167 }
168 
169 
170 template<class Type>
172 {
173  if (this->updated())
174  {
175  return;
176  }
177 
178  if (freestreamBCPtr_)
179  {
180  freestreamBCPtr_->evaluate();
181  freestreamValue() = freestreamBCPtr_();
182  }
183 
185 }
186 
187 
188 template<class Type>
190 {
192  os.writeEntryIfDifferent<word>("phi", "phi", this->phiName_);
193 
194  if (freestreamBCPtr_)
195  {
196  os.beginBlock("freestreamBC");
197  freestreamBCPtr_->write(os);
198  os.endBlock();
199  }
200  else
201  {
202  freestreamValue().writeEntry("freestreamValue", os);
203  }
205 }
206 
207 
208 // ************************************************************************* //
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: fvPatchField.C:32
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void write(Ostream &) const
Write.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
freestreamFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
const Field< Type > & freestreamValue() const
Same as refValue()
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:375
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:372
virtual void readDict(const dictionary &dict)
Read dictionary entries.
virtual void rmap(const fvPatchField< Type > &ptf, const labelList &addr)
Reverse map the given fvPatchField onto this fvPatchField.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:336
virtual void autoMap(const fvPatchFieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
OBJstream os(runTime.globalPath()/outputName)
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:391
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
Reading is optional [identical to READ_IF_PRESENT].
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
This boundary condition provides a generic outflow condition, with specified inflow for the case of r...