All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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  <entryName> <rampFunction>;
35  <entryName>Coeffs
36  {
37  start 10;
38  duration 20;
39  }
40  \endverbatim
41  or
42  \verbatim
43  <entryName>
44  {
45  type <rampFunction>;
46  start 10;
47  duration 20;
48  }
49  \endverbatim
50 
51  Where:
52  \table
53  Property | Description | Required | Default value
54  start | Start time | no | 0
55  duration | Duration | yes |
56  \endtable
57 
58 See also
59  Foam::Function1
60 
61 SourceFiles
62  Ramp.C
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #ifndef Ramp_H
67 #define Ramp_H
68 
69 #include "Function1.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 namespace Function1s
76 {
77 
78 /*---------------------------------------------------------------------------*\
79  Class Ramp Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 template <class Function1Type>
83 class Ramp
84 :
85  public FieldFunction1<scalar, Function1Type>
86 {
87 protected:
88 
89  // Protected data
90 
91  //- Start-time of the ramp function
92  scalar start_;
93 
94  //- Duration of the ramp function
95  scalar duration_;
96 
97  //- Return the end-time of the ramp function
98  inline scalar end() const
99  {
100  return start_ + duration_;
101  }
102 
103  //- Simple linear ramp function which form the basis of many more
104  // complex ramp functions
105  inline scalar linearRamp(const scalar t) const
106  {
107  return max(min((t - start_)/duration_, 1), 0);
108  }
110  //- The gradient of the linear ramp within the bounds of the ramp
111  // duration
112  inline scalar dLinearRampDt() const
113  {
114  return 1/duration_;
115  }
116 
117 
118 private:
120  // Private Member Functions
121 
122  //- Read the coefficients from the given dictionary
123  void read(const dictionary& coeffs);
124 
125 
126 public:
127 
128  // Constructors
129 
130  //- Construct from entry name and dictionary
131  Ramp
132  (
133  const word& entryName,
134  const dictionary& dict
135  );
136 
137 
138  //- Destructor
139  virtual ~Ramp();
140 
141 
142  // Member Functions
143 
144  //- Return value for time t
145  virtual scalar value(const scalar t) const = 0;
146 
147  //- Write in dictionary format
148  virtual void writeData(Ostream& os) const;
149 
150 
151  // Member Operators
152 
153  //- Disallow default bitwise assignment
154  void operator=(const Ramp<Function1Type>&) = delete;
155 };
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Function1s
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #ifdef NoRepository
166  #include "Ramp.C"
167 #endif
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #endif
172 
173 // ************************************************************************* //
scalar duration_
Duration of the ramp function.
Definition: Ramp.H:109
const word const dictionary & dict
Definition: Function1.H:84
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:158
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
scalar start_
Start-time of the ramp function.
Definition: Ramp.H:106
const word & entryName
Definition: Function1.H:84
scalar linearRamp(const scalar t) const
Simple linear ramp function which form the basis of many more.
Definition: Ramp.H:119
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
scalar dLinearRampDt() const
The gradient of the linear ramp within the bounds of the ramp.
Definition: Ramp.H:126
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Ramp.C:61
Ramp(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Ramp.C:40
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:97
Namespace for OpenFOAM.
scalar end() const
Return the end-time of the ramp function.
Definition: Ramp.H:112