Nektar++
ForcingAxiSymmetric.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ForcingAxiSymmetric.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: Forcing for axi-symmetric flow.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 std::string ForcingAxiSymmetric::className = SolverUtils::GetForcingFactory().
44  RegisterCreatorFunction("AxiSymmetric",
45  ForcingAxiSymmetric::create,
46  "Forcing for axi-symmetric flow (around x=0)");
47 
48 ForcingAxiSymmetric::ForcingAxiSymmetric(
50  const std::weak_ptr<SolverUtils::EquationSystem> &pEquation)
51  : Forcing(pSession, pEquation)
52 {
53 }
54 
57  const unsigned int& pNumForcingFields,
58  const TiXmlElement* pForce)
59 {
60  boost::ignore_unused(pForce);
61 
62  int spacedim = pFields[0]->GetGraph()->GetSpaceDimension();
63  int nPoints = pFields[0]->GetTotPoints();
64 
65  m_NumVariable = pNumForcingFields;
67  m_session, spacedim);
68 
69  // Get coordinates
71  for (int i = 0; i < 3; i++)
72  {
73  coords[i] = Array<OneD, NekDouble> (nPoints);
74  }
75  pFields[0]->GetCoords(coords[0], coords[1], coords[2]);
76 
77  // Calculate fac = -1/r if r!=0, fac = 0 if r == 0
79  for (int i = 0; i < nPoints; ++i)
80  {
81  if (coords[0][i] < NekConstants::kNekZeroTol)
82  {
83  m_geomFactor[i] = 0;
84  }
85  else
86  {
87  m_geomFactor[i] = -1.0/coords[0][i];
88  }
89  }
90 
91  // Project m_geomFactor to solution space
92  Array<OneD, NekDouble> tmpCoeff (pFields[0]->GetNcoeffs(), 0.0);
93  pFields[0]->FwdTrans_IterPerExp(m_geomFactor, tmpCoeff);
94  pFields[0]->BwdTrans(tmpCoeff, m_geomFactor);
95 
97  for (int i = 0; i < m_NumVariable; ++i)
98  {
99  m_Forcing[i] = Array<OneD, NekDouble> (pFields[0]->GetTotPoints(), 0.0);
100  }
101 }
102 
105  const Array<OneD, Array<OneD, NekDouble> >& inarray,
106  Array<OneD, Array<OneD, NekDouble> >& outarray,
107  const NekDouble& time)
108 {
109  boost::ignore_unused(time);
110 
111  int nPoints = pFields[0]->GetTotPoints();
112 
113  // Get (E+p)
114  Array<OneD, NekDouble> tmp (nPoints, 0.0);
115  m_varConv->GetPressure(inarray, tmp);
116  Vmath::Vadd(nPoints, tmp, 1,
117  inarray[m_NumVariable-1], 1, tmp, 1);
118 
119  // F-rho = -1/r *rhou
120  Vmath::Vmul(nPoints, m_geomFactor, 1,
121  inarray[1], 1, m_Forcing[0], 1);
122 
123  // F-rhou_r = -1/r *rhou_r * u_r and F-rhou_y = -1/r *rhou_y * u_r
124  for (int i = 1; i < 3; ++i)
125  {
126  Vmath::Vmul(nPoints, inarray[1], 1,
127  inarray[i], 1, m_Forcing[i], 1);
128  Vmath::Vdiv(nPoints, m_Forcing[i], 1,
129  inarray[0], 1, m_Forcing[i], 1);
130  Vmath::Vmul(nPoints, m_Forcing[i], 1,
131  m_geomFactor, 1, m_Forcing[i], 1);
132  }
133 
134  // F-E = -1/r *(E+p)*u
135  Vmath::Vmul(nPoints, inarray[1], 1,
136  tmp, 1, m_Forcing[m_NumVariable-1], 1);
137  Vmath::Vdiv(nPoints, m_Forcing[m_NumVariable-1], 1,
138  inarray[0], 1, m_Forcing[m_NumVariable-1], 1);
139  Vmath::Vmul(nPoints, m_Forcing[m_NumVariable-1], 1,
141 
142  // Swirl
143  if (m_NumVariable == 5)
144  {
145  // F-rhou_r -= (-1/r) * rho * u_theta * u_theta
146  Vmath::Vmul(nPoints, inarray[3], 1,
147  inarray[3], 1, tmp, 1);
148  Vmath::Vdiv(nPoints, tmp, 1,
149  inarray[0], 1, tmp, 1);
150  Vmath::Vmul(nPoints, tmp, 1,
151  m_geomFactor, 1, tmp, 1);
152  Vmath::Vsub(nPoints, m_Forcing[1], 1,
153  tmp, 1, m_Forcing[1], 1);
154 
155  // F-rhou_theta = 2 * (-1/r *rhou_theta * u_r)
156  Vmath::Vmul(nPoints, inarray[1], 1,
157  inarray[3], 1, m_Forcing[3], 1);
158  Vmath::Vdiv(nPoints, m_Forcing[3], 1,
159  inarray[0], 1, m_Forcing[3], 1);
160  Vmath::Vmul(nPoints, m_Forcing[3], 1,
161  m_geomFactor, 1, m_Forcing[3], 1);
162  Vmath::Smul(nPoints, 2.0,
163  m_Forcing[3], 1, m_Forcing[3], 1);
164  }
165 
166  // Apply forcing
167  for (int i = 0; i < m_NumVariable; i++)
168  {
169  Vmath::Vadd(nPoints, outarray[i], 1,
170  m_Forcing[i], 1, outarray[i], 1);
171  }
172 }
173 
174 }
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:107
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44
STL namespace.
void Vdiv(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:244
static const NekDouble kNekZeroTol
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
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
double NekDouble
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:103
virtual 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)
Array< OneD, NekDouble > m_geomFactor
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
VariableConverterSharedPtr m_varConv
virtual 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:72
std::shared_ptr< SessionReader > SessionReaderSharedPtr
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