mappedValueFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 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 
27 #include "mappedPolyPatch.H"
28 #include "volFields.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
35 {
36  return
37  mapperPtr_.valid()
38  ? mapperPtr_()
39  : mappedPatchBase::getMap(this->patch().patch());
40 }
41 
42 
43 template<class Type>
46 {
47  const fvMesh& nbrMesh =
48  refCast<const fvMesh>(this->mapper().nbrMesh());
49 
50  const VolField<Type>& nbrField =
51  this->mapper().sameRegion()
52  && this->fieldName_ == this->internalField().name()
53  ? refCast<const VolField<Type>>(this->internalField())
54  : nbrMesh.template lookupObject<VolField<Type>>(this->fieldName_);
55 
56  const label nbrPatchi = this->mapper().nbrPolyPatch().index();
57 
58  return nbrField.boundaryField()[nbrPatchi];
59 }
60 
61 
62 template<class Type>
65 (
66  const Field<Type>& nbrPatchField
67 ) const
68 {
69  // Since we're inside initEvaluate/evaluate there might be processor
70  // comms underway. Change the tag we use.
71  int oldTag = UPstream::msgType();
72  UPstream::msgType() = oldTag + 1;
73 
74  // Map values
75  tmp<Field<Type>> tResult = this->mapper().fromNeighbour(nbrPatchField);
76 
77  // Set the average, if necessary
78  if (setAverage_)
79  {
80  const Type nbrAverageValue =
81  gSum(this->patch().magSf()*tResult())
82  /gSum(this->patch().magSf());
83 
84  if (mag(nbrAverageValue)/mag(average_) > 0.5)
85  {
86  tResult.ref() *= mag(average_)/mag(nbrAverageValue);
87  }
88  else
89  {
90  tResult.ref() += average_ - nbrAverageValue;
91  }
92  }
93 
94  // Restore tag
95  UPstream::msgType() = oldTag;
96 
97  return tResult;
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
103 template<class Type>
105 (
106  const fvPatch& p,
108 )
109 :
110  fixedValueFvPatchField<Type>(p, iF),
111  fieldName_(iF.name()),
112  setAverage_(false),
113  average_(Zero),
114  mapperPtr_(nullptr)
115 {}
116 
117 
118 template<class Type>
120 (
121  const fvPatch& p,
123  const dictionary& dict
124 )
125 :
126  fixedValueFvPatchField<Type>(p, iF, dict),
127  fieldName_(dict.lookupOrDefault<word>("field", iF.name())),
128  setAverage_
129  (
130  dict.lookupOrDefault<bool>("setAverage", dict.found("average"))
131  ),
132  average_
133  (
134  setAverage_
135  ? dict.lookup<Type>("average", iF.dimensions())
136  : Zero
137  ),
138  mapperPtr_
139  (
140  mappedPatchBase::specified(dict)
141  ? new mappedPatchBase
142  (
143  p.patch(),
144  dict,
145  mappedPatchBase::transformType::specified
146  )
147  : nullptr
148  )
149 {
150  if (!mapperPtr_.valid() && !isA<mappedPatchBase>(p.patch()))
151  {
152  OStringStream str;
153  str << "Field " << this->internalField().name() << " of type "
154  << type() << " on patch " << this->patch().name()
155  << " of type " << p.patch().type() << " does not "
156  << "have mapping specified (i.e., neighbourPatch, and/or "
157  << "neighbourRegion entries) nor is the patch of "
158  << mappedPolyPatch::typeName << " type";
160  << stringOps::breakIntoIndentedLines(str.str()).c_str()
161  << exit(FatalIOError);
162  }
163 
164  this->mapper().validateForField
165  (
166  *this,
167  iF,
168  dict,
169  this->mapper().sameUntransformedPatch()
170  && this->fieldName_ == this->internalField().name()
173  );
174 }
175 
176 
177 template<class Type>
179 (
181  const fvPatch& p,
183  const fieldMapper& mapper
184 )
185 :
186  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
187  fieldName_(ptf.fieldName_),
188  setAverage_(ptf.setAverage_),
189  average_(ptf.average_),
190  mapperPtr_
191  (
192  ptf.mapperPtr_.valid()
193  ? new mappedPatchBase(p.patch(), ptf.mapperPtr_())
194  : nullptr
195  )
196 {}
197 
198 
199 template<class Type>
201 (
204 )
205 :
206  fixedValueFvPatchField<Type>(ptf, iF),
207  fieldName_(ptf.fieldName_),
208  setAverage_(ptf.setAverage_),
209  average_(ptf.average_),
210  mapperPtr_
211  (
212  ptf.mapperPtr_.valid()
213  ? new mappedPatchBase(ptf.patch().patch(), ptf.mapperPtr_())
214  : nullptr
215  )
216 {}
217 
218 
219 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
220 
221 template<class Type>
223 (
224  const fvPatchField<Type>& ptf,
225  const fieldMapper& mapper
226 )
227 {
229 
230  if (mapperPtr_.valid())
231  {
232  mapperPtr_->clearOut(false);
233  }
234 }
235 
236 
237 template<class Type>
239 (
240  const fvPatchField<Type>& ptf
241 )
242 {
244 
245  if (mapperPtr_.valid())
246  {
247  mapperPtr_->clearOut(false);
248  }
249 }
250 
251 
252 template<class Type>
254 {
255  if (this->updated())
256  {
257  return;
258  }
259 
260  this->operator==(mappedValues(nbrPatchField()));
261 
263 }
264 
265 
266 template<class Type>
268 {
270 
272  (
273  os,
274  "field",
275  this->internalField().name(),
276  fieldName_
277  );
278 
279  if (setAverage_)
280  {
281  writeEntry(os, "average", average_);
282  }
283 
284  if (mapperPtr_.valid())
285  {
286  mapperPtr_->write(os);
287  }
288 
289  writeEntry(os, "value", *this);
290 }
291 
292 
293 // ************************************************************************* //
bool found
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
const word & name() const
Return name.
Definition: IOobject.H:307
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:91
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:374
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:237
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:210
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:203
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:368
virtual void map(const fvPatchField< Type > &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:193
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:120
virtual const word & name() const
Return name.
Definition: fvPatch.H:126
void validateForField(const PatchField &field, const FieldType &iF, const dictionary &context, const label froms=from::any) const
Validate that the map is appropriate for the given.
Engine and base class for poly patches which provides interpolative mapping between two globally conf...
This boundary condition maps the values from a neighbouring patch to this patch.
const mappedPatchBase & mapper() const
Return the mapping engine.
virtual void write(Ostream &) const
Write.
mappedValueFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
autoPtr< mappedPatchBase > mapperPtr_
The mapping engine.
const word fieldName_
The field to map.
tmp< Field< Type > > mappedValues(const Field< Type > &nbrPatchField) const
Return the mapped values, given the neighbouring field.
const fvPatchField< Type > & nbrPatchField() const
Return the neighbouring patch field.
virtual void map(const fvPatchField< Type > &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
bool valid(const PtrList< ModelType > &l)
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
Definition: stringOps.C:963
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
Type gSum(const FieldField< Field, Type > &f)
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p