Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::SolverUtils::Forcing Class Referenceabstract

Defines a forcing term to be explicitly applied. More...

#include <Forcing.h>

Inheritance diagram for Nektar::SolverUtils::Forcing:
Inheritance graph
[legend]
Collaboration diagram for Nektar::SolverUtils::Forcing:
Collaboration graph
[legend]

Public Member Functions

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 const
Array< OneD, const Array< OneD,
NekDouble > > & 
GetForces ()
 
SOLVER_UTILS_EXPORT Array
< OneD, Array< OneD, NekDouble > > & 
UpdateForces ()
 

Static Public Member Functions

static SOLVER_UTILS_EXPORT
std::vector< ForcingSharedPtr
Load (const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
 

Protected Member Functions

SOLVER_UTILS_EXPORT Forcing (const LibUtilities::SessionReaderSharedPtr &)
 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
 
SOLVER_UTILS_EXPORT void EvaluateFunction (Array< OneD, MultiRegions::ExpListSharedPtr > pFields, LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName, Array< OneD, NekDouble > &pArray, const std::string &pFunctionName, NekDouble pTime=NekDouble(0))
 
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)
 

Protected Attributes

LibUtilities::SessionReaderSharedPtr m_session
 Session reader. More...
 
Array< OneD, Array< OneD,
NekDouble > > 
m_Forcing
 Evaluated forcing function. More...
 
int m_NumVariable
 Number of variables. More...
 

Detailed Description

Defines a forcing term to be explicitly applied.

Definition at line 70 of file Forcing.h.

Constructor & Destructor Documentation

virtual SOLVER_UTILS_EXPORT Nektar::SolverUtils::Forcing::~Forcing ( )
inlinevirtual

Definition at line 73 of file Forcing.h.

73 {}
Nektar::SolverUtils::Forcing::Forcing ( const LibUtilities::SessionReaderSharedPtr pSession)
protected

Constructor.

Definition at line 53 of file Forcing.cpp.

54  : m_session(pSession)
55  {
56 
57  }
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:100

Member Function Documentation

void Nektar::SolverUtils::Forcing::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.

Parameters
fieldsExpansion lists corresponding to input arrays
inarrayu^n from previous timestep
outarrayoutput array to append forcing to

Definition at line 73 of file Forcing.cpp.

References v_Apply().

78  {
79  v_Apply(fields, inarray, outarray, time);
80  }
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
void Nektar::SolverUtils::Forcing::EvaluateFunction ( Array< OneD, MultiRegions::ExpListSharedPtr pFields,
LibUtilities::SessionReaderSharedPtr  pSession,
std::string  pFieldName,
Array< OneD, NekDouble > &  pArray,
const std::string &  pFunctionName,
NekDouble  pTime = NekDouble(0) 
)
protected

Definition at line 161 of file Forcing.cpp.

References ASSERTL0, Nektar::LibUtilities::FieldIO::CreateForFile(), Nektar::LibUtilities::eFunctionTypeExpression, Nektar::LibUtilities::eFunctionTypeFile, m_session, and Vmath::Zero().

Referenced by Nektar::SolverUtils::ForcingBody::Update(), Nektar::ForcingMovingBody::v_Apply(), and Nektar::SolverUtils::ForcingAbsorption::v_InitObject().

168  {
169  ASSERTL0(pSession->DefinesFunction(pFunctionName),
170  "Function '" + pFunctionName + "' does not exist.");
171 
172  unsigned int nq = pFields[0]->GetNpoints();
173  if (pArray.num_elements() != nq)
174  {
175  pArray = Array<OneD, NekDouble> (nq);
176  }
177 
179  vType = pSession->GetFunctionType(pFunctionName, pFieldName);
181  {
182  Array<OneD, NekDouble> x0(nq);
183  Array<OneD, NekDouble> x1(nq);
184  Array<OneD, NekDouble> x2(nq);
185 
186  pFields[0]->GetCoords(x0, x1, x2);
188  pSession->GetFunction(pFunctionName, pFieldName);
189 
190  ffunc->Evaluate(x0, x1, x2, pTime, pArray);
191  }
192  else if (vType == LibUtilities::eFunctionTypeFile)
193  {
194  std::string filename = pSession->GetFunctionFilename(
195  pFunctionName,
196  pFieldName);
197 
198  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
199  std::vector<std::vector<NekDouble> > FieldData;
200  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
201  Vmath::Zero(vCoeffs.num_elements(), vCoeffs, 1);
202 
205  fld->Import(filename, FieldDef, FieldData);
206 
207  int idx = -1;
208  for (int i = 0; i < FieldDef.size(); ++i)
209  {
210  for (int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
211  {
212  if (FieldDef[i]->m_fields[j] == pFieldName)
213  {
214  idx = j;
215  }
216  }
217 
218  if (idx >= 0)
219  {
220  pFields[0]->ExtractDataToCoeffs(
221  FieldDef[i],
222  FieldData[i],
223  FieldDef[i]->m_fields[idx],
224  vCoeffs);
225  }
226  else
227  {
228  cout << "Field " + pFieldName + " not found." << endl;
229  }
230  }
231  pFields[0]->BwdTrans_IterPerExp(vCoeffs, pArray);
232  }
233  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:309
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:100
boost::shared_ptr< Equation > EquationSharedPtr
static boost::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
Definition: FieldIO.cpp:212
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:373
void Nektar::SolverUtils::Forcing::EvaluateTimeFunction ( LibUtilities::SessionReaderSharedPtr  pSession,
std::string  pFieldName,
Array< OneD, NekDouble > &  pArray,
const std::string &  pFunctionName,
NekDouble  pTime = NekDouble(0) 
)
protected

Definition at line 131 of file Forcing.cpp.

References ASSERTL0.

Referenced by Nektar::SolverUtils::ForcingBody::v_Apply(), and Nektar::SolverUtils::ForcingAbsorption::v_Apply().

137  {
138  ASSERTL0(pSession->DefinesFunction(pFunctionName),
139  "Function '" + pFunctionName + "' does not exist.");
140 
142  pSession->GetFunction(pFunctionName, pFieldName);
143 
144  EvaluateTimeFunction(pTime,ffunc,pArray);
145  }
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:131
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
boost::shared_ptr< Equation > EquationSharedPtr
void Nektar::SolverUtils::Forcing::EvaluateTimeFunction ( const NekDouble  pTime,
const LibUtilities::EquationSharedPtr pEqn,
Array< OneD, NekDouble > &  pArray 
)
protected

Definition at line 148 of file Forcing.cpp.

152  {
153  // dummy array of zero pts.
154  Array<OneD, NekDouble> x0(pArray.num_elements(),0.0);
155 
156  pEqn->Evaluate(x0, x0, x0, pTime, pArray);
157  }
const Nektar::Array< OneD, const Array< OneD, NekDouble > > & Nektar::SolverUtils::Forcing::GetForces ( )

Definition at line 126 of file Forcing.cpp.

References m_Forcing.

127  {
128  return m_Forcing;
129  }
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:102
void Nektar::SolverUtils::Forcing::InitObject ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)

Initialise the forcing object.

Definition at line 59 of file Forcing.cpp.

References v_InitObject().

63  {
64  v_InitObject(pFields, pNumForcingFields, pForce);
65  }
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)=0
vector< ForcingSharedPtr > Nektar::SolverUtils::Forcing::Load ( const LibUtilities::SessionReaderSharedPtr pSession,
const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields = 0 
)
static

Definition at line 86 of file Forcing.cpp.

References Nektar::SolverUtils::GetForcingFactory().

Referenced by Nektar::APE::v_InitObject(), Nektar::CompressibleFlowSystem::v_InitObject(), Nektar::UnsteadyViscousBurgers::v_InitObject(), and Nektar::IncNavierStokes::v_InitObject().

90  {
91  vector<ForcingSharedPtr> vForceList;
92 
93  if (!pSession->DefinesElement("Nektar/Forcing"))
94  {
95  return vForceList;
96  }
97 
98  TiXmlElement* vForcing = pSession->GetElement("Nektar/Forcing");
99  if (vForcing)
100  {
101  unsigned int vNumForcingFields = pNumForcingFields;
102  if (!pNumForcingFields)
103  {
104  vNumForcingFields = pFields.num_elements();
105  }
106 
107  TiXmlElement* vForce = vForcing->FirstChildElement("FORCE");
108  while (vForce)
109  {
110  string vType = vForce->Attribute("TYPE");
111 
112  vForceList.push_back(GetForcingFactory().CreateInstance(
113  vType, pSession, pFields,
114  vNumForcingFields, vForce));
115  vForce = vForce->NextSiblingElement("FORCE");
116  }
117  }
118  return vForceList;
119  }
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44
Nektar::Array< OneD, Array< OneD, NekDouble > > & Nektar::SolverUtils::Forcing::UpdateForces ( )

Definition at line 121 of file Forcing.cpp.

References m_Forcing.

122  {
123  return m_Forcing;
124  }
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:102
virtual SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Forcing::v_Apply ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble time 
)
protectedpure virtual
virtual SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Forcing::v_InitObject ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)
protectedpure virtual

Member Data Documentation

Array<OneD, Array<OneD, NekDouble> > Nektar::SolverUtils::Forcing::m_Forcing
protected
int Nektar::SolverUtils::Forcing::m_NumVariable
protected
LibUtilities::SessionReaderSharedPtr Nektar::SolverUtils::Forcing::m_session
protected