Square.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-2021 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::Square
29
30Description
31 A templated square-wave function with support for offset, etc.
32
33 The wave period can be specified directly
34
35 \f[
36 a square((t - t0) / p)) s + l
37 \f]
38
39 Or it can be specified by the frequency
40
41 \f[
42 a square(f (t - t0)) s + l
43 \f]
44
45 where
46
47 \f$ square(t) \f$ is the square-wave function in range \f$ [-1, 1] \f$
48 with a mark/space ratio of \f$ r \f$
49
50 \vartable
51 symbol | Description | Units
52 a | Amplitude | -
53 f | Frequency | [1/s]
54 p | Period | [s]
55 s | Type scale factor | -
56 l | Type offset level | -
57 t | Time | [s]
58 t0 | Start time offset | [s]
59 r | mark/space ratio | -
60 \endvartable
61
62 The dictionary specification would typically resemble this:
63 \verbatim
64 entry1
65 {
66 type square;
67 frequency 10;
68 amplitude 0.1;
69
70 // A scalar Function1
71 scale 2e-6;
72 level 2e-6;
73 }
74 entry2
75 {
76 type square;
77 frequency 10;
78
79 // A vector Function1
80 scale (1 0.1 0);
81 level (10 1 0);
82 }
83 \endverbatim
84
85 where the entries mean:
86 \table
87 Property | Description | Type | Reqd | Default
88 type | Function type: square | word | yes |
89 amplitude | Amplitude | Function1<scalar> | no | 1
90 frequency | Frequency [1/s] | Function1<scalar> | or period |
91 period | Period [s] | Function1<scalar> | or frequency |
92 scale | Scale factor (Type) | Function1<Type> | yes |
93 level | Offset level (Type) | Function1<Type> | yes |
94 t0 | Start time offset | scalar | no | 0
95 mark | Positive amount | scalar | no | 1
96 space | Negative amount | scalar | no | 1
97 \endtable
98
99Note
100 For slow oscillations it can be more intuitive to specify the period.
101
102\*---------------------------------------------------------------------------*/
103
104#ifndef Function1Types_Square_H
105#define Function1Types_Square_H
106
107#include "Sine.H"
108
109// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110
111namespace Foam
112{
113namespace Function1Types
114{
115
116/*---------------------------------------------------------------------------*\
117 Class Square Declaration
118\*---------------------------------------------------------------------------*/
119
120template<class Type>
121class Square
122:
123 public Function1Types::Sine<Type>
124{
125 // Private Data
126
127 //- Mark/space ratio (square function only)
128 scalar mark_;
129
130 //- Mark/space ratio (square function only)
131 scalar space_;
132
133public:
134
135 // Runtime type information
136 TypeName("square");
137
138
139 // Generated Methods
140
141 //- No copy assignment
142 void operator=(const Square<Type>&) = delete;
143
144
145 // Constructors
146
147 //- Construct from entry name, dictionary and optional registry
148 Square
149 (
150 const word& entryName,
151 const dictionary& dict,
152 const objectRegistry* obrPtr = nullptr
153 );
154
155 //- Copy construct
156 explicit Square(const Square<Type>& rhs);
157
158 //- Construct and return a clone
159 virtual tmp<Function1<Type>> clone() const
160 {
161 return tmp<Function1<Type>>(new Square<Type>(*this));
162 }
163
164
165 //- Destructor
166 virtual ~Square() = default;
167
168
169 // Member Functions
170
171 //- Return value for time t
172 virtual inline Type value(const scalar t) const
173 {
174 return Sine<Type>::squareValue(t, mark_ / (mark_ + space_));
175 }
176
177 //- Write in dictionary format
178 virtual void writeData(Ostream& os) const;
179
180 //- Write coefficient entries in dictionary format
181 virtual void writeEntries(Ostream& os) const;
182};
183
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186
187} // End namespace Function1Types
188} // End namespace Foam
189
190// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191
192#ifdef NoRepository
193 #include "Square.C"
194#endif
195
196// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197
198#endif
199
200// ************************************************************************* //
A templated sine function, with support for offset etc.
Definition: Sine.H:208
Type squareValue(const scalar t, const scalar posFrac) const
Return value for time t, using square form.
Definition: SineI.H:114
A templated square-wave function with support for offset, etc.
Definition: Square.H:228
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Square.H:263
virtual ~Square()=default
Destructor.
virtual Type value(const scalar t) const
Return value for time t.
Definition: Square.H:276
void operator=(const Square< Type > &)=delete
No copy assignment.
Square(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Square.C:35
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Square.C:68
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Square.C:59
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
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