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 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  //- No copy assignment
128  void operator=(const Sampled<Type>&) = delete;
129 
130 
131 public:
132 
133  // Runtime type information
134  TypeName("sampled");
135 
136 
137  // Constructors
138 
139  //- Construct from entry name and dictionary
140  Sampled
141  (
142  const polyPatch& pp,
143  const word& type,
144  const word& entryName,
145  const dictionary& dict,
146  const bool faceValues = true
147  );
148 
149  //- Copy constructor
150  explicit Sampled(const Sampled<Type>& ut);
151 
152  //- Copy constructor setting patch
153  explicit Sampled
154  (
155  const Sampled<Type>& ut,
156  const polyPatch& pp
157  );
158 
159  //- Construct and return a clone
160  virtual tmp<PatchFunction1<Type>> clone() const
161  {
163  (
164  new Sampled<Type>(*this)
165  );
166  }
167 
168  //- Construct and return a clone setting patch
169  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
170  {
172  (
173  new Sampled<Type>(*this, pp)
174  );
175  }
176 
177 
178  //- Destructor
179  virtual ~Sampled() = default;
180 
181 
182  // Member Functions
183 
184  //- Field to sample. Either on my or nbr mesh
186 
187  // Evaluation
188 
189  //- Return sampled value
190  virtual tmp<Field<Type>> value(const scalar x) const;
191 
192  //- Is value constant (i.e. independent of x)
193  virtual inline bool constant() const
194  {
195  return false;
196  }
197 
198  //- Is value uniform (i.e. independent of coordinate)
199  virtual inline bool uniform() const
200  {
201  return false;
202  }
203 
204  //- Integrate between two values
205  virtual tmp<Field<Type>> integrate
206  (
207  const scalar x1,
208  const scalar x2
209  ) const;
210 
211 
212  // I-O
213 
214  //- Write in dictionary format
215  virtual void writeData(Ostream& os) const;
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace PatchFunction1Types
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #ifdef NoRepository
227  #include "Sampled.C"
228 #endif
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #endif
233 
234 // ************************************************************************* //
volFieldsFwd.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:59
Foam::PatchFunction1Types::Sampled::sampleField
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:111
PatchFunction1.H
Foam::PatchFunction1Types::Sampled::Sampled
Sampled(const polyPatch &pp, const word &type, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name and dictionary.
Definition: Sampled.C:54
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:105
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:120
Foam::PatchFunction1Types::Sampled::fieldName_
word fieldName_
Name of the field.
Definition: Sampled.H:158
Foam::PatchFunction1::type
const polyPatch const word & type
Definition: PatchFunction1.H:119
Foam::PatchFunction1Types::Sampled::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Sampled.C:322
Foam::PatchFunction1Types::Sampled::haveSampleField
bool haveSampleField() const
Field to sample. Either on my or nbr mesh.
Definition: Sampled.C:130
Foam::PatchFunction1Types::Sampled::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: Sampled.H:248
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::PatchFunction1Types::Sampled::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Sampled.C:334
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:63
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:209
Foam::PatchFunction1::pp
const polyPatch & pp
Definition: PatchFunction1.H:118
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:121
Foam::PatchFunction1Types::Sampled::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: Sampled.H:242
Foam::PatchFunction1Types::Sampled::value
virtual tmp< Field< Type > > value(const scalar x) const
Return sampled value.
Definition: Sampled.C:151
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:123
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:116
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:218
mappedPatchBase.H