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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::mappedPatchFieldBase
28 
29 Description
30  Functionality for sampling fields using mappedPatchBase. Every call to
31  mappedField() returns a sampled field, optionally scaled to maintain an
32  area-weighted average.
33 
34  Example usage:
35  \verbatim
36  {
37  field T; // default is same as fvPatchField
38  setAverage false;
39  average 1.0; // only if setAverage=true
40  interpolationScheme cellPoint; // default is cell
41  }
42  \endverbatim
43 
44  \table
45  Property | Description | Required | Default
46  field | name of field to be mapped | no | this field name
47  setAverage | use average value | no | false |
48  average | average value to apply if \c setAverage = yes | partly |
49  interpolationScheme | interpolation scheme | partly | cell |
50  \endtable
51 
52 SourceFiles
53  mappedPatchFieldBase.C
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #ifndef mappedPatchFieldBase_H
58 #define mappedPatchFieldBase_H
59 
61 #include "volFieldsFwd.H"
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace Foam
66 {
67 
68 // Forward Declarations
69 class mappedPatchBase;
70 template<class> class interpolation;
71 class mapDistribute;
72 
73 /*---------------------------------------------------------------------------*\
74  Class mappedPatchFieldBase Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class Type>
78 class mappedPatchFieldBase
79 {
80  // Private Member Functions
81 
82  //- Selective retrieval of "average" entry from the dictionary
83  static Type getAverage(const dictionary& dict, bool mandatory);
84 
85 
86 protected:
87 
88  // Protected data
89 
90  //- Mapping engine
91  const mappedPatchBase& mapper_;
92 
93  //- Underlying patch field
94  const fvPatchField<Type>& patchField_;
95 
96  //- Name of field to sample
98 
99  //- If true adjust the mapped field to maintain average value average_
100  const bool setAverage_;
101 
102  //- Average value the mapped field is adjusted to maintain if
103  //- setAverage_ is set true
104  const Type average_;
105 
106  //- Interpolation scheme to use for nearestcell mode
108 
109 
110  // Protected Member Functions
111 
112  //- Construct field from registered elements
113  template<class T>
114  void initRetrieveField
115  (
116  const objectRegistry& obr,
117  const word& region,
118  const word& patch,
119  const mapDistribute& map,
120  const word& fieldName,
121  const Field<T>& fld
122  ) const;
123 
124 
125 public:
126 
127  // Constructors
128 
129  //- Construct from components
131  (
132  const mappedPatchBase& mapper,
133  const fvPatchField<Type>& patchField,
134  const word& fieldName,
135  const bool setAverage,
136  const Type average,
137  const word& interpolationScheme
138  );
139 
140  //- Construct from dictionary
142  (
143  const mappedPatchBase& mapper,
144  const fvPatchField<Type>& patchField,
145  const dictionary& dict
146  );
147 
148  //- Construct from dictionary and initial field value
149  // (for when running in database mode)
151  (
152  const mappedPatchBase& mapper,
153  const fvPatchField<Type>& patchField,
154  const dictionary& dict,
155  const Field<Type>& fld
156  );
157 
158  //- Construct empty
160  (
161  const mappedPatchBase& mapper,
162  const fvPatchField<Type>& patchField
163  );
164 
165  //- Construct copy
166  explicit mappedPatchFieldBase
167  (
169  );
170 
171  //- Construct copy, resetting patch and field
173  (
174  const mappedPatchBase& mapper,
175  const fvPatchField<Type>& patchField,
176  const mappedPatchFieldBase<Type>& base
177  );
178 
179 
180  //- Destructor
181  virtual ~mappedPatchFieldBase<Type>() = default;
182 
183 
184  // Member Functions
185 
186  //- Field to sample. Either on my or nbr mesh
187  template<class T>
189  (
190  const word& fieldName
191  ) const;
192 
193  //- Field to sample. Either on my or nbr mesh
195 
196  //- Map sampleField onto *this patch
197  virtual tmp<Field<Type>> mappedField() const;
198 
199  //- Map internal of sampleField onto *this patch
200  virtual tmp<Field<Type>> mappedInternalField() const;
201 
202  //- Map optional weightField onto *this patch. Default is deltaCoeffs
203  virtual tmp<scalarField> mappedWeightField() const;
204 
205  //- Map optional weightField (given by name) onto *this patch
206  virtual void mappedWeightField
207  (
208  const word& weightFieldName,
209  tmp<scalarField>& thisWeights,
210  tmp<scalarField>& nbrWeights
211  ) const;
212 
213  //- Write
214  virtual void write(Ostream& os) const;
215 
216 
217  // Helpers
218 
219  //- Check that patch is of correct type
220  static const mappedPatchBase& mapper
221  (
222  const fvPatch& p,
224  );
225 
226  //- Initialise field to retrieve (used e.g. when value read from
227  // dictionary)
228  template<class T>
229  void initRetrieveField
230  (
231  const word& fieldName,
232  const Field<T>& fld
233  ) const;
234 
235  //- Store elements of field onto (sub) registry
236  template<class T>
237  void storeField
238  (
239  const objectRegistry& obr,
240  const word& region,
241  const word& patch,
242  const labelListList& procToMap,
243  const word& fieldName,
244  const Field<T>& fld
245  ) const;
246 
247  //- Construct field from registered elements
248  template<class T>
249  void retrieveField
250  (
251  const bool allowUnset,
252  const objectRegistry& obr,
253  const word& region,
254  const word& patch,
255  const labelListList& procToMap,
256  const word& fieldName,
257  Field<T>& fld
258  ) const;
259 
260  //- Wrapper for mapDistribute::distribute that knows about
261  //- dabase mapping
262  template<class T>
263  void distribute(const word& fieldName, Field<T>& newValues) const;
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #ifdef NoRepository
274  #include "mappedPatchFieldBase.C"
275 #endif
276 
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 
279 #endif
280 
281 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
volFieldsFwd.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::mappedPatchFieldBase::average_
const Type average_
Definition: mappedPatchFieldBase.H:130
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:223
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:120
Foam::mappedPatchFieldBase::mappedField
virtual tmp< Field< Type > > mappedField() const
Map sampleField onto *this patch.
Definition: mappedPatchFieldBase.C:452
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:123
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::mappedPatchFieldBase::storeField
void storeField(const objectRegistry &obr, const word &region, const word &patch, const labelListList &procToMap, const word &fieldName, const Field< T > &fld) const
Store elements of field onto (sub) registry.
Definition: mappedPatchFieldBase.C:54
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:411
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:104
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:797
Foam::mappedPatchFieldBase::mappedWeightField
virtual tmp< scalarField > mappedWeightField() const
Map optional weightField onto *this patch. Default is deltaCoeffs.
Definition: mappedPatchFieldBase.C:697
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::mappedPatchFieldBase::interpolationScheme_
word interpolationScheme_
Interpolation scheme to use for nearestcell mode.
Definition: mappedPatchFieldBase.H:133
Foam::mappedPatchFieldBase::write
virtual void write(Ostream &os) const
Write.
Definition: mappedPatchFieldBase.C:842
Foam::mappedPatchFieldBase::mapper_
const mappedPatchBase & mapper_
Mapping engine.
Definition: mappedPatchFieldBase.H:117
Foam::mappedPatchFieldBase::sampleField
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
Definition: mappedPatchFieldBase.C:402
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:661
Foam::mappedPatchFieldBase::initRetrieveField
void initRetrieveField(const objectRegistry &obr, const word &region, const word &patch, const mapDistribute &map, const word &fieldName, const Field< T > &fld) const
Construct field from registered elements.
Definition: mappedPatchFieldBase.C:170
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:126
Foam::mappedPatchFieldBase::retrieveField
void retrieveField(const bool allowUnset, const objectRegistry &obr, const word &region, const word &patch, const labelListList &procToMap, const word &fieldName, Field< T > &fld) const
Construct field from registered elements.
Definition: mappedPatchFieldBase.C:104
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