Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
Nektar::FieldUtils::ProcessWSS Class Reference

This processing module calculates the wall shear stress and adds it as an extra-field to the output file, and writes it to a surface output file. More...

#include <ProcessWSS.h>

Inheritance diagram for Nektar::FieldUtils::ProcessWSS:
[legend]

Public Member Functions

 ProcessWSS (FieldSharedPtr f)
 
virtual ~ProcessWSS ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
virtual std::string GetModuleName ()
 
virtual std::string GetModuleDescription ()
 
- Public Member Functions inherited from Nektar::FieldUtils::ProcessBoundaryExtract
 ProcessBoundaryExtract (FieldSharedPtr f)
 
virtual ~ProcessBoundaryExtract ()
 
virtual ModulePriority GetModulePriority ()
 
- Public Member Functions inherited from Nektar::FieldUtils::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::FieldUtils::ProcessBoundaryExtract
static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 
- Static Public Attributes inherited from Nektar::FieldUtils::ProcessBoundaryExtract
static ModuleKey className
 

Protected Member Functions

void GetViscosity (const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, NekDouble > &mu, NekDouble &lambda)
 
void GetVelocity (const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, Array< OneD, NekDouble > > &vel)
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 

Private Attributes

int m_spacedim
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

This processing module calculates the wall shear stress and adds it as an extra-field to the output file, and writes it to a surface output file.

Definition at line 49 of file ProcessWSS.h.

Constructor & Destructor Documentation

◆ ProcessWSS()

Nektar::FieldUtils::ProcessWSS::ProcessWSS ( FieldSharedPtr  f)

Definition at line 55 of file ProcessWSS.cpp.

◆ ~ProcessWSS()

Nektar::FieldUtils::ProcessWSS::~ProcessWSS ( )
virtual

Definition at line 59 of file ProcessWSS.cpp.

60 {
61 }

Member Function Documentation

◆ create()

static std::shared_ptr<Module> Nektar::FieldUtils::ProcessWSS::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file ProcessWSS.h.

54  {
56  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ GetModuleDescription()

virtual std::string Nektar::FieldUtils::ProcessWSS::GetModuleDescription ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::ProcessBoundaryExtract.

Definition at line 70 of file ProcessWSS.h.

71  {
72  return "Calculating wall shear stress";
73  }

◆ GetModuleName()

virtual std::string Nektar::FieldUtils::ProcessWSS::GetModuleName ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::ProcessBoundaryExtract.

Definition at line 65 of file ProcessWSS.h.

66  {
67  return "ProcessWSS";
68  }

◆ GetVelocity()

void Nektar::FieldUtils::ProcessWSS::GetVelocity ( const Array< OneD, MultiRegions::ExpListSharedPtr exp,
Array< OneD, Array< OneD, NekDouble > > &  vel 
)
protected

Definition at line 400 of file ProcessWSS.cpp.

403 {
404  int npoints = exp[0]->GetNpoints();
405  if(boost::iequals(m_f->m_variables[0], "u"))
406  {
407  // IncNavierStokesSolver
408  for (int i = 0; i < m_spacedim; ++i)
409  {
410  vel[i] = Array<OneD, NekDouble>(npoints);
411  Vmath::Vcopy(npoints,
412  exp[i]->GetPhys(), 1,
413  vel[i], 1);
414  }
415  }
416  else if(boost::iequals(m_f->m_variables[0], "rho") &&
417  boost::iequals(m_f->m_variables[1], "rhou"))
418  {
419  // CompressibleFlowSolver
420  for (int i = 0; i < m_spacedim; ++i)
421  {
422  vel[i] = Array<OneD, NekDouble>(npoints);
423  Vmath::Vdiv(npoints,
424  exp[i + 1]->GetPhys(), 1,
425  exp[0]->GetPhys(), 1,
426  vel[i], 1);
427  }
428  }
429  else
430  {
431  // Unknown
432  ASSERTL0(false, "Could not identify velocity for WSS");
433  }
434 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
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:257
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199

References ASSERTL0, Nektar::FieldUtils::Module::m_f, m_spacedim, Vmath::Vcopy(), and Vmath::Vdiv().

Referenced by Process().

◆ GetViscosity()

void Nektar::FieldUtils::ProcessWSS::GetViscosity ( const Array< OneD, MultiRegions::ExpListSharedPtr exp,
Array< OneD, NekDouble > &  mu,
NekDouble lambda 
)
protected

Definition at line 300 of file ProcessWSS.cpp.

304 {
305  NekDouble m_mu;
306  int npoints = exp[0]->GetNpoints();
307 
308  if(boost::iequals(m_f->m_variables[0], "u"))
309  {
310  // IncNavierStokesSolver
311  m_mu = m_f->m_session->GetParameter("Kinvis");
312  Vmath::Fill(npoints, m_mu, mu, 1);
313  lambda = 0;
314  }
315  else if(boost::iequals(m_f->m_variables[0], "rho") &&
316  boost::iequals(m_f->m_variables[1], "rhou"))
317  {
318  // CompressibleFlowSolver
319  std::string m_ViscosityType;
320  m_f->m_session->LoadParameter ("mu", m_mu, 1.78e-05);
321  m_f->m_session->LoadParameter ("lambda", lambda, -2.0/3.0);
322  m_f->m_session->LoadSolverInfo("ViscosityType", m_ViscosityType
323  , "Constant");
324 
325  if (m_ViscosityType == "Variable")
326  {
327  // Check equation of state
328  std::string eosType;
329  bool m_idealGas;
330  m_f->m_session->LoadSolverInfo("EquationOfState", eosType,
331  "IdealGas");
332  m_idealGas = boost::iequals(eosType,"IdealGas");
333  ASSERTL0(m_idealGas,
334  "Only IdealGas EOS implemented for Variable ViscosityType");
335 
336  // Get relevant parameters
337  NekDouble m_gamma;
338  NekDouble m_pInf;
340  NekDouble m_gasConstant;
341  NekDouble cv_inv;
342  m_f->m_session->LoadParameter("Gamma", m_gamma, 1.4);
343  m_f->m_session->LoadParameter("pInf", m_pInf, 101325);
344  m_f->m_session->LoadParameter("rhoInf", m_rhoInf, 1.225);
345  m_f->m_session->LoadParameter("GasConstant", m_gasConstant
346  , 287.058);
347 
348  // Get temperature from flowfield
349  cv_inv = (m_gamma - 1.0) / m_gasConstant;
350  // e = 1/rho ( E - 1/2 ( rhou^2/rho + ... ) )
351  Array<OneD, NekDouble> tmp(npoints, 0.0);
352  Array<OneD, NekDouble> energy(npoints, 0.0);
353  Array<OneD, NekDouble> temperature(npoints, 0.0);
354  Vmath::Vcopy(npoints, exp[m_spacedim+1]->GetPhys(), 1, energy, 1);
355  for (int i = 0; i < m_spacedim; i++)
356  {
357  // rhou^2
358  Vmath::Vmul(npoints, exp[i + 1]->GetPhys(), 1
359  , exp[i + 1]->GetPhys(), 1, tmp, 1);
360  // rhou^2/rho
361  Vmath::Vdiv(npoints, tmp, 1, exp[0]->GetPhys(), 1, tmp, 1);
362  // 0.5 rhou^2/rho
363  Vmath::Smul(npoints, 0.5, tmp, 1, tmp, 1);
364  // E - 0.5 rhou^2/rho - ...
365  Vmath::Vsub(npoints, energy, 1, tmp, 1, energy, 1);
366  }
367  // rhoe/rho
368  Vmath::Vdiv(npoints, energy, 1, exp[0]->GetPhys(), 1, energy, 1);
369  // T = e/Cv
370  Vmath::Smul(npoints, cv_inv, energy, 1, temperature, 1 );
371 
372  // Variable viscosity through the Sutherland's law
373  //
374  // WARNING, if this routine is modified the same must be done in the
375  // CompressibleFlowSolver function in VariableConverter.cpp
376  // (this class should be restructured).
377 
378  const NekDouble C = .38175;
379  NekDouble mu_star = m_mu;
380  NekDouble T_star = m_pInf / (m_rhoInf * m_gasConstant);
381  NekDouble ratio;
382  for (int i = 0; i < npoints; ++i)
383  {
384  ratio = temperature[i] / T_star;
385  mu[i] = mu_star * ratio * sqrt(ratio) * (1 + C) / (ratio + C);
386  }
387  }
388  else
389  {
390  Vmath::Fill(npoints, m_mu, mu, 1);
391  }
392  }
393  else
394  {
395  // Unknown
396  ASSERTL0(false, "Invalid variables for WSS");
397  }
398 }
NekDouble m_mu
NekDouble m_rhoInf
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 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 Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
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
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267

References ASSERTL0, Vmath::Fill(), Nektar::FieldUtils::Module::m_f, m_mu, m_rhoInf, m_spacedim, Vmath::Smul(), tinysimd::sqrt(), Vmath::Vcopy(), Vmath::Vdiv(), Vmath::Vmul(), and Vmath::Vsub().

Referenced by Process().

◆ Process()

void Nektar::FieldUtils::ProcessWSS::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::ProcessBoundaryExtract.

Definition at line 63 of file ProcessWSS.cpp.

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);
90  Array<OneD, Array<OneD, NekDouble> > grad(ngrad);
91  Array<OneD, Array<OneD, NekDouble> > stress(nstress), fstress(nstress);
92  Array<OneD, Array<OneD, NekDouble> > fshear(nshear);
93 
94  Array<OneD, MultiRegions::ExpListSharedPtr> BndExp(nshear);
95  Array<OneD, MultiRegions::ExpListSharedPtr> BndElmtExp(nfields);
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
108  SpatialDomains::BoundaryConditions bcs(m_f->m_session,
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
141  // stress components size of total number of quadrature
142  // points for elements in this bnd
143  for (i = 0; i < ngrad; ++i)
144  {
145  grad[i] = Array<OneD, NekDouble>(nqe);
146  }
147 
148  for (i = 0; i < nstress; ++i)
149  {
150  stress[i] = Array<OneD, NekDouble>(nqe);
151  }
152 
153  Array<OneD, NekDouble> div(nqe, 0.0);
154 
155  // initialise arrays in the boundary
156  for (i = 0; i < nstress; ++i)
157  {
158  fstress[i] = Array<OneD, NekDouble>(nqb);
159  }
160 
161  for (i = 0; i < nshear; ++i)
162  {
163  fshear[i] = Array<OneD, NekDouble>(nqb, 0.0);
164  }
165 
166  // Extract Velocities
167  GetVelocity( BndElmtExp, velocity);
168 
169  // Extract viscosity coefficients
170  NekDouble lambda;
171  Array<OneD, NekDouble> mu(nqe, 0.0);
172  GetViscosity( BndElmtExp, mu, lambda);
173 
174  // Compute gradients
175  for (i = 0; i < m_spacedim; ++i)
176  {
177  if (m_spacedim == 2)
178  {
179  BndElmtExp[i]->PhysDeriv(velocity[i],
180  grad[i * m_spacedim + 0],
181  grad[i * m_spacedim + 1]);
182  }
183  else
184  {
185  BndElmtExp[i]->PhysDeriv(velocity[i],
186  grad[i * m_spacedim + 0],
187  grad[i * m_spacedim + 1],
188  grad[i * m_spacedim + 2]);
189  }
190  // Add contribution to div(u)
191  Vmath::Vadd(nqe, grad[i * m_spacedim + i], 1, div, 1, div, 1);
192  }
193 
194  // Velocity divergence scaled by lambda * mu
195  Vmath::Smul(nqe, lambda, div, 1, div, 1);
196  Vmath::Vmul(nqe, mu, 1, div, 1, div, 1);
197 
198  // Compute stress component terms
199  // tau_ij = mu*(u_i,j + u_j,i) + mu*lambda*delta_ij*div(u)
200  for (i = 0; i < m_spacedim; ++i)
201  {
202  for (j = i; j < m_spacedim; ++j)
203  {
204  Vmath::Vadd(nqe, grad[i * m_spacedim + j], 1,
205  grad[j * m_spacedim + i], 1,
206  stress[i * m_spacedim + j], 1);
207 
208  Vmath::Vmul(nqe, mu, 1,
209  stress[i * m_spacedim + j], 1,
210  stress[i * m_spacedim + j], 1);
211 
212  if (i == j)
213  {
214  // Add divergence term to diagonal
215  Vmath::Vadd(nqe, stress[i * m_spacedim + j], 1,
216  div, 1,
217  stress[i * m_spacedim + j], 1);
218  }
219  else
220  {
221  // Copy to make symmetric
222  Vmath::Vcopy(nqe, stress[i * m_spacedim + j], 1,
223  stress[j * m_spacedim + i], 1);
224  }
225  }
226  }
227 
228  // Get boundary stress values.
229  for (j = 0; j < nstress; ++j)
230  {
231  m_f->m_exp[0]->ExtractElmtToBndPhys(bnd, stress[j], fstress[j]);
232  }
233 
234  // Get normals
235  Array<OneD, Array<OneD, NekDouble> > normals;
236  m_f->m_exp[0]->GetBoundaryNormals(bnd, normals);
237  // Reverse normals, to get correct orientation for the body
238  for (i = 0; i < m_spacedim; ++i)
239  {
240  Vmath::Neg(nqb, normals[i], 1);
241  }
242 
243  // calculate wss, and update coeffs in the boundary expansion
244  // S = tau_ij * n_j
245  for (i = 0; i < m_spacedim; ++i)
246  {
247  for (j = 0; j < m_spacedim; ++j)
248  {
249  Vmath::Vvtvp(nqb, normals[j], 1,
250  fstress[i * m_spacedim + j], 1,
251  fshear[i], 1, fshear[i], 1);
252  }
253  }
254 
255  // T = S - (S.n)n
256  for (i = 0; i < m_spacedim; ++i)
257  {
258  Vmath::Vvtvp(nqb, normals[i], 1, fshear[i], 1,
259  fshear[nshear - 1], 1, fshear[nshear - 1], 1);
260  }
261  Vmath::Smul(nqb, -1.0, fshear[nshear - 1], 1,
262  fshear[nshear - 1], 1);
263 
264  for (i = 0; i < m_spacedim; i++)
265  {
266  Vmath::Vvtvp(nqb, normals[i], 1, fshear[nshear - 1], 1,
267  fshear[i], 1, fshear[i], 1);
268  BndExp[i]->FwdTrans_IterPerExp(fshear[i],
269  BndExp[i]->UpdateCoeffs());
270  }
271 
272  // Tw
273  Vmath::Zero(nqb, fshear[nshear - 1], 1);
274  for (i = 0; i < m_spacedim; ++i)
275  {
276  Vmath::Vvtvp(nqb, fshear[i], 1, fshear[i], 1,
277  fshear[nshear - 1], 1, fshear[nshear - 1], 1);
278  }
279  Vmath::Vsqrt(nqb, fshear[nshear - 1], 1, fshear[nshear - 1], 1);
280  BndExp[nshear - 1]->FwdTrans_IterPerExp(fshear[nshear - 1],
281  BndExp[nshear - 1]->UpdateCoeffs());
282  }
283  }
284 
285  if (m_spacedim == 2)
286  {
287  m_f->m_variables[0] = "Shear_x";
288  m_f->m_variables[1] = "Shear_y";
289  m_f->m_variables[2] = "Shear_mag";
290  }
291  else
292  {
293  m_f->m_variables[0] = "Shear_x";
294  m_f->m_variables[1] = "Shear_y";
295  m_f->m_variables[2] = "Shear_z";
296  m_f->m_variables[3] = "Shear_mag";
297  }
298 }
virtual void Process(po::variables_map &vm)
void GetViscosity(const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, NekDouble > &mu, NekDouble &lambda)
Definition: ProcessWSS.cpp:300
void GetVelocity(const Array< OneD, MultiRegions::ExpListSharedPtr > exp, Array< OneD, Array< OneD, NekDouble > > &vel)
Definition: ProcessWSS.cpp:400
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:475
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:461
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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436

References ASSERTL0, Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions(), GetVelocity(), GetViscosity(), Nektar::FieldUtils::Module::m_f, m_spacedim, Vmath::Neg(), Nektar::FieldUtils::ProcessBoundaryExtract::Process(), Vmath::Smul(), Vmath::Vadd(), Vmath::Vcopy(), Vmath::Vmul(), Vmath::Vsqrt(), Vmath::Vvtvp(), and Vmath::Zero().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessWSS::className
static
Initial value:
"Computes wall shear stress field.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: ProcessWSS.h:53
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

Definition at line 57 of file ProcessWSS.h.

◆ m_spacedim

int Nektar::FieldUtils::ProcessWSS::m_spacedim
private

Definition at line 83 of file ProcessWSS.h.

Referenced by GetVelocity(), GetViscosity(), and Process().