Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ForcingSponge.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ForcingSponge.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: Sponge forcing
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 namespace Nektar
39 {
40 namespace SolverUtils
41 {
42 
44  RegisterCreatorFunction("Sponge",
46  "Forcing Sponge");
47 
49  : Forcing(pSession),
50  m_hasRefFlow(false),
51  m_hasRefFlowTime(false)
52  {
53  }
54 
56  const Array<OneD, MultiRegions::ExpListSharedPtr>& pFields,
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("SPONGECOEFF");
65  ASSERTL0(funcNameElmt, "Requires SPONGECOEFF tag, specifying function "
66  "name which prescribes sponge coefficient.");
67 
68  string funcName = funcNameElmt->GetText();
69  ASSERTL0(m_session->DefinesFunction(funcName),
70  "Function '" + funcName + "' not defined.");
71 
72  std::string s_FieldStr;
73  m_Sponge = Array<OneD, Array<OneD, NekDouble> > (m_NumVariable);
74  m_Forcing = Array<OneD, Array<OneD, NekDouble> > (m_NumVariable);
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.");
80  m_Sponge[i] = Array<OneD, NekDouble> (npts, 0.0);
81  m_Forcing[i] = Array<OneD, NekDouble> (npts, 0.0);
82  EvaluateFunction(pFields, m_session, s_FieldStr,
83  m_Sponge[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 
93  m_Refflow = Array<OneD, Array<OneD, NekDouble> > (m_NumVariable);
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 
118  const Array<OneD, MultiRegions::ExpListSharedPtr> &fields,
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);
127  Array<OneD, Array<OneD, NekDouble> > RefflowScaled(m_NumVariable);
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_Sponge[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_Sponge[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 }