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 -------------------------------------------------------------------------------
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::PatchFunction1Types::Sampled
28 
29 Description
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 
39 Usage
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 
69 SourceFiles
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 
83 namespace Foam
84 {
85 namespace PatchFunction1Types
86 {
87 
88 /*---------------------------------------------------------------------------*\
89  Class Sampled Declaration
90 \*---------------------------------------------------------------------------*/
91 
92 template<class Type>
93 class 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 
104 protected:
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 
128 public:
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  );
161 
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 
180 
181  //- Destructor
182  virtual ~Sampled() = default;
183 
184 
185  // Member Functions
186 
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
208  virtual tmp<Field<Type>> integrate
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 
221 
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 // ************************************************************************* //
Foam::PatchFunction1Types::Sampled::Sampled
Sampled(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name and dictionary.
Definition: Sampled.C:54
volFieldsFwd.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::PatchFunction1Types::Sampled::setAverage_
const bool setAverage_
If true adjust the mapped field to maintain average value average_.
Definition: Sampled.H:161
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::PatchFunction1Types::Sampled::sampleField
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:106
PatchFunction1.H
Foam::PatchFunction1Types::Sampled::interpolationScheme_
word interpolationScheme_
Interpolation scheme to use for nearestcell mode.
Definition: Sampled.H:168
Foam::mappedPatchBase
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
Definition: mappedPatchBase.H:112
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:118
Foam::PatchFunction1Types::Sampled::fieldName_
word fieldName_
Name of the field.
Definition: Sampled.H:158
Foam::PatchFunction1Types::Sampled::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Sampled.C:317
Foam::PatchFunction1Types::Sampled::haveSampleField
bool haveSampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:125
Foam::PatchFunction1Types::Sampled::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: Sampled.H:251
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::PatchFunction1Types::Sampled::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Sampled.C:329
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:60
Foam::PatchFunction1Types::Sampled::TypeName
TypeName("sampled")
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Sampled.C
Foam::PatchFunction1Types::Sampled::~Sampled
virtual ~Sampled()=default
Destructor.
Foam::PatchFunction1Types::Sampled::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: Sampled.H:212
Foam::PatchFunction1::pp
const polyPatch & pp
Definition: PatchFunction1.H:116
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:119
Foam::PatchFunction1Types::Sampled::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: Sampled.H:245
Foam::PatchFunction1Types::Sampled::value
virtual tmp< Field< Type > > value(const scalar x) const
Return sampled value.
Definition: Sampled.C:146
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:121
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PatchFunction1Types::Sampled::operator=
void operator=(const Sampled< Type > &)=delete
No copy assignment.
Foam::PatchFunction1::dictionary
dictionary
Definition: PatchFunction1.H:114
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::PatchFunction1Types::Sampled
PatchFunction1 to sample an existing field.
Definition: Sampled.H:142
Foam::PatchFunction1Types::Sampled::average_
const Type average_
Definition: Sampled.H:165
Foam::PatchFunction1Types::Sampled::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: Sampled.H:221
mappedPatchBase.H