Nektar++
ForcingAbsorption.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ForcingAbsorption.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Absorption layer forcing
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 namespace Nektar
39 {
40 namespace SolverUtils
41 {
42 
44  RegisterCreatorFunction("Absorption",
46  "Forcing Absorption");
47 
49  : Forcing(pSession),
50  m_hasRefFlow(false),
51  m_hasRefFlowTime(false)
52  {
53  }
54 
57  const unsigned int& pNumForcingFields,
58  const TiXmlElement* pForce)
59  {
60  m_NumVariable = pNumForcingFields;
61  int npts = pFields[0]->GetTotPoints();
62 
63  const TiXmlElement* funcNameElmt;
64  funcNameElmt = pForce->FirstChildElement("COEFF");
65  ASSERTL0(funcNameElmt, "Requires COEFF tag, specifying function "
66  "name which prescribes absorption layer coefficient.");
67 
68  string funcName = funcNameElmt->GetText();
69  ASSERTL0(m_session->DefinesFunction(funcName),
70  "Function '" + funcName + "' not defined.");
71 
72  std::string s_FieldStr;
75  for (int i = 0; i < m_NumVariable; ++i)
76  {
77  s_FieldStr = m_session->GetVariable(i);
78  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
79  "Variable '" + s_FieldStr + "' not defined.");
81  m_Forcing[i] = Array<OneD, NekDouble> (npts, 0.0);
82  EvaluateFunction(pFields, m_session, s_FieldStr,
83  m_Absorption[i], funcName);
84  }
85 
86  funcNameElmt = pForce->FirstChildElement("REFFLOW");
87  if (funcNameElmt)
88  {
89  string funcName = funcNameElmt->GetText();
90  ASSERTL0(m_session->DefinesFunction(funcName),
91  "Function '" + funcName + "' not defined.");
92 
94  for (int i = 0; i < m_NumVariable; ++i)
95  {
96  s_FieldStr = m_session->GetVariable(i);
97  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
98  "Variable '" + s_FieldStr + "' not defined.");
99  m_Refflow[i] = Array<OneD, NekDouble> (npts, 0.0);
100  EvaluateFunction(pFields, m_session, s_FieldStr,
101  m_Refflow[i], funcName);
102  }
103  m_hasRefFlow = true;
104  }
105 
106  funcNameElmt = pForce->FirstChildElement("REFFLOWTIME");
107  if (funcNameElmt)
108  {
109  m_funcNameTime = funcNameElmt->GetText();
110  ASSERTL0(m_session->DefinesFunction(funcName),
111  "Function '" + funcName + "' not defined.");
112  m_hasRefFlowTime = true;
113  }
114 
115  }
116 
119  const Array<OneD, Array<OneD, NekDouble> > &inarray,
120  Array<OneD, Array<OneD, NekDouble> > &outarray,
121  const NekDouble &time)
122  {
123  int nq = m_Forcing[0].num_elements();
124 
125  std::string s_FieldStr;
126  Array<OneD, NekDouble> TimeScale(1);
128 
129  if (m_hasRefFlow)
130  {
131  for (int i = 0; i < m_NumVariable; i++)
132  {
133  RefflowScaled[i] = Array<OneD, NekDouble> (nq);
134  if (m_hasRefFlowTime)
135  {
136  s_FieldStr = m_session->GetVariable(i);
137  EvaluateTimeFunction(m_session, s_FieldStr, TimeScale, m_funcNameTime, time);
138  Vmath::Smul(nq, TimeScale[0], m_Refflow[i],1,RefflowScaled[i],1);
139  }
140  else
141  {
142  Vmath::Vcopy(nq, m_Refflow[i],1, RefflowScaled[i],1);
143  }
144 
145 
146  Vmath::Vsub(nq, inarray[i], 1,
147  RefflowScaled[i], 1, m_Forcing[i], 1);
148  Vmath::Vmul(nq, m_Absorption[i], 1,
149  m_Forcing[i], 1, m_Forcing[i], 1);
150  Vmath::Vadd(nq, m_Forcing[i], 1,
151  outarray[i], 1, outarray[i], 1);
152  }
153  }
154  else
155  {
156  for (int i = 0; i < m_NumVariable; i++)
157  {
158  Vmath::Vmul(nq, m_Absorption[i], 1,
159  inarray[i], 1, m_Forcing[i], 1);
160  Vmath::Vadd(nq, m_Forcing[i], 1,
161  outarray[i], 1, outarray[i], 1);
162  }
163  }
164  }
165 
166 }
167 }
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
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:97
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
ForcingAbsorption(const LibUtilities::SessionReaderSharedPtr &pSession)
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)
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:42
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))
Definition: Forcing.cpp:140
Array< OneD, Array< OneD, NekDouble > > m_Absorption
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
static std::string className
Name of the class.
static SOLVER_UTILS_EXPORT ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
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:199
Array< OneD, Array< OneD, NekDouble > > m_Refflow
static std::string npts
Definition: InputFld.cpp:43
double NekDouble
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:95
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:329
int m_NumVariable
Number of variables.
Definition: Forcing.h:99
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Defines a forcing term to be explicitly applied.
Definition: Forcing.h:70
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1038
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:285
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:169