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 -------------------------------------------------------------------------------
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, 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 
159  //- Destructor
160  virtual ~Square() = default;
161 
162 
163  // Member Functions
164 
165  //- Return value for time t
166  virtual inline Type value(const scalar t) const
167  {
168  return Sine<Type>::squareValue(t, mark_ / (mark_ + space_));
169  }
170 
171  //- Write in dictionary format
172  virtual void writeData(Ostream& os) const;
173 
174  //- Write coefficient entries in dictionary format
175  void writeEntries(Ostream& os) const;
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Function1Types
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #ifdef NoRepository
187  #include "Square.C"
188 #endif
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************************************************************* //
Sine.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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:68
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::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::Function1Types::Square
A templated square-wave function with support for offset, etc.
Definition: Square.H:225
Foam::Function1Types::Square::Square
Square(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Square.C:35
Foam::Function1Types::Square::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Square.C:59
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
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:270
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