Commit 15cd7c14 authored by Henry Weller's avatar Henry Weller
Browse files

Function1Types::Sine: Changed parameters to be of type Function1 for greater flexibility

    Templated sine function with support for an offset level.

        \f[
            a sin(2 \pi f (t - t_0)) s + l
        \f]

    where

    \vartable
        symbol  | Description       | Data type
        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
        t       | Time [s]          | scalar
    \endvartable
parent d64e8f14
......@@ -32,10 +32,10 @@ template<class Type>
void Foam::Function1Types::Sine<Type>::read(const dictionary& coeffs)
{
t0_ = coeffs.lookupOrDefault<scalar>("t0", 0);
amplitude_ = coeffs.lookupOrDefault<scalar>("amplitude", 1);
frequency_ = readScalar(coeffs.lookup("frequency"));
scale_ = pTraits<Type>(coeffs.lookup("scale"));
level_ = pTraits<Type>(coeffs.lookup("level"));
amplitude_ = Function1<scalar>::New("amplitude", coeffs);
frequency_ = Function1<scalar>::New("frequency", coeffs);
scale_ = Function1<Type>::New("scale", coeffs);
level_ = Function1<Type>::New("level", coeffs);
}
......@@ -58,9 +58,10 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
:
Function1<Type>(se),
t0_(se.t0_),
amplitude_(se.amplitude_),
frequency_(se.frequency_),
level_(se.level_)
amplitude_(se.amplitude_, false),
frequency_(se.frequency_, false),
scale_(se.scale_, false),
level_(se.level_, false)
{}
......@@ -77,9 +78,10 @@ template<class Type>
Type Foam::Function1Types::Sine<Type>::value(const scalar t) const
{
return
amplitude_*sin(constant::mathematical::twoPi*frequency_*(t - t0_))
*scale_
+ level_;
amplitude_->value(t)
*sin(constant::mathematical::twoPi*frequency_->value(t)*(t - t0_))
*scale_->value(t)
+ level_->value(t);
}
......@@ -91,7 +93,7 @@ Type Foam::Function1Types::Sine<Type>::integrate
) const
{
NotImplemented;
return level_;
return level_->value(t1);
}
......
......@@ -34,12 +34,13 @@ Description
where
\vartable
a | Amplitude
f | Frequency [1/s]
s | Type scale factor
l | Type offset level
t_0 | Start time [s]
t | Time [s]
symbol | Description | Data type
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
t | Time [s] | scalar
\endvartable
Example for a scalar:
......@@ -80,16 +81,6 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
namespace Function1Types
{
template<class Type> class Sine;
};
template<class Type>
Ostream& operator<<(Ostream&, const Function1Types::Sine<Type>&);
namespace Function1Types
{
......@@ -108,16 +99,16 @@ class Sine
scalar t0_;
//- Scalar amplitude of the sin function
scalar amplitude_;
autoPtr<Function1<scalar>> amplitude_;
//- Frequency of the sin function
scalar frequency_;
autoPtr<Function1<scalar>> frequency_;
//- Scaling factor of the sin function
Type scale_;
autoPtr<Function1<Type>> scale_;
//- Level to which the sin function is added
Type level_;
autoPtr<Function1<Type>> level_;
// Private Member Functions
......@@ -167,16 +158,6 @@ public:
//- Integrate between the two time values t1 and t2
Type integrate(const scalar t1, const scalar t2) const;
// I/O
//- Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream& os,
const Sine<Type>& cnst
);
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
};
......
......@@ -27,30 +27,6 @@ License
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const Function1Types::Sine<Type>& se
)
{
os << static_cast<const Function1<Type>& >(se)
<< token::SPACE << se.t0_
<< token::SPACE << se.amplitude_
<< token::SPACE << se.frequency_
<< token::SPACE << se.scale_
<< token::SPACE << se.level_;
// Check state of Ostream
os.check
(
"Ostream& operator<<(Ostream&, const Sine<Type>&)"
);
return os;
}
template<class Type>
void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
{
......@@ -59,10 +35,10 @@ void Foam::Function1Types::Sine<Type>::writeData(Ostream& os) const
os << indent << word(this->name() + "Coeffs") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.writeKeyword("t0") << t0_ << token::END_STATEMENT << nl;
os.writeKeyword("amplitude") << amplitude_ << token::END_STATEMENT << nl;
os.writeKeyword("frequency") << frequency_ << token::END_STATEMENT << nl;
os.writeKeyword("scale") << scale_ << token::END_STATEMENT << nl;
os.writeKeyword("level") << level_ << token::END_STATEMENT << nl;
amplitude_->writeData(os);
frequency_->writeData(os);
scale_->writeData(os);
level_->writeData(os);
os << decrIndent << indent << token::END_BLOCK << endl;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment