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

#include <ForcingAbsorption.h>

Inheritance diagram for Nektar::SolverUtils::ForcingAbsorption:
[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 Types

typedef bg::model::point< NekDouble, 3, bg::cs::cartesian > BPoint
 
typedef std::pair< BPoint, unsigned int > BPointPair
 
typedef bgi::rtree< BPointPair, bgi::rstar< 16 > > BRTree
 

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)
 
- Protected Member Functions inherited from Nektar::SolverUtils::Forcing
SOLVER_UTILS_EXPORT Forcing (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 Constructor. More...
 
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)
 

Protected Attributes

bool m_hasRefFlow
 
bool m_hasRefFlowTime
 
Array< OneD, Array< OneD, NekDouble > > m_Absorption
 
Array< OneD, Array< OneD, NekDouble > > m_Refflow
 
std::string m_funcNameTime
 
std::vector< unsigned int > m_bRegions
 
std::shared_ptr< BRTreem_rtree
 
- 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...
 

Private Member Functions

 ForcingAbsorption (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 
virtual ~ForcingAbsorption (void)
 
void CalcAbsorption (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pForce)
 

Friends

class MemoryManager< ForcingAbsorption >
 

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

Detailed Description

Definition at line 57 of file ForcingAbsorption.h.

Member Typedef Documentation

◆ BPoint

Definition at line 81 of file ForcingAbsorption.h.

◆ BPointPair

typedef std::pair<BPoint, unsigned int> Nektar::SolverUtils::ForcingAbsorption::BPointPair
protected

Definition at line 82 of file ForcingAbsorption.h.

◆ BRTree

typedef bgi::rtree<BPointPair, bgi::rstar<16> > Nektar::SolverUtils::ForcingAbsorption::BRTree
protected

Definition at line 83 of file ForcingAbsorption.h.

Constructor & Destructor Documentation

◆ ForcingAbsorption()

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

Definition at line 55 of file ForcingAbsorption.cpp.

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

◆ ~ForcingAbsorption()

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

Definition at line 108 of file ForcingAbsorption.h.

References CalcAbsorption().

108 {};

Member Function Documentation

◆ CalcAbsorption()

void Nektar::SolverUtils::ForcingAbsorption::CalcAbsorption ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const TiXmlElement *  pForce 
)
private

Definition at line 106 of file ForcingAbsorption.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::StdRegions::find(), Nektar::ParseUtils::GenerateVector(), Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions(), Nektar::SolverUtils::Forcing::GetFunction(), m_Absorption, m_bRegions, Nektar::SolverUtils::Forcing::m_NumVariable, m_rtree, and Nektar::SolverUtils::Forcing::m_session.

Referenced by v_InitObject(), and ~ForcingAbsorption().

110  {
111  const TiXmlElement *funcNameElmt = pForce->FirstChildElement("COEFF");
112  ASSERTL0(funcNameElmt,
113  "Requires COEFF tag, specifying function "
114  "name which prescribes absorption layer coefficient.");
115  string funcName = funcNameElmt->GetText();
116  ASSERTL0(m_session->DefinesFunction(funcName),
117  "Function '" + funcName + "' not defined.");
118 
119  int npts = pFields[0]->GetTotPoints();
120 
121  m_Absorption = Array<OneD, Array<OneD, NekDouble> >(m_NumVariable);
122  for (int i = 0; i < m_NumVariable; ++i)
123  {
124  m_Absorption[i] = Array<OneD, NekDouble>(npts, 0.0);
125  }
126 
127  funcNameElmt = pForce->FirstChildElement("BOUNDARYREGIONS");
128  if (funcNameElmt)
129  {
130  ASSERTL0(ParseUtils::GenerateVector(funcNameElmt->GetText(),
131  m_bRegions),
132  "Unable to process list of BOUNDARYREGIONS in Absorption "
133  "Forcing: " +
134  std::string(funcNameElmt->GetText()));
135 
136  // alter m_bRegions so that it contains the boundaryRegions of this rank
137  std::vector<unsigned int> localBRegions;
138  SpatialDomains::BoundaryConditions bcs(m_session, pFields[0]->GetGraph());
139  SpatialDomains::BoundaryRegionCollection regions = bcs.GetBoundaryRegions();
140  SpatialDomains::BoundaryRegionCollection::iterator it1;
141  int n = 0;
142  for (it1 = regions.begin(); it1 != regions.end(); ++it1)
143  {
144  if (std::find(m_bRegions.begin(), m_bRegions.end(), it1->first) != m_bRegions.end())
145  {
146  localBRegions.push_back(n);
147  }
148  n++;
149  }
150  m_bRegions = localBRegions;
151 
152  if (m_bRegions.size() == 0)
153  {
154  return;
155  }
156 
157  std::vector<Array<OneD, const NekDouble> > points;
158 
159  Array<OneD, Array<OneD, NekDouble> > x(3);
160  for (int i = 0; i < 3; i++)
161  {
162  x[i] = Array<OneD, NekDouble>(npts, 0.0);
163  }
164  pFields[0]->GetCoords(x[0], x[1], x[2]);
165  for (int i = 0; i < 3; i++)
166  {
167  points.push_back(x[i]);
168  }
169 
170  Array<OneD, NekDouble> t(npts, 0.0);
171  points.push_back(t);
172 
173  Array<OneD, NekDouble> r(npts, 0.0);
174  std::vector<unsigned int>::iterator it;
175  std::vector<BPointPair> inPoints;
176  Array<OneD, Array<OneD, NekDouble> > b(3);
177  for (it = m_bRegions.begin(); it != m_bRegions.end(); ++it)
178  {
179  int bpts = pFields[0]->GetBndCondExpansions()[*it]->GetNpoints();
180  for (int i = 0; i < 3; i++)
181  {
182  b[i] = Array<OneD, NekDouble>(bpts, 0.0);
183  }
184  pFields[0]->GetBndCondExpansions()[*it]->GetCoords(
185  b[0], b[1], b[2]);
186  for (int i = 0;
187  i < pFields[0]->GetBndCondExpansions()[*it]->GetNpoints();
188  ++i)
189  {
190  inPoints.push_back(
191  BPointPair(BPoint(b[0][i], b[1][i], b[2][i]), i));
192  }
193  }
195  m_rtree->insert(inPoints.begin(), inPoints.end());
196 
197  for (int i = 0; i < npts; ++i)
198  {
199  std::vector<BPointPair> result;
200  BPoint sPoint(x[0][i], x[1][i], x[2][i]);
201  m_rtree->query(bgi::nearest(sPoint, 1), std::back_inserter(result));
202  r[i] = bg::distance(sPoint, result[0].first);
203  }
204  points.push_back(r);
205 
206  std::string s_FieldStr;
207  for (int i = 0; i < m_NumVariable; ++i)
208  {
209  s_FieldStr = m_session->GetVariable(i);
210  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
211  "Variable '" + s_FieldStr + "' not defined.");
212 
214  m_session->GetFunction(funcName, s_FieldStr);
215  ASSERTL0(ffunc->GetVlist() == "x y z t r",
216  "EVARS of " + funcName + " must be 'r'");
217 
218  ffunc->Evaluate(points, m_Absorption[i]);
219  }
220  }
221  else
222  {
223  for (int i = 0; i < m_NumVariable; ++i)
224  {
225  std::string s_FieldStr = m_session->GetVariable(i);
226  GetFunction(pFields, m_session, funcName)->Evaluate(s_FieldStr, m_Absorption[i]);
227  }
228  }
229  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
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:159
bg::model::point< NekDouble, 3, bg::cs::cartesian > BPoint
Array< OneD, Array< OneD, NekDouble > > m_Absorption
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135
std::vector< unsigned int > m_bRegions
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:103
std::pair< BPoint, unsigned int > BPointPair
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:131
int m_NumVariable
Number of variables.
Definition: Forcing.h:109
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358

◆ create()

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

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

69  {
71  AllocateSharedPtr(pSession, pEquation);
72  p->InitObject(pFields, pNumForcingFields, pForce);
73  return p;
74  }
SOLVER_UTILS_EXPORT typedef std::shared_ptr< Forcing > ForcingSharedPtr
A shared pointer to an EquationSystem object.
Definition: Forcing.h:52
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ v_Apply()

void Nektar::SolverUtils::ForcingAbsorption::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 231 of file ForcingAbsorption.cpp.

References Nektar::SolverUtils::Forcing::EvaluateTimeFunction(), m_Absorption, Nektar::SolverUtils::Forcing::m_Forcing, m_funcNameTime, m_hasRefFlow, m_hasRefFlowTime, Nektar::SolverUtils::Forcing::m_NumVariable, m_Refflow, Nektar::SolverUtils::Forcing::m_session, Vmath::Smul(), Vmath::Vadd(), Vmath::Vcopy(), Vmath::Vmul(), and Vmath::Vsub().

236  {
237  boost::ignore_unused(fields);
238 
239  int nq = m_Forcing[0].num_elements();
240 
241  std::string s_FieldStr;
242  Array<OneD, NekDouble> TimeScale(1);
243  Array<OneD, Array<OneD, NekDouble> > RefflowScaled(m_NumVariable);
244 
245  if (m_hasRefFlow)
246  {
247  for (int i = 0; i < m_NumVariable; i++)
248  {
249  RefflowScaled[i] = Array<OneD, NekDouble> (nq);
250  if (m_hasRefFlowTime)
251  {
252  s_FieldStr = m_session->GetVariable(i);
253  EvaluateTimeFunction(m_session, s_FieldStr, TimeScale, m_funcNameTime, time);
254  Vmath::Smul(nq, TimeScale[0], m_Refflow[i],1,RefflowScaled[i],1);
255  }
256  else
257  {
258  Vmath::Vcopy(nq, m_Refflow[i],1, RefflowScaled[i],1);
259  }
260 
261 
262  Vmath::Vsub(nq, inarray[i], 1,
263  RefflowScaled[i], 1, m_Forcing[i], 1);
264  Vmath::Vmul(nq, m_Absorption[i], 1,
265  m_Forcing[i], 1, m_Forcing[i], 1);
266  Vmath::Vadd(nq, m_Forcing[i], 1,
267  outarray[i], 1, outarray[i], 1);
268  }
269  }
270  else
271  {
272  for (int i = 0; i < m_NumVariable; i++)
273  {
274  Vmath::Vmul(nq, m_Absorption[i], 1,
275  inarray[i], 1, m_Forcing[i], 1);
276  Vmath::Vadd(nq, m_Forcing[i], 1,
277  outarray[i], 1, outarray[i], 1);
278  }
279  }
280  }
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
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:107
Array< OneD, Array< OneD, NekDouble > > m_Absorption
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:216
Array< OneD, Array< OneD, NekDouble > > m_Refflow
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:103
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:346
int m_NumVariable
Number of variables.
Definition: Forcing.h:109
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
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:302
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:186

◆ v_InitObject()

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

Implements Nektar::SolverUtils::Forcing.

Definition at line 64 of file ForcingAbsorption.cpp.

References ASSERTL0, CalcAbsorption(), Nektar::SolverUtils::Forcing::GetFunction(), Nektar::SolverUtils::Forcing::m_Forcing, m_funcNameTime, m_hasRefFlow, m_hasRefFlowTime, Nektar::SolverUtils::Forcing::m_NumVariable, m_Refflow, and Nektar::SolverUtils::Forcing::m_session.

68  {
69  m_NumVariable = pNumForcingFields;
70  int npts = pFields[0]->GetTotPoints();
71 
72  CalcAbsorption(pFields, pForce);
73 
74  m_Forcing = Array<OneD, Array<OneD, NekDouble> >(m_NumVariable);
75  for (int i = 0; i < m_NumVariable; ++i)
76  {
77  m_Forcing[i] = Array<OneD, NekDouble>(npts, 0.0);
78  }
79 
80  const TiXmlElement* funcNameElmt = pForce->FirstChildElement("REFFLOW");
81  if (funcNameElmt)
82  {
83  string funcName = funcNameElmt->GetText();
84  ASSERTL0(m_session->DefinesFunction(funcName),
85  "Function '" + funcName + "' not defined.");
86  m_Refflow = Array<OneD, Array<OneD, NekDouble> > (m_NumVariable);
87  for (int i = 0; i < m_NumVariable; ++i)
88  {
89  std::string s_FieldStr = m_session->GetVariable(i);
90  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
91  "Variable '" + s_FieldStr + "' not defined.");
92  m_Refflow[i] = Array<OneD, NekDouble> (npts, 0.0);
93  GetFunction(pFields, m_session, funcName)->Evaluate(s_FieldStr, m_Refflow[i]);
94  }
95  m_hasRefFlow = true;
96  }
97 
98  funcNameElmt = pForce->FirstChildElement("REFFLOWTIME");
99  if (funcNameElmt)
100  {
101  m_funcNameTime = funcNameElmt->GetText();
102  m_hasRefFlowTime = true;
103  }
104  }
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:107
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void CalcAbsorption(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const TiXmlElement *pForce)
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:159
Array< OneD, Array< OneD, NekDouble > > m_Refflow
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:103
int m_NumVariable
Number of variables.
Definition: Forcing.h:109

Friends And Related Function Documentation

◆ MemoryManager< ForcingAbsorption >

friend class MemoryManager< ForcingAbsorption >
friend

Definition at line 60 of file ForcingAbsorption.h.

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::ForcingAbsorption::className
static
Initial value:
RegisterCreatorFunction("Absorption",
"Forcing Absorption")

Name of the class.

Definition at line 77 of file ForcingAbsorption.h.

◆ m_Absorption

Array<OneD, Array<OneD, NekDouble> > Nektar::SolverUtils::ForcingAbsorption::m_Absorption
protected

Definition at line 87 of file ForcingAbsorption.h.

Referenced by CalcAbsorption(), and v_Apply().

◆ m_bRegions

std::vector<unsigned int> Nektar::SolverUtils::ForcingAbsorption::m_bRegions
protected

Definition at line 90 of file ForcingAbsorption.h.

Referenced by CalcAbsorption().

◆ m_funcNameTime

std::string Nektar::SolverUtils::ForcingAbsorption::m_funcNameTime
protected

Definition at line 89 of file ForcingAbsorption.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_hasRefFlow

bool Nektar::SolverUtils::ForcingAbsorption::m_hasRefFlow
protected

Definition at line 85 of file ForcingAbsorption.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_hasRefFlowTime

bool Nektar::SolverUtils::ForcingAbsorption::m_hasRefFlowTime
protected

Definition at line 86 of file ForcingAbsorption.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_Refflow

Array<OneD, Array<OneD, NekDouble> > Nektar::SolverUtils::ForcingAbsorption::m_Refflow
protected

Definition at line 88 of file ForcingAbsorption.h.

Referenced by v_Apply(), and v_InitObject().

◆ m_rtree

std::shared_ptr<BRTree> Nektar::SolverUtils::ForcingAbsorption::m_rtree
protected

Definition at line 91 of file ForcingAbsorption.h.

Referenced by CalcAbsorption().