SineI.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 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 \*---------------------------------------------------------------------------*/
28 
29 #include "mathematicalConstants.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const scalar t
37 ) const
38 {
39  // The cycle: (freq * time) or (time / period)
40  return
41  (
42  frequency_
43  ? (t - t0_) * frequency_->value(t)
44  : (t - t0_) / (period_->value(t) + VSMALL)
45  );
46 }
47 
48 
49 template<class Type>
50 inline Foam::scalar
52 {
53  return
54  (
55  cos(constant::mathematical::twoPi * this->cycle(t))
56  * (amplitude_ ? amplitude_->value(t) : 1.0)
57  );
58 }
59 
60 
61 template<class Type>
62 inline Foam::scalar
64 {
65  return
66  (
67  sin(constant::mathematical::twoPi * this->cycle(t))
68  * (amplitude_ ? amplitude_->value(t) : 1.0)
69  );
70 }
71 
72 
73 template<class Type>
74 inline Foam::scalar
76 (
77  const scalar t,
78  const scalar posFrac
79 ) const
80 {
81  const scalar cyc = this->cycle(t);
82 
83  return
84  (
85  // Fraction of incomplete cycle
86  ((cyc - std::floor(cyc)) < posFrac ? 1.0 : -1.0)
87  * (amplitude_ ? amplitude_->value(t) : 1.0)
88  );
89 }
90 
91 
92 template<class Type>
93 inline Type Foam::Function1Types::Sine<Type>::cosValue(const scalar t) const
94 {
95  return
96  (
97  cosForm(t) * scale_->value(t) + level_->value(t)
98  );
99 }
100 
101 
102 template<class Type>
103 inline Type Foam::Function1Types::Sine<Type>::sinValue(const scalar t) const
104 {
105  return
106  (
107  sinForm(t) * scale_->value(t) + level_->value(t)
108  );
109 }
110 
111 
112 template<class Type>
114 (
115  const scalar t,
116  const scalar posFrac
117 ) const
118 {
119  return
120  (
121  squareForm(t, posFrac) * scale_->value(t) + level_->value(t)
122  );
123 }
124 
125 
126 // ************************************************************************* //
mathematicalConstants.H
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::Function1Types::Sine::squareForm
scalar squareForm(const scalar t, const scalar posFrac) const
Calculated square value at time t.
Definition: SineI.H:76
Foam::Function1Types::Sine::sinValue
Type sinValue(const scalar t) const
Return value for time t, using sin form.
Definition: SineI.H:103
Foam::constant::mathematical::twoPi
constexpr scalar twoPi(2 *M_PI)
Foam::Function1Types::Sine::cosValue
Type cosValue(const scalar t) const
Return value for time t, using cos form.
Definition: SineI.H:93
Foam::Function1Types::Sine::sinForm
scalar sinForm(const scalar t) const
Calculated sin value at time t.
Definition: SineI.H:63
Foam::Function1Types::Sine::cycle
scalar cycle(const scalar t) const
The cycle: (freq * time) or (time / period)
Definition: SineI.H:35
Foam::Function1Types::Sine::cosForm
scalar cosForm(const scalar t) const
Calculated cos value at time t.
Definition: SineI.H:51
Foam::Function1Types::Sine::squareValue
Type squareValue(const scalar t, const scalar posFrac) const
Return value for time t, using square form.
Definition: SineI.H:114
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265