Square.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Function1Types::Square
26 
27 Description
28  Templated square-wave function with support for an offset level.
29 
30  \f[
31  a square(f (t - t_0)) s + l
32  \f]
33 
34  where
35 
36  \f$ square(t) \f$ is the square-wave function in range \f$ [-1, 1] \f$
37  with a mark/space ratio of \f$ r \f$
38 
39  \vartable
40  symbol | Description | Data type | Default
41  a | Amplitude | Function1<scalar> |
42  f | Frequency [1/s] | Function1<scalar> |
43  s | Type scale factor | Function1<Type> |
44  l | Type offset level | Function1<Type> |
45  t_0 | Start time [s] | scalar | 0
46  r | mark/space ratio | scalar | 1
47  t | Time [s] | scalar
48  \endvartable
49 
50  Example for a scalar:
51  \verbatim
52  <entryName> square;
53  <entryName>Coeffs
54  {
55  frequency 10;
56  amplitude 0.1;
57  scale 2e-6;
58  level 2e-6;
59  }
60  \endverbatim
61 
62  Example for a vector:
63  \verbatim
64  <entryName> square;
65  <entryName>Coeffs
66  {
67  frequency 10;
68  amplitude 1;
69  scale (1 0.1 0);
70  level (10 1 0);
71  }
72  \endverbatim
73 
74 SourceFiles
75  Square.C
76 
77 \*---------------------------------------------------------------------------*/
78 
79 #ifndef Square_H
80 #define Square_H
81 
82 #include "Function1.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 namespace Function1Types
89 {
90 
91 /*---------------------------------------------------------------------------*\
92  Class Square Declaration
93 \*---------------------------------------------------------------------------*/
94 
95 template<class Type>
96 class Square
97 :
98  public Function1<Type>
99 {
100  // Private data
101 
102  //- Start-time for the square function
103  scalar t0_;
104 
105  //- Mark/space ratio of the square function
106  scalar markSpace_;
107 
108  //- Scalar amplitude of the square function
109  autoPtr<Function1<scalar>> amplitude_;
110 
111  //- Frequency of the square function
112  autoPtr<Function1<scalar>> frequency_;
113 
114  //- Scaling factor of the square function
115  autoPtr<Function1<Type>> scale_;
116 
117  //- Level to which the square function is added
118  autoPtr<Function1<Type>> level_;
119 
120 
121  // Private Member Functions
122 
123  //- Read the coefficients from the given dictionary
124  void read(const dictionary& coeffs);
125 
126  //- Disallow default bitwise assignment
127  void operator=(const Square<Type>&);
128 
129 
130 public:
131 
132  // Runtime type information
133  TypeName("square");
134 
135 
136  // Constructors
137 
138  //- Construct from entry name and dictionary
139  Square
140  (
141  const word& entryName,
143  );
144 
145  //- Copy constructor
146  Square(const Square<Type>& se);
147 
148 
149  //- Destructor
150  virtual ~Square();
151 
152 
153  // Member Functions
154 
155  //- Return value for time t
156  virtual inline Type value(const scalar t) const;
157 
158  //- Write in dictionary format
159  virtual void writeData(Ostream& os) const;
160 };
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 } // End namespace Function1Types
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #include "SquareI.H"
171 
172 #ifdef NoRepository
173  #include "Square.C"
174 #endif
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
179 
180 // ************************************************************************* //
const word const dictionary & dict
Definition: Function1.H:90
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Square.C:78
virtual ~Square()
Destructor.
Definition: Square.C:71
virtual Type value(const scalar t) const
Return value for time t.
Definition: SquareI.H:31
const word & entryName
Definition: Function1.H:90
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Templated square-wave function with support for an offset level.
Definition: Square.H:142
Namespace for OpenFOAM.
Square(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Square.C:44