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 
61  {
63 
64  int nVariables = m_fields.size();
65  int npoints = GetNpoints();
67  for (int i = 0; i < nVariables; ++i)
68  {
69  m_viscousForcing[i] = Array<OneD, NekDouble>(npoints, 0.0);
70  }
71  }
72 
74  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
75  Array<OneD, Array<OneD, NekDouble>> &outarray,
76  const Array<OneD, const Array<OneD, NekDouble>> &pFwd,
77  const Array<OneD, const Array<OneD, NekDouble>> &pBwd)
78  {
79  int npoints = GetNpoints();
80  int nvariables = inarray.size();
81 
82  NavierStokesCFE::v_DoDiffusion(inarray, outarray, pFwd, pBwd);
83 
84  for (int i = 0; i < nvariables; ++i)
85  {
86  Vmath::Vadd(npoints,
87  m_viscousForcing[i], 1,
88  outarray[i], 1,
89  outarray[i], 1);
90  }
91  }
92 
93  /**
94  * @brief Return the flux vector for the LDG diffusion problem.
95  * \todo Complete the viscous flux vector
96  */
98  const Array<OneD, const Array<OneD, NekDouble>> &physfield,
99  TensorOfArray3D<NekDouble> &derivativesO1,
100  TensorOfArray3D<NekDouble> &viscousTensor)
101  {
102  int i, j;
103  int nVariables = m_fields.size();
104  int nPts = physfield[0].size();
105 
106  // 1/r
108  Array<OneD, NekDouble> invR (nPts,0.0);
109  for (int i = 0; i < 3; i++)
110  {
111  coords[i] = Array<OneD, NekDouble> (nPts);
112  }
113  m_fields[0]->GetCoords(coords[0], coords[1], coords[2]);
114  for (int i = 0; i < nPts; ++i)
115  {
116  if (coords[0][i] < NekConstants::kNekZeroTol)
117  {
118  invR[i] = 0;
119  }
120  else
121  {
122  invR[i] = 1.0/coords[0][i];
123  }
124  }
125 
126  // Stokes hypothesis
127  const NekDouble lambda = -2.0/3.0;
128 
129  // Auxiliary variables
130  Array<OneD, NekDouble > divVel (nPts, 0.0);
131  Array<OneD, NekDouble > tmp (nPts, 0.0);
132 
133  // Update viscosity and thermal conductivity
134  GetViscosityAndThermalCondFromTemp(physfield[nVariables-2], m_mu,
136 
137  // Velocity divergence = d(u_r)/dr + d(u_z)/dz + u_r/r
138  Vmath::Vadd(nPts, derivativesO1[0][0], 1, derivativesO1[1][1], 1,
139  divVel, 1);
140  Vmath::Vvtvp(nPts, physfield[0], 1 , invR, 1, divVel, 1, divVel, 1);
141 
142  // Velocity divergence scaled by lambda * mu
143  Vmath::Smul(nPts, lambda, divVel, 1, divVel, 1);
144  Vmath::Vmul(nPts, m_mu, 1, divVel, 1, divVel, 1);
145 
146  // Viscous flux vector for the rho equation = 0
147  for (i = 0; i < m_spacedim; ++i)
148  {
149  Vmath::Zero(nPts, viscousTensor[i][0], 1);
150  }
151 
152  // Viscous stress tensor (for the momentum equations)
153 
154  for (i = 0; i < 2; ++i)
155  {
156  for (j = i; j < 2; ++j)
157  {
158  Vmath::Vadd(nPts, derivativesO1[i][j], 1,
159  derivativesO1[j][i], 1,
160  viscousTensor[i][j+1], 1);
161 
162  Vmath::Vmul(nPts, m_mu, 1,
163  viscousTensor[i][j+1], 1,
164  viscousTensor[i][j+1], 1);
165 
166  if (i == j)
167  {
168  // Add divergence term to diagonal
169  Vmath::Vadd(nPts, viscousTensor[i][j+1], 1,
170  divVel, 1,
171  viscousTensor[i][j+1], 1);
172  }
173  else
174  {
175  // Copy to make symmetric
176  Vmath::Vcopy(nPts, viscousTensor[i][j+1], 1,
177  viscousTensor[j][i+1], 1);
178  }
179  }
180  }
181  // Swirl case
182  if(m_spacedim == 3)
183  {
184  // Tau_theta_theta = mu ( 2*u_r/r - 2/3*div(u))
185  Vmath::Vmul(nPts, physfield[0], 1 , invR, 1,
186  viscousTensor[2][3], 1);
187  Vmath::Smul(nPts, 2.0, viscousTensor[2][3], 1,
188  viscousTensor[2][3], 1);
189  Vmath::Vmul(nPts, m_mu, 1, viscousTensor[2][3], 1,
190  viscousTensor[2][3], 1);
191  Vmath::Vadd(nPts, viscousTensor[2][3], 1,
192  divVel, 1,
193  viscousTensor[2][3], 1);
194 
195  // Tau_r_theta = mu (-u_theta/r + d(u_theta)/dr )
196  Vmath::Vmul(nPts, physfield[2], 1 , invR, 1,
197  viscousTensor[2][1], 1);
198  Vmath::Smul(nPts, -1.0, viscousTensor[2][1], 1,
199  viscousTensor[2][1], 1);
200  Vmath::Vadd(nPts, derivativesO1[0][2], 1 , viscousTensor[2][1], 1,
201  viscousTensor[2][1], 1);
202  Vmath::Vmul(nPts, m_mu, 1, viscousTensor[2][1], 1,
203  viscousTensor[2][1], 1);
204  Vmath::Vcopy(nPts, viscousTensor[2][1], 1,
205  viscousTensor[0][3], 1);
206 
207  // Tau_z_theta = mu (d(u_theta)/dz )
208  Vmath::Vmul(nPts, m_mu, 1, derivativesO1[1][2], 1,
209  viscousTensor[2][2], 1);
210  Vmath::Vcopy(nPts, viscousTensor[2][2], 1,
211  viscousTensor[1][3], 1);
212  }
213 
214  // Terms for the energy equation
215  for (i = 0; i < m_spacedim; ++i)
216  {
217  Vmath::Zero(nPts, viscousTensor[i][m_spacedim+1], 1);
218  // u_j * tau_ij
219  for (j = 0; j < m_spacedim; ++j)
220  {
221  Vmath::Vvtvp(nPts, physfield[j], 1,
222  viscousTensor[i][j+1], 1,
223  viscousTensor[i][m_spacedim+1], 1,
224  viscousTensor[i][m_spacedim+1], 1);
225  }
226  // Add k*T_i
227  if (i != 2)
228  {
230  derivativesO1[i][m_spacedim], 1,
231  viscousTensor[i][m_spacedim+1], 1,
232  viscousTensor[i][m_spacedim+1], 1);
233  }
234  else
235  {
236  Vmath::Vmul(nPts, derivativesO1[i][m_spacedim], 1 ,
237  invR, 1, tmp, 1);
239  tmp, 1,
240  viscousTensor[i][m_spacedim+1], 1,
241  viscousTensor[i][m_spacedim+1], 1);
242  }
243  }
244 
245  // Update viscous forcing
246  // r-momentum: F = 1/r * (tau_rr - tau_theta_theta)
247  if(m_spacedim == 3)
248  {
249  Vmath::Vsub(nPts, viscousTensor[0][1], 1, viscousTensor[2][3], 1,
250  m_viscousForcing[1], 1);
251  Vmath::Vmul(nPts, m_viscousForcing[1], 1 ,
252  invR, 1, m_viscousForcing[1], 1);
253  }
254  else
255  {
256  Vmath::Vmul(nPts, viscousTensor[0][1], 1 ,
257  invR, 1, m_viscousForcing[1], 1);
258  }
259 
260  // z-momentum: F = 1/r * tau_r_z
261  Vmath::Vmul(nPts, viscousTensor[0][2], 1 ,
262  invR, 1, m_viscousForcing[2], 1);
263 
264  // Theta_momentum: F = 2* tau_r_theta
265  if(m_spacedim == 3)
266  {
267  Vmath::Vmul(nPts, viscousTensor[0][3], 1 ,
268  invR, 1, m_viscousForcing[3], 1);
269  Vmath::Smul(nPts, 2.0, m_viscousForcing[3], 1,
270  m_viscousForcing[3], 1);
271  }
272 
273  // Energy: F = 1/r* viscousTensor_T_r
274  Vmath::Vmul(nPts, viscousTensor[0][m_spacedim+1], 1 ,
275  invR, 1, m_viscousForcing[m_spacedim+1], 1);
276  }
277 }
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
virtual void v_GetViscousFluxVector(const Array< OneD, const Array< OneD, NekDouble >> &physfield, TensorOfArray3D< NekDouble > &derivatives, TensorOfArray3D< NekDouble > &viscousTensor)
Return the flux vector for the LDG diffusion problem.
virtual void v_DoDiffusion(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const Array< OneD, const Array< OneD, NekDouble >> &pFwd, const Array< OneD, const Array< OneD, NekDouble >> &pBwd)
Array< OneD, Array< OneD, NekDouble > > m_viscousForcing
virtual void v_InitObject()
Initialization object for CompressibleFlowSystem class.
Array< OneD, NekDouble > m_thermalConductivity
void GetViscosityAndThermalCondFromTemp(const Array< OneD, NekDouble > &temperature, Array< OneD, NekDouble > &mu, Array< OneD, NekDouble > &thermalCond)
Update viscosity todo: add artificial viscosity here.
virtual void v_DoDiffusion(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const Array< OneD, const Array< OneD, NekDouble >> &pFwd, const Array< OneD, const Array< OneD, NekDouble >> &pBwd)
Array< OneD, NekDouble > m_mu
virtual void v_InitObject()
Initialization object for CompressibleFlowSystem class.
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:174
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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:192
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:513
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:322
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:225
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199
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:372