Ramp.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-2022 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::Ramp
26 
27 Description
28  Ramp function base class for the set of scalar functions starting from 0 and
29  increasing monotonically to 1 from \c start over the \c duration and
30  remaining at 1 thereafter.
31 
32 Usage
33  \verbatim
34  <name> <rampFunction>;
35  <name>Coeffs
36  {
37  start 10;
38  duration 20;
39  }
40  \endverbatim
41  or
42  \verbatim
43  <name>
44  {
45  type <rampFunction>;
46  start 10;
47  duration 20;
48  }
49  \endverbatim
50  or including a constant scaling factor:
51  \verbatim
52  <name>
53  {
54  type scale;
55 
56  scale
57  {
58  type <rampFunction>;
59 
60  start 0;
61  duration 10;
62  }
63 
64  value 100;
65  }
66  \endverbatim
67  for more details of scaling the ramp see Foam::Function1s::Scale.
68 
69  Where:
70  \table
71  Property | Description | Required | Default value
72  start | Start time | no | 0
73  duration | Duration | yes |
74  \endtable
75 
76 See also
77  Foam::Function1
78  Foam::Function1s::Scale
79 
80 SourceFiles
81  Ramp.C
82 
83 \*---------------------------------------------------------------------------*/
84 
85 #ifndef Ramp_H
86 #define Ramp_H
87 
88 #include "Function1.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 namespace Function1s
95 {
96 
97 /*---------------------------------------------------------------------------*\
98  Class Ramp Declaration
99 \*---------------------------------------------------------------------------*/
100 
101 template<class Function1Type>
102 class Ramp
103 :
104  public FieldFunction1<scalar, Function1Type>
105 {
106 protected:
107 
108  // Protected data
109 
110  //- Start-time of the ramp function
111  scalar start_;
112 
113  //- Duration of the ramp function
114  scalar duration_;
115 
116  //- Return the end-time of the ramp function
117  inline scalar end() const
118  {
119  return start_ + duration_;
120  }
121 
122  //- Simple linear ramp function which form the basis of many more
123  // complex ramp functions
124  inline scalar linearRamp(const scalar t) const
125  {
126  return max(min((t - start_)/duration_, 1), 0);
127  }
129  //- The gradient of the linear ramp within the bounds of the ramp
130  // duration
131  inline scalar dLinearRampDt() const
132  {
133  return 1/duration_;
134  }
135 
136 
137 private:
139  // Private Member Functions
140 
141  //- Read the coefficients from the given dictionary
142  void read(const dictionary& dict);
143 
144 
145 public:
146 
147  // Constructors
148 
149  //- Construct from name and dictionary
150  Ramp
151  (
152  const word& name,
153  const dictionary& dict
154  );
155 
156 
157  //- Destructor
158  virtual ~Ramp();
159 
160 
161  // Member Functions
162 
163  //- Return value for time t
164  virtual scalar value(const scalar t) const = 0;
165 
166  //- Write data to dictionary stream
167  virtual void write(Ostream& os) const;
168 
169 
170  // Member Operators
171 
172  //- Disallow default bitwise assignment
173  void operator=(const Ramp<Function1Type>&) = delete;
174 };
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Function1s
180 } // End namespace Foam
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #ifdef NoRepository
185  #include "Ramp.C"
186 #endif
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************************************************************* //
dictionary dict
scalar duration_
Duration of the ramp function.
Definition: Ramp.H:128
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
virtual ~Ramp()
Destructor.
Definition: Ramp.C:54
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
virtual void write(Ostream &os) const
Write data to dictionary stream.
Definition: Ramp.C:61
scalar start_
Start-time of the ramp function.
Definition: Ramp.H:125
scalar linearRamp(const scalar t) const
Simple linear ramp function which form the basis of many more.
Definition: Ramp.H:138
A class for handling words, derived from string.
Definition: word.H:59
Ramp(const word &name, const dictionary &dict)
Construct from name and dictionary.
Definition: Ramp.C:40
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
scalar dLinearRampDt() const
The gradient of the linear ramp within the bounds of the ramp.
Definition: Ramp.H:145
void operator=(const Ramp< Function1Type > &)=delete
Disallow default bitwise assignment.
virtual scalar value(const scalar t) const =0
Return value for time t.
Ramp function base class for the set of scalar functions starting from 0 and increasing monotonically...
Definition: Ramp.H:116
Namespace for OpenFOAM.
scalar end() const
Return the end-time of the ramp function.
Definition: Ramp.H:131