Loading...
Searching...
No Matches
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-2024 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 Foam_Function1Types_Sine_H
102#define Foam_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 //- Return a clone
196 virtual tmp<Function1<Type>> clone() const
197 {
198 return Function1<Type>::Clone(*this);
199 }
200
202 //- Destructor
203 virtual ~Sine() = default;
204
205
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 {
214 return Sine<Type>::sinValue(t);
215 }
216
217 //- Integrate between two (scalar) values
218 virtual Type integrate(const scalar x1, const scalar x2) const
219 {
221 }
223 //- Write in dictionary format
224 virtual void writeData(Ostream& os) const;
225
226 //- Write coefficient entries in dictionary format
227 virtual void writeEntries(Ostream& os) const;
228};
229
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233} // End namespace Function1Types
234} // End namespace Foam
235
236// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238#include "SineI.H"
239
240#ifdef NoRepository
241 #include "Sine.C"
242#endif
243
244// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245
246#endif
247
248// ************************************************************************* //
A templated sine function, with support for offset etc.
Definition Sine.H:204
virtual tmp< Function1< Type > > clone() const
Return a clone.
Definition Sine.H:314
virtual ~Sine()=default
Destructor.
autoPtr< Function1< scalar > > period_
Period of the function (or specify frequency).
Definition Sine.H:222
scalar squareForm(const scalar t, const scalar posFrac) const
Calculated square value at time t.
Definition SineI.H:69
virtual Type value(const scalar t) const
Return value for time t.
Definition Sine.H:336
Type squareValue(const scalar t, const scalar posFrac) const
Return value for time t, using square form.
Definition SineI.H:107
scalar t0_
Start-time for the function.
Definition Sine.H:212
void operator=(const Sine< Type > &)=delete
No copy assignment.
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition Sine.C:99
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition Sine.H:344
scalar sinForm(const scalar t) const
Calculated sin value at time t.
Definition SineI.H:56
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition Sine.C:78
scalar cosForm(const scalar t) const
Calculated cos value at time t.
Definition SineI.H:44
Sine(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition Sine.C:28
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:86
autoPtr< Function1< Type > > scale_
Scaling factor for the function.
Definition Sine.H:232
Type sinValue(const scalar t) const
Return value for time t, using sin form.
Definition SineI.H:96
autoPtr< Function1< Type > > level_
Level to add to the scaled function.
Definition Sine.H:237
autoPtr< Function1< scalar > > frequency_
Frequency of the function (or specify period).
Definition Sine.H:227
scalar cycle(const scalar t) const
The cycle: (freq * time) or (time / period).
Definition SineI.H:28
virtual void userTimeToTime(const Time &t)
Convert time.
Definition Sine.C:71
Function1(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name.
Definition Function1.C:31
static tmp< Function1< Type > > Clone(const Derived &fun)
Clone a Function1.
Definition Function1.H:190
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68