Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Nektar::SolverUtils::ForcingNoise Class Reference

#include <ForcingNoise.h>

Inheritance diagram for Nektar::SolverUtils::ForcingNoise:
[legend]

Static Public Member Functions

static SOLVER_UTILS_EXPORT ForcingSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::SolverUtils::Forcing
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtrLoad (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

SOLVER_UTILS_EXPORT void v_InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce) override
 
SOLVER_UTILS_EXPORT void v_Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time) override
 
- Protected Member Functions inherited from Nektar::SolverUtils::Forcing
SOLVER_UTILS_EXPORT Forcing (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 Constructor. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)=0
 
virtual SOLVER_UTILS_EXPORT void v_Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)=0
 
virtual SOLVER_UTILS_EXPORT void v_PreApply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_ApplyCoeff (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, std::string pName, bool pCache=false)
 Get a SessionFunction by name. More...
 
SOLVER_UTILS_EXPORT void EvaluateTimeFunction (LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName, Array< OneD, NekDouble > &pArray, const std::string &pFunctionName, NekDouble pTime=NekDouble(0))
 
SOLVER_UTILS_EXPORT void EvaluateTimeFunction (const NekDouble pTime, const LibUtilities::EquationSharedPtr &pEqn, Array< OneD, NekDouble > &pArray)
 

Private Member Functions

 ForcingNoise (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 
 ~ForcingNoise (void) override
 

Private Attributes

int m_index
 
int m_updateFreq
 
int m_numSteps
 
NekDouble m_noise
 

Friends

class MemoryManager< ForcingNoise >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::SolverUtils::Forcing
virtual SOLVER_UTILS_EXPORT ~Forcing ()
 
SOLVER_UTILS_EXPORT void InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
 Initialise the forcing object. More...
 
SOLVER_UTILS_EXPORT void Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Apply the forcing. More...
 
SOLVER_UTILS_EXPORT void PreApply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Change the advection velocity before applying the forcing. For example, subtracting the frame velocity from the advection velocity in the MovingRefercenceFrame. More...
 
SOLVER_UTILS_EXPORT void ApplyCoeff (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Apply the forcing. More...
 
SOLVER_UTILS_EXPORT const Array< OneD, const Array< OneD, NekDouble > > & GetForces ()
 
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > & UpdateForces ()
 
- Protected Attributes inherited from Nektar::SolverUtils::Forcing
LibUtilities::SessionReaderSharedPtr m_session
 Session reader. More...
 
const std::weak_ptr< EquationSystemm_equ
 Weak pointer to equation system using this forcing. More...
 
Array< OneD, Array< OneD, NekDouble > > m_Forcing
 Evaluated forcing function. More...
 
int m_NumVariable
 Number of variables. More...
 
std::map< std::string, SolverUtils::SessionFunctionSharedPtrm_sessionFunctions
 Map of known SessionFunctions. More...
 

Detailed Description

Definition at line 48 of file ForcingNoise.h.

Constructor & Destructor Documentation

◆ ForcingNoise()

Nektar::SolverUtils::ForcingNoise::ForcingNoise ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::weak_ptr< EquationSystem > &  pEquation 
)
private

Definition at line 47 of file ForcingNoise.cpp.

49 : Forcing(pSession, pEquation)
50{
51}
SOLVER_UTILS_EXPORT Forcing(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
Constructor.
Definition: Forcing.cpp:48

◆ ~ForcingNoise()

Nektar::SolverUtils::ForcingNoise::~ForcingNoise ( void  )
inlineoverrideprivate

Definition at line 84 of file ForcingNoise.h.

84{};

Member Function Documentation

◆ create()

static SOLVER_UTILS_EXPORT ForcingSharedPtr Nektar::SolverUtils::ForcingNoise::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::weak_ptr< EquationSystem > &  pEquation,
const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)
inlinestatic

Creates an instance of this class.

Definition at line 54 of file ForcingNoise.h.

59 {
62 p->InitObject(pFields, pNumForcingFields, pForce);
63 return p;
64 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
SOLVER_UTILS_EXPORT typedef std::shared_ptr< Forcing > ForcingSharedPtr
A shared pointer to an EquationSystem object.
Definition: Forcing.h:53

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::SolverUtils::ForcingSharedPtr, and CellMLToNektar.cellml_metadata::p.

◆ v_Apply()

void Nektar::SolverUtils::ForcingNoise::v_Apply ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Forcing.

Definition at line 108 of file ForcingNoise.cpp.

113{
114 // Do not apply forcing if exceeded m_numSteps
115 if (m_numSteps && (m_index >= m_numSteps))
116 {
117 return;
118 }
119
120 // Update forcing (change seed to avoid getting same result)
121 if (m_updateFreq && m_index && !((m_index) % m_updateFreq))
122 {
123 for (int i = 0; i < m_NumVariable; ++i)
124 {
125 Vmath::FillWhiteNoise(outarray[i].size(), m_noise, m_Forcing[i], 1);
126 }
127 }
128
129 // Apply forcing
130 for (int i = 0; i < m_NumVariable; i++)
131 {
132 Vmath::Vadd(outarray[i].size(), outarray[i], 1, m_Forcing[i], 1,
133 outarray[i], 1);
134 }
135
136 ++m_index;
137}
int m_NumVariable
Number of variables.
Definition: Forcing.h:121
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:119
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.hpp:180
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
Definition: Vmath.cpp:154

References Vmath::FillWhiteNoise(), Nektar::SolverUtils::Forcing::m_Forcing, m_index, m_noise, m_numSteps, Nektar::SolverUtils::Forcing::m_NumVariable, m_updateFreq, and Vmath::Vadd().

◆ v_InitObject()

void Nektar::SolverUtils::ForcingNoise::v_InitObject ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Forcing.

Definition at line 53 of file ForcingNoise.cpp.

56{
57 m_NumVariable = pNumForcingFields;
58 int nq = pFields[0]->GetTotPoints();
59
60 const TiXmlElement *noiseElmt = pForce->FirstChildElement("WHITENOISE");
61 ASSERTL0(noiseElmt, "Requires WHITENOISE tag specifying "
62 "magnitude of white noise force.");
63
64 string noiseValue = noiseElmt->GetText();
65
66 m_noise = std::stod(noiseValue);
67
68 // Load optional parameters
69 const TiXmlElement *freqElmt = pForce->FirstChildElement("UPDATEFREQ");
70 if (freqElmt)
71 {
72 string freqValue = freqElmt->GetText();
73 m_updateFreq = boost::lexical_cast<int>(freqValue);
74 }
75 else
76 {
77 // Default is 0 (never update forcing)
78 m_updateFreq = 0;
79 }
80
81 const TiXmlElement *stepsElmt = pForce->FirstChildElement("NSTEPS");
82 if (stepsElmt)
83 {
84 string stepsValue = stepsElmt->GetText();
85 m_numSteps = boost::lexical_cast<int>(stepsValue);
86 }
87 else
88 {
89 // Default is 0 (use noise in the entire simulation)
90 m_numSteps = 0;
91 }
92
93 m_Forcing = Array<OneD, Array<OneD, NekDouble>>(m_NumVariable);
94
95 // Fill forcing: use rank in seed to avoid repeated results
96 int seed = -m_session->GetComm()->GetRank();
97 m_Forcing[0] = Array<OneD, NekDouble>(nq, 0.0);
98 Vmath::FillWhiteNoise(nq, m_noise, m_Forcing[0], 1, seed);
99 for (int i = 1; i < m_NumVariable; ++i)
100 {
101 m_Forcing[i] = Array<OneD, NekDouble>(nq, 0.0);
103 }
104
105 m_index = 0;
106}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:115

References ASSERTL0, Vmath::FillWhiteNoise(), Nektar::SolverUtils::Forcing::m_Forcing, m_index, m_noise, m_numSteps, Nektar::SolverUtils::Forcing::m_NumVariable, Nektar::SolverUtils::Forcing::m_session, and m_updateFreq.

Friends And Related Function Documentation

◆ MemoryManager< ForcingNoise >

friend class MemoryManager< ForcingNoise >
friend

Definition at line 1 of file ForcingNoise.h.

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::ForcingNoise::className
static
Initial value:
=
"White Noise Forcing")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static SOLVER_UTILS_EXPORT ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
Definition: ForcingNoise.h:54
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:42

Name of the class.

Definition at line 67 of file ForcingNoise.h.

◆ m_index

int Nektar::SolverUtils::ForcingNoise::m_index
private

Definition at line 86 of file ForcingNoise.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_noise

NekDouble Nektar::SolverUtils::ForcingNoise::m_noise
private

Definition at line 89 of file ForcingNoise.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_numSteps

int Nektar::SolverUtils::ForcingNoise::m_numSteps
private

Definition at line 88 of file ForcingNoise.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_updateFreq

int Nektar::SolverUtils::ForcingNoise::m_updateFreq
private

Definition at line 87 of file ForcingNoise.h.

Referenced by v_Apply(), and v_InitObject().