Nektar++
NavierStokesCFEAxisym.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: NavierStokesCFEAxisym.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: Navier Stokes equations in conservative variables
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 string NavierStokesCFEAxisym::className =
43  "NavierStokesCFEAxisym", NavierStokesCFEAxisym::create,
44  "Axisymmetric NavierStokes equations in conservative variables.");
45 
46 NavierStokesCFEAxisym::NavierStokesCFEAxisym(
49  : UnsteadySystem(pSession, pGraph),
50  CompressibleFlowSystem(pSession, pGraph),
51  NavierStokesCFE(pSession, pGraph)
52 {
53 }
54 
56 {
57 }
58 
59 void NavierStokesCFEAxisym::v_InitObject(bool DeclareFields)
60 {
61  NavierStokesCFE::v_InitObject(DeclareFields);
62 
63  int nVariables = m_fields.size();
64  int npoints = GetNpoints();
66  for (int i = 0; i < nVariables; ++i)
67  {
68  m_viscousForcing[i] = Array<OneD, NekDouble>(npoints, 0.0);
69  }
70 }
71 
73  const Array<OneD, Array<OneD, NekDouble>> &inarray,
74  Array<OneD, Array<OneD, NekDouble>> &outarray,
75  const Array<OneD, Array<OneD, NekDouble>> &pFwd,
76  const Array<OneD, Array<OneD, NekDouble>> &pBwd)
77 {
78  int npoints = GetNpoints();
79  int nvariables = inarray.size();
80 
81  NavierStokesCFE::v_DoDiffusion(inarray, outarray, pFwd, pBwd);
82 
83  for (int i = 0; i < nvariables; ++i)
84  {
85  Vmath::Vadd(npoints, m_viscousForcing[i], 1, outarray[i], 1,
86  outarray[i], 1);
87  }
88 }
89 
90 /**
91  * @brief Return the flux vector for the LDG diffusion problem.
92  * \todo Complete the viscous flux vector
93  */
95  const Array<OneD, const Array<OneD, NekDouble>> &physfield,
96  TensorOfArray3D<NekDouble> &derivativesO1,
97  TensorOfArray3D<NekDouble> &viscousTensor)
98 {
99  int i, j;
100  int nVariables = m_fields.size();
101  int nPts = physfield[0].size();
102 
103  // 1/r
105  Array<OneD, NekDouble> invR(nPts, 0.0);
106  for (int i = 0; i < 3; i++)
107  {
108  coords[i] = Array<OneD, NekDouble>(nPts);
109  }
110  m_fields[0]->GetCoords(coords[0], coords[1], coords[2]);
111  for (int i = 0; i < nPts; ++i)
112  {
113  if (coords[0][i] < NekConstants::kNekZeroTol)
114  {
115  invR[i] = 0;
116  }
117  else
118  {
119  invR[i] = 1.0 / coords[0][i];
120  }
121  }
122 
123  // Stokes hypothesis
124  const NekDouble lambda = -2.0 / 3.0;
125 
126  // Auxiliary variables
127  Array<OneD, NekDouble> divVel(nPts, 0.0);
128  Array<OneD, NekDouble> tmp(nPts, 0.0);
129  Array<OneD, NekDouble> mu(nPts, 0.0);
130  Array<OneD, NekDouble> thermalConductivity(nPts, 0.0);
131 
132  // Update viscosity and thermal conductivity
133  GetViscosityAndThermalCondFromTemp(physfield[nVariables - 2], mu,
134  thermalConductivity);
135 
136  // Velocity divergence = d(u_r)/dr + d(u_z)/dz + u_r/r
137  Vmath::Vadd(nPts, derivativesO1[0][0], 1, derivativesO1[1][1], 1, divVel,
138  1);
139  Vmath::Vvtvp(nPts, physfield[0], 1, invR, 1, divVel, 1, divVel, 1);
140 
141  // Velocity divergence scaled by lambda * mu
142  Vmath::Smul(nPts, lambda, divVel, 1, divVel, 1);
143  Vmath::Vmul(nPts, mu, 1, divVel, 1, divVel, 1);
144 
145  // Viscous flux vector for the rho equation = 0
146  for (i = 0; i < m_spacedim; ++i)
147  {
148  Vmath::Zero(nPts, viscousTensor[i][0], 1);
149  }
150 
151  // Viscous stress tensor (for the momentum equations)
152 
153  for (i = 0; i < 2; ++i)
154  {
155  for (j = i; j < 2; ++j)
156  {
157  Vmath::Vadd(nPts, derivativesO1[i][j], 1, derivativesO1[j][i], 1,
158  viscousTensor[i][j + 1], 1);
159 
160  Vmath::Vmul(nPts, mu, 1, viscousTensor[i][j + 1], 1,
161  viscousTensor[i][j + 1], 1);
162 
163  if (i == j)
164  {
165  // Add divergence term to diagonal
166  Vmath::Vadd(nPts, viscousTensor[i][j + 1], 1, divVel, 1,
167  viscousTensor[i][j + 1], 1);
168  }
169  else
170  {
171  // Copy to make symmetric
172  Vmath::Vcopy(nPts, viscousTensor[i][j + 1], 1,
173  viscousTensor[j][i + 1], 1);
174  }
175  }
176  }
177  // Swirl case
178  if (m_spacedim == 3)
179  {
180  // Tau_theta_theta = mu ( 2*u_r/r - 2/3*div(u))
181  Vmath::Vmul(nPts, physfield[0], 1, invR, 1, viscousTensor[2][3], 1);
182  Vmath::Smul(nPts, 2.0, viscousTensor[2][3], 1, viscousTensor[2][3], 1);
183  Vmath::Vmul(nPts, mu, 1, viscousTensor[2][3], 1, viscousTensor[2][3],
184  1);
185  Vmath::Vadd(nPts, viscousTensor[2][3], 1, divVel, 1,
186  viscousTensor[2][3], 1);
187 
188  // Tau_r_theta = mu (-u_theta/r + d(u_theta)/dr )
189  Vmath::Vmul(nPts, physfield[2], 1, invR, 1, viscousTensor[2][1], 1);
190  Vmath::Smul(nPts, -1.0, viscousTensor[2][1], 1, viscousTensor[2][1], 1);
191  Vmath::Vadd(nPts, derivativesO1[0][2], 1, viscousTensor[2][1], 1,
192  viscousTensor[2][1], 1);
193  Vmath::Vmul(nPts, mu, 1, viscousTensor[2][1], 1, viscousTensor[2][1],
194  1);
195  Vmath::Vcopy(nPts, viscousTensor[2][1], 1, viscousTensor[0][3], 1);
196 
197  // Tau_z_theta = mu (d(u_theta)/dz )
198  Vmath::Vmul(nPts, mu, 1, derivativesO1[1][2], 1, viscousTensor[2][2],
199  1);
200  Vmath::Vcopy(nPts, viscousTensor[2][2], 1, viscousTensor[1][3], 1);
201  }
202 
203  // Terms for the energy equation
204  for (i = 0; i < m_spacedim; ++i)
205  {
206  Vmath::Zero(nPts, viscousTensor[i][m_spacedim + 1], 1);
207  // u_j * tau_ij
208  for (j = 0; j < m_spacedim; ++j)
209  {
210  Vmath::Vvtvp(nPts, physfield[j], 1, viscousTensor[i][j + 1], 1,
211  viscousTensor[i][m_spacedim + 1], 1,
212  viscousTensor[i][m_spacedim + 1], 1);
213  }
214  // Add k*T_i
215  if (i != 2)
216  {
217  Vmath::Vvtvp(nPts, thermalConductivity, 1,
218  derivativesO1[i][m_spacedim], 1,
219  viscousTensor[i][m_spacedim + 1], 1,
220  viscousTensor[i][m_spacedim + 1], 1);
221  }
222  else
223  {
224  Vmath::Vmul(nPts, derivativesO1[i][m_spacedim], 1, invR, 1, tmp, 1);
225  Vmath::Vvtvp(nPts, thermalConductivity, 1, tmp, 1,
226  viscousTensor[i][m_spacedim + 1], 1,
227  viscousTensor[i][m_spacedim + 1], 1);
228  }
229  }
230 
231  // Update viscous forcing
232  // r-momentum: F = 1/r * (tau_rr - tau_theta_theta)
233  if (m_spacedim == 3)
234  {
235  Vmath::Vsub(nPts, viscousTensor[0][1], 1, viscousTensor[2][3], 1,
236  m_viscousForcing[1], 1);
237  Vmath::Vmul(nPts, m_viscousForcing[1], 1, invR, 1, m_viscousForcing[1],
238  1);
239  }
240  else
241  {
242  Vmath::Vmul(nPts, viscousTensor[0][1], 1, invR, 1, m_viscousForcing[1],
243  1);
244  }
245 
246  // z-momentum: F = 1/r * tau_r_z
247  Vmath::Vmul(nPts, viscousTensor[0][2], 1, invR, 1, m_viscousForcing[2], 1);
248 
249  // Theta_momentum: F = 2* tau_r_theta
250  if (m_spacedim == 3)
251  {
252  Vmath::Vmul(nPts, viscousTensor[0][3], 1, invR, 1, m_viscousForcing[3],
253  1);
254  Vmath::Smul(nPts, 2.0, m_viscousForcing[3], 1, m_viscousForcing[3], 1);
255  }
256 
257  // Energy: F = 1/r* viscousTensor_T_r
258  Vmath::Vmul(nPts, viscousTensor[0][m_spacedim + 1], 1, invR, 1,
259  m_viscousForcing[m_spacedim + 1], 1);
260 }
261 } // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
virtual void v_InitObject(bool DeclareFields=true) override
Initialization object for CompressibleFlowSystem class.
virtual void v_DoDiffusion(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const Array< OneD, Array< OneD, NekDouble >> &pFwd, const Array< OneD, Array< OneD, NekDouble >> &pBwd) override
Array< OneD, Array< OneD, NekDouble > > m_viscousForcing
virtual void v_GetViscousFluxVector(const Array< OneD, const Array< OneD, NekDouble >> &physfield, TensorOfArray3D< NekDouble > &derivatives, TensorOfArray3D< NekDouble > &viscousTensor) override
Return the flux vector for the LDG diffusion problem.
virtual void v_InitObject(bool DeclareField=true) override
Initialization object for CompressibleFlowSystem class.
virtual void v_DoDiffusion(const Array< OneD, Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const Array< OneD, Array< OneD, NekDouble >> &pFwd, const Array< OneD, Array< OneD, NekDouble >> &pBwd) override
void GetViscosityAndThermalCondFromTemp(const Array< OneD, NekDouble > &temperature, Array< OneD, NekDouble > &mu, Array< OneD, NekDouble > &thermalCond)
Update viscosity todo: add artificial viscosity here.
int m_spacedim
Spatial dimension (>= expansion dim).
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT int GetNpoints()
Base class for unsteady solvers.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static const NekDouble kNekZeroTol
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
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:209
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:574
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:359
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:248
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
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:419