Square< Type > Class Template Reference

A templated square-wave function with support for offset, etc. More...

Inheritance diagram for Square< Type >:
[legend]
Collaboration diagram for Square< Type >:
[legend]

Public Member Functions

 TypeName ("square")
 
void operator= (const Square< Type > &)=delete
 No copy assignment. More...
 
 Square (const word &entryName, const dictionary &dict)
 Construct from entry name and dictionary. More...
 
 Square (const Square< Type > &rhs)
 Copy construct. More...
 
virtual ~Square ()=default
 Destructor. More...
 
virtual Type value (const scalar t) const
 Return value for time t. More...
 
virtual void writeData (Ostream &os) const
 Write in dictionary format. More...
 
void writeEntries (Ostream &os) const
 Write coefficient entries in dictionary format. More...
 
- Public Member Functions inherited from Sine< Type >
 TypeName ("sine")
 
void operator= (const Sine< Type > &)=delete
 No copy assignment. More...
 
 Sine (const word &entryName, const dictionary &dict)
 Construct from entry name and dictionary. More...
 
 Sine (const Sine< Type > &rhs)
 Copy construct. More...
 
virtual ~Sine ()=default
 Destructor. More...
 
virtual void convertTimeBase (const Time &t)
 Convert time. More...
 
void writeEntries (Ostream &os) const
 Write coefficient entries in dictionary format. More...
 
- Public Member Functions inherited from Function1< Type >
 TypeName ("Function1") declareRunTimeSelectionTable(autoPtr
 Runtime type information. More...
 
 Function1 (const word &entryName)
 Construct from entry name. More...
 
 Function1 (const word &entryName, const dictionary &dict)
 Construct from entry name and dictionary. More...
 
 Function1 (const Function1< Type > &rhs)
 Copy construct. More...
 
virtual tmp< Function1< Type > > clone () const =0
 Construct and return a clone. More...
 
virtual ~Function1 ()=default
 Destructor. More...
 
virtual tmp< Field< Type > > value (const scalarField &x) const
 Return value as a function of (scalar) independent variable. More...
 
virtual Type integrate (const scalar x1, const scalar x2) const
 Integrate between two (scalar) values. More...
 
virtual tmp< Field< Type > > integrate (const scalarField &x1, const scalarField &x2) const
 Integrate between two (scalar) values. More...
 
void writeEntries (Ostream &os) const
 Write coefficient entries in dictionary format. More...
 

Additional Inherited Members

- Public Types inherited from Function1< Type >
typedef Type returnType
 
- Static Public Member Functions inherited from Function1< Type >
static autoPtr< Function1< Type > > New (const word &entryName, const dictionary &dict, const word &redirectType, const bool mandatory=true)
 Selector, with fallback redirection. More...
 
static autoPtr< Function1< Type > > NewCompat (const word &entryName, std::initializer_list< std::pair< const char *, int >> compat, const dictionary &dict, const word &redirectType=word::null, const bool mandatory=true)
 Compatibility selector, with fallback redirection. More...
 
static autoPtr< Function1< Type > > New (const word &entryName, const dictionary &dict, const bool mandatory=true)
 Selector, without fallback redirection. More...
 
static autoPtr< Function1< Type > > NewIfPresent (const word &entryName, const dictionary &dict, const word &redirectType=word::null)
 An optional selector. More...
 
- Public Attributes inherited from Function1< Type >
 Function1
 
 dictionary
 
const wordentryName
 
const word const dictionarydict
 
const word const dictionary entryName
 
const word const dictionary dict
 
- Protected Member Functions inherited from Sine< Type >
scalar cycle (const scalar t) const
 The cycle: (freq * time) or (time / period) More...
 
scalar cosForm (const scalar t) const
 Calculated cos value at time t. More...
 
scalar sinForm (const scalar t) const
 Calculated sin value at time t. More...
 
scalar squareForm (const scalar t, const scalar posFrac) const
 Calculated square value at time t. More...
 
Type cosValue (const scalar t) const
 Return value for time t, using cos form. More...
 
Type sinValue (const scalar t) const
 Return value for time t, using sin form. More...
 
Type squareValue (const scalar t, const scalar posFrac) const
 Return value for time t, using square form. More...
 
- Protected Member Functions inherited from Function1< Type >
void operator= (const Function1< Type > &)=delete
 No copy assignment. More...
 
- Protected Attributes inherited from Sine< Type >
scalar t0_
 Start-time for the function. More...
 
autoPtr< Function1< scalar > > amplitude_
 Scalar amplitude of the function (optional) More...
 
autoPtr< Function1< scalar > > period_
 Period of the function (or specify frequency) More...
 
autoPtr< Function1< scalar > > frequency_
 Frequency of the function (or specify period) More...
 
autoPtr< Function1< Type > > scale_
 Scaling factor for the function. More...
 
autoPtr< Function1< Type > > level_
 Level to add to the scaled function. More...
 

Detailed Description

template<class Type>
class Foam::Function1Types::Square< Type >

A templated square-wave function with support for offset, etc.

The wave period can be specified directly

\[ a square((t - t0) / p)) s + l \]

Or it can be specified by the frequency

\[ a square(f (t - t0)) s + l \]

where

\( square(t) \) is the square-wave function in range \( [-1, 1] \) with a mark/space ratio of \( r \)

\( 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 -

The dictionary specification would typically resemble this:

    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);
    }

where the entries mean:

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
Note
For slow oscillations it can be more intuitive to specify the period.

Definition at line 225 of file Square.H.

Constructor & Destructor Documentation

◆ Square() [1/2]

Square ( const word entryName,
const dictionary dict 
)

Construct from entry name and dictionary.

Definition at line 35 of file Square.C.

◆ Square() [2/2]

Square ( const Square< Type > &  rhs)
explicit

Copy construct.

Definition at line 47 of file Square.C.

◆ ~Square()

virtual ~Square ( )
virtualdefault

Destructor.

Member Function Documentation

◆ TypeName()

TypeName ( "square"  )

◆ operator=()

void operator= ( const Square< Type > &  )
delete

No copy assignment.

◆ value()

virtual Type value ( const scalar  t) const
inlinevirtual

Return value for time t.

Reimplemented from Sine< Type >.

Definition at line 265 of file Square.H.

References Sine< Type >::squareValue().

Here is the call graph for this function:

◆ writeData()

void writeData ( Ostream os) const
virtual

Write in dictionary format.

Reimplemented from Sine< Type >.

Definition at line 67 of file Square.C.

References Ostream::beginBlock(), Ostream::endBlock(), Ostream::endEntry(), Foam::name(), and Function1< Type >::writeData().

Here is the call graph for this function:

◆ writeEntries()

void writeEntries ( Ostream os) const

Write coefficient entries in dictionary format.

Definition at line 58 of file Square.C.

References Sine< Type >::writeEntries(), and Ostream::writeEntryIfDifferent().

Here is the call graph for this function:

The documentation for this class was generated from the following files: