Scale.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) 2017-2025 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::Function1s::Scale
26 
27 Description
28  Function1 which scales a given 'value' function by a 'scale' scalar function
29  and scales the 'x' argument of the 'value' and 'scale' functions by the
30  optional 'xScale' scalar function.
31 
32  This is particularly useful to ramp a time-varying value by one of the
33  monotonic ramp functions.
34 
35 Usage
36  For a vector:
37  \verbatim
38  <name>
39  {
40  type scale;
41 
42  scale
43  {
44  type linearRamp;
45 
46  start 0;
47  duration 10;
48  }
49 
50  value
51  {
52  type sine;
53 
54  frequency 10;
55  amplitude 1;
56  scale (1 0.1 0);
57  level (10 1 0);
58  }
59  }
60  \endverbatim
61 
62  Simplified usage to scale by a constant factor, e.g. 2:
63  \verbatim
64  <name>
65  {
66  type scale;
67 
68  scale 2;
69 
70  value
71  {
72  type sine;
73 
74  frequency 10;
75  amplitude 1;
76  scale (1 0.1 0);
77  level (10 1 0);
78  }
79  }
80  \endverbatim
81 
82  Including the optional 'xScale' function:
83  \verbatim
84  <name>
85  {
86  type scale;
87 
88  xScale 0.5;
89  scale 2;
90 
91  value
92  {
93  type sine;
94 
95  frequency 10;
96  amplitude 1;
97  scale (1 0.1 0);
98  level (10 1 0);
99  }
100  }
101  \endverbatim
102 
103  Where:
104  \table
105  Property | Description | Required
106  value | Function of type Function1<Type> | yes
107  scale | Scaling function of type Function1<scalar> | yes
108  xScale | 'x' scaling function of type Function1<scalar> | no
109  \endtable
110 
111 See also
112  Foam::Function1s::ramp
113  Foam::Function1s::reverseRamp
114 
115 SourceFiles
116  Scale.C
117 
118 \*---------------------------------------------------------------------------*/
119 
120 #ifndef Scale_H
121 #define Scale_H
122 
123 #include "Function1.H"
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 namespace Foam
128 {
129 namespace Function1s
130 {
131 
132 /*---------------------------------------------------------------------------*\
133  Class Scale Declaration
134 \*---------------------------------------------------------------------------*/
135 
136 template<class Type>
137 class Scale
138 :
139  public FieldFunction1<Type, Scale<Type>>
140 {
141  // Private Data
142 
143  //- Scalar scaling function
144  const autoPtr<Function1<scalar>> scale_;
145 
146  //- Is the scalar scaling function constant?
147  const bool constantScale_;
148 
149  //- Argument scaling function
150  const autoPtr<Function1<scalar>> xScale_;
151 
152  //- Is the argument scaling function constant?
153  const bool constantXScale_;
154 
155  //- Value function
156  const autoPtr<Function1<Type>> value_;
157 
158  //- Is the value function constant?
159  const bool constantValue_;
160 
161 
162 public:
163 
164  // Runtime type information
165  TypeName("scale");
166 
167 
168  // Constructors
169 
170  //- Construct from name and functions
171  Scale
172  (
173  const word& name,
174  const Function1<scalar>& scale,
175  const Function1<scalar>& xScale,
176  const Function1<Type>& value
177  );
178 
179  //- Construct from name and dictionary
181  (
182  const word& name,
183  const unitConversions& units,
184  const dictionary& dict
185  );
186 
187  //- Copy constructor
188  Scale(const Scale<Type>& se);
189 
190 
191  //- Destructor
192  virtual ~Scale();
193 
194 
195  // Member Functions
196 
197  //- Return value
198  virtual inline Type value(const scalar x) const;
199 
200  //- Integrate between two values
201  virtual inline Type integral(const scalar x1, const scalar x2) const;
202 
203  //- Is this function guaranteed to be constant?
204  virtual inline bool constant() const;
205 
206  //- Write data to dictionary stream
207  virtual void write(Ostream& os, const unitConversions& units) const;
208 
209 
210  // Member Operators
211 
212  //- Disallow default bitwise assignment
213  void operator=(const Scale<Type>&) = delete;
214 };
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace Function1s
220 } // End namespace Foam
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 #include "ScaleI.H"
225 
226 #ifdef NoRepository
227  #include "Scale.C"
228 #endif
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #endif
233 
234 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Function1 which scales a given 'value' function by a 'scale' scalar function and scales the 'x' argum...
Definition: Scale.H:155
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: ScaleI.H:47
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Scale.C:96
void operator=(const Scale< Type > &)=delete
Disallow default bitwise assignment.
virtual Type value(const scalar x) const
Return value.
Definition: ScaleI.H:31
virtual ~Scale()
Destructor.
Definition: Scale.C:88
virtual bool constant() const
Is this function guaranteed to be constant?
Definition: ScaleI.H:75
Scale(const word &name, const Function1< scalar > &scale, const Function1< scalar > &xScale, const Function1< Type > &value)
Construct from name and functions.
Definition: Scale.C:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict