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-2020 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::Function1s::Square
26 
27 Description
28  Templated square-wave function with support for an offset level.
29 
30  \f[
31  a square(f (x - x_0) ) + l
32  \f]
33 
34  where
35 
36  \f$square(x)\f$ is the square-wave function in range \f$[-1, 1]\f$ with a
37  mark/space ratio of \f$r\f$
38 
39  \vartable
40  Symbol | Description | Data type | Default
41  a | Amplitude | Function1<Type> |
42  f | Frequency | scalar |
43  x_0 | Phase | scalar | 0
44  l | Offset level | Function1<Type> |
45  r | Mark/space ratio | scalar | 1
46  \endvartable
47 
48  Example for a scalar:
49  \verbatim
50  <name> square;
51  <name>Coeffs
52  {
53  amplitude 2e-7;
54  frequency 10;
55  start 0;
56  level 2e-6;
57  markSpace 0.5;
58  }
59  \endverbatim
60 
61  Example for a vector:
62  \verbatim
63  <name> square;
64  <name>Coeffs
65  {
66  amplitude (1 0.1 0);
67  frequency 10;
68  start 0;
69  level (10 1 0);
70  markSpace 0.5;
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 Function1s
89 {
90 
91 /*---------------------------------------------------------------------------*\
92  Class Square Declaration
93 \*---------------------------------------------------------------------------*/
94 
95 template<class Type>
96 class Square
97 :
98  public FieldFunction1<Type, Square<Type>>
99 {
100  // Private Data
101 
102  //- Scalar amplitude of the square function
103  autoPtr<Function1<Type>> amplitude_;
104 
105  //- Frequency of the square function
106  scalar frequency_;
107 
108  //- Argument offset
109  scalar start_;
110 
111  //- Level to which the square function is added
112  autoPtr<Function1<Type>> level_;
113 
114  //- Mark/space ratio of the square function; the fraction of one period
115  // in which the function value is at the higher of the two possible
116  // values.
117  scalar markSpace_;
118 
119  //- Is this function integrable?
120  bool integrable_;
121 
122 
123  // Private Member Functions
124 
125  //- Read the coefficients from the given dictionary
126  void read(const dictionary& dict);
127 
128 
129 public:
130 
131  // Runtime type information
132  TypeName("square");
133 
134 
135  // Constructors
136 
137  //- Construct from name and dictionary
138  Square
139  (
140  const word& name,
141  const dictionary& dict
142  );
143 
144  //- Copy constructor
145  Square(const Square<Type>& se);
146 
147 
148  //- Destructor
149  virtual ~Square();
150 
151 
152  // Member Functions
153 
154  //- Return value
155  virtual inline Type value(const scalar x) const;
156 
157  //- Integrate between two values
158  virtual inline Type integral(const scalar x1, const scalar x2) const;
159 
160  //- Write data to dictionary stream
161  virtual void write(Ostream& os) const;
162 
163 
164  // Member Operators
165 
166  //- Disallow default bitwise assignment
167  void operator=(const Square<Type>&) = delete;
168 };
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace Function1s
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #include "SquareI.H"
179 
180 #ifdef NoRepository
181  #include "Square.C"
182 #endif
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #endif
187 
188 // ************************************************************************* //
virtual ~Square()
Destructor.
Definition: Square.C:76
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: SquareI.H:47
const word const dictionary & dict
Definition: Function1.H:84
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Return the name of the entry.
virtual Type value(const scalar x) const
Return value.
Definition: SquareI.H:32
void operator=(const Square< Type > &)=delete
Disallow default bitwise assignment.
virtual void write(Ostream &os) const
Write data to dictionary stream.
Definition: Square.C:83
Templated square-wave function with support for an offset level.
Definition: Square.H:131
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Square(const word &name, const dictionary &dict)
Construct from name and dictionary.
Definition: Square.C:49
Namespace for OpenFOAM.