Nektar++
Forcing.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Forcing.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Abstract base class for forcing terms.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42  namespace SolverUtils
43  {
45  {
46  static ForcingFactory instance;
47  return instance;
48  }
49 
50  Forcing::Forcing(
52  const std::weak_ptr<EquationSystem> &pEquation)
53  : m_session(pSession), m_equ(pEquation)
54  {
55 
56  }
57 
60  const unsigned int& pNumForcingFields,
61  const TiXmlElement* pForce)
62  {
63  v_InitObject(pFields, pNumForcingFields, pForce);
64  }
65 
66 
67  /**
68  * @param fields Expansion lists corresponding to input arrays
69  * @param inarray u^n from previous timestep
70  * @param outarray output array to append forcing to
71  */
74  const Array<OneD, Array<OneD, NekDouble> >& inarray,
75  Array<OneD, Array<OneD, NekDouble> >& outarray,
76  const NekDouble& time)
77  {
78  v_Apply(fields, inarray, outarray, time);
79  }
80 
81 
82  /**
83  *
84  */
85  vector<ForcingSharedPtr> Forcing::Load(
87  const std::weak_ptr<EquationSystem> &pEquation,
89  const unsigned int& pNumForcingFields)
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, pEquation, pFields,
114  vNumForcingFields, vForce));
115  vForce = vForce->NextSiblingElement("FORCE");
116  }
117  }
118  return vForceList;
119  }
120 
122  {
123  return m_Forcing;
124  }
125 
127  {
128  return m_Forcing;
129  }
130 
133  std::string pFieldName,
134  Array<OneD, NekDouble>& pArray,
135  const std::string& pFunctionName,
136  NekDouble pTime)
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  }
146 
147 
149  const NekDouble pTime,
151  Array<OneD, NekDouble>& pArray)
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  }
158 
161  const LibUtilities::SessionReaderSharedPtr &pSession,
162  std::string pName,
163  bool pCache)
164  {
165  if (pCache)
166  {
167  if ((m_sessionFunctions.find(pName) == m_sessionFunctions.end())
168  || (m_sessionFunctions[pName]->GetSession() != pSession)
169  || (m_sessionFunctions[pName]->GetExpansion() != pFields[0])
170  )
171  {
172  m_sessionFunctions[pName] =
174  pSession, pFields[0], pName, pCache);
175  }
176 
177  return m_sessionFunctions[pName];
178  }
179  else
180  {
181  return SessionFunctionSharedPtr(new SessionFunction(pSession, pFields[0], pName, pCache));
182  }
183  }
184 
185  }
186 }
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
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::map< std::string, SolverUtils::SessionFunctionSharedPtr > m_sessionFunctions
Map of known SessionFunctions.
Definition: Forcing.h:111
SOLVER_UTILS_EXPORT void InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Initialise the forcing object.
Definition: Forcing.cpp:58
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
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.
Definition: Forcing.cpp:72
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > & UpdateForces()
Definition: Forcing.cpp:121
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44
STL namespace.
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtr > Load(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
Definition: Forcing.cpp:85
SOLVER_UTILS_EXPORT const Array< OneD, const Array< OneD, NekDouble > > & GetForces()
Definition: Forcing.cpp:126
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
double NekDouble
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:131
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)=0
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
std::shared_ptr< SessionReader > SessionReaderSharedPtr
Provides a generic Factory class.
Definition: NekFactory.hpp:103
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