Cosine.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) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Function1Types::Cosine
28 
29 Description
30  A templated cosine function, with support for offset etc.
31 
32  The wave period can be specified directly
33 
34  \f[
35  a cos(2 \pi (t - t0) / p)) s + l
36  \f]
37 
38  Or it can be specified by the frequency
39 
40  \f[
41  a cos(2 \pi f (t - t0)) s + l
42  \f]
43 
44  where
45  \vartable
46  Symbol | Description | Units
47  a | Amplitude | -
48  f | Frequency | [1/s]
49  p | Period | [s]
50  s | Type scale factor | -
51  l | Type offset level | -
52  t | Time | [s]
53  t0 | Start time offset | [s]
54  \endvartable
55 
56  The dictionary specification would typically resemble this:
57  \verbatim
58  entry1
59  {
60  type cosine;
61  frequency 10;
62  amplitude 0.1;
63 
64  // A scalar Function1
65  scale 2e-6;
66  level 2e-6;
67  }
68  entry2
69  {
70  type cosine;
71  frequency 10;
72 
73  // A vector Function1
74  scale (1 0.1 0);
75  level (10 1 0);
76  }
77  \endverbatim
78 
79  where the entries mean:
80  \table
81  Property | Description | Type | Reqd | Default
82  type | Function type: cosine | word | yes |
83  amplitude | Amplitude | Function1<scalar> | no | 1
84  frequency | Frequency [1/s] | Function1<scalar> | or period |
85  period | Period [s] | Function1<scalar> | or frequency |
86  scale | Scale factor (Type) | Function1<Type> | yes |
87  level | Offset level (Type) | Function1<Type> | yes |
88  t0 | Start time offset | scalar | no | 0
89  \endtable
90 
91 Note
92  For slow oscillations it can be more intuitive to specify the period.
93 
94 SourceFiles
95  Cosine.C
96 
97 \*---------------------------------------------------------------------------*/
98 
99 #ifndef Function1Types_Cosine_H
100 #define Function1Types_Cosine_H
101 
102 #include "Sine.H"
103 
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 
106 namespace Foam
107 {
108 namespace Function1Types
109 {
110 
111 /*---------------------------------------------------------------------------*\
112  Class Cosine Declaration
113 \*---------------------------------------------------------------------------*/
114 
115 template<class Type>
116 class Cosine
117 :
118  public Function1Types::Sine<Type>
119 {
120 public:
121 
122  // Runtime type information
123  TypeName("cosine");
124 
125 
126  // Generated Methods
127 
128  //- No copy assignment
129  void operator=(const Cosine<Type>&) = delete;
130 
131 
132  // Constructors
133 
134  //- Construct from entry name, dictionary and optional registry
135  Cosine
136  (
137  const word& entryName,
138  const dictionary& dict,
139  const objectRegistry* obrPtr = nullptr
140  )
141  :
142  Sine<Type>(entryName, dict, obrPtr)
143  {}
144 
145  //- Copy construct
146  explicit Cosine(const Cosine<Type>& rhs)
147  :
148  Sine<Type>(rhs)
149  {}
150 
151 
152  //- Destructor
153  virtual ~Cosine() = default;
154 
155 
156  // Member Functions
157 
158  //- Return value for time t
159  virtual inline Type value(const scalar t) const
160  {
161  return Sine<Type>::cosValue(t);
162  }
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Function1Types
169 } // End namespace Foam
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #endif
174 
175 // ************************************************************************* //
Sine.H
Foam::Function1Types::Sine::Sine
Sine(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Sine.C:35
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Function1::dictionary
dictionary
Definition: Function1.H:131
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:133
Foam::Function1Types::Sine
A templated sine function, with support for offset etc.
Definition: Sine.H:205
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:134
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1Types::Cosine::Cosine
Cosine(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Cosine.H:223
Foam::Function1Types::Cosine::operator=
void operator=(const Cosine< Type > &)=delete
No copy assignment.
Foam::Function1Types::Cosine::Cosine
Cosine(const Cosine< Type > &rhs)
Copy construct.
Definition: Cosine.H:233
Foam::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::Function1Types::Cosine::TypeName
TypeName("cosine")
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Function1Types::Cosine::value
virtual Type value(const scalar t) const
Return value for time t.
Definition: Cosine.H:246
Foam::Function1Types::Cosine
A templated cosine function, with support for offset etc.
Definition: Cosine.H:203
Foam::Function1Types::Sine::cosValue
Type cosValue(const scalar t) const
Return value for time t, using cos form.
Definition: SineI.H:93
Foam::Function1Types::Cosine::~Cosine
virtual ~Cosine()=default
Destructor.