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  NavierStokesCFE(pSession, pGraph)
51  {
52  }
53 
55  {
56 
57  }
58 
60  {
62 
63  int nVariables = m_fields.num_elements();
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, const 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.num_elements();
80 
81  NavierStokesCFE::v_DoDiffusion(inarray, outarray, pFwd, pBwd);
82 
83  for (int i = 0; i < nvariables; ++i)
84  {
85  Vmath::Vadd(npoints,
86  m_viscousForcing[i], 1,
87  outarray[i], 1,
88  outarray[i], 1);
89  }
90  }
91 
92  /**
93  * @brief Return the flux vector for the LDG diffusion problem.
94  * \todo Complete the viscous flux vector
95  */
97  const Array<OneD, Array<OneD, NekDouble> > &physfield,
98  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &derivativesO1,
99  Array<OneD, Array<OneD, Array<OneD, NekDouble> > > &viscousTensor)
100  {
101  int i, j;
102  int nVariables = m_fields.num_elements();
103  int nPts = physfield[0].num_elements();
104 
105  // 1/r
107  Array<OneD, NekDouble> invR (nPts,0.0);
108  for (int i = 0; i < 3; i++)
109  {
110  coords[i] = Array<OneD, NekDouble> (nPts);
111  }
112  m_fields[0]->GetCoords(coords[0], coords[1], coords[2]);
113  for (int i = 0; i < nPts; ++i)
114  {
115  if (coords[0][i] < NekConstants::kNekZeroTol)
116  {
117  invR[i] = 0;
118  }
119  else
120  {
121  invR[i] = 1.0/coords[0][i];
122  }
123  }
124 
125  // Stokes hypothesis
126  const NekDouble lambda = -2.0/3.0;
127 
128  // Auxiliary variables
129  Array<OneD, NekDouble > divVel (nPts, 0.0);
130  Array<OneD, NekDouble > tmp (nPts, 0.0);
131 
132  // Update viscosity and thermal conductivity
133  GetViscosityAndThermalCondFromTemp(physfield[nVariables-2], m_mu,
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,
138  divVel, 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, m_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,
158  derivativesO1[j][i], 1,
159  viscousTensor[i][j+1], 1);
160 
161  Vmath::Vmul(nPts, m_mu, 1,
162  viscousTensor[i][j+1], 1,
163  viscousTensor[i][j+1], 1);
164 
165  if (i == j)
166  {
167  // Add divergence term to diagonal
168  Vmath::Vadd(nPts, viscousTensor[i][j+1], 1,
169  divVel, 1,
170  viscousTensor[i][j+1], 1);
171  }
172  else
173  {
174  // Copy to make symmetric
175  Vmath::Vcopy(nPts, viscousTensor[i][j+1], 1,
176  viscousTensor[j][i+1], 1);
177  }
178  }
179  }
180  // Swirl case
181  if(m_spacedim == 3)
182  {
183  // Tau_theta_theta = mu ( 2*u_r/r - 2/3*div(u))
184  Vmath::Vmul(nPts, physfield[0], 1 , invR, 1,
185  viscousTensor[2][3], 1);
186  Vmath::Smul(nPts, 2.0, viscousTensor[2][3], 1,
187  viscousTensor[2][3], 1);
188  Vmath::Vmul(nPts, m_mu, 1, viscousTensor[2][3], 1,
189  viscousTensor[2][3], 1);
190  Vmath::Vadd(nPts, viscousTensor[2][3], 1,
191  divVel, 1,
192  viscousTensor[2][3], 1);
193 
194  // Tau_r_theta = mu (-u_theta/r + d(u_theta)/dr )
195  Vmath::Vmul(nPts, physfield[2], 1 , invR, 1,
196  viscousTensor[2][1], 1);
197  Vmath::Smul(nPts, -1.0, viscousTensor[2][1], 1,
198  viscousTensor[2][1], 1);
199  Vmath::Vadd(nPts, derivativesO1[0][2], 1 , viscousTensor[2][1], 1,
200  viscousTensor[2][1], 1);
201  Vmath::Vmul(nPts, m_mu, 1, viscousTensor[2][1], 1,
202  viscousTensor[2][1], 1);
203  Vmath::Vcopy(nPts, viscousTensor[2][1], 1,
204  viscousTensor[0][3], 1);
205 
206  // Tau_z_theta = mu (d(u_theta)/dz )
207  Vmath::Vmul(nPts, m_mu, 1, derivativesO1[1][2], 1,
208  viscousTensor[2][2], 1);
209  Vmath::Vcopy(nPts, viscousTensor[2][2], 1,
210  viscousTensor[1][3], 1);
211  }
212 
213  // Terms for the energy equation
214  for (i = 0; i < m_spacedim; ++i)
215  {
216  Vmath::Zero(nPts, viscousTensor[i][m_spacedim+1], 1);
217  // u_j * tau_ij
218  for (j = 0; j < m_spacedim; ++j)
219  {
220  Vmath::Vvtvp(nPts, physfield[j], 1,
221  viscousTensor[i][j+1], 1,
222  viscousTensor[i][m_spacedim+1], 1,
223  viscousTensor[i][m_spacedim+1], 1);
224  }
225  // Add k*T_i
226  if (i != 2)
227  {
229  derivativesO1[i][m_spacedim], 1,
230  viscousTensor[i][m_spacedim+1], 1,
231  viscousTensor[i][m_spacedim+1], 1);
232  }
233  else
234  {
235  Vmath::Vmul(nPts, derivativesO1[i][m_spacedim], 1 ,
236  invR, 1, tmp, 1);
238  tmp, 1,
239  viscousTensor[i][m_spacedim+1], 1,
240  viscousTensor[i][m_spacedim+1], 1);
241  }
242  }
243 
244  // Update viscous forcing
245  // r-momentum: F = 1/r * (tau_rr - tau_theta_theta)
246  if(m_spacedim == 3)
247  {
248  Vmath::Vsub(nPts, viscousTensor[0][1], 1, viscousTensor[2][3], 1,
249  m_viscousForcing[1], 1);
250  Vmath::Vmul(nPts, m_viscousForcing[1], 1 ,
251  invR, 1, m_viscousForcing[1], 1);
252  }
253  else
254  {
255  Vmath::Vmul(nPts, viscousTensor[0][1], 1 ,
256  invR, 1, m_viscousForcing[1], 1);
257  }
258 
259  // z-momentum: F = 1/r * tau_r_z
260  Vmath::Vmul(nPts, viscousTensor[0][2], 1 ,
261  invR, 1, m_viscousForcing[2], 1);
262 
263  // Theta_momentum: F = 2* tau_r_theta
264  if(m_spacedim == 3)
265  {
266  Vmath::Vmul(nPts, viscousTensor[0][3], 1 ,
267  invR, 1, m_viscousForcing[3], 1);
268  Vmath::Smul(nPts, 2.0, m_viscousForcing[3], 1,
269  m_viscousForcing[3], 1);
270  }
271 
272  // Energy: F = 1/r* viscousTensor_T_r
273  Vmath::Vmul(nPts, viscousTensor[0][m_spacedim+1], 1 ,
274  invR, 1, m_viscousForcing[m_spacedim+1], 1);
275  }
276 }
virtual void v_InitObject()
Initialization object for CompressibleFlowSystem class.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
Array< OneD, NekDouble > m_thermalConductivity
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:445
STL namespace.
virtual void v_DoDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const Array< OneD, Array< OneD, NekDouble > > &pFwd, const Array< OneD, Array< OneD, NekDouble > > &pBwd)
virtual void v_InitObject()
Initialization object for CompressibleFlowSystem class.
virtual void v_GetViscousFluxVector(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &derivatives, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &viscousTensor)
Return the flux vector for the LDG diffusion problem.
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
Base class for unsteady solvers.
int m_spacedim
Spatial dimension (>= expansion dim).
double NekDouble
EquationSystemFactory & GetEquationSystemFactory()
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
Array< OneD, Array< OneD, NekDouble > > m_viscousForcing
void GetViscosityAndThermalCondFromTemp(const Array< OneD, NekDouble > &temperature, Array< OneD, NekDouble > &mu, Array< OneD, NekDouble > &thermalCond)
Update viscosity todo: add artificial viscosity here.
SOLVER_UTILS_EXPORT int GetNpoints()
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
Array< OneD, NekDouble > m_mu
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual void v_DoDiffusion(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const Array< OneD, Array< OneD, NekDouble > > &pFwd, const Array< OneD, Array< OneD, NekDouble > > &pBwd)
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
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