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