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(p.patch(), dict, false)
142  : nullptr
143  )
144 {
145  if (!mapperPtr_.valid() && !isA<mappedPatchBase>(p.patch()))
146  {
147  OStringStream str;
148  str << "Field " << this->internalField().name() << " of type "
149  << type() << " on patch " << this->patch().name()
150  << " of type " << p.patch().type() << " does not "
151  << "have mapping specified (i.e., neighbourPatch, and/or "
152  << "neighbourRegion entries) nor is the patch of "
153  << mappedPolyPatch::typeName << " type";
155  << stringOps::breakIntoIndentedLines(str.str()).c_str()
156  << exit(FatalIOError);
157  }
158 
159  this->mapper().validateForField
160  (
161  *this,
162  iF,
163  dict,
164  this->mapper().sameUntransformedPatch()
165  && this->fieldName_ == this->internalField().name()
168  );
169 }
170 
171 
172 template<class Type>
174 (
176  const fvPatch& p,
178  const fieldMapper& mapper
179 )
180 :
181  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
182  fieldName_(ptf.fieldName_),
183  setAverage_(ptf.setAverage_),
184  average_(ptf.average_),
185  mapperPtr_
186  (
187  ptf.mapperPtr_.valid()
188  ? new mappedPatchBase(p.patch(), ptf.mapperPtr_())
189  : nullptr
190  )
191 {}
192 
193 
194 template<class Type>
196 (
199 )
200 :
201  fixedValueFvPatchField<Type>(ptf, iF),
202  fieldName_(ptf.fieldName_),
203  setAverage_(ptf.setAverage_),
204  average_(ptf.average_),
205  mapperPtr_
206  (
207  ptf.mapperPtr_.valid()
208  ? new mappedPatchBase(ptf.patch().patch(), ptf.mapperPtr_())
209  : nullptr
210  )
211 {}
212 
213 
214 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
215 
216 template<class Type>
218 (
219  const fvPatchField<Type>& ptf,
220  const fieldMapper& mapper
221 )
222 {
224 
225  if (mapperPtr_.valid())
226  {
227  mapperPtr_->clearOut();
228  }
229 }
230 
231 
232 template<class Type>
234 (
235  const fvPatchField<Type>& ptf
236 )
237 {
239 
240  if (mapperPtr_.valid())
241  {
242  mapperPtr_->clearOut();
243  }
244 }
245 
246 
247 template<class Type>
249 {
250  if (this->updated())
251  {
252  return;
253  }
254 
255  this->operator==(mappedValues(nbrPatchField()));
256 
258 }
259 
260 
261 template<class Type>
263 {
265 
267  (
268  os,
269  "field",
270  this->internalField().name(),
271  fieldName_
272  );
273 
274  if (setAverage_)
275  {
276  writeEntry(os, "average", average_);
277  }
278 
279  if (mapperPtr_.valid())
280  {
281  mapperPtr_->write(os);
282  }
283 
284  writeEntry(os, "value", *this);
285 }
286 
287 
288 // ************************************************************************* //
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:310
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 keyword definitions, which are a keyword followed by any number of values (e....
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:99
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:362
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:229
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:202
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:195
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:356
virtual void map(const fvPatchField< Type > &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:185
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:181
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
dimensioned< scalar > mag(const dimensioned< Type > &)
IOerror FatalIOError
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