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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::Function1Types::ramp
29 
30 Description
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 
61 See also
62  Foam::Function1
63 
64 SourceFiles
65  ramp.C
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #ifndef Function1Types_ramp_H
70 #define Function1Types_ramp_H
71 
72 #include "Function1.H"
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76 namespace Foam
77 {
78 namespace Function1Types
79 {
80 
81 /*---------------------------------------------------------------------------*\
82  Class ramp Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class ramp
86 :
87  public Function1<scalar>
88 {
89 protected:
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 
107 private:
108 
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 
118 public:
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  void writeEntries(Ostream& os) const;
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Function1Types
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #endif
159 
160 // ************************************************************************* //
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Function1< scalar >::entryName
const word & entryName
Definition: Function1.H:133
Function1.H
Foam::Function1Types::ramp::~ramp
virtual ~ramp()=default
Destructor.
Foam::Function1Types::ramp::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: ramp.C:69
Foam::Function1Types::ramp
Ramp function base class for the set of scalar functions starting from 0 and increasing monotonically...
Definition: ramp.H:99
Foam::Function1< scalar >::dict
const word const dictionary & dict
Definition: Function1.H:134
Foam::Function1Types::ramp::linearRamp
scalar linearRamp(const scalar t) const
Definition: ramp.H:115
Foam::Function1Types::ramp::userTimeToTime
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: ramp.C:62
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1Types::ramp::value
virtual scalar value(const scalar t) const =0
Return value for time t.
Foam::Function1< scalar >::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Function1Types::ramp::duration_
scalar duration_
Duration of the ramp function.
Definition: ramp.H:111
Foam::Function1Types::ramp::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: ramp.C:55
Foam::Function1Types::ramp::start_
scalar start_
Start-time of the ramp function.
Definition: ramp.H:108
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Function1Types::ramp::ramp
ramp(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: ramp.C:41