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

#include <ForcingBody.h>

Inheritance diagram for Nektar::SolverUtils::ForcingBody:
[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 classNameBody
 Name of the class. More...
 
static std::string classNameField
 

Protected Member Functions

virtual SOLVER_UTILS_EXPORT void v_InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
 
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)
 
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)
 
- 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_PreApply (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

 ForcingBody (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 
virtual ~ForcingBody (void)
 
void Update (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, Array< OneD, NekDouble > > &inarray, const NekDouble &time)
 

Private Attributes

std::string m_funcName
 
bool m_hasTimeFcnScaling
 
LibUtilities::EquationSharedPtr m_timeFcnEqn
 
bool m_transform
 

Friends

class MemoryManager< ForcingBody >
 

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 51 of file ForcingBody.h.

Constructor & Destructor Documentation

◆ ForcingBody()

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

Definition at line 54 of file ForcingBody.cpp.

57  : Forcing(pSession, pEquation),
58  m_hasTimeFcnScaling(false)
59  {
60  }
SOLVER_UTILS_EXPORT Forcing(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
Constructor.
Definition: Forcing.cpp:50

◆ ~ForcingBody()

virtual Nektar::SolverUtils::ForcingBody::~ForcingBody ( void  )
inlineprivatevirtual

Definition at line 102 of file ForcingBody.h.

102 {};

Member Function Documentation

◆ create()

static SOLVER_UTILS_EXPORT ForcingSharedPtr Nektar::SolverUtils::ForcingBody::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 58 of file ForcingBody.h.

64  {
66  AllocateSharedPtr(pSession, pEquation);
67  p->InitObject(pFields, pNumForcingFields, pForce);
68  return p;
69  }
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:52

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

◆ Update()

void Nektar::SolverUtils::ForcingBody::Update ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
const NekDouble time 
)
private

Definition at line 128 of file ForcingBody.cpp.

132  {
133  for (int i = 0; i < m_NumVariable; ++i)
134  {
136  GetFunctionType(m_funcName, m_session->GetVariable(i)))
137  {
139  GetFunction(m_funcName, m_session->GetVariable(i));
140  if (!boost::iequals(eqn->GetVlist(), "x y z t"))
141  {
142  // Coupled forcing
143  int nq = pFields[0]->GetNpoints();
144  Array<OneD, NekDouble> xc(nq), yc(nq), zc(nq), t(nq, time);
145  std::string varstr = "x y z";
146  std::vector<Array<OneD, const NekDouble>> fielddata = {
147  xc, yc, zc, t};
148 
149  for (int j = 0; j < m_NumVariable; ++j)
150  {
151  varstr += " " + m_session->GetVariable(j);
152  fielddata.push_back(inarray[j]);
153  }
154 
155  // Evaluate function
156  m_session->GetFunction(m_funcName, m_session->GetVariable(i))->
157  Evaluate(fielddata, m_Forcing[i]);
158  continue;
159  }
160  }
161  std::string s_FieldStr = m_session->GetVariable(i);
162  ASSERTL0(m_session->DefinesFunction(m_funcName, s_FieldStr),
163  "Variable '" + s_FieldStr + "' not defined.");
164  GetFunction(pFields, m_session, m_funcName, true)->Evaluate(
165  s_FieldStr, m_Forcing[i], time);
166  }
167 
168  // If singleMode or halfMode, transform the forcing term to be in
169  // physical space in the plane, but Fourier space in the homogeneous
170  // direction
171  if (m_transform)
172  {
173  for (int i = 0; i < m_NumVariable; ++i)
174  {
175  pFields[0]->HomogeneousFwdTrans(m_Forcing[i], m_Forcing[i]);
176  }
177  }
178  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
int m_NumVariable
Number of variables.
Definition: Forcing.h:124
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:122
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.
Definition: Forcing.cpp:202
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:118
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:131

References ASSERTL0, Nektar::LibUtilities::eFunctionTypeExpression, Nektar::SolverUtils::Forcing::GetFunction(), Nektar::SolverUtils::Forcing::m_Forcing, m_funcName, Nektar::SolverUtils::Forcing::m_NumVariable, Nektar::SolverUtils::Forcing::m_session, and m_transform.

Referenced by v_Apply(), v_ApplyCoeff(), and v_InitObject().

◆ v_Apply()

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

Implements Nektar::SolverUtils::Forcing.

Definition at line 181 of file ForcingBody.cpp.

186  {
188  {
189  Array<OneD, NekDouble> TimeFcn(1);
190 
191  for (int i = 0; i < m_NumVariable; i++)
192  {
193  EvaluateTimeFunction(time, m_timeFcnEqn, TimeFcn);
194 
195  Vmath::Svtvp(outarray[i].size(), TimeFcn[0],
196  m_Forcing[i], 1,
197  outarray[i], 1,
198  outarray[i], 1);
199  }
200  }
201  else
202  {
203  Update(fields, inarray, time);
204 
205  for (int i = 0; i < m_NumVariable; i++)
206  {
207  Vmath::Vadd(outarray[i].size(), outarray[i], 1,
208  m_Forcing[i], 1, outarray[i], 1);
209  }
210  }
211  }
void Update(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, Array< OneD, NekDouble > > &inarray, const NekDouble &time)
LibUtilities::EquationSharedPtr m_timeFcnEqn
Definition: ForcingBody.h:95
SOLVER_UTILS_EXPORT void EvaluateTimeFunction(LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName, Array< OneD, NekDouble > &pArray, const std::string &pFunctionName, NekDouble pTime=NekDouble(0))
Definition: Forcing.cpp:174
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:565
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.cpp:322

References Nektar::SolverUtils::Forcing::EvaluateTimeFunction(), Nektar::SolverUtils::Forcing::m_Forcing, m_hasTimeFcnScaling, Nektar::SolverUtils::Forcing::m_NumVariable, m_timeFcnEqn, Vmath::Svtvp(), Update(), and Vmath::Vadd().

◆ v_ApplyCoeff()

void Nektar::SolverUtils::ForcingBody::v_ApplyCoeff ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble time 
)
protectedvirtual

Reimplemented from Nektar::SolverUtils::Forcing.

Definition at line 213 of file ForcingBody.cpp.

218  {
219  int ncoeff = outarray[m_NumVariable - 1].size();
220  Array<OneD, NekDouble> tmp(ncoeff, 0.0);
221 
223  {
224  Array<OneD, NekDouble> TimeFcn(1);
225 
226  for (int i = 0; i < m_NumVariable; ++i)
227  {
228  EvaluateTimeFunction(time, m_timeFcnEqn, TimeFcn);
229 
230  fields[i]->FwdTrans(m_Forcing[i], tmp);
231 
232  Vmath::Svtvp(ncoeff, TimeFcn[0],
233  tmp, 1,
234  outarray[i], 1,
235  outarray[i], 1);
236  }
237  }
238  else
239  {
240  Update(fields, inarray, time);
241 
242  for (int i = 0; i < m_NumVariable; ++i)
243  {
244  fields[i]->FwdTrans(m_Forcing[i], tmp);
245 
246  Vmath::Vadd(ncoeff, outarray[i], 1,
247  tmp, 1, outarray[i], 1);
248  }
249  }
250  }

References Nektar::SolverUtils::Forcing::EvaluateTimeFunction(), Nektar::SolverUtils::Forcing::m_Forcing, m_hasTimeFcnScaling, Nektar::SolverUtils::Forcing::m_NumVariable, m_timeFcnEqn, Vmath::Svtvp(), Update(), and Vmath::Vadd().

◆ v_InitObject()

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

Implements Nektar::SolverUtils::Forcing.

Definition at line 62 of file ForcingBody.cpp.

66  {
67  m_NumVariable = pNumForcingFields;
68 
69  const TiXmlElement* funcNameElmt = pForce->FirstChildElement("BODYFORCE");
70  if(!funcNameElmt)
71  {
72  funcNameElmt = pForce->FirstChildElement("FIELDFORCE");
73 
74  ASSERTL0(funcNameElmt, "Requires BODYFORCE or FIELDFORCE tag "
75  "specifying function name which prescribes body force.");
76  }
77 
78  m_funcName = funcNameElmt->GetText();
79  ASSERTL0(m_session->DefinesFunction(m_funcName),
80  "Function '" + m_funcName + "' not defined.");
81 
82  bool singleMode, halfMode;
83  m_session->MatchSolverInfo("ModeType","SingleMode",singleMode,false);
84  m_session->MatchSolverInfo("ModeType","HalfMode", halfMode, false);
85  bool homogeneous = pFields[0]->GetExpType() == MultiRegions::e3DH1D ||
86  pFields[0]->GetExpType() == MultiRegions::e3DH2D;
87  m_transform = (singleMode || halfMode || homogeneous);
88 
89  // Time function is optional
90  funcNameElmt = pForce->FirstChildElement("BODYFORCETIMEFCN");
91  if(!funcNameElmt)
92  {
93  funcNameElmt = pForce->FirstChildElement("FIELDFORCETIMEFCN");
94  }
95 
96  // Load time function if specified
97  if(funcNameElmt)
98  {
99  std::string funcNameTime = funcNameElmt->GetText();
100 
101  ASSERTL0(!funcNameTime.empty(),
102  "Expression must be given in BODYFORCETIMEFCN or "
103  "FIELDFORCETIMEFCN.");
104 
105  m_session->SubstituteExpressions(funcNameTime);
107  ::AllocateSharedPtr(m_session->GetInterpreter(),funcNameTime);
108 
109  m_hasTimeFcnScaling = true;
110  }
111 
112  m_Forcing = Array<OneD, Array<OneD, NekDouble> > (m_NumVariable);
113  for (int i = 0; i < m_NumVariable; ++i)
114  {
115  m_Forcing[i] = Array<OneD, NekDouble> (pFields[0]->GetTotPoints(), 0.0);
116  }
117 
118  Array<OneD, Array<OneD, NekDouble> > tmp(pFields.size());
119  for (int i = 0; i < m_NumVariable; ++i)
120  {
121  tmp[i] = pFields[i]->GetPhys();
122  }
123 
124  Update(pFields, tmp, 0.0);
125  }

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::MultiRegions::e3DH1D, Nektar::MultiRegions::e3DH2D, Nektar::SolverUtils::Forcing::m_Forcing, m_funcName, m_hasTimeFcnScaling, Nektar::SolverUtils::Forcing::m_NumVariable, Nektar::SolverUtils::Forcing::m_session, m_timeFcnEqn, m_transform, and Update().

Friends And Related Function Documentation

◆ MemoryManager< ForcingBody >

friend class MemoryManager< ForcingBody >
friend

Definition at line 1 of file ForcingBody.h.

Member Data Documentation

◆ classNameBody

std::string Nektar::SolverUtils::ForcingBody::classNameBody
static
Initial value:
RegisterCreatorFunction("Body",
"Body Forcing")
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: ForcingBody.h:58
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44

Name of the class.

Definition at line 72 of file ForcingBody.h.

◆ classNameField

std::string Nektar::SolverUtils::ForcingBody::classNameField
static
Initial value:
RegisterCreatorFunction("Field",
"Field Forcing")

Definition at line 73 of file ForcingBody.h.

◆ m_funcName

std::string Nektar::SolverUtils::ForcingBody::m_funcName
private

Definition at line 93 of file ForcingBody.h.

Referenced by Update(), and v_InitObject().

◆ m_hasTimeFcnScaling

bool Nektar::SolverUtils::ForcingBody::m_hasTimeFcnScaling
private

Definition at line 94 of file ForcingBody.h.

Referenced by v_Apply(), v_ApplyCoeff(), and v_InitObject().

◆ m_timeFcnEqn

LibUtilities::EquationSharedPtr Nektar::SolverUtils::ForcingBody::m_timeFcnEqn
private

Definition at line 95 of file ForcingBody.h.

Referenced by v_Apply(), v_ApplyCoeff(), and v_InitObject().

◆ m_transform

bool Nektar::SolverUtils::ForcingBody::m_transform
private

Definition at line 96 of file ForcingBody.h.

Referenced by Update(), and v_InitObject().