ENH: support frequency or period for Sine/Square Function1 (#1917)

- For slow oscillations it can be more intuitive to specify the
  period.

ENH: separate mark/space for Square

- makes it easier to tailor the desired intervals.

BUG: incorrect square wave fraction with negative phase shifts

ENH: additional cosine Function1

STYLE: avoid code duplication by inheriting Cosine/Square from Sine.
This commit is contained in:
Mark Olesen
2020-11-16 11:39:57 +01:00
parent 2f2dcdcf6f
commit 8d2d894ae0
16 changed files with 654 additions and 249 deletions

View File

@ -61,4 +61,48 @@ rampf1
}
sine1
{
type sine;
frequency 0.1;
scale 1;
level 0;
}
sine2
{
type sine;
period 10;
scale 1;
level 0;
}
cosine1
{
type cosine;
period 10;
scale 1;
level 0;
}
sine6
{
type sine;
period 6;
t0 -1.5; // want cos
scale 1;
level 0;
}
cosine6
{
type cosine;
period 6;
scale 1;
level 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
Test-plotFunction1.C
EXE = $(FOAM_USER_APPBIN)/Test-plotFunction1

View File

@ -0,0 +1,15 @@
EXE_INC = \
-DFULLDEBUG -g -O0 \
-I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/radiation/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-llagrangianIntermediate \
-lradiationModels \
-lregionModels \
-lfiniteVolume \
-lmeshTools \
-lsampling

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Application
Test-plotFunction1
Description
Plot scalar Function1 entries
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "fieldTypes.H"
#include "Function1.H"
#include "PtrList.H"
#include "Fstream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::noBanner();
argList::noParallel();
argList::setAdvanced("case"); // Hide -case : has no meaning here
argList::addOption("begin", "scalar", "The start time (default: 0)");
argList::addOption("end", "scalar", "The end time (default: 1)");
argList::addOption("incr", "scalar", "The time increment (default: 0.1)");
argList::addOption("timeBase", "scalar", "The time base (default: 1)");
argList::addNote
(
"Read scalar functions from each file and produces"
" time/value output for each"
);
argList::noMandatoryArgs();
argList::addArgument("file1");
argList::addArgument("...");
argList::addArgument("fileN");
#include "setRootCase.H"
const scalar begTime = args.getOrDefault<scalar>("begin", 0);
const scalar endTime = args.getOrDefault<scalar>("end", 1);
const scalar incrTime = args.getOrDefault<scalar>("incr", 0.1);
const scalar timeBase = args.getOrDefault<scalar>("timeBase", 1);
Info().precision(10);
for (label argi=1; argi < args.size(); ++argi)
{
IFstream is(args[argi]);
dictionary dict(is);
for (const entry& dEntry : dict)
{
autoPtr<Function1<scalar>> funPtr =
Function1<scalar>::New(dEntry.keyword(), dict);
auto& fun = *funPtr;
InfoErr<< nl;
fun.writeData(InfoErr);
InfoErr<< nl;
Info<< nl << "# " << fun.type() << nl;
for (scalar t = begTime; t < endTime; t += incrTime)
{
Info<< t << tab << fun.value(t*timeBase) << nl;
}
Info<< nl;
}
}
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,170 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::Cosine
Description
A templated cosine function, with support for offset etc.
The wave period can be specified directly
\f[
a cos(2 \pi (t - t0) / p)) s + l
\f]
Or it can be specified by the frequency
\f[
a cos(2 \pi f (t - t0)) s + l
\f]
where
\vartable
Symbol | Description | Units
a | Amplitude | -
f | Frequency | [1/s]
p | Period | [s]
s | Type scale factor | -
l | Type offset level | -
t | Time | [s]
t0 | Start time offset | [s]
\endvartable
The dictionary specification would typically resemble this:
\verbatim
entry1
{
type cosine;
frequency 10;
amplitude 0.1;
// A scalar Function1
scale 2e-6;
level 2e-6;
}
entry2
{
type cosine;
frequency 10;
// A vector Function1
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
where the entries mean:
\table
Property | Description | Type | Reqd | Default
type | Function type: cosine | word | yes |
amplitude | Amplitude | Function1<scalar> | no | 1
frequency | Frequency [1/s] | Function1<scalar> | or period |
period | Period [s] | Function1<scalar> | or frequency |
scale | Scale factor (Type) | Function1<Type> | yes |
level | Offset level (Type) | Function1<Type> | yes |
t0 | Start time offset | scalar | no | 0
\endtable
Note
For slow oscillations it can be more intuitive to specify the period.
SourceFiles
Cosine.C
\*---------------------------------------------------------------------------*/
#ifndef function1Types_Cosine_H
#define function1Types_Cosine_H
#include "Sine.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function1Types
{
/*---------------------------------------------------------------------------*\
Class Cosine Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Cosine
:
public Function1Types::Sine<Type>
{
public:
// Runtime type information
TypeName("cosine");
// Generated Methods
//- No copy assignment
void operator=(const Cosine<Type>&) = delete;
// Constructors
//- Construct from entry name and dictionary
Cosine(const word& entryName, const dictionary& dict)
:
Sine<Type>(entryName, dict)
{}
//- Copy construct
explicit Cosine(const Cosine<Type>& rhs)
:
Sine<Type>(rhs)
{}
//- Destructor
virtual ~Cosine() = default;
// Member Functions
//- Return value for time t
virtual inline Type value(const scalar t) const
{
return Sine<Type>::cosValue(t);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function1Types
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -30,17 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1Types::Sine<Type>::read(const dictionary& coeffs)
{
t0_ = coeffs.getOrDefault<scalar>("t0", 0);
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::Sine<Type>::Sine
(
@ -48,21 +37,31 @@ Foam::Function1Types::Sine<Type>::Sine
const dictionary& dict
)
:
Function1<Type>(entryName, dict)
Function1<Type>(entryName, dict),
t0_(dict.getOrDefault<scalar>("t0", 0)),
amplitude_(Function1<scalar>::NewIfPresent("amplitude", dict)),
period_(Function1<scalar>::NewIfPresent("period", dict)),
frequency_(nullptr),
scale_(Function1<Type>::New("scale", dict)),
level_(Function1<Type>::New("level", dict))
{
read(dict);
if (!period_)
{
frequency_ = Function1<scalar>::New("frequency", dict);
}
}
template<class Type>
Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& rhs)
:
Function1<Type>(se),
t0_(se.t0_),
amplitude_(se.amplitude_.clone()),
frequency_(se.frequency_.clone()),
scale_(se.scale_.clone()),
level_(se.level_.clone())
Function1<Type>(rhs),
t0_(rhs.t0_),
amplitude_(rhs.amplitude_.clone()),
period_(rhs.period_.clone()),
frequency_(rhs.frequency_.clone()),
scale_(rhs.scale_.clone()),
level_(rhs.level_.clone())
{}
@ -71,9 +70,19 @@ Foam::Function1Types::Sine<Type>::Sine(const Sine<Type>& se)
template<class Type>
void Foam::Function1Types::Sine<Type>::writeEntries(Ostream& os) const
{
os.writeEntry("t0", t0_);
amplitude_->writeData(os);
frequency_->writeData(os);
os.writeEntryIfDifferent<scalar>("t0", 0, t0_);
if (amplitude_)
{
amplitude_->writeData(os);
}
if (period_)
{
period_->writeData(os);
}
if (frequency_)
{
frequency_->writeData(os);
}
scale_->writeData(os);
level_->writeData(os);
}

View File

@ -28,55 +28,78 @@ Class
Foam::Function1Types::Sine
Description
Templated sine function with support for an offset level.
A templated sine function, with support for offset etc.
The wave period can be specified directly
\f[
a sin(2 \pi f (t - t_0)) s + l
a sin(2 \pi (t - t0) / p)) s + l
\f]
Or it can be specified by the frequency
\f[
a sin(2 \pi f (t - t0)) 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
Symbol | Description | Units
a | Amplitude | -
f | Frequency | [1/s]
p | Period | [s]
s | Type scale factor | -
l | Type offset level | -
t | Time | [s]
t0 | Start time offset | [s]
\endvartable
Example for a scalar:
The dictionary specification would typically resemble this:
\verbatim
<entryName> sine;
<entryName>Coeffs
{
frequency 10;
amplitude 0.1;
scale 2e-6;
level 2e-6;
}
entry1
{
type sine;
frequency 10;
amplitude 0.1;
// A scalar Function1
scale 2e-6;
level 2e-6;
}
entry2
{
type sine;
frequency 10;
// A vector Function1
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
Example for a vector:
\verbatim
<entryName> sine;
<entryName>Coeffs
{
frequency 10;
amplitude 1;
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
where the entries mean:
\table
Property | Description | Type | Reqd | Default
type | Function type: sine | word | yes |
amplitude | Amplitude | Function1<scalar> | no | 1
frequency | Frequency [1/s] | Function1<scalar> | or period |
period | Period [s] | Function1<scalar> | or frequency |
scale | Scale factor (Type) | Function1<Type> | yes |
level | Offset level (Type) | Function1<Type> | yes |
t0 | Start time offset | scalar | no | 0
\endtable
Note
For slow oscillations it can be more intuitive to specify the period.
SourceFiles
Sine.C
SineI.H
\*---------------------------------------------------------------------------*/
#ifndef Sine_H
#define Sine_H
#ifndef function1Types_Sine_H
#define function1Types_Sine_H
#include "Function1.H"
@ -88,7 +111,7 @@ namespace Function1Types
{
/*---------------------------------------------------------------------------*\
Class Sine Declaration
Class Sine Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
@ -96,28 +119,53 @@ class Sine
:
public Function1<Type>
{
// Private data
protected:
//- Start-time for the sin function
// Protected Data
//- Start-time for the function
scalar t0_;
//- Scalar amplitude of the sin function
//- Scalar amplitude of the function (optional)
autoPtr<Function1<scalar>> amplitude_;
//- Frequency of the sin function
//- Period of the function (or specify frequency)
autoPtr<Function1<scalar>> period_;
//- Frequency of the function (or specify period)
autoPtr<Function1<scalar>> frequency_;
//- Scaling factor of the sin function
//- Scaling factor for the function
autoPtr<Function1<Type>> scale_;
//- Level to which the sin function is added
//- Level to add to the scaled function
autoPtr<Function1<Type>> level_;
// Private Member Functions
// Protected Member Functions
//- The cycle: (freq * time) or (time / period)
inline scalar cycle(const scalar t) const;
//- Calculated cos value at time t
inline scalar cosForm(const scalar t) const;
//- Calculated sin value at time t
inline scalar sinForm(const scalar t) const;
//- Calculated square value at time t.
// The positive fraction is 0-1
inline scalar squareForm(const scalar t, const scalar posFrac) const;
//- Return value for time t, using cos form
inline Type cosValue(const scalar t) const;
//- Return value for time t, using sin form
inline Type sinValue(const scalar t) const;
//- Return value for time t, using square form
inline Type squareValue(const scalar t, const scalar posFrac) const;
//- Read the coefficients from the given dictionary
void read(const dictionary& coeffs);
public:
@ -134,14 +182,10 @@ public:
// Constructors
//- Construct from entry name and dictionary
Sine
(
const word& entryName,
const dictionary& dict
);
Sine(const word& entryName, const dictionary& dict);
//- Copy constructor
explicit Sine(const Sine<Type>& se);
//- Copy construct
explicit Sine(const Sine<Type>& rhs);
//- Destructor
@ -151,7 +195,10 @@ public:
// Member Functions
//- Return value for time t
virtual inline Type value(const scalar t) const;
virtual inline Type value(const scalar t) const
{
return Sine<Type>::sinValue(t);
}
//- Write in dictionary format
virtual void writeData(Ostream& os) const;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,19 +26,100 @@ License
\*---------------------------------------------------------------------------*/
#include "Sine.H"
#include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function1Types::Sine<Type>::value(const scalar t) const
inline Foam::scalar Foam::Function1Types::Sine<Type>::cycle
(
const scalar t
) const
{
// The cycle: (freq * time) or (time / period)
return
(
frequency_
? (t - t0_) * frequency_->value(t)
: (t - t0_) / (period_->value(t) + VSMALL)
);
}
template<class Type>
inline Foam::scalar
Foam::Function1Types::Sine<Type>::cosForm(const scalar t) const
{
return
amplitude_->value(t)
*sin(constant::mathematical::twoPi*frequency_->value(t)*(t - t0_))
*scale_->value(t)
+ level_->value(t);
(
cos(constant::mathematical::twoPi * this->cycle(t))
* (amplitude_ ? amplitude_->value(t) : 1.0)
);
}
template<class Type>
inline Foam::scalar
Foam::Function1Types::Sine<Type>::sinForm(const scalar t) const
{
return
(
sin(constant::mathematical::twoPi * this->cycle(t))
* (amplitude_ ? amplitude_->value(t) : 1.0)
);
}
template<class Type>
inline Foam::scalar
Foam::Function1Types::Sine<Type>::squareForm
(
const scalar t,
const scalar posFrac
) const
{
const scalar cyc = this->cycle(t);
return
(
// Fraction of incomplete cycle
((cyc - std::floor(cyc)) < posFrac ? 1.0 : -1.0)
* (amplitude_ ? amplitude_->value(t) : 1.0)
);
}
template<class Type>
inline Type Foam::Function1Types::Sine<Type>::cosValue(const scalar t) const
{
return
(
cosForm(t) * scale_->value(t) + level_->value(t)
);
}
template<class Type>
inline Type Foam::Function1Types::Sine<Type>::sinValue(const scalar t) const
{
return
(
sinForm(t) * scale_->value(t) + level_->value(t)
);
}
template<class Type>
inline Type Foam::Function1Types::Sine<Type>::squareValue
(
const scalar t,
const scalar posFrac
) const
{
return
(
squareForm(t, posFrac) * scale_->value(t) + level_->value(t)
);
}

View File

@ -30,18 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
void Foam::Function1Types::Square<Type>::read(const dictionary& coeffs)
{
t0_ = coeffs.getOrDefault<scalar>("t0", 0);
markSpace_ = coeffs.getOrDefault<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
(
@ -49,22 +37,18 @@ Foam::Function1Types::Square<Type>::Square
const dictionary& dict
)
:
Function1<Type>(entryName, dict)
{
read(dict);
}
Sine<Type>(entryName, dict),
mark_(dict.getOrDefaultCompat<scalar>("mark", {{"markSpace", 2006}}, 1)),
space_(dict.getOrDefault<scalar>("space", 1))
{}
template<class Type>
Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
Foam::Function1Types::Square<Type>::Square(const Square<Type>& rhs)
:
Function1<Type>(se),
t0_(se.t0_),
markSpace_(se.markSpace_),
amplitude_(se.amplitude_.clone()),
frequency_(se.frequency_.clone()),
scale_(se.scale_.clone()),
level_(se.level_.clone())
Sine<Type>(rhs),
mark_(rhs.mark_),
space_(rhs.space_)
{}
@ -73,12 +57,9 @@ Foam::Function1Types::Square<Type>::Square(const Square<Type>& se)
template<class Type>
void Foam::Function1Types::Square<Type>::writeEntries(Ostream& os) const
{
os.writeEntry("t0", t0_);
os.writeEntry("markSpace", markSpace_);
amplitude_->writeData(os);
frequency_->writeData(os);
scale_->writeData(os);
level_->writeData(os);
os.writeEntryIfDifferent<scalar>("mark", 1, mark_);
os.writeEntryIfDifferent<scalar>("space", 1, space_);
Sine<Type>::writeEntries(os);
}

View File

@ -28,11 +28,19 @@ Class
Foam::Function1Types::Square
Description
Templated square-wave function with support for an offset level.
A templated square-wave function with support for offset, etc.
\f[
a square(f (t - t_0)) s + l
\f]
The wave period can be specified directly
\f[
a square((t - t0) / p)) s + l
\f]
Or it can be specified by the frequency
\f[
a square(f (t - t0)) s + l
\f]
where
@ -40,49 +48,63 @@ Description
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
symbol | Description | Units
a | Amplitude | -
f | Frequency | [1/s]
p | Period | [s]
s | Type scale factor | -
l | Type offset level | -
t | Time | [s]
t0 | Start time offset | [s]
r | mark/space ratio | -
\endvartable
Example for a scalar:
The dictionary specification would typically resemble this:
\verbatim
<entryName> square;
<entryName>Coeffs
{
frequency 10;
amplitude 0.1;
scale 2e-6;
level 2e-6;
}
entry1
{
type square;
frequency 10;
amplitude 0.1;
// A scalar Function1
scale 2e-6;
level 2e-6;
}
entry2
{
type square;
frequency 10;
// A vector Function1
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
Example for a vector:
\verbatim
<entryName> square;
<entryName>Coeffs
{
frequency 10;
amplitude 1;
scale (1 0.1 0);
level (10 1 0);
}
\endverbatim
where the entries mean:
\table
Property | Description | Type | Reqd | Default
type | Function type: square | word | yes |
amplitude | Amplitude | Function1<scalar> | no | 1
frequency | Frequency [1/s] | Function1<scalar> | or period |
period | Period [s] | Function1<scalar> | or frequency |
scale | Scale factor (Type) | Function1<Type> | yes |
level | Offset level (Type) | Function1<Type> | yes |
t0 | Start time offset | scalar | no | 0
mark | Positive amount | scalar | no | 1
space | Negative amount | scalar | no | 1
\endtable
SourceFiles
Square.C
Note
For slow oscillations it can be more intuitive to specify the period.
\*---------------------------------------------------------------------------*/
#ifndef Square_H
#define Square_H
#ifndef function1Types_Square_H
#define function1Types_Square_H
#include "Function1.H"
#include "Sine.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -98,34 +120,15 @@ namespace Function1Types
template<class Type>
class Square
:
public Function1<Type>
public Function1Types::Sine<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);
//- Mark/space ratio (square function only)
scalar mark_;
//- Mark/space ratio (square function only)
scalar space_;
public:
@ -142,13 +145,9 @@ public:
// Constructors
//- Construct from entry name and dictionary
Square
(
const word& entryName,
const dictionary& dict
);
Square(const word& entryName, const dictionary& dict);
//- Copy constructor
//- Copy construct
explicit Square(const Square<Type>& rhs);
@ -159,7 +158,10 @@ public:
// Member Functions
//- Return value for time t
virtual inline Type value(const scalar t) const;
virtual inline Type value(const scalar t) const
{
return Sine<Type>::squareValue(t, mark_ / (mark_ + space_));
}
//- Write in dictionary format
virtual void writeData(Ostream& os) const;
@ -176,8 +178,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "SquareI.H"
#ifdef NoRepository
#include "Square.C"
#endif

View File

@ -1,55 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
-------------------------------------------------------------------------------
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"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline 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);
}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,6 +32,7 @@ License
#include "OneConstant.H"
#include "PolynomialEntry.H"
#include "Sine.H"
#include "Cosine.H"
#include "Square.H"
#include "CSV.H"
#include "Table.H"
@ -48,6 +50,7 @@ License
makeFunction1Type(ZeroConstant, Type); \
makeFunction1Type(OneConstant, Type); \
makeFunction1Type(Polynomial, Type); \
makeFunction1Type(Cosine, Type); \
makeFunction1Type(Sine, Type); \
makeFunction1Type(Square, Type); \
makeFunction1Type(CSV, Type); \

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,7 @@ License
#define makePatchFunction1s(Type) \
makePatchFunction1(Type); \
makePatchFunction1Type(ConstantField, Type); \
makePatchFunction1Type(MappedFile, Type); \
makePatchFunction1Type(MappedFile, Type); \
makePatchFunction1Type(UniformValueField, Type);
#define addUniformValueFieldFunction1s(F1Type, Type) \
@ -77,6 +77,12 @@ namespace Foam
addUniformValueFieldFunction1s(polynomial, symmTensor);
addUniformValueFieldFunction1s(polynomial, tensor);
addUniformValueFieldFunction1s(cosine, scalar);
addUniformValueFieldFunction1s(cosine, vector);
addUniformValueFieldFunction1s(cosine, sphericalTensor);
addUniformValueFieldFunction1s(cosine, symmTensor);
addUniformValueFieldFunction1s(cosine, tensor);
addUniformValueFieldFunction1s(sine, scalar);
addUniformValueFieldFunction1s(sine, vector);
addUniformValueFieldFunction1s(sine, sphericalTensor);

View File

@ -23,11 +23,10 @@ boundaryField
{
inlet
{
type uniformFixedValue; // oscillatingFixedValue;
type uniformFixedValue;
uniformValue sine;
uniformValueCoeffs
{
amplitude constant 1;
frequency constant 3000;
scale constant 50;
level constant 101325;

View File

@ -63,12 +63,10 @@ functions
libs (fieldFunctionObjects);
writeControl writeTime;
mode vortex2D;
scale sine;
scale cosine;
scaleCoeffs
{
amplitude 1;
frequency 0.0625; // = 1/16
t0 -4; // want cos -> time shift = -(pi/2)/(2 pi f)
period 16
scale 1;
level 0;
}

View File

@ -64,14 +64,12 @@ functions
libs (fieldFunctionObjects);
writeControl writeTime;
mode vortex3D;
scale sine;
scale cosine;
scaleCoeffs
{
amplitude 1;
frequency 0.16666;// = 1/6
t0 -1.5; // want cos -> time shift = -(pi/2)/(2 pi f)
scale 1;
level 0;
period 6;
scale 1;
level 0;
}
origin (0 0 0);
refDir (1 0 0);