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-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::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  const scalar start_;
112 
113  //- Duration of the ramp function
114  const 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  }
128 
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 public:
138 
139  // Constructors
140 
141  //- Construct from name and dictionary
142  Ramp
143  (
144  const word& name,
146  const dictionary& dict
147  );
148 
149 
150  //- Destructor
151  virtual ~Ramp();
152 
153 
154  // Member Functions
155 
156  //- Return value for time t
157  virtual scalar value(const scalar t) const = 0;
158 
159  //- Write data to dictionary stream
160  virtual void write(Ostream& os, const unitConversions& units) const;
161 
162 
163  // Member Operators
164 
165  //- Disallow default bitwise assignment
166  void operator=(const Ramp<Function1Type>&) = delete;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Function1s
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #ifdef NoRepository
178  #include "Ramp.C"
179 #endif
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Ramp function base class for the set of scalar functions starting from 0 and increasing monotonically...
Definition: Ramp.H:119
scalar linearRamp(const scalar t) const
Simple linear ramp function which form the basis of many more.
Definition: Ramp.H:138
void operator=(const Ramp< Function1Type > &)=delete
Disallow default bitwise assignment.
Ramp(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Ramp.C:32
scalar end() const
Return the end-time of the ramp function.
Definition: Ramp.H:131
scalar dLinearRampDt() const
The gradient of the linear ramp within the bounds of the ramp.
Definition: Ramp.H:145
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Ramp.C:55
const scalar start_
Start-time of the ramp function.
Definition: Ramp.H:125
virtual scalar value(const scalar t) const =0
Return value for time t.
virtual ~Ramp()
Destructor.
Definition: Ramp.C:47
const scalar duration_
Duration of the ramp function.
Definition: Ramp.H:128
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const HashTable< unitConversion > & units()
Get the table of unit conversions.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dictionary dict