mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
DataEntry/Sine: New DataEntryType which evaluates a sin function with offset
Description
Templated sine function with support for an offset level.
\f[
a sin(2 \pi f (t - t_0)) s + l
\f]
where
\vartable
a | Amplitude
f | Frequency [1/s]
s | Type scale factor
l | Type offset level
t_0 | Start time [s]
t | Time [s]
\endvartable
Example for a scalar:
\verbatim
<entryName> sine;
<entryName>Coeffs
{
frequency 10;
amplitude 0.1;
scale 2e-6;
level 2e-6;
}
\endverbatim
Example for a vector:
\verbatim
<entryName> sine;
<entryName>Coeffs
{
frequency 10;
amplitude 1;
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
This commit is contained in:
102
src/OpenFOAM/primitives/functions/DataEntry/Sine/Sine.C
Normal file
102
src/OpenFOAM/primitives/functions/DataEntry/Sine/Sine.C
Normal file
@ -0,0 +1,102 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "Sine.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::DataEntryTypes::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"));
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::DataEntryTypes::Sine<Type>::Sine
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& ext
|
||||
)
|
||||
:
|
||||
DataEntry<Type>(entryName)
|
||||
{
|
||||
read(dict.subDict(entryName + ext));
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::DataEntryTypes::Sine<Type>::Sine(const Sine<Type>& se)
|
||||
:
|
||||
DataEntry<Type>(se),
|
||||
t0_(se.t0_),
|
||||
amplitude_(se.amplitude_),
|
||||
frequency_(se.frequency_),
|
||||
level_(se.level_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::DataEntryTypes::Sine<Type>::~Sine()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Type Foam::DataEntryTypes::Sine<Type>::value(const scalar t) const
|
||||
{
|
||||
return
|
||||
amplitude_*sin(constant::mathematical::twoPi*frequency_*(t - t0_))
|
||||
*scale_
|
||||
+ level_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::DataEntryTypes::Sine<Type>::integrate
|
||||
(
|
||||
const scalar t1,
|
||||
const scalar t2
|
||||
) const
|
||||
{
|
||||
NotImplemented;
|
||||
return level_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "SineIO.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
200
src/OpenFOAM/primitives/functions/DataEntry/Sine/Sine.H
Normal file
200
src/OpenFOAM/primitives/functions/DataEntry/Sine/Sine.H
Normal file
@ -0,0 +1,200 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::DataEntryTypes::Sine
|
||||
|
||||
Description
|
||||
Templated sine function with support for an offset level.
|
||||
|
||||
\f[
|
||||
a sin(2 \pi f (t - t_0)) s + l
|
||||
\f]
|
||||
|
||||
where
|
||||
|
||||
\vartable
|
||||
a | Amplitude
|
||||
f | Frequency [1/s]
|
||||
s | Type scale factor
|
||||
l | Type offset level
|
||||
t_0 | Start time [s]
|
||||
t | Time [s]
|
||||
\endvartable
|
||||
|
||||
Example for a scalar:
|
||||
\verbatim
|
||||
<entryName> sine;
|
||||
<entryName>Coeffs
|
||||
{
|
||||
frequency 10;
|
||||
amplitude 0.1;
|
||||
scale 2e-6;
|
||||
level 2e-6;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Example for a vector:
|
||||
\verbatim
|
||||
<entryName> sine;
|
||||
<entryName>Coeffs
|
||||
{
|
||||
frequency 10;
|
||||
amplitude 1;
|
||||
scale (1 0.1 0);
|
||||
level (10 1 0);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
Sine.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Sine_H
|
||||
#define Sine_H
|
||||
|
||||
#include "DataEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
namespace DataEntryTypes
|
||||
{
|
||||
template<class Type> class Sine;
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
Ostream& operator<<(Ostream&, const DataEntryTypes::Sine<Type>&);
|
||||
|
||||
namespace DataEntryTypes
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Sine Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class Sine
|
||||
:
|
||||
public DataEntry<Type>
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Start-time for the sin function
|
||||
scalar t0_;
|
||||
|
||||
//- Scalar amplitude of the sin function
|
||||
scalar amplitude_;
|
||||
|
||||
//- Frequency of the sin function
|
||||
scalar frequency_;
|
||||
|
||||
//- Scaling factor of the sin function
|
||||
Type scale_;
|
||||
|
||||
//- Level to which the sin function is added
|
||||
Type level_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Read the coefficients from the given dictionary
|
||||
void read(const dictionary& coeffs);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator===(const Sine<Type>&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Runtime type information
|
||||
TypeName("sine");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and dictionary
|
||||
Sine
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict,
|
||||
const word& ext = "Coeffs"
|
||||
);
|
||||
|
||||
//- Copy constructor
|
||||
Sine(const Sine<Type>& se);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<DataEntry<Type>> clone() const
|
||||
{
|
||||
return tmp<DataEntry<Type>>(new Sine<Type>(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~Sine();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return value for time t
|
||||
Type value(const scalar t) const;
|
||||
|
||||
//- 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;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace DataEntryTypes
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "Sine.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
70
src/OpenFOAM/primitives/functions/DataEntry/Sine/SineIO.C
Normal file
70
src/OpenFOAM/primitives/functions/DataEntry/Sine/SineIO.C
Normal file
@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "Sine.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const DataEntryTypes::Sine<Type>& se
|
||||
)
|
||||
{
|
||||
os << static_cast<const DataEntry<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::DataEntryTypes::Sine<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
DataEntry<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("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;
|
||||
os << decrIndent << indent << token::END_BLOCK << endl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
#include "Constant.H"
|
||||
#include "PolynomialEntry.H"
|
||||
#include "Sine.H"
|
||||
#include "CSV.H"
|
||||
#include "Table.H"
|
||||
#include "TableFile.H"
|
||||
@ -40,17 +41,13 @@ namespace Foam
|
||||
{
|
||||
makeDataEntry(label);
|
||||
makeDataEntryType(Constant, label);
|
||||
|
||||
// Polynomial functions and interpolation do evaluate to label
|
||||
// Instead evaluate a scalar and convert to label as appropriate
|
||||
// makeDataEntryType(Polynomial, label);
|
||||
// makeDataEntryType(CSV, label);
|
||||
// makeDataEntryType(Table, label);
|
||||
// makeDataEntryType(TableFile, label);
|
||||
|
||||
makeDataEntry(scalar);
|
||||
makeDataEntryType(Constant, scalar);
|
||||
makeDataEntryType(Polynomial, scalar);
|
||||
makeDataEntryType(Sine, scalar);
|
||||
makeDataEntryType(CSV, scalar);
|
||||
makeDataEntryType(Table, scalar);
|
||||
makeDataEntryType(TableFile, scalar);
|
||||
@ -58,6 +55,7 @@ namespace Foam
|
||||
makeDataEntry(vector);
|
||||
makeDataEntryType(Constant, vector);
|
||||
makeDataEntryType(Polynomial, vector);
|
||||
makeDataEntryType(Sine, vector);
|
||||
makeDataEntryType(CSV, vector);
|
||||
makeDataEntryType(Table, vector);
|
||||
makeDataEntryType(TableFile, vector);
|
||||
@ -65,6 +63,7 @@ namespace Foam
|
||||
makeDataEntry(sphericalTensor);
|
||||
makeDataEntryType(Constant, sphericalTensor);
|
||||
makeDataEntryType(Polynomial, sphericalTensor);
|
||||
makeDataEntryType(Sine, sphericalTensor);
|
||||
makeDataEntryType(CSV, sphericalTensor);
|
||||
makeDataEntryType(Table, sphericalTensor);
|
||||
makeDataEntryType(TableFile, sphericalTensor);
|
||||
@ -72,6 +71,7 @@ namespace Foam
|
||||
makeDataEntry(symmTensor);
|
||||
makeDataEntryType(Constant, symmTensor);
|
||||
makeDataEntryType(Polynomial, symmTensor);
|
||||
makeDataEntryType(Sine, symmTensor);
|
||||
makeDataEntryType(CSV, symmTensor);
|
||||
makeDataEntryType(Table, symmTensor);
|
||||
makeDataEntryType(TableFile, symmTensor);
|
||||
@ -79,6 +79,7 @@ namespace Foam
|
||||
makeDataEntry(tensor);
|
||||
makeDataEntryType(Constant, tensor);
|
||||
makeDataEntryType(Polynomial, tensor);
|
||||
makeDataEntryType(Sine, tensor);
|
||||
makeDataEntryType(CSV, tensor);
|
||||
makeDataEntryType(Table, tensor);
|
||||
makeDataEntryType(TableFile, tensor);
|
||||
|
||||
Reference in New Issue
Block a user