mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
Function1Types::Square: New square-wave Function1 with the same controls as Sine
with optional specification of the mark/space ratio
Templated square-wave function with support for an offset level.
\f[
a square(f (t - t_0)) s + l
\f]
where
\f$ square(t) \f$ is the square-wave function in range \f$ [-1, 1] \f$
with a mark/space ratio of \f$ r \f$
\vartable
symbol | Description | Data type | Default
a | Amplitude | Function1<scalar> |
f | Frequency [1/s] | Function1<scalar> |
s | Type scale factor | Function1<Type> |
l | Type offset level | Function1<Type> |
t_0 | Start time [s] | scalar | 0
r | mark/space ratio | scalar | 1
t | Time [s] | scalar
\endvartable
Example for a scalar:
\verbatim
<entryName> square;
<entryName>Coeffs
{
frequency 10;
amplitude 0.1;
scale 2e-6;
level 2e-6;
}
\endverbatim
This commit is contained in:
@ -85,18 +85,6 @@ Type Foam::Function1Types::Sine<Type>::value(const scalar t) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
Type Foam::Function1Types::Sine<Type>::integrate
|
|
||||||
(
|
|
||||||
const scalar t1,
|
|
||||||
const scalar t2
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
NotImplemented;
|
|
||||||
return level_->value(t1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
|
void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -155,9 +155,6 @@ public:
|
|||||||
//- Return value for time t
|
//- Return value for time t
|
||||||
Type value(const scalar t) const;
|
Type value(const scalar t) const;
|
||||||
|
|
||||||
//- Integrate between the two time values t1 and t2
|
|
||||||
Type integrate(const scalar t1, const scalar t2) const;
|
|
||||||
|
|
||||||
//- Write in dictionary format
|
//- Write in dictionary format
|
||||||
virtual void writeData(Ostream& os) const;
|
virtual void writeData(Ostream& os) const;
|
||||||
};
|
};
|
||||||
|
|||||||
118
src/OpenFOAM/primitives/functions/Function1/Square/Square.C
Normal file
118
src/OpenFOAM/primitives/functions/Function1/Square/Square.C
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "Square.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::Function1Types::Square<Type>::read(const dictionary& coeffs)
|
||||||
|
{
|
||||||
|
t0_ = coeffs.lookupOrDefault<scalar>("t0", 0);
|
||||||
|
markSpace_ = coeffs.lookupOrDefault<scalar>("markSpace", 1);
|
||||||
|
amplitude_ = Function1<scalar>::New("amplitude", coeffs);
|
||||||
|
frequency_ = Function1<scalar>::New("frequency", coeffs);
|
||||||
|
scale_ = Function1<Type>::New("scale", coeffs);
|
||||||
|
level_ = Function1<Type>::New("level", coeffs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::Square<Type>::Square
|
||||||
|
(
|
||||||
|
const word& entryName,
|
||||||
|
const dictionary& dict,
|
||||||
|
const word& ext
|
||||||
|
)
|
||||||
|
:
|
||||||
|
Function1<Type>(entryName)
|
||||||
|
{
|
||||||
|
read(dict.subDict(entryName + ext));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
|
||||||
|
:
|
||||||
|
Function1<Type>(se),
|
||||||
|
t0_(se.t0_),
|
||||||
|
markSpace_(se.markSpace_),
|
||||||
|
amplitude_(se.amplitude_, false),
|
||||||
|
frequency_(se.frequency_, false),
|
||||||
|
scale_(se.scale_, false),
|
||||||
|
level_(se.level_, false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::Function1Types::Square<Type>::~Square()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Type Foam::Function1Types::Square<Type>::value(const scalar t) const
|
||||||
|
{
|
||||||
|
// Number of waves including fractions
|
||||||
|
scalar waves = frequency_->value(t)*(t - t0_);
|
||||||
|
|
||||||
|
// Number of complete waves
|
||||||
|
scalar nWaves;
|
||||||
|
|
||||||
|
// Fraction of last incomplete wave
|
||||||
|
scalar waveFrac = std::modf(waves, &nWaves);
|
||||||
|
|
||||||
|
// Mark fraction of a wave
|
||||||
|
scalar markFrac = markSpace_/(1.0 + markSpace_);
|
||||||
|
|
||||||
|
return
|
||||||
|
amplitude_->value(t)
|
||||||
|
*(waveFrac < markFrac ? 1 : -1)
|
||||||
|
*scale_->value(t)
|
||||||
|
+ level_->value(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::Function1Types::Square<Type>::writeData(Ostream& os) const
|
||||||
|
{
|
||||||
|
Function1<Type>::writeData(os);
|
||||||
|
os << token::END_STATEMENT << nl;
|
||||||
|
os << indent << word(this->name() + "Coeffs") << nl;
|
||||||
|
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
|
||||||
|
os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl;
|
||||||
|
os.writeKeyword("markSpace") << markSpace_ << token::END_STATEMENT << nl;
|
||||||
|
amplitude_->writeData(os);
|
||||||
|
frequency_->writeData(os);
|
||||||
|
scale_->writeData(os);
|
||||||
|
level_->writeData(os);
|
||||||
|
os << decrIndent << indent << token::END_BLOCK << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
185
src/OpenFOAM/primitives/functions/Function1/Square/Square.H
Normal file
185
src/OpenFOAM/primitives/functions/Function1/Square/Square.H
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::Function1Types::Square
|
||||||
|
|
||||||
|
Description
|
||||||
|
Templated square-wave function with support for an offset level.
|
||||||
|
|
||||||
|
\f[
|
||||||
|
a square(f (t - t_0)) s + l
|
||||||
|
\f]
|
||||||
|
|
||||||
|
where
|
||||||
|
|
||||||
|
\f$ square(t) \f$ is the square-wave function in range \f$ [-1, 1] \f$
|
||||||
|
with a mark/space ratio of \f$ r \f$
|
||||||
|
|
||||||
|
\vartable
|
||||||
|
symbol | Description | Data type | Default
|
||||||
|
a | Amplitude | Function1<scalar> |
|
||||||
|
f | Frequency [1/s] | Function1<scalar> |
|
||||||
|
s | Type scale factor | Function1<Type> |
|
||||||
|
l | Type offset level | Function1<Type> |
|
||||||
|
t_0 | Start time [s] | scalar | 0
|
||||||
|
r | mark/space ratio | scalar | 1
|
||||||
|
t | Time [s] | scalar
|
||||||
|
\endvartable
|
||||||
|
|
||||||
|
Example for a scalar:
|
||||||
|
\verbatim
|
||||||
|
<entryName> square;
|
||||||
|
<entryName>Coeffs
|
||||||
|
{
|
||||||
|
frequency 10;
|
||||||
|
amplitude 0.1;
|
||||||
|
scale 2e-6;
|
||||||
|
level 2e-6;
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
Example for a vector:
|
||||||
|
\verbatim
|
||||||
|
<entryName> square;
|
||||||
|
<entryName>Coeffs
|
||||||
|
{
|
||||||
|
frequency 10;
|
||||||
|
amplitude 1;
|
||||||
|
scale (1 0.1 0);
|
||||||
|
level (10 1 0);
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
Square.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Square_H
|
||||||
|
#define Square_H
|
||||||
|
|
||||||
|
#include "Function1.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace Function1Types
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Square Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
class Square
|
||||||
|
:
|
||||||
|
public Function1<Type>
|
||||||
|
{
|
||||||
|
// Private data
|
||||||
|
|
||||||
|
//- Start-time for the square function
|
||||||
|
scalar t0_;
|
||||||
|
|
||||||
|
//- Mark/space ratio of the square function
|
||||||
|
scalar markSpace_;
|
||||||
|
|
||||||
|
//- Scalar amplitude of the square function
|
||||||
|
autoPtr<Function1<scalar>> amplitude_;
|
||||||
|
|
||||||
|
//- Frequency of the square function
|
||||||
|
autoPtr<Function1<scalar>> frequency_;
|
||||||
|
|
||||||
|
//- Scaling factor of the square function
|
||||||
|
autoPtr<Function1<Type>> scale_;
|
||||||
|
|
||||||
|
//- Level to which the square function is added
|
||||||
|
autoPtr<Function1<Type>> level_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Read the coefficients from the given dictionary
|
||||||
|
void read(const dictionary& coeffs);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const Square<Type>&);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Runtime type information
|
||||||
|
TypeName("square");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from entry name and dictionary
|
||||||
|
Square
|
||||||
|
(
|
||||||
|
const word& entryName,
|
||||||
|
const dictionary& dict,
|
||||||
|
const word& ext = "Coeffs"
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Copy constructor
|
||||||
|
Square(const Square<Type>& se);
|
||||||
|
|
||||||
|
//- Construct and return a clone
|
||||||
|
virtual tmp<Function1<Type>> clone() const
|
||||||
|
{
|
||||||
|
return tmp<Function1<Type>>(new Square<Type>(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~Square();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Return value for time t
|
||||||
|
Type value(const scalar t) const;
|
||||||
|
|
||||||
|
//- Write in dictionary format
|
||||||
|
virtual void writeData(Ostream& os) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Function1Types
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "Square.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -26,16 +26,12 @@ License
|
|||||||
#include "Constant.H"
|
#include "Constant.H"
|
||||||
#include "PolynomialEntry.H"
|
#include "PolynomialEntry.H"
|
||||||
#include "Sine.H"
|
#include "Sine.H"
|
||||||
|
#include "Square.H"
|
||||||
#include "CSV.H"
|
#include "CSV.H"
|
||||||
#include "Table.H"
|
#include "Table.H"
|
||||||
#include "TableFile.H"
|
#include "TableFile.H"
|
||||||
|
|
||||||
#include "label.H"
|
#include "fieldTypes.H"
|
||||||
#include "scalar.H"
|
|
||||||
#include "vector.H"
|
|
||||||
#include "sphericalTensor.H"
|
|
||||||
#include "symmTensor.H"
|
|
||||||
#include "tensor.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -44,6 +40,7 @@ License
|
|||||||
makeFunction1Type(Constant, Type); \
|
makeFunction1Type(Constant, Type); \
|
||||||
makeFunction1Type(Polynomial, Type); \
|
makeFunction1Type(Polynomial, Type); \
|
||||||
makeFunction1Type(Sine, Type); \
|
makeFunction1Type(Sine, Type); \
|
||||||
|
makeFunction1Type(Square, Type); \
|
||||||
makeFunction1Type(CSV, Type); \
|
makeFunction1Type(CSV, Type); \
|
||||||
makeFunction1Type(Table, Type); \
|
makeFunction1Type(Table, Type); \
|
||||||
makeFunction1Type(TableFile, Type);
|
makeFunction1Type(TableFile, Type);
|
||||||
|
|||||||
Reference in New Issue
Block a user