All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Product2.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Function2s::Product
26 
27 Description
28  Function2 which returns the product of two independent Function1-s of the
29  two input arguments. The two function1s are specified as value1 and value2.
30 
31  Example to scale a table of vectors in the first argument with a ramp in
32  the second argument:
33  \verbatim
34  <name>
35  {
36  type product;
37  value1<vector> table
38  (
39  (0.00 (0 0 0))
40  (0.25 (1 0 0))
41  (0.50 (0 0 0))
42  );
43  value2<scalar>
44  {
45  type linearRamp;
46  start 1;
47  duration 4;
48  }
49  }
50  \endverbatim
51 
52  Note that only one type specification (the <vector>/<scalar>/... part)
53  is needed in general for the value entries, and no type specifications
54  are needed if the function is scalar.
55 
56 SourceFiles
57  Product.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef Product2_H
62 #define Product2_H
63 
64 #include "Function1.H"
65 #include "Function2.H"
66 #include "fieldTypes.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 namespace Function2s
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class ProductValueTypeIsValid Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type, class ValueType, class Enable = void>
81 {
82  static const bool value = false;
83 };
84 
85 
86 template<class Type>
87 struct ProductValueTypeIsValid<Type, scalar>
88 {
89  static const bool value = true;
90 };
91 
92 
93 template<class Type, class ValueType>
95 <
96  Type,
97  ValueType,
98  typename std::enable_if
99  <
100  (pTraits<ValueType>::rank > 0)
101  && (pTraits<ValueType>::rank <= pTraits<Type>::rank)
102  >::type
103 >
104 {
105  static const bool value =
106  std::is_same
107  <
108  Type,
109  typename outerProduct
110  <
111  ValueType,
112  typename typeOfRank
113  <
114  scalar,
116  >::type
117  >::type
118  >::value;
119 };
120 
121 
122 /*---------------------------------------------------------------------------*\
123  Class ProductFilter Declaration
124 \*---------------------------------------------------------------------------*/
125 
126 template<class Type>
127 struct ProductFilter
128 {
129  inline const Type& operator()(const Type& value) const
130  {
131  return value;
132  }
133 
134  template<class WrongType>
135  const Type& operator()(const WrongType& value) const
136  {
137  return NullObjectRef<Type>();
138  }
139 };
140 
141 
142 /*---------------------------------------------------------------------------*\
143  Class ProductFunction1s Declaration
144 \*---------------------------------------------------------------------------*/
145 
146 template<class Type, direction rank = pTraits<Type>::rank>
147 class ProductFunction1s
148 :
149  public ProductFunction1s<Type, rank - 1>
150 {
151  // Private Typedefs
152 
153  //- Type of the function
154  typedef
155  Function1
156  <
157  typename std::conditional
158  <
159  rank == pTraits<Type>::rank,
160  Type,
162  >::type
163  > function1Type;
164 
165 
166 public:
167 
168  // Public Data
169 
170  //- Functions
172 
173 
174  // Constructors
175 
176  //- Construct from a dictionary
178  (
179  const unitConversions& units,
180  const dictionary& dict,
181  const Pair<Tuple2<word, label>>& typeAndRanks
182  );
183 
184  //- Copy construct
186 
187 
188  // Public Member Functions
189 
190  //- Evaluate
191  inline Type value(const scalar x, const scalar y) const;
192 
193  //- Write to a stream
194  void write(Ostream& os, const unitConversions& units) const;
195 };
196 
197 
198 /*---------------------------------------------------------------------------*\
199  Class ProductFunction1s<0> Declaration
200 \*---------------------------------------------------------------------------*/
201 
202 template<class Type>
203 class ProductFunction1s<Type, 0>
204 {
205 public:
206 
207  // Public Data
208 
209  //- Functions
211 
212 
213  // Constructors
214 
215  //- Construct from a dictionary
217  (
218  const unitConversions& units,
219  const dictionary& dict,
220  const Pair<Tuple2<word, label>>& typeAndRanks
221  );
222 
223  //- Copy construct
225 
226 
227  // Public Member Functions
228 
229  //- Evaluate
230  inline Type value(const scalar x, const scalar y) const;
231 
232  //- Write to a stream
233  void write(Ostream& os, const unitConversions& units) const;
234 };
235 
236 
237 /*---------------------------------------------------------------------------*\
238  Class Product Declaration
239 \*---------------------------------------------------------------------------*/
240 
241 template<class Type>
242 class Product
243 :
244  public FieldFunction2<Type, Product<Type>>
245 {
246  // Private Data
247 
248  //- Functions
250 
251 
252 public:
253 
254  // Runtime type information
255  TypeName("product");
256 
257 
258  // Constructors
259 
260  //- Construct from name and dictionary
261  Product
262  (
263  const word& name,
264  const unitConversions& units,
265  const dictionary& dict
266  );
267 
268  //- Copy constructor
269  Product(const Product<Type>& se);
270 
271 
272  //- Destructor
273  virtual ~Product();
274 
275 
276  // Member Functions
277 
278  //- Return value
279  virtual inline Type value(const scalar x, const scalar y) const;
280 
281  //- Write in dictionary format
282  virtual void write(Ostream& os, const unitConversions& units) const;
283 
284 
285  // Member Operators
286 
287  //- Disallow default bitwise assignment
288  void operator=(const Product<Type>&) = delete;
289 };
290 
291 
292 // Global Functions
293 
294 //- Return the name of the value entry for the given argument
295 inline word valueName(const direction argument);
296 
297 //- Return the name of the value entry for the given argument and type name
298 inline word valueName(const direction argument, const word& typeName);
299 
300 //- Return the name of the value entry for the given argument and type
301 template<class Type>
302 inline word valueName(const direction argument);
303 
304 //- Return the name of the value entry for the given argument and type and rank
305 inline word valueName
306 (
307  const direction argument,
308  const Tuple2<word, label>& typeAndRank
309 );
310 
311 //- Lookup the type and rank for the value entry for the given argument
312 template<class Type, class ValueType>
314 (
315  const dictionary& dict,
316  const direction argument,
317  Tuple2<word, label>& typeAndRank,
318  label& found
319 );
320 
321 //- Lookup the type and rank for the value entry for the given argument
322 template<class Type>
324 (
325  const dictionary& dict,
326  const direction argument
327 );
328 
329 //- Lookup the types and ranks for the value entries
330 template<class Type>
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Function2s
337 } // End namespace Foam
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 #include "Product2I.H"
342 
343 #ifdef NoRepository
344  #include "Product2.C"
345 #endif
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #endif
350 
351 // ************************************************************************* //
scalar y
bool found
Run-time selectable general function of one variable.
Definition: Function1.H:125
const word & name() const
Return the name of the entry.
Definition: Function2.C:78
Pair< autoPtr< function1Type > > fs
Functions.
Definition: Product2.H:170
void write(Ostream &os, const unitConversions &units) const
Write to a stream.
Definition: Product2.C:141
Type value(const scalar x, const scalar y) const
Evaluate.
Definition: Product2I.H:32
ProductFunction1s(const unitConversions &units, const dictionary &dict, const Pair< Tuple2< word, label >> &typeAndRanks)
Construct from a dictionary.
Definition: Product2.C:32
Function2 which returns the product of two independent Function1-s of the two input arguments....
Definition: Product2.H:244
void operator=(const Product< Type > &)=delete
Disallow default bitwise assignment.
virtual ~Product()
Destructor.
Definition: Product2.C:133
virtual void write(Ostream &os, const unitConversions &units) const
Write in dictionary format.
Definition: Product2.C:177
Product(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Product2.C:111
virtual Type value(const scalar x, const scalar y) const
Return value.
Definition: Product2I.H:70
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:65
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Traits class for primitives.
Definition: pTraits.H:53
A class for handling words, derived from string.
Definition: word.H:62
Include the header files for all the primitive types that Fields are instantiated for.
void lookupValueTypeAndRank(const dictionary &dict, const direction argument, Tuple2< word, label > &typeAndRank, label &found)
Lookup the type and rank for the value entry for the given argument.
Definition: Product2.C:190
Pair< Tuple2< word, label > > lookupValueTypeAndRanks(const dictionary &dict)
Lookup the types and ranks for the value entries.
word valueName(const direction argument)
Return the name of the value entry for the given argument.
Definition: Product2I.H:81
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const HashTable< unitConversion > & units()
Get the table of unit conversions.
uint8_t direction
Definition: direction.H:45
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
const Type & operator()(const Type &value) const
Definition: Product2.H:128