ramp.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017 OpenFOAM Foundation
9 Copyright (C) 2020-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::Function1Types::ramp
29
30Description
31 Ramp function base class for the set of scalar functions starting from 0 and
32 increasing monotonically to 1 from \c start over the \c duration and
33 remaining at 1 thereafter.
34
35 Usage:
36 \verbatim
37 <entryName> <rampFunction>;
38 <entryName>Coeffs
39 {
40 start 10;
41 duration 20;
42 }
43 \endverbatim
44 or
45 \verbatim
46 <entryName>
47 {
48 type <rampFunction>;
49 start 10;
50 duration 20;
51 }
52 \endverbatim
53
54 Where:
55 \table
56 Property | Description | Required | Default value
57 start | Start time | no | 0
58 duration | Duration | yes |
59 \endtable
60
61See also
62 Foam::Function1
63
64SourceFiles
65 ramp.C
66
67\*---------------------------------------------------------------------------*/
68
69#ifndef Function1Types_ramp_H
70#define Function1Types_ramp_H
71
72#include "Function1.H"
73
74// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75
76namespace Foam
77{
78namespace Function1Types
79{
80
81/*---------------------------------------------------------------------------*\
82 Class ramp Declaration
83\*---------------------------------------------------------------------------*/
84
85class ramp
86:
87 public Function1<scalar>
88{
89protected:
90
91 // Protected Data
92
93 //- Start-time of the ramp function
94 scalar start_;
95
96 //- Duration of the ramp function
97 scalar duration_;
98
99 //- Simple linear ramp function
100 //- that forms the basis of many more complex ramp functions
101 inline scalar linearRamp(const scalar t) const
102 {
103 return max(min((t - start_)/duration_, 1), 0);
104 }
105
106
107private:
109 // Private Member Functions
110
111 //- Read the coefficients from the given dictionary
112 void read(const dictionary& coeffs);
113
114 //- No copy assignment
115 void operator=(const ramp&) = delete;
116
117
118public:
119
120 // Constructors
121
122 //- Construct from entry name, dictionary and optional registry
123 ramp
124 (
125 const word& entryName,
126 const dictionary& dict,
127 const objectRegistry* obrPtr = nullptr
128 );
129
130
131 //- Destructor
132 virtual ~ramp() = default;
133
134
135 // Member Functions
136
137 //- Convert time
138 virtual void userTimeToTime(const Time& t);
139
140 //- Return value for time t
141 virtual scalar value(const scalar t) const = 0;
142
143 //- Write in dictionary format
144 virtual void writeData(Ostream& os) const;
145
146 //- Write coefficient entries in dictionary format
147 virtual void writeEntries(Ostream& os) const;
148};
149
150
151// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152
153} // End namespace Function1Types
154} // End namespace Foam
156// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157
158#endif
159
160// ************************************************************************* //
Linear ramp function starting from 0 and increasing linearly to 1 from start over the duration and re...
Definition: linearRamp.H:60
Ramp function base class for the set of scalar functions starting from 0 and increasing monotonically...
Definition: ramp.H:102
scalar linearRamp(const scalar t) const
Definition: ramp.H:115
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: ramp.C:69
scalar start_
Start-time of the ramp function.
Definition: ramp.H:108
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: ramp.C:55
virtual ~ramp()=default
Destructor.
scalar duration_
Duration of the ramp function.
Definition: ramp.H:111
virtual scalar value(const scalar t) const =0
Return value for time t.
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: ramp.C:62
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
const word const dictionary & dict
Definition: Function1.H:134
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
const word & entryName
Definition: Function1.H:133
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33