Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace SolverUtils
43 {
44 
45  std::string ForcingAbsorption::className = GetForcingFactory().
46  RegisterCreatorFunction("Absorption",
47  ForcingAbsorption::create,
48  "Forcing Absorption");
49 
50  ForcingAbsorption::ForcingAbsorption(const LibUtilities::SessionReaderSharedPtr& pSession)
51  : Forcing(pSession),
52  m_hasRefFlow(false),
53  m_hasRefFlowTime(false)
54  {
55  }
56 
59  const unsigned int& pNumForcingFields,
60  const TiXmlElement* pForce)
61  {
62  m_NumVariable = pNumForcingFields;
63  int npts = pFields[0]->GetTotPoints();
64 
65  const TiXmlElement* funcNameElmt;
66  funcNameElmt = pForce->FirstChildElement("COEFF");
67  ASSERTL0(funcNameElmt, "Requires COEFF tag, specifying function "
68  "name which prescribes absorption layer coefficient.");
69 
70  string funcName = funcNameElmt->GetText();
71  ASSERTL0(m_session->DefinesFunction(funcName),
72  "Function '" + funcName + "' not defined.");
73 
74  std::string s_FieldStr;
77  for (int i = 0; i < m_NumVariable; ++i)
78  {
79  s_FieldStr = m_session->GetVariable(i);
80  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
81  "Variable '" + s_FieldStr + "' not defined.");
83  m_Forcing[i] = Array<OneD, NekDouble> (npts, 0.0);
84  EvaluateFunction(pFields, m_session, s_FieldStr,
85  m_Absorption[i], funcName);
86  }
87 
88  funcNameElmt = pForce->FirstChildElement("REFFLOW");
89  if (funcNameElmt)
90  {
91  string funcName = funcNameElmt->GetText();
92  ASSERTL0(m_session->DefinesFunction(funcName),
93  "Function '" + funcName + "' not defined.");
94 
96  for (int i = 0; i < m_NumVariable; ++i)
97  {
98  s_FieldStr = m_session->GetVariable(i);
99  ASSERTL0(m_session->DefinesFunction(funcName, s_FieldStr),
100  "Variable '" + s_FieldStr + "' not defined.");
101  m_Refflow[i] = Array<OneD, NekDouble> (npts, 0.0);
102  EvaluateFunction(pFields, m_session, s_FieldStr,
103  m_Refflow[i], funcName);
104  }
105  m_hasRefFlow = true;
106  }
107 
108  funcNameElmt = pForce->FirstChildElement("REFFLOWTIME");
109  if (funcNameElmt)
110  {
111  m_funcNameTime = funcNameElmt->GetText();
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:121
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:97
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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:44
STL namespace.
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:151
Array< OneD, Array< OneD, NekDouble > > m_Absorption
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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:1047
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