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-2024 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  const autoPtr<Function1<Type>> amplitude_;
104 
105  //- Frequency of the square function
106  const scalar frequency_;
107 
108  //- Argument offset
109  const scalar start_;
110 
111  //- Level to which the square function is added
112  const 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  const scalar markSpace_;
118 
119  //- Is this function integrable?
120  const bool integrable_;
121 
122 
123 public:
124 
125  // Runtime type information
126  TypeName("square");
127 
128 
129  // Constructors
130 
131  //- Construct from name and dictionary
132  Square
133  (
134  const word& name,
135  const unitConversions& units,
136  const dictionary& dict
137  );
138 
139  //- Copy constructor
140  Square(const Square<Type>& se);
141 
142 
143  //- Destructor
144  virtual ~Square();
145 
146 
147  // Member Functions
148 
149  //- Return value
150  virtual inline Type value(const scalar x) const;
151 
152  //- Integrate between two values
153  virtual inline Type integral(const scalar x1, const scalar x2) const;
154 
155  //- Write data to dictionary stream
156  virtual void write(Ostream& os, const unitConversions& units) const;
157 
158 
159  // Member Operators
160 
161  //- Disallow default bitwise assignment
162  void operator=(const Square<Type>&) = delete;
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Function1s
169 } // End namespace Foam
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #include "SquareI.H"
174 
175 #ifdef NoRepository
176  #include "Square.C"
177 #endif
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Templated square-wave function with support for an offset level.
Definition: Square.H:134
virtual ~Square()
Destructor.
Definition: Square.C:64
Square(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Square.C:32
void operator=(const Square< Type > &)=delete
Disallow default bitwise assignment.
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: SquareI.H:47
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Square.C:72
virtual Type value(const scalar x) const
Return value.
Definition: SquareI.H:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict