mappedPatchFieldBase.H
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) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2021 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 Class
28  Foam::mappedPatchFieldBase
29 
30 Description
31  Functionality for sampling fields using mappedPatchBase. Every call to
32  mappedField() returns a sampled field, optionally scaled to maintain an
33  area-weighted average.
34 
35  Example usage:
36  \verbatim
37  {
38  field T; // default is same as fvPatchField
39  setAverage false;
40  average 1.0; // only if setAverage=true
41  interpolationScheme cellPoint; // default is cell
42  }
43  \endverbatim
44 
45  \table
46  Property | Description | Required | Default
47  field | name of field to be mapped | no | this field name
48  setAverage | use average value | no | false |
49  average | average value to apply if \c setAverage = yes | partly |
50  interpolationScheme | interpolation scheme | partly | cell |
51  \endtable
52 
53 SourceFiles
54  mappedPatchFieldBase.C
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #ifndef mappedPatchFieldBase_H
59 #define mappedPatchFieldBase_H
60 
62 #include "volFieldsFwd.H"
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 // Forward Declarations
70 template<class> class interpolation;
71 class mapDistribute;
72 class mappedPatchBase;
73 
74 /*---------------------------------------------------------------------------*\
75  Class mappedPatchFieldBase Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type>
79 class mappedPatchFieldBase
80 {
81  // Private Member Functions
82 
83  //- Selective retrieval of "average" entry from the dictionary
84  static Type getAverage(const dictionary& dict, bool mandatory);
85 
86 
87 protected:
88 
89  // Protected Data
90 
91  //- Mapping engine
92  const mappedPatchBase& mapper_;
93 
94  //- Underlying patch field
95  const fvPatchField<Type>& patchField_;
96 
97  //- Name of field to sample
99 
100  //- If true adjust the mapped field to maintain average value average_
101  const bool setAverage_;
102 
103  //- Average value the mapped field is adjusted to maintain if
104  //- setAverage_ is set true
105  const Type average_;
106 
107  //- Interpolation scheme to use for nearestcell mode
109 
110 
111  // Protected Member Functions
112 
113  //- Construct field from registered elements
114  template<class T>
115  void initRetrieveField
116  (
117  const objectRegistry& obr,
118  const word& region,
119  const word& patch,
120  const labelListList& map,
121  const word& fieldName,
122  const Field<T>& fld
123  ) const;
124 
125  //- Helper : storeField and retrieveField and interpolate. Leaves fld
126  // unchanged (and returns false) if new values cannot be retrieved.
127  // Returns true otherwise.
128  template<class T>
130  (
131  const word& fieldName,
132  const label myComm,
133  const labelListList& subMap,
134  const label constructSize,
135  const labelListList& constructMap,
136  const labelListList& address,
137  const scalarListList& weights,
138  Field<T>& fld
139  ) const;
140 
141 
142  //- Initialise field to retrieve (e.g. when value read from dictionary)
143  template<class T>
144  void initRetrieveField
145  (
146  const word& fieldName,
147  const Field<T>& fld
148  ) const;
149 
150 
151  //- Store elements of field onto (sub) registry
152  template<class T>
153  void storeField
154  (
155  const objectRegistry& obr,
156  const word& region,
157  const word& patch,
158  const label myComm,
159  const labelListList& procToMap,
160  const word& fieldName,
161  const Field<T>& fld
162  ) const;
163 
164  //- Construct field from registered elements.
165  // \return true if successful
166  template<class T>
167  bool retrieveField
168  (
169  const bool allowUnset,
170  const objectRegistry& obr,
171  const word& region,
172  const word& patch,
173  const label myComm,
174  const labelListList& procToMap,
175  const word& fieldName,
176  Field<T>& fld
177  ) const;
178 
179 
180 public:
181 
182  // Constructors
183 
184  //- Construct from components
186  (
187  const mappedPatchBase& mapper,
188  const fvPatchField<Type>& patchField,
189  const word& fieldName,
190  const bool setAverage,
191  const Type average,
192  const word& interpolationScheme
193  );
194 
195  //- Construct from dictionary
197  (
198  const mappedPatchBase& mapper,
199  const fvPatchField<Type>& patchField,
200  const dictionary& dict
201  );
202 
203  //- Construct from dictionary and initial field value
204  // (for when running in database mode)
206  (
207  const mappedPatchBase& mapper,
208  const fvPatchField<Type>& patchField,
209  const dictionary& dict,
210  const Field<Type>& fld
211  );
212 
213  //- Construct empty
215  (
216  const mappedPatchBase& mapper,
217  const fvPatchField<Type>& patchField
218  );
219 
220  //- Construct copy
221  explicit mappedPatchFieldBase
222  (
224  );
225 
226  //- Construct copy, resetting patch and field
228  (
229  const mappedPatchBase& mapper,
230  const fvPatchField<Type>& patchField,
231  const mappedPatchFieldBase<Type>& base
232  );
233 
234 
235  //- Destructor
236  virtual ~mappedPatchFieldBase<Type>() = default;
237 
238 
239  // Member Functions
240 
241  //- Field to sample. Either on my or nbr mesh
242  template<class T>
244  (
245  const word& fieldName
246  ) const;
247 
248  //- Field to sample. Either on my or nbr mesh
250 
251  //- Map sampleField onto *this patch
252  virtual tmp<Field<Type>> mappedField() const;
253 
254  //- Map internal of sampleField onto *this patch
255  virtual tmp<Field<Type>> mappedInternalField() const;
256 
257  //- Map optional weightField onto *this patch. Default is deltaCoeffs
258  virtual tmp<scalarField> mappedWeightField() const;
259 
260  //- Map optional weightField (given by name) onto *this patch
261  virtual void mappedWeightField
262  (
263  const word& weightFieldName,
264  tmp<scalarField>& thisWeights,
265  tmp<scalarField>& nbrWeights
266  ) const;
267 
268  //- Write
269  virtual void write(Ostream& os) const;
270 
271 
272  // Helpers
273 
274  //- Check that patch is of correct type
275  static const mappedPatchBase& mapper
276  (
277  const fvPatch& p,
279  );
280 
281  //- Wrapper for mapDistribute::distribute that knows about
282  //- dabase mapping
283  template<class T>
284  void distribute(const word& fieldName, Field<T>& newValues) const;
285 };
286 
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 } // End namespace Foam
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #ifdef NoRepository
295  #include "mappedPatchFieldBase.C"
296 #endif
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
volFieldsFwd.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::mappedPatchFieldBase::average_
const Type average_
Definition: mappedPatchFieldBase.H:131
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::mappedPatchFieldBase::mappedPatchFieldBase
mappedPatchFieldBase(const mappedPatchBase &mapper, const fvPatchField< Type > &patchField, const word &fieldName, const bool setAverage, const Type average, const word &interpolationScheme)
Construct from components.
Definition: mappedPatchFieldBase.C:321
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::mappedPatchFieldBase::patchField_
const fvPatchField< Type > & patchField_
Underlying patch field.
Definition: mappedPatchFieldBase.H:121
Foam::mappedPatchFieldBase::storeAndRetrieveField
bool storeAndRetrieveField(const word &fieldName, const label myComm, const labelListList &subMap, const label constructSize, const labelListList &constructMap, const labelListList &address, const scalarListList &weights, Field< T > &fld) const
Helper : storeField and retrieveField and interpolate. Leaves fld.
Definition: mappedPatchFieldBase.C:252
Foam::mappedPatchFieldBase::mappedField
virtual tmp< Field< Type > > mappedField() const
Map sampleField onto *this patch.
Definition: mappedPatchFieldBase.C:614
Foam::mappedPatchFieldBase::storeField
void storeField(const objectRegistry &obr, const word &region, const word &patch, const label myComm, const labelListList &procToMap, const word &fieldName, const Field< T > &fld) const
Store elements of field onto (sub) registry.
Definition: mappedPatchFieldBase.C:54
Foam::mappedPatchBase
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Definition: mappedPatchBase.H:112
Foam::mappedPatchFieldBase::fieldName_
word fieldName_
Name of field to sample.
Definition: mappedPatchFieldBase.H:124
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::mappedPatchFieldBase::retrieveField
bool retrieveField(const bool allowUnset, const objectRegistry &obr, const word &region, const word &patch, const label myComm, const labelListList &procToMap, const word &fieldName, Field< T > &fld) const
Construct field from registered elements.
Definition: mappedPatchFieldBase.C:105
Foam::Field< T >
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
Foam::mappedPatchFieldBase::distribute
void distribute(const word &fieldName, Field< T > &newValues) const
Definition: mappedPatchFieldBase.C:524
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::mappedPatchFieldBase
Functionality for sampling fields using mappedPatchBase. Every call to mappedField() returns a sample...
Definition: mappedPatchFieldBase.H:105
Foam::mappedPatchFieldBase::mapper
static const mappedPatchBase & mapper(const fvPatch &p, const DimensionedField< Type, volMesh > &iF)
Check that patch is of correct type.
Definition: mappedPatchFieldBase.C:959
Foam::mappedPatchFieldBase::mappedWeightField
virtual tmp< scalarField > mappedWeightField() const
Map optional weightField onto *this patch. Default is deltaCoeffs.
Definition: mappedPatchFieldBase.C:859
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::mappedPatchFieldBase::initRetrieveField
void initRetrieveField(const objectRegistry &obr, const word &region, const word &patch, const labelListList &map, const word &fieldName, const Field< T > &fld) const
Construct field from registered elements.
Definition: mappedPatchFieldBase.C:201
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::mappedPatchFieldBase::interpolationScheme_
word interpolationScheme_
Interpolation scheme to use for nearestcell mode.
Definition: mappedPatchFieldBase.H:134
Foam::mappedPatchFieldBase::write
virtual void write(Ostream &os) const
Write.
Definition: mappedPatchFieldBase.C:1007
Foam::mappedPatchFieldBase::mapper_
const mappedPatchBase & mapper_
Mapping engine.
Definition: mappedPatchFieldBase.H:118
Foam::mappedPatchFieldBase::sampleField
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
Definition: mappedPatchFieldBase.C:515
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< labelList >
fixedValueFvPatchFields.H
Foam::mappedPatchFieldBase::mappedInternalField
virtual tmp< Field< Type > > mappedInternalField() const
Map internal of sampleField onto *this patch.
Definition: mappedPatchFieldBase.C:823
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
mappedPatchFieldBase.C
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::mappedPatchFieldBase::setAverage_
const bool setAverage_
If true adjust the mapped field to maintain average value average_.
Definition: mappedPatchFieldBase.H:127
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:328
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54