Sine.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) 2016-2017 OpenFOAM Foundation
9 Copyright (C) 2020-2022 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::Sine
29
30Description
31 A templated sine function, with support for offset etc.
32
33 The wave period can be specified directly
34
35 \f[
36 a sin(2 \pi (t - t0) / p)) s + l
37 \f]
38
39 Or it can be specified by the frequency
40
41 \f[
42 a sin(2 \pi f (t - t0)) s + l
43 \f]
44
45 where
46 \vartable
47 Symbol | Description | Units
48 a | Amplitude | -
49 f | Frequency | [1/s]
50 p | Period | [s]
51 s | Type scale factor | -
52 l | Type offset level | -
53 t | Time | [s]
54 t0 | Start time offset | [s]
55 \endvartable
56
57 The dictionary specification would typically resemble this:
58 \verbatim
59 entry1
60 {
61 type sine;
62 frequency 10;
63 amplitude 0.1;
64
65 // A scalar Function1
66 scale 2e-6;
67 level 2e-6;
68 }
69 entry2
70 {
71 type sine;
72 frequency 10;
73
74 // A vector Function1
75 scale (1 0.1 0);
76 level (10 1 0);
77 }
78 \endverbatim
79
80 where the entries mean:
81 \table
82 Property | Description | Type | Reqd | Default
83 type | Function type: sine | word | yes |
84 amplitude | Amplitude | Function1<scalar> | no | 1
85 frequency | Frequency [1/s] | Function1<scalar> | or period |
86 period | Period [s] | Function1<scalar> | or frequency |
87 scale | Scale factor (Type) | Function1<Type> | yes |
88 level | Offset level (Type) | Function1<Type> | yes |
89 t0 | Start time offset | scalar | no | 0
90 \endtable
91
92Note
93 For slow oscillations it can be more intuitive to specify the period.
94
95SourceFiles
96 Sine.C
97 SineI.H
98
99\*---------------------------------------------------------------------------*/
100
101#ifndef Function1Types_Sine_H
102#define Function1Types_Sine_H
103
104#include "Function1.H"
105
106// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107
108namespace Foam
109{
110namespace Function1Types
111{
112
113/*---------------------------------------------------------------------------*\
114 Class Sine Declaration
115\*---------------------------------------------------------------------------*/
116
117template<class Type>
118class Sine
119:
120 public Function1<Type>
121{
122protected:
123
124 // Protected Data
125
126 //- Start-time for the function
127 scalar t0_;
128
129 //- Scalar amplitude of the function (optional)
130 autoPtr<Function1<scalar>> amplitude_;
131
132 //- Period of the function (or specify frequency)
133 autoPtr<Function1<scalar>> period_;
134
135 //- Frequency of the function (or specify period)
136 autoPtr<Function1<scalar>> frequency_;
137
138 //- Scaling factor for the function
139 autoPtr<Function1<Type>> scale_;
140
141 //- Level to add to the scaled function
142 autoPtr<Function1<Type>> level_;
143
144
145 // Protected Member Functions
146
147 //- The cycle: (freq * time) or (time / period)
148 inline scalar cycle(const scalar t) const;
149
150 //- Calculated cos value at time t
151 inline scalar cosForm(const scalar t) const;
152
153 //- Calculated sin value at time t
154 inline scalar sinForm(const scalar t) const;
155
156 //- Calculated square value at time t.
157 // The positive fraction is 0-1
158 inline scalar squareForm(const scalar t, const scalar posFrac) const;
159
160 //- Return value for time t, using cos form
161 inline Type cosValue(const scalar t) const;
162
163 //- Return value for time t, using sin form
164 inline Type sinValue(const scalar t) const;
165
166 //- Return value for time t, using square form
167 inline Type squareValue(const scalar t, const scalar posFrac) const;
168
169
170public:
171
172 // Runtime type information
173 TypeName("sine");
174
175
176 // Generated Methods
177
178 //- No copy assignment
179 void operator=(const Sine<Type>&) = delete;
180
181
182 // Constructors
183
184 //- Construct from entry name, dictionary and optional registry
185 Sine
186 (
187 const word& entryName,
188 const dictionary& dict,
189 const objectRegistry* obrPtr = nullptr
190 );
191
192 //- Copy construct
193 explicit Sine(const Sine<Type>& rhs);
194
195 //- Construct and return a clone
196 virtual tmp<Function1<Type>> clone() const
197 {
198 return tmp<Function1<Type>>(new Sine<Type>(*this));
199 }
200
201
202 //- Destructor
203 virtual ~Sine() = default;
204
206 // Member Functions
207
208 //- Convert time
209 virtual void userTimeToTime(const Time& t);
210
211 //- Return value for time t
212 virtual inline Type value(const scalar t) const
213 {
215 }
216
217 //- Write in dictionary format
218 virtual void writeData(Ostream& os) const;
219
220 //- Write coefficient entries in dictionary format
221 virtual void writeEntries(Ostream& os) const;
222};
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227} // End namespace Function1Types
228} // End namespace Foam
230// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231
232#include "SineI.H"
233
234#ifdef NoRepository
235 #include "Sine.C"
236#endif
237
238// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239
240#endif
241
242// ************************************************************************* //
A templated sine function, with support for offset etc.
Definition: Sine.H:208
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Sine.H:283
virtual ~Sine()=default
Destructor.
autoPtr< Function1< scalar > > period_
Period of the function (or specify frequency)
Definition: Sine.H:220
scalar squareForm(const scalar t, const scalar posFrac) const
Calculated square value at time t.
Definition: SineI.H:76
virtual Type value(const scalar t) const
Return value for time t.
Definition: Sine.H:299
Type squareValue(const scalar t, const scalar posFrac) const
Return value for time t, using square form.
Definition: SineI.H:114
scalar t0_
Start-time for the function.
Definition: Sine.H:214
void operator=(const Sine< Type > &)=delete
No copy assignment.
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Sine.C:106
scalar sinForm(const scalar t) const
Calculated sin value at time t.
Definition: SineI.H:63
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Sine.C:85
scalar cosForm(const scalar t) const
Calculated cos value at time t.
Definition: SineI.H:51
Sine(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Sine.C:35
autoPtr< Function1< scalar > > amplitude_
Scalar amplitude of the function (optional)
Definition: Sine.H:217
Type cosValue(const scalar t) const
Return value for time t, using cos form.
Definition: SineI.H:93
autoPtr< Function1< Type > > scale_
Scaling factor for the function.
Definition: Sine.H:226
Type sinValue(const scalar t) const
Return value for time t, using sin form.
Definition: SineI.H:103
autoPtr< Function1< Type > > level_
Level to add to the scaled function.
Definition: Sine.H:229
autoPtr< Function1< scalar > > frequency_
Frequency of the function (or specify period)
Definition: Sine.H:223
scalar cycle(const scalar t) const
The cycle: (freq * time) or (time / period)
Definition: SineI.H:35
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: Sine.C:78
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
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
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 managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73