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 | Copyright (C) 2016 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,
142  const dictionary& dict,
143  const word& ext = "Coeffs"
144  );
145 
146  //- Copy constructor
147  Square(const Square<Type>& se);
148 
149  //- Construct and return a clone
150  virtual tmp<Function1<Type>> clone() const
151  {
152  return tmp<Function1<Type>>(new Square<Type>(*this));
153  }
154 
155 
156  //- Destructor
157  virtual ~Square();
158 
159 
160  // Member Functions
161 
162  //- Return value for time t
163  Type value(const scalar t) const;
164 
165  //- Write in dictionary format
166  virtual void writeData(Ostream& os) const;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Function1Types
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #ifdef NoRepository
178  #include "Square.C"
179 #endif
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
const word const dictionary & dict
Definition: Function1.H:88
Square(const word &entryName, const dictionary &dict, const word &ext="Coeffs")
Construct from entry name and dictionary.
Definition: Square.C:44
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual ~Square()
Destructor.
Definition: Square.C:72
const word & entryName
Definition: Function1.H:88
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Square.H:196
A class for handling words, derived from string.
Definition: word.H:59
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Square.C:102
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Type value(const scalar t) const
Return value for time t.
Definition: Square.C:79
Templated square-wave function with support for an offset level.
Definition: Square.H:142
A class for managing temporary objects.
Definition: PtrList.H:54
Namespace for OpenFOAM.