Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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...
 

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 51 of file Forcing.cpp.

52  : m_session(pSession)
53  {
54 
55  }
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:95

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 71 of file Forcing.cpp.

References v_Apply().

76  {
77  v_Apply(fields, inarray, outarray, time);
78  }
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 149 of file Forcing.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::eFunctionTypeExpression, Nektar::LibUtilities::eFunctionTypeFile, m_session, and Vmath::Zero().

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

156  {
157  ASSERTL0(pSession->DefinesFunction(pFunctionName),
158  "Function '" + pFunctionName + "' does not exist.");
159 
160  unsigned int nq = pFields[0]->GetNpoints();
161  if (pArray.num_elements() != nq)
162  {
163  pArray = Array<OneD, NekDouble> (nq);
164  }
165 
167  vType = pSession->GetFunctionType(pFunctionName, pFieldName);
169  {
170  Array<OneD, NekDouble> x0(nq);
171  Array<OneD, NekDouble> x1(nq);
172  Array<OneD, NekDouble> x2(nq);
173 
174  pFields[0]->GetCoords(x0, x1, x2);
176  pSession->GetFunction(pFunctionName, pFieldName);
177 
178  ffunc->Evaluate(x0, x1, x2, pTime, pArray);
179  }
180  else if (vType == LibUtilities::eFunctionTypeFile)
181  {
182  std::string filename = pSession->GetFunctionFilename(
183  pFunctionName,
184  pFieldName);
185 
186  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
187  std::vector<std::vector<NekDouble> > FieldData;
188  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
189  Vmath::Zero(vCoeffs.num_elements(), vCoeffs, 1);
190 
193  fld->Import(filename, FieldDef, FieldData);
194 
195  int idx = -1;
196  for (int i = 0; i < FieldDef.size(); ++i)
197  {
198  for (int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
199  {
200  if (FieldDef[i]->m_fields[j] == pFieldName)
201  {
202  idx = j;
203  }
204  }
205 
206  if (idx >= 0)
207  {
208  pFields[0]->ExtractDataToCoeffs(
209  FieldDef[i],
210  FieldData[i],
211  FieldDef[i]->m_fields[idx],
212  vCoeffs);
213  }
214  else
215  {
216  cout << "Field " + pFieldName + " not found." << endl;
217  }
218  }
219  pFields[0]->BwdTrans_IterPerExp(vCoeffs, pArray);
220  }
221  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:225
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:95
boost::shared_ptr< Equation > EquationSharedPtr
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:359
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 119 of file Forcing.cpp.

References ASSERTL0.

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

125  {
126  ASSERTL0(pSession->DefinesFunction(pFunctionName),
127  "Function '" + pFunctionName + "' does not exist.");
128 
130  pSession->GetFunction(pFunctionName, pFieldName);
131 
132  EvaluateTimeFunction(pTime,ffunc,pArray);
133  }
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:119
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
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 136 of file Forcing.cpp.

140  {
141  // dummy array of zero pts.
142  Array<OneD, NekDouble> x0(pArray.num_elements(),0.0);
143 
144  pEqn->Evaluate(x0, x0, x0, pTime, pArray);
145  }
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 57 of file Forcing.cpp.

References v_InitObject().

61  {
62  v_InitObject(pFields, pNumForcingFields, pForce);
63  }
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 84 of file Forcing.cpp.

References Nektar::SolverUtils::GetForcingFactory().

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

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