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 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 Class
28  Foam::Function1Types::Square
29 
30 Description
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 
99 Note
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 
111 namespace Foam
112 {
113 namespace Function1Types
114 {
115 
116 /*---------------------------------------------------------------------------*\
117  Class Square Declaration
118 \*---------------------------------------------------------------------------*/
119 
120 template<class Type>
121 class 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 
133 public:
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 and dictionary
148  Square(const word& entryName, const dictionary& dict);
149 
150  //- Copy construct
151  explicit Square(const Square<Type>& rhs);
152 
153 
154  //- Destructor
155  virtual ~Square() = default;
156 
157 
158  // Member Functions
159 
160  //- Return value for time t
161  virtual inline Type value(const scalar t) const
162  {
163  return Sine<Type>::squareValue(t, mark_ / (mark_ + space_));
164  }
165 
166  //- Write in dictionary format
167  virtual void writeData(Ostream& os) const;
168 
169  //- Write coefficient entries in dictionary format
170  void writeEntries(Ostream& os) const;
171 };
172 
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 } // End namespace Function1Types
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #ifdef NoRepository
182  #include "Square.C"
183 #endif
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
Sine.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Square.C
Foam::Function1Types::Square::operator=
void operator=(const Square< Type > &)=delete
No copy assignment.
Foam::Function1::dictionary
dictionary
Definition: Function1.H:131
Foam::Function1Types::Square::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Square.C:67
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:135
Foam::Function1Types::Square
A templated square-wave function with support for offset, etc.
Definition: Square.H:225
Foam::Function1Types::Square::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Square.C:58
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::Function1Types::Square::Square
Square(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Square.C:35
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Function1Types::Square::~Square
virtual ~Square()=default
Destructor.
Foam::Function1Types::Square::value
virtual Type value(const scalar t) const
Return value for time t.
Definition: Square.H:265
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Function1Types::Square::TypeName
TypeName("square")
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