ConstantField.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::ConstantField
28 
29 Description
30  Templated function that returns a constant value.
31 
32  Usage - for entry <entryName> returning the value <value>:
33  \verbatim
34  <entryName> constant <value>
35  \endverbatim
36 
37 SourceFiles
38  ConstantField.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef PatchFunction1Types_ConstantField_H
43 #define PatchFunction1Types_ConstantField_H
44 
45 #include "PatchFunction1.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 namespace PatchFunction1Types
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class ConstantField Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class Type>
59 class ConstantField
60 :
61  public PatchFunction1<Type>
62 {
63  // Private Data
64 
65  //- Is uniform?
66  bool isUniform_;
67 
68  //- If uniform the uniformValue
69  Type uniformValue_;
70 
71  //- ConstantField value
72  Field<Type> value_;
73 
74 
75  // Private Member Functions
76 
77  //- Helper to read value from dictionary
78  static Field<Type> getValue
79  (
80  const word& keyword,
81  const dictionary& dict,
82  const label len,
83  bool& isUniform,
84  Type& uniformValue
85  );
86 
87  //- No copy assignment
88  void operator=(const ConstantField<Type>&) = delete;
89 
90 
91 public:
92 
93  //- Runtime type information
94  TypeName("constant");
95 
96 
97  // Constructors
98 
99  //- Construct from components
101  (
102  const polyPatch& pp,
103  const word& entryName,
104  const bool isUniform,
105  const Type& uniformValue,
106  const Field<Type>& nonUniformValue,
108  const bool faceValues = true
109  );
110 
111  //- Construct from entry name and dictionary
113  (
114  const polyPatch& pp,
115  const word& type,
116  const word& entryName,
117  const dictionary& dict,
118  const bool faceValues = true
119  );
120 
121  //- Copy construct
122  explicit ConstantField(const ConstantField<Type>& cnst);
123 
124  //- Copy constructor setting patch
125  explicit ConstantField
126  (
127  const ConstantField<Type>& cnst,
128  const polyPatch& pp
129  );
130 
131  //- Construct and return a clone
132  virtual tmp<PatchFunction1<Type>> clone() const
133  {
134  return tmp<PatchFunction1<Type>>(new ConstantField<Type>(*this));
135  }
136 
137  //- Construct and return a clone setting patch
138  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
139  {
141  (
142  new ConstantField<Type>(*this, pp)
143  );
144  }
145 
146 
147  //- Destructor
148  virtual ~ConstantField() = default;
149 
150 
151  // Member Functions
152 
153  // Evaluation
154 
155  //- Return constant value
156  virtual inline tmp<Field<Type>> value(const scalar x) const;
157 
158  //- Is value constant (i.e. independent of x)
159  virtual inline bool constant() const
160  {
161  return true;
162  }
163 
164  //- Is value uniform (i.e. independent of coordinate)
165  virtual inline bool uniform() const
166  {
167  return isUniform_ && PatchFunction1<Type>::uniform();
168  }
169 
170  //- Integrate between two values
171  virtual inline tmp<Field<Type>> integrate
172  (
173  const scalar x1,
174  const scalar x2
175  ) const;
176 
177 
178  // Mapping
179 
180  //- Map (and resize as needed) from self given a mapping object
181  virtual void autoMap(const FieldMapper& mapper);
182 
183  //- Reverse map the given PatchFunction1 onto this PatchFunction1
184  virtual void rmap
185  (
186  const PatchFunction1<Type>& pf1,
187  const labelList& addr
188  );
189 
190 
191  // I-O
192 
193  //- Write in dictionary format
194  virtual void writeData(Ostream& os) const;
195 };
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace PatchFunction1Types
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #include "ConstantFieldI.H"
206 
207 #ifdef NoRepository
208  #include "ConstantField.C"
209 #endif
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::PatchFunction1Types::ConstantField::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: ConstantField.C:253
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::PatchFunction1::faceValues
bool faceValues() const
Whether to generate face or point values on patch.
PatchFunction1.H
Foam::PatchFunction1Types::ConstantField
Templated function that returns a constant value.
Definition: ConstantField.H:58
Foam::PatchFunction1Types::ConstantField::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: ConstantField.H:158
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:120
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:385
Foam::PatchFunction1::type
const polyPatch const word & type
Definition: PatchFunction1.H:119
ConstantFieldI.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
Foam::PatchFunction1Types::ConstantField::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: ConstantField.H:137
Foam::PatchFunction1::uniform
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
Definition: PatchFunction1.C:133
Foam::PatchFunction1Types::ConstantField::value
virtual tmp< Field< Type > > value(const scalar x) const
Return constant value.
Definition: ConstantFieldI.H:36
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::PatchFunction1Types::ConstantField::TypeName
TypeName("constant")
Runtime type information.
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::ConstantField::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: ConstantField.H:131
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PatchFunction1Types::ConstantField::ConstantField
ConstantField(const polyPatch &pp, const word &entryName, const bool isUniform, const Type &uniformValue, const Field< Type > &nonUniformValue, const dictionary &dict=dictionary::null, const bool faceValues=true)
Construct from components.
Definition: ConstantField.C:34
Foam::PatchFunction1Types::ConstantField::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: ConstantField.C:225
Foam::PatchFunction1Types::ConstantField::~ConstantField
virtual ~ConstantField()=default
Destructor.
Foam::PatchFunction1Types::ConstantField::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: ConstantField.H:164
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::List< label >
Foam::PatchFunction1Types::ConstantField::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: ConstantFieldI.H:52
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PatchFunction1Types::ConstantField::rmap
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: ConstantField.C:241
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::uniformValue
Definition: uniformValue.H:50
ConstantField.C