Sampled.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) 2018-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::PatchFunction1Types::Sampled
28
29Description
30 PatchFunction1 to sample an existing field.
31
32 It is the exact functionality from mappedField boundary condition
33 with the following differences:
34 - the field name is specified. So any derived fields will have the
35 same field name to sample.
36 - if used with uniformFixedValue boundary condition there is the problem
37 that that re-evaluates instead of reading/mapping.
38
39Usage
40 \table
41 Property | Description | Required | Default value
42 field | Field name | yes |
43 sampleMode | how to obtain samples | yes |
44 sampleRegion | mesh to sample | no | ""
45 samplePatch | patch to sample | no | ""
46 offsetMode | how to offset samples | no | uniform
47 offset | uniform offset vector | no | (0 0 0)
48 interpolationScheme | interpolation method | yes | cell
49 setAverage | optional average adjustment | no | false
50 average | optional average value | no |
51 \endtable
52
53 Example of the boundary condition specification:
54 \verbatim
55 <patchName>
56 {
57 // Field to sample
58 field U;
59
60 // Geometric/mapping info (equivalent of 'mappedPatch' patch type)
61 sampleMode nearestCell;
62 offset (0 -0.001 0);
63
64 // Field specific info (equivalent of 'mappedField' patch field type)
65 interpolationScheme cell;
66 }
67 \endverbatim
68
69SourceFiles
70 Sampled.C
71
72\*---------------------------------------------------------------------------*/
73
74#ifndef PatchFunction1Types_Sampled_H
75#define PatchFunction1Types_Sampled_H
76
77#include "PatchFunction1.H"
78#include "mappedPatchBase.H"
79#include "volFieldsFwd.H"
80
81// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82
83namespace Foam
84{
85namespace PatchFunction1Types
86{
87
88/*---------------------------------------------------------------------------*\
89 Class Sampled Declaration
90\*---------------------------------------------------------------------------*/
91
92template<class Type>
93class Sampled
94:
95 public PatchFunction1<Type>,
96 public mappedPatchBase
97{
98 // Private Member Functions
99
100 //- Selective retrieval of "average" entry from the dictionary
101 static Type getAverage(const dictionary& dict, bool mandatory);
102
103
104protected:
105
106 // Protected data
107
108 //- Name of the field
109 word fieldName_;
110
111 //- If true adjust the mapped field to maintain average value average_
112 const bool setAverage_;
113
114 //- Average value the mapped field is adjusted to maintain if
115 //- setAverage_ is set true
116 const Type average_;
117
118 //- Interpolation scheme to use for nearestcell mode
120
121
122 // Private Member Functions
123
124 //- Field to sample. Either on my or nbr mesh
125 bool haveSampleField() const;
126
127
128public:
129
130 // Runtime type information
131 TypeName("sampled");
132
133
134 // Generated Methods
135
136 //- No copy assignment
137 void operator=(const Sampled<Type>&) = delete;
138
139
140 // Constructors
141
142 //- Construct from entry name and dictionary
143 Sampled
144 (
145 const polyPatch& pp,
146 const word& redirectType,
147 const word& entryName,
148 const dictionary& dict,
149 const bool faceValues = true
150 );
151
152 //- Copy construct
153 explicit Sampled(const Sampled<Type>& rhs);
154
155 //- Copy construct setting patch
156 explicit Sampled
157 (
158 const Sampled<Type>& rhs,
159 const polyPatch& pp
160 );
162 //- Construct and return a clone
163 virtual tmp<PatchFunction1<Type>> clone() const
164 {
166 (
167 new Sampled<Type>(*this)
168 );
169 }
170
171 //- Construct and return a clone setting patch
172 virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
173 {
175 (
176 new Sampled<Type>(*this, pp)
177 );
178 }
179
181 //- Destructor
182 virtual ~Sampled() = default;
183
184
185 // Member Functions
187 //- Field to sample. Either on my or nbr mesh
189
190 // Evaluation
191
192 //- Return sampled value
193 virtual tmp<Field<Type>> value(const scalar x) const;
194
195 //- Is value constant (i.e. independent of x)
196 virtual inline bool constant() const
197 {
198 return false;
199 }
200
201 //- Is value uniform (i.e. independent of coordinate)
202 virtual inline bool uniform() const
203 {
204 return false;
205 }
206
207 //- Integrate between two values
209 (
210 const scalar x1,
211 const scalar x2
212 ) const;
213
214
215 // I-O
216
217 //- Write in dictionary format
218 virtual void writeData(Ostream& os) const;
219};
220
222// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223
224} // End namespace PatchFunction1Types
225} // End namespace Foam
226
227// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228
229#ifdef NoRepository
230 #include "Sampled.C"
231#endif
232
233// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234
235#endif
236
237// ************************************************************************* //
Generic GeometricField class.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
PatchFunction1 to sample an existing field.
Definition: Sampled.H:146
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Sampled.C:317
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: Sampled.H:251
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Sampled.C:329
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: Sampled.H:221
bool haveSampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:125
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: Sampled.H:245
virtual tmp< Field< Type > > value(const scalar x) const
Return sampled value.
Definition: Sampled.C:146
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: Sampled.H:212
virtual ~Sampled()=default
Destructor.
word fieldName_
Name of the field.
Definition: Sampled.H:158
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:106
word interpolationScheme_
Interpolation scheme to use for nearestcell mode.
Definition: Sampled.H:168
void operator=(const Sampled< Type > &)=delete
No copy assignment.
const bool setAverage_
If true adjust the mapped field to maintain average value average_.
Definition: Sampled.H:161
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const polyPatch const word const word & entryName
const polyPatch const word const word const dictionary & dict
const polyPatch & pp
const polyPatch const word const word const dictionary const bool faceValues
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73