Nektar++
ProcessWSS.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessWSS.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: Computes wss field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 
38 #include "ProcessWSS.h"
39 
41 #include <MultiRegions/ExpList.h>
42 
43 using namespace std;
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
48 {
49 
50 ModuleKey ProcessWSS::className = GetModuleFactory().RegisterCreatorFunction(
51  ModuleKey(eProcessModule, "wss"),
52  ProcessWSS::create,
53  "Computes wall shear stress field.");
54 
55 ProcessWSS::ProcessWSS(FieldSharedPtr f) : ProcessBoundaryExtract(f)
56 {
57 }
58 
60 {
61 }
62 
63 void ProcessWSS::Process(po::variables_map &vm)
64 {
66 
67  int i, j;
68  int nfields = m_f->m_variables.size();
69  int expdim = m_f->m_graph->GetSpaceDimension();
70  m_spacedim = expdim + m_f->m_numHomogeneousDir;
71 
72 
73  if (m_f->m_exp[0]->GetNumElmts() == 0)
74  {
75  return;
76  }
77 
78  if (m_spacedim == 1)
79  {
80  ASSERTL0(false, "Error: wss for a 1D problem cannot "
81  "be computed");
82  }
83 
84  // Declare arrays
85  int nshear = m_spacedim + 1;
86  int nstress = m_spacedim * m_spacedim;
87  int ngrad = m_spacedim * m_spacedim;
88 
89  Array<OneD, Array<OneD, NekDouble> > velocity(nfields);
91  Array<OneD, Array<OneD, NekDouble> > stress(nstress), fstress(nstress);
92  Array<OneD, Array<OneD, NekDouble> > fshear(nshear);
93 
96 
97  // will resuse nfields expansions to write shear components.
98  if(nshear > nfields)
99  {
100  m_f->m_exp.resize(nshear);
101  for (i = nfields; i < nshear; ++i)
102  {
103  m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
104  }
105  }
106 
107  // Create map of boundary ids for partitioned domains
109  m_f->m_exp[0]->GetGraph());
111  bcs.GetBoundaryRegions();
112  map<int, int> BndRegionMap;
113  int cnt = 0;
114  for (auto &breg_it : bregions)
115  {
116  BndRegionMap[breg_it.first] = cnt++;
117  }
118 
119  // Loop over boundaries to Write
120  for (int b = 0; b < m_f->m_bndRegionsToWrite.size(); ++b)
121  {
122  if (BndRegionMap.count(m_f->m_bndRegionsToWrite[b]) == 1)
123  {
124  int bnd = BndRegionMap[m_f->m_bndRegionsToWrite[b]];
125  // Get expansion list for boundary and for elements containing this
126  // bnd
127  for (i = 0; i < nshear; i++)
128  {
129  BndExp[i] = m_f->m_exp[i]->UpdateBndCondExpansion(bnd);
130  }
131  for (i = 0; i < nfields; i++)
132  {
133  m_f->m_exp[i]->GetBndElmtExpansion(bnd, BndElmtExp[i]);
134  }
135 
136  // Get number of points in expansions
137  int nqb = BndExp[0]->GetTotPoints();
138  int nqe = BndElmtExp[0]->GetTotPoints();
139 
140  // Initialise local arrays for the velocity gradients, and stress
141  // components
142  // size of total number of quadrature points for elements in this
143  // bnd
144  for (i = 0; i < ngrad; ++i)
145  {
146  grad[i] = Array<OneD, NekDouble>(nqe);
147  }
148 
149  for (i = 0; i < nstress; ++i)
150  {
151  stress[i] = Array<OneD, NekDouble>(nqe);
152  }
153 
154  Array<OneD, NekDouble> div(nqe, 0.0);
155 
156  // initialise arrays in the boundary
157  for (i = 0; i < nstress; ++i)
158  {
159  fstress[i] = Array<OneD, NekDouble>(nqb);
160  }
161 
162  for (i = 0; i < nshear; ++i)
163  {
164  fshear[i] = Array<OneD, NekDouble>(nqb, 0.0);
165  }
166 
167  // Extract Velocities
168  GetVelocity( BndElmtExp, velocity);
169 
170  // Extract viscosity coefficients
171  NekDouble lambda;
172  Array<OneD, NekDouble> mu(nqe, 0.0);
173  GetViscosity( BndElmtExp, mu, lambda);
174 
175  // Compute gradients
176  for (i = 0; i < m_spacedim; ++i)
177  {
178  if (m_spacedim == 2)
179  {
180  BndElmtExp[i]->PhysDeriv(velocity[i],
181  grad[i * m_spacedim + 0],
182  grad[i * m_spacedim + 1]);
183  }
184  else
185  {
186  BndElmtExp[i]->PhysDeriv(velocity[i],
187  grad[i * m_spacedim + 0],
188  grad[i * m_spacedim + 1],
189  grad[i * m_spacedim + 2]);
190  }
191  // Add contribution to div(u)
192  Vmath::Vadd(nqe, grad[i * m_spacedim + i], 1, div, 1, div, 1);
193  }
194 
195  // Velocity divergence scaled by lambda * mu
196  Vmath::Smul(nqe, lambda, div, 1, div, 1);
197  Vmath::Vmul(nqe, mu, 1, div, 1, div, 1);
198 
199  // Compute stress component terms
200  // tau_ij = mu*(u_i,j + u_j,i) + mu*lambda*delta_ij*div(u)
201  for (i = 0; i < m_spacedim; ++i)
202  {
203  for (j = i; j < m_spacedim; ++j)
204  {
205  Vmath::Vadd(nqe, grad[i * m_spacedim + j], 1,
206  grad[j * m_spacedim + i], 1,
207  stress[i * m_spacedim + j], 1);
208 
209  Vmath::Vmul(nqe, mu, 1,
210  stress[i * m_spacedim + j], 1,
211  stress[i * m_spacedim + j], 1);
212 
213  if (i == j)
214  {
215  // Add divergence term to diagonal
216  Vmath::Vadd(nqe, stress[i * m_spacedim + j], 1,
217  div, 1,
218  stress[i * m_spacedim + j], 1);
219  }
220  else
221  {
222  // Copy to make symmetric
223  Vmath::Vcopy(nqe, stress[i * m_spacedim + j], 1,
224  stress[j * m_spacedim + i], 1);
225  }
226  }
227  }
228 
229  // Get boundary stress values.
230  for (j = 0; j < nstress; ++j)
231  {
232  m_f->m_exp[0]->ExtractElmtToBndPhys(bnd, stress[j], fstress[j]);
233  }
234 
235  // Get normals
237  m_f->m_exp[0]->GetBoundaryNormals(bnd, normals);
238  // Reverse normals, to get correct orientation for the body
239  for (i = 0; i < m_spacedim; ++i)
240  {
241  Vmath::Neg(nqb, normals[i], 1);
242  }
243 
244  // calculate wss, and update coeffs in the boundary expansion
245  // S = tau_ij * n_j
246  for (i = 0; i < m_spacedim; ++i)
247  {
248  for (j = 0; j < m_spacedim; ++j)
249  {
250  Vmath::Vvtvp(nqb, normals[j], 1,
251  fstress[i * m_spacedim + j], 1,
252  fshear[i], 1, fshear[i], 1);
253  }
254  }
255 
256  // T = S - (S.n)n
257  for (i = 0; i < m_spacedim; ++i)
258  {
259  Vmath::Vvtvp(nqb, normals[i], 1, fshear[i], 1,
260  fshear[nshear - 1], 1, fshear[nshear - 1], 1);
261  }
262  Vmath::Smul(nqb, -1.0, fshear[nshear - 1], 1,
263  fshear[nshear - 1], 1);
264 
265  for (i = 0; i < m_spacedim; i++)
266  {
267  Vmath::Vvtvp(nqb, normals[i], 1, fshear[nshear - 1], 1,
268  fshear[i], 1, fshear[i], 1);
269  BndExp[i]->FwdTrans_IterPerExp(fshear[i],
270  BndExp[i]->UpdateCoeffs());
271  }
272 
273  // Tw
274  Vmath::Zero(nqb, fshear[nshear - 1], 1);
275  for (i = 0; i < m_spacedim; ++i)
276  {
277  Vmath::Vvtvp(nqb, fshear[i], 1, fshear[i], 1,
278  fshear[nshear - 1], 1, fshear[nshear - 1], 1);
279  }
280  Vmath::Vsqrt(nqb, fshear[nshear - 1], 1, fshear[nshear - 1], 1);
281  BndExp[nshear - 1]->FwdTrans_IterPerExp(fshear[nshear - 1],
282  BndExp[nshear - 1]->UpdateCoeffs());
283  }
284  }
285 
286  if (m_spacedim == 2)
287  {
288  m_f->m_variables[0] = "Shear_x";
289  m_f->m_variables[1] = "Shear_y";
290  m_f->m_variables[2] = "Shear_mag";
291  }
292  else
293  {
294  m_f->m_variables[0] = "Shear_x";
295  m_f->m_variables[1] = "Shear_y";
296  m_f->m_variables[2] = "Shear_z";
297  m_f->m_variables[3] = "Shear_mag";
298  }
299 }
300 
304  NekDouble &lambda)
305 {
306  NekDouble m_mu;
307  int npoints = exp[0]->GetNpoints();
308 
309  if(boost::iequals(m_f->m_variables[0], "u"))
310  {
311  // IncNavierStokesSolver
312  m_mu = m_f->m_session->GetParameter("Kinvis");
313  Vmath::Fill(npoints, m_mu, mu, 1);
314  lambda = 0;
315  }
316  else if(boost::iequals(m_f->m_variables[0], "rho") &&
317  boost::iequals(m_f->m_variables[1], "rhou"))
318  {
319  // CompressibleFlowSolver
320  std::string m_ViscosityType;
321  m_f->m_session->LoadParameter ("mu", m_mu, 1.78e-05);
322  m_f->m_session->LoadParameter ("lambda", lambda, -2.0/3.0);
323  m_f->m_session->LoadSolverInfo("ViscosityType", m_ViscosityType
324  , "Constant");
325 
326  if (m_ViscosityType == "Variable")
327  {
328  // Check equation of state
329  std::string eosType;
330  bool m_idealGas;
331  m_f->m_session->LoadSolverInfo("EquationOfState", eosType,
332  "IdealGas");
333  m_idealGas = boost::iequals(eosType,"IdealGas");
334  ASSERTL0(m_idealGas,
335  "Only IdealGas EOS implemented for Variable ViscosityType");
336 
337  // Get relevant parameters
338  NekDouble m_gamma;
339  NekDouble m_pInf;
341  NekDouble m_gasConstant;
342  NekDouble cv_inv;
343  m_f->m_session->LoadParameter("Gamma", m_gamma, 1.4);
344  m_f->m_session->LoadParameter("pInf", m_pInf, 101325);
345  m_f->m_session->LoadParameter("rhoInf", m_rhoInf, 1.225);
346  m_f->m_session->LoadParameter("GasConstant", m_gasConstant
347  , 287.058);
348 
349  // Get temperature from flowfield
350  cv_inv = (m_gamma - 1.0) / m_gasConstant;
351  // e = 1/rho ( E - 1/2 ( rhou^2/rho + ... ) )
352  Array<OneD, NekDouble> tmp(npoints, 0.0);
353  Array<OneD, NekDouble> energy(npoints, 0.0);
354  Array<OneD, NekDouble> temperature(npoints, 0.0);
355  Vmath::Vcopy(npoints, exp[m_spacedim+1]->GetPhys(), 1, energy, 1);
356  for (int i = 0; i < m_spacedim; i++)
357  {
358  // rhou^2
359  Vmath::Vmul(npoints, exp[i + 1]->GetPhys(), 1
360  , exp[i + 1]->GetPhys(), 1, tmp, 1);
361  // rhou^2/rho
362  Vmath::Vdiv(npoints, tmp, 1, exp[0]->GetPhys(), 1, tmp, 1);
363  // 0.5 rhou^2/rho
364  Vmath::Smul(npoints, 0.5, tmp, 1, tmp, 1);
365  // E - 0.5 rhou^2/rho - ...
366  Vmath::Vsub(npoints, energy, 1, tmp, 1, energy, 1);
367  }
368  // rhoe/rho
369  Vmath::Vdiv(npoints, energy, 1, exp[0]->GetPhys(), 1, energy, 1);
370  // T = e/Cv
371  Vmath::Smul(npoints, cv_inv, energy, 1, temperature, 1 );
372 
373  // Variable viscosity through the Sutherland's law
374  //
375  // WARNING, if this routine is modified the same must be done in the
376  // CompressibleFlowSolver function in VariableConverter.cpp
377  // (this class should be restructured).
378 
379  const NekDouble C = .38175;
380  NekDouble mu_star = m_mu;
381  NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
382  NekDouble ratio;
383  for (int i = 0; i < npoints; ++i)
384  {
385  ratio = temperature[i] / T_star;
386  mu[i] = mu_star * ratio * sqrt(ratio) * (1 + C) / (ratio + C);
387  }
388  }
389  else
390  {
391  Vmath::Fill(npoints, m_mu, mu, 1);
392  }
393  }
394  else
395  {
396  // Unknown
397  ASSERTL0(false, "Invalid variables for WSS");
398  }
399 }
400 
404 {
405  int npoints = exp[0]->GetNpoints();
406  if(boost::iequals(m_f->m_variables[0], "u"))
407  {
408  // IncNavierStokesSolver
409  for (int i = 0; i < m_spacedim; ++i)
410  {
411  vel[i] = Array<OneD, NekDouble>(npoints);
412  Vmath::Vcopy(npoints,
413  exp[i]->GetPhys(), 1,
414  vel[i], 1);
415  }
416  }
417  else if(boost::iequals(m_f->m_variables[0], "rho") &&
418  boost::iequals(m_f->m_variables[1], "rhou"))
419  {
420  // CompressibleFlowSolver
421  for (int i = 0; i < m_spacedim; ++i)
422  {
423  vel[i] = Array<OneD, NekDouble>(npoints);
424  Vmath::Vdiv(npoints,
425  exp[i + 1]->GetPhys(), 1,
426  exp[0]->GetPhys(), 1,
427  vel[i], 1);
428  }
429  }
430  else
431  {
432  // Unknown
433  ASSERTL0(false, "Could not identify velocity for WSS");
434  }
435 }
436 
437 }
438 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:411
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
virtual void Process(po::variables_map &vm)
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
void GetViscosity(const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, NekDouble > &mu, NekDouble &lambda)
Definition: ProcessWSS.cpp:301
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
This processing module sets up for the boundary field to be extracted.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
NekDouble m_mu
NekDouble m_rhoInf
void GetVelocity(const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, Array< OneD, NekDouble > > &vel)
Definition: ProcessWSS.cpp:401
std::pair< ModuleType, std::string > ModuleKey
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
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Definition: ProcessWSS.cpp:63
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:399
double NekDouble
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
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
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
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:238
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
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.