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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::mappedPatchFieldBase
29
30Description
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
53SourceFiles
54 mappedPatchFieldBase.C
55
56\*---------------------------------------------------------------------------*/
57
58#ifndef mappedPatchFieldBase_H
59#define mappedPatchFieldBase_H
60
62#include "volFieldsFwd.H"
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68
69// Forward Declarations
70template<class> class interpolation;
71class mapDistribute;
72class mappedPatchBase;
73
74/*---------------------------------------------------------------------------*\
75 Class mappedPatchFieldBase Declaration
76\*---------------------------------------------------------------------------*/
77
78template<class Type>
79class 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
87protected:
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
98 word fieldName_;
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>
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;
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,
139 ) const;
140
141
142 //- Initialise field to retrieve (e.g. when value read from dictionary)
143 template<class T>
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,
177 ) const;
178
179
180public:
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,
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;
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// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type.
Definition: Field.H:82
Generic GeometricField class.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Functionality for sampling fields using mappedPatchBase. Every call to mappedField() returns a sample...
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.
const mappedPatchBase & mapper_
Mapping engine.
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.
virtual tmp< Field< Type > > mappedField() const
Map sampleField onto *this patch.
const GeometricField< T, fvPatchField, volMesh > & sampleField(const word &fieldName) const
Field to sample. Either on my or nbr mesh.
static const mappedPatchBase & mapper(const fvPatch &p, const DimensionedField< Type, volMesh > &iF)
Check that patch is of correct type.
word fieldName_
Name of field to sample.
virtual tmp< scalarField > mappedWeightField() const
Map optional weightField onto *this patch. Default is deltaCoeffs.
virtual tmp< Field< Type > > mappedInternalField() const
Map internal of sampleField onto *this patch.
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
const fvPatchField< Type > & patchField_
Underlying patch field.
word interpolationScheme_
Interpolation scheme to use for nearestcell mode.
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.
const bool setAverage_
If true adjust the mapped field to maintain average value average_.
void distribute(const word &fieldName, Field< T > &newValues) const
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.
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
runTime write()
dictionary dict