Nektar++
Loading...
Searching...
No Matches
EquationSystems/NavierStokesCFE.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NavierStokesCFE.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
37
38namespace Nektar
39{
40
43 "NavierStokesCFE", NavierStokesCFE::create,
44 "NavierStokes equations in conservative variables.");
45
49 : UnsteadySystem(pSession, pGraph), CompressibleFlowSystem(pSession, pGraph)
50{
51}
52
53/**
54 * @brief Initialization object for CompressibleFlowSystem class.
55 */
56void NavierStokesCFE::v_InitObject(bool DeclareFields)
57{
59
60 // rest of initialisation is in this routine so it can also be called
61 // in NavierStokesImplicitCFE initialisation
63}
64
66{
67 // Get gas constant from session file and compute Cp
68 NekDouble gasConstant;
69 m_session->LoadParameter("GasConstant", gasConstant, 287.058);
70 m_Cp = m_gamma / (m_gamma - 1.0) * gasConstant;
71 m_Cv = m_Cp / m_gamma;
72
73 m_session->LoadParameter("Twall", m_Twall, 300.15);
74
75 // Viscosity
76 m_session->LoadSolverInfo("ViscosityType", m_ViscosityType, "Constant");
77 m_session->LoadParameter("mu", m_muRef, 1.78e-05);
78 if (m_ViscosityType == "Variable")
79 {
80 m_is_mu_variable = true;
81 }
82
83 // Thermal conductivity or Prandtl
84 if (m_session->DefinesParameter("thermalConductivity"))
85 {
86 ASSERTL0(!m_session->DefinesParameter("Pr"),
87 "Cannot define both Pr and thermalConductivity.");
88
89 m_session->LoadParameter("thermalConductivity",
92 }
93 else
94 {
95 m_session->LoadParameter("Pr", m_Prandtl, 0.72);
97 }
98
99 if (m_shockCaptureType == "Physical")
100 {
101 m_is_shockCaptPhys = true;
102 }
103
104 std::string diffName;
105 m_session->LoadSolverInfo("DiffusionType", diffName, "LDGNS");
106
109 if ("InteriorPenalty" == diffName)
110 {
111 m_is_diffIP = true;
113 }
114
115 if ("LDGNS" == diffName || "LDGNS3DHomogeneous1D" == diffName)
116 {
117 m_diffusion->SetFluxPenaltyNS(&NavierStokesCFE::v_GetFluxPenalty, this);
118 }
119
121 {
122 m_diffusion->SetFluxVectorNS(
124 }
125 else
126 {
128 this);
129 }
130
131 m_diffusion->SetDiffusionFluxCons(
132 &NavierStokesCFE::GetViscousFluxVectorConservVar<false>, this);
133
134 m_diffusion->SetDiffusionFluxConsTrace(
135 &NavierStokesCFE::GetViscousFluxVectorConservVar<true>, this);
136
137 m_diffusion->SetSpecialBndTreat(&NavierStokesCFE::SpecialBndTreat, this);
138
139 m_diffusion->SetDiffusionSymmFluxCons(
141
142 // Concluding initialisation of diffusion operator
143 m_diffusion->InitObject(m_session, m_fields);
144 m_diffusion->SetGridVelocityTrace(
145 m_gridVelocityTrace); // If not ALE and movement this is just 0s
146}
147
149 const Array<OneD, Array<OneD, NekDouble>> &inarray,
151 const Array<OneD, Array<OneD, NekDouble>> &pFwd,
152 const Array<OneD, Array<OneD, NekDouble>> &pBwd)
153{
154 size_t nvariables = inarray.size();
155 size_t npointsIn = GetNpoints();
156 size_t npointsOut = m_meshDistorted
157 ? GetNcoeffs()
158 : npointsIn; // If mesh is distorted then outarray
159 // is in coefficient space
160 size_t nTracePts = GetTraceTotPoints();
161
162 // this should be preallocated
163 Array<OneD, Array<OneD, NekDouble>> outarrayDiff(nvariables);
164 for (size_t i = 0; i < nvariables; ++i)
165 {
166 outarrayDiff[i] = Array<OneD, NekDouble>(npointsOut, 0.0);
167 }
168
169 // Set artificial viscosity based on NS viscous tensor
171 {
172 if (m_varConv->GetFlagCalcDivCurl())
173 {
174 Array<OneD, NekDouble> div(npointsIn), curlSquare(npointsIn);
175 GetDivCurlSquared(m_fields, inarray, div, curlSquare, pFwd, pBwd);
176
177 // Set volume and trace artificial viscosity
178 m_varConv->SetAv(m_fields, inarray, div, curlSquare);
179 }
180 else
181 {
182 m_varConv->SetAv(m_fields, inarray);
183 }
184 }
185
186 if (m_is_diffIP)
187 {
188 if (m_bndEvaluateTime < 0.0)
189 {
190 NEKERROR(ErrorUtil::efatal, "m_bndEvaluateTime not setup");
191 }
192
193 // Diffusion term in physical rhs form
194 if (m_meshDistorted)
195 {
196 m_diffusion->DiffuseCoeffs(nvariables, m_fields, inarray,
197 outarrayDiff, m_bndEvaluateTime, pFwd,
198 pBwd);
199 }
200 else
201 {
202 m_diffusion->Diffuse(nvariables, m_fields, inarray, outarrayDiff,
203 m_bndEvaluateTime, pFwd, pBwd);
204 }
205 for (size_t i = 0; i < nvariables; ++i)
206 {
207 Vmath::Vadd(npointsOut, outarrayDiff[i], 1, outarray[i], 1,
208 outarray[i], 1);
209 }
210 }
211 else
212 {
213 // Get primitive variables [u,v,w,T]
214 Array<OneD, Array<OneD, NekDouble>> inarrayDiff(nvariables - 1);
215 Array<OneD, Array<OneD, NekDouble>> inFwd(nvariables - 1);
216 Array<OneD, Array<OneD, NekDouble>> inBwd(nvariables - 1);
217
218 for (size_t i = 0; i < nvariables - 1; ++i)
219 {
220 inarrayDiff[i] = Array<OneD, NekDouble>{npointsIn};
221 inFwd[i] = Array<OneD, NekDouble>{nTracePts};
222 inBwd[i] = Array<OneD, NekDouble>{nTracePts};
223 }
224
225 // Extract temperature
226 m_varConv->GetTemperature(inarray, inarrayDiff[nvariables - 2]);
227
228 // Extract velocities
229 m_varConv->GetVelocityVector(inarray, inarrayDiff);
230
231 // Repeat calculation for trace space
232 if (pFwd == NullNekDoubleArrayOfArray ||
234 {
237 }
238 else
239 {
240 m_varConv->GetTemperature(pFwd, inFwd[nvariables - 2]);
241 m_varConv->GetTemperature(pBwd, inBwd[nvariables - 2]);
242
243 m_varConv->GetVelocityVector(pFwd, inFwd);
244 m_varConv->GetVelocityVector(pBwd, inBwd);
245 }
246
247 // Diffusion term in physical rhs form
248 if (m_meshDistorted)
249 {
250 m_diffusion->DiffuseCoeffs(nvariables, m_fields, inarrayDiff,
251 outarrayDiff, inFwd, inBwd);
252 }
253 else
254 {
255 m_diffusion->Diffuse(nvariables, m_fields, inarrayDiff,
256 outarrayDiff, inFwd, inBwd);
257 }
258
259 for (size_t i = 0; i < nvariables; ++i)
260 {
261 Vmath::Vadd(npointsOut, outarrayDiff[i], 1, outarray[i], 1,
262 outarray[i], 1);
263 }
264 }
265
266 // Add artificial diffusion through Laplacian operator
268 {
269 m_artificialDiffusion->DoArtificialDiffusion(inarray, outarray);
270 }
271}
272
273/**
274 * @brief Return the flux vector for the LDG diffusion problem.
275 * \todo Complete the viscous flux vector
276 */
278 const Array<OneD, const Array<OneD, NekDouble>> &physfield,
279 TensorOfArray3D<NekDouble> &derivativesO1,
280 TensorOfArray3D<NekDouble> &viscousTensor)
281{
282 // Auxiliary variables
283 size_t nScalar = physfield.size();
284 size_t nPts = physfield[0].size();
285 Array<OneD, NekDouble> divVel(nPts, 0.0);
286
287 // Stokes hypothesis
288 const NekDouble lambda = -2.0 / 3.0;
289
290 // Update viscosity and thermal conductivity
291 Array<OneD, NekDouble> mu(nPts, 0.0);
292 Array<OneD, NekDouble> thermalConductivity(nPts, 0.0);
293 GetViscosityAndThermalCondFromTemp(physfield[nScalar - 1], mu,
294 thermalConductivity);
295
296 // Velocity divergence
297 for (int j = 0; j < m_spacedim; ++j)
298 {
299 Vmath::Vadd(nPts, divVel, 1, derivativesO1[j][j], 1, divVel, 1);
300 }
301
302 // Velocity divergence scaled by lambda * mu
303 Vmath::Smul(nPts, lambda, divVel, 1, divVel, 1);
304 Vmath::Vmul(nPts, mu, 1, divVel, 1, divVel, 1);
305
306 // Viscous flux vector for the rho equation = 0
307 for (int i = 0; i < m_spacedim; ++i)
308 {
309 Vmath::Zero(nPts, viscousTensor[i][0], 1);
310 }
311
312 // Viscous stress tensor (for the momentum equations)
313 for (int i = 0; i < m_spacedim; ++i)
314 {
315 for (int j = i; j < m_spacedim; ++j)
316 {
317 Vmath::Vadd(nPts, derivativesO1[i][j], 1, derivativesO1[j][i], 1,
318 viscousTensor[i][j + 1], 1);
319
320 Vmath::Vmul(nPts, mu, 1, viscousTensor[i][j + 1], 1,
321 viscousTensor[i][j + 1], 1);
322
323 if (i == j)
324 {
325 // Add divergence term to diagonal
326 Vmath::Vadd(nPts, viscousTensor[i][j + 1], 1, divVel, 1,
327 viscousTensor[i][j + 1], 1);
328 }
329 else
330 {
331 // Copy to make symmetric
332 Vmath::Vcopy(nPts, viscousTensor[i][j + 1], 1,
333 viscousTensor[j][i + 1], 1);
334 }
335 }
336 }
337
338 // Terms for the energy equation
339 for (int i = 0; i < m_spacedim; ++i)
340 {
341 Vmath::Zero(nPts, viscousTensor[i][m_spacedim + 1], 1);
342 // u_j * tau_ij
343 for (int j = 0; j < m_spacedim; ++j)
344 {
345 Vmath::Vvtvp(nPts, physfield[j], 1, viscousTensor[i][j + 1], 1,
346 viscousTensor[i][m_spacedim + 1], 1,
347 viscousTensor[i][m_spacedim + 1], 1);
348 }
349 // Add k*T_i
350 Vmath::Vvtvp(nPts, thermalConductivity, 1, derivativesO1[i][m_spacedim],
351 1, viscousTensor[i][m_spacedim + 1], 1,
352 viscousTensor[i][m_spacedim + 1], 1);
353 }
354}
355
356/**
357 * @brief Return the flux vector for the LDG diffusion problem.
358 * \todo Complete the viscous flux vector
359 */
361 const Array<OneD, const Array<OneD, NekDouble>> &physfield,
362 TensorOfArray3D<NekDouble> &derivativesO1,
363 TensorOfArray3D<NekDouble> &viscousTensor)
364{
365 // Factor to rescale 1d points in dealiasing.
366 NekDouble OneDptscale = 2;
367 // Get number of points to dealias a cubic non-linearity
368 size_t nScalar = physfield.size();
369 size_t nPts = m_fields[0]->Get1DScaledTotPoints(OneDptscale);
370 size_t nPts_orig = physfield[0].size();
371
372 // Auxiliary variables
373 Array<OneD, NekDouble> divVel(nPts, 0.0);
374
375 // Stokes hypothesis
376 const NekDouble lambda = -2.0 / 3.0;
377
378 // Update viscosity and thermal conductivity
379 Array<OneD, NekDouble> mu(nPts, 0.0);
380 Array<OneD, NekDouble> thermalConductivity(nPts, 0.0);
381 GetViscosityAndThermalCondFromTemp(physfield[nScalar - 1], mu,
382 thermalConductivity);
383
384 // Interpolate inputs and initialise interpolated output
388 for (int i = 0; i < m_spacedim; ++i)
389 {
390 // Interpolate velocity
391 vel_interp[i] = Array<OneD, NekDouble>(nPts);
392 m_fields[0]->PhysInterp1DScaled(OneDptscale, physfield[i],
393 vel_interp[i]);
394
395 // Interpolate derivatives
396 deriv_interp[i] = Array<OneD, Array<OneD, NekDouble>>(m_spacedim + 1);
397 for (int j = 0; j < m_spacedim + 1; ++j)
398 {
399 deriv_interp[i][j] = Array<OneD, NekDouble>(nPts);
400 m_fields[0]->PhysInterp1DScaled(OneDptscale, derivativesO1[i][j],
401 deriv_interp[i][j]);
402 }
403
404 // Output (start from j=1 since flux is zero for rho)
406 for (int j = 1; j < m_spacedim + 2; ++j)
407 {
408 out_interp[i][j] = Array<OneD, NekDouble>(nPts);
409 }
410 }
411
412 // Velocity divergence
413 for (int j = 0; j < m_spacedim; ++j)
414 {
415 Vmath::Vadd(nPts, divVel, 1, deriv_interp[j][j], 1, divVel, 1);
416 }
417
418 // Velocity divergence scaled by lambda * mu
419 Vmath::Smul(nPts, lambda, divVel, 1, divVel, 1);
420 Vmath::Vmul(nPts, mu, 1, divVel, 1, divVel, 1);
421
422 // Viscous flux vector for the rho equation = 0 (no need to dealias)
423 for (int i = 0; i < m_spacedim; ++i)
424 {
425 Vmath::Zero(nPts_orig, viscousTensor[i][0], 1);
426 }
427
428 // Viscous stress tensor (for the momentum equations)
429 for (int i = 0; i < m_spacedim; ++i)
430 {
431 for (int j = i; j < m_spacedim; ++j)
432 {
433 Vmath::Vadd(nPts, deriv_interp[i][j], 1, deriv_interp[j][i], 1,
434 out_interp[i][j + 1], 1);
435
436 Vmath::Vmul(nPts, mu, 1, out_interp[i][j + 1], 1,
437 out_interp[i][j + 1], 1);
438
439 if (i == j)
440 {
441 // Add divergence term to diagonal
442 Vmath::Vadd(nPts, out_interp[i][j + 1], 1, divVel, 1,
443 out_interp[i][j + 1], 1);
444 }
445 else
446 {
447 // Make symmetric
448 out_interp[j][i + 1] = out_interp[i][j + 1];
449 }
450 }
451 }
452
453 // Terms for the energy equation
454 for (int i = 0; i < m_spacedim; ++i)
455 {
456 Vmath::Zero(nPts, out_interp[i][m_spacedim + 1], 1);
457 // u_j * tau_ij
458 for (int j = 0; j < m_spacedim; ++j)
459 {
460 Vmath::Vvtvp(nPts, vel_interp[j], 1, out_interp[i][j + 1], 1,
461 out_interp[i][m_spacedim + 1], 1,
462 out_interp[i][m_spacedim + 1], 1);
463 }
464 // Add k*T_i
465 Vmath::Vvtvp(nPts, thermalConductivity, 1, deriv_interp[i][m_spacedim],
466 1, out_interp[i][m_spacedim + 1], 1,
467 out_interp[i][m_spacedim + 1], 1);
468 }
469
470 // Project to original space
471 for (int i = 0; i < m_spacedim; ++i)
472 {
473 for (int j = 1; j < m_spacedim + 2; ++j)
474 {
475 m_fields[0]->PhysGalerkinProjection1DScaled(
476 OneDptscale, out_interp[i][j], viscousTensor[i][j]);
477 }
478 }
479}
480
481/**
482 * @brief For very special treatment. For general boundaries it does nothing
483 * But for WallViscous and WallAdiabatic, special treatment is needed
484 * because they get the same Bwd value, special treatment is needed for
485 * boundary treatment of diffusion flux
486 * Note: This special treatment could be removed by seperating
487 * WallViscous and WallAdiabatic into two different classes.
488 *
489 */
492{
493 size_t nConvectiveFields = consvar.size();
494 size_t ndens = 0;
495 size_t nengy = nConvectiveFields - 1;
496
497 Array<OneD, Array<OneD, NekDouble>> bndCons{nConvectiveFields};
498 Array<OneD, NekDouble> bndTotEngy;
499 Array<OneD, NekDouble> bndPressure;
501 Array<OneD, NekDouble> bndIntEndy;
502 size_t nLengthArray = 0;
503
504 size_t cnt = 0;
505 size_t nBndRegions = m_fields[nengy]->GetBndCondExpansions().size();
506 for (size_t j = 0; j < nBndRegions; ++j)
507 {
508 if (m_fields[nengy]
509 ->GetBndConditions()[j]
510 ->GetBoundaryConditionType() == SpatialDomains::ePeriodic)
511 {
512 continue;
513 }
514
515 size_t nBndEdges =
516 m_fields[nengy]->GetBndCondExpansions()[j]->GetExpSize();
517 for (size_t e = 0; e < nBndEdges; ++e)
518 {
519 size_t nBndEdgePts = m_fields[nengy]
520 ->GetBndCondExpansions()[j]
521 ->GetExp(e)
522 ->GetTotPoints();
523
524 int id2 = m_fields[0]->GetTrace()->GetPhys_Offset(
525 m_fields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(cnt++));
526
527 // Imposing Temperature Twall at the wall
529 m_fields[nengy]->GetBndConditions()[j]->GetUserDefined(),
530 "WallViscous"))
531 {
532 if (nBndEdgePts != nLengthArray)
533 {
534 for (size_t i = 0; i < nConvectiveFields; ++i)
535 {
536 bndCons[i] = Array<OneD, NekDouble>{nBndEdgePts, 0.0};
537 }
538 bndTotEngy = Array<OneD, NekDouble>{nBndEdgePts, 0.0};
539 bndPressure = Array<OneD, NekDouble>{nBndEdgePts, 0.0};
540 bndRho = Array<OneD, NekDouble>{nBndEdgePts, 0.0};
541 bndIntEndy = Array<OneD, NekDouble>{nBndEdgePts, 0.0};
542 nLengthArray = nBndEdgePts;
543 }
544 else
545 {
546 Vmath::Zero(nLengthArray, bndPressure, 1);
547 Vmath::Zero(nLengthArray, bndRho, 1);
548 Vmath::Zero(nLengthArray, bndIntEndy, 1);
549 }
550
552
553 for (size_t k = 0; k < nConvectiveFields; ++k)
554 {
555 Vmath::Vcopy(nBndEdgePts, tmp = consvar[k] + id2, 1,
556 bndCons[k], 1);
557 }
558
559 m_varConv->GetPressure(bndCons, bndPressure);
560 Vmath::Fill(nLengthArray, m_Twall, bndTotEngy, 1);
561 m_varConv->GetRhoFromPT(bndPressure, bndTotEngy, bndRho);
562 m_varConv->GetEFromRhoP(bndRho, bndPressure, bndIntEndy);
563 m_varConv->GetDynamicEnergy(bndCons, bndTotEngy);
564
565 Vmath::Vvtvp(nBndEdgePts, bndIntEndy, 1, bndCons[ndens], 1,
566 bndTotEngy, 1, bndTotEngy, 1);
567
568 Vmath::Vcopy(nBndEdgePts, bndTotEngy, 1,
569 tmp = consvar[nengy] + id2, 1);
570 }
571 }
572 }
573}
574
575/**
576 *
577 * @brief Calculate and return the Symmetric flux in IP method.
578 */
580 const size_t nDim, const Array<OneD, Array<OneD, NekDouble>> &inaverg,
581 const Array<OneD, Array<OneD, NekDouble>> &inarray,
582 TensorOfArray3D<NekDouble> &outarray, Array<OneD, int> &nonZeroIndex,
583 const Array<OneD, Array<OneD, NekDouble>> &normal)
584{
585 size_t nConvectiveFields = inarray.size();
586 size_t nPts = inaverg[nConvectiveFields - 1].size();
587 nonZeroIndex = Array<OneD, int>{nConvectiveFields - 1, 0};
588 for (size_t i = 0; i < nConvectiveFields - 1; ++i)
589 {
590 nonZeroIndex[i] = i + 1;
591 }
592
593 Array<OneD, NekDouble> mu(nPts, 0.0);
594 Array<OneD, NekDouble> thermalConductivity(nPts, 0.0);
595 Array<OneD, NekDouble> temperature(nPts, 0.0);
596 m_varConv->GetTemperature(inaverg, temperature);
597 GetViscosityAndThermalCondFromTemp(temperature, mu, thermalConductivity);
598
599 std::vector<NekDouble> inAvgTmp(nConvectiveFields);
600 std::vector<NekDouble> inTmp(nConvectiveFields);
601 std::vector<NekDouble> outTmp(nConvectiveFields);
602 for (size_t d = 0; d < nDim; ++d)
603 {
604 for (size_t nderiv = 0; nderiv < nDim; ++nderiv)
605 {
606 for (size_t p = 0; p < nPts; ++p)
607 {
608 // rearrenge data
609 for (size_t f = 0; f < nConvectiveFields; ++f)
610 {
611 inAvgTmp[f] = inaverg[f][p];
612 inTmp[f] = inarray[f][p];
613 }
614
615 GetViscousFluxBilinearFormKernel(nDim, d, nderiv,
616 inAvgTmp.data(), inTmp.data(),
617 mu[p], outTmp.data());
618
619 for (size_t f = 0; f < nConvectiveFields; ++f)
620 {
621 outarray[d][f][p] += normal[nderiv][p] * outTmp[f];
622 }
623 }
624 }
625 }
626}
627
628/**
629 * @brief Return the penalty vector for the LDGNS diffusion problem.
630 */
632 const Array<OneD, const Array<OneD, NekDouble>> &uFwd,
633 const Array<OneD, const Array<OneD, NekDouble>> &uBwd,
634 Array<OneD, Array<OneD, NekDouble>> &penaltyCoeff)
635{
636 size_t nTracePts = uFwd[0].size();
637
638 // Compute average temperature
639 size_t nVariables = uFwd.size();
640 Array<OneD, NekDouble> tAve{nTracePts, 0.0};
641 Vmath::Svtsvtp(nTracePts, 0.5, uFwd[nVariables - 1], 1, 0.5,
642 uBwd[nVariables - 1], 1, tAve, 1);
643
644 // Get average viscosity and thermal conductivity
645 Array<OneD, NekDouble> muAve{nTracePts, 0.0};
646 Array<OneD, NekDouble> tcAve{nTracePts, 0.0};
647
648 GetViscosityAndThermalCondFromTemp(tAve, muAve, tcAve);
649
650 // Compute penalty term
651 for (size_t i = 0; i < nVariables; ++i)
652 {
653 // Get jump of u variables
654 Vmath::Vsub(nTracePts, uFwd[i], 1, uBwd[i], 1, penaltyCoeff[i], 1);
655 // Multiply by variable coefficient = {coeff} ( u^+ - u^- )
656 if (i < nVariables - 1)
657 {
658 Vmath::Vmul(nTracePts, muAve, 1, penaltyCoeff[i], 1,
659 penaltyCoeff[i], 1);
660 }
661 else
662 {
663 Vmath::Vmul(nTracePts, tcAve, 1, penaltyCoeff[i], 1,
664 penaltyCoeff[i], 1);
665 }
666 }
667}
668
669/**
670 * @brief Update viscosity
671 * todo: add artificial viscosity here
672 */
674 const Array<OneD, NekDouble> &temperature, Array<OneD, NekDouble> &mu,
675 Array<OneD, NekDouble> &thermalCond)
676{
677 size_t nPts = temperature.size();
678
679 for (size_t p = 0; p < nPts; ++p)
680 {
681 GetViscosityAndThermalCondFromTempKernel(temperature[p], mu[p],
682 thermalCond[p]);
683 }
684
685 // Add artificial viscosity if wanted
686 // move this above and add in kernel
688 {
689 size_t nTracePts = m_fields[0]->GetTrace()->GetTotPoints();
690 if (nPts != nTracePts)
691 {
692 Vmath::Vadd(nPts, mu, 1, m_varConv->GetAv(), 1, mu, 1);
693 }
694 else
695 {
696 Vmath::Vadd(nPts, mu, 1, m_varConv->GetAvTrace(), 1, mu, 1);
697 }
698
699 // Update thermal conductivity
700 NekDouble tRa = m_Cp / m_Prandtl;
701 Vmath::Smul(nPts, tRa, mu, 1, thermalCond, 1);
702 }
703}
704
705/**
706 * @brief Get divergence and curl squared
707 *
708 * @param input
709 * fields -> expansion list pointer
710 * cnsVar -> conservative variables
711 * cnsVarFwd -> forward trace of conservative variables
712 * cnsVarBwd -> backward trace of conservative variables
713 * @paran output
714 * divSquare -> divergence
715 * curlSquare -> curl squared
716 *
717 */
720 const Array<OneD, Array<OneD, NekDouble>> &cnsVar,
722 const Array<OneD, Array<OneD, NekDouble>> &cnsVarFwd,
723 const Array<OneD, Array<OneD, NekDouble>> &cnsVarBwd)
724{
725 size_t nDim = fields[0]->GetCoordim(0);
726 size_t nVar = cnsVar.size();
727 size_t nPts = cnsVar[0].size();
728 size_t nPtsTrc = cnsVarFwd[0].size();
729
730 // These should be allocated once
731 Array<OneD, Array<OneD, NekDouble>> primVar(nVar - 1), primVarFwd(nVar - 1),
732 primVarBwd(nVar - 1);
733
734 for (unsigned short d = 0; d < nVar - 2; ++d)
735 {
736 primVar[d] = Array<OneD, NekDouble>(nPts, 0.0);
737 primVarFwd[d] = Array<OneD, NekDouble>(nPtsTrc, 0.0);
738 primVarBwd[d] = Array<OneD, NekDouble>(nPtsTrc, 0.0);
739 }
740 size_t ergLoc = nVar - 2;
741 primVar[ergLoc] = Array<OneD, NekDouble>(nPts, 0.0);
742 primVarFwd[ergLoc] = Array<OneD, NekDouble>(nPtsTrc, 0.0);
743 primVarBwd[ergLoc] = Array<OneD, NekDouble>(nPtsTrc, 0.0);
744
745 // Get primitive variables [u,v,w,T=0]
746 // Possibly should be changed to [rho,u,v,w,T] to make IP and LDGNS more
747 // consistent with each other
748 for (unsigned short d = 0; d < nVar - 2; ++d)
749 {
750 // Volume
751 for (size_t p = 0; p < nPts; ++p)
752 {
753 primVar[d][p] = cnsVar[d + 1][p] / cnsVar[0][p];
754 }
755 // Trace
756 for (size_t p = 0; p < nPtsTrc; ++p)
757 {
758 primVarFwd[d][p] = cnsVarFwd[d + 1][p] / cnsVarFwd[0][p];
759 primVarBwd[d][p] = cnsVarBwd[d + 1][p] / cnsVarBwd[0][p];
760 }
761 }
762
763 // this should be allocated once
765 for (unsigned short j = 0; j < nDim; ++j)
766 {
767 primVarDer[j] = Array<OneD, Array<OneD, NekDouble>>(nVar - 1);
768 for (unsigned short i = 0; i < nVar - 1; ++i)
769 {
770 primVarDer[j][i] = Array<OneD, NekDouble>(nPts, 0.0);
771 }
772 }
773
774 // Get derivative tensor
775 m_diffusion->DiffuseCalcDerivative(fields, primVar, primVarDer, primVarFwd,
776 primVarBwd);
777
778 // Get div curl squared
779 GetDivCurlFromDvelT(primVarDer, div, curlSquare);
780}
781
782/**
783 * @brief Get divergence and curl from velocity derivative tensor
784 *
785 */
788 Array<OneD, NekDouble> &curlSquare)
789{
790 size_t nDim = pVarDer.size();
791 size_t nPts = div.size();
792
793 // div velocity
794 for (size_t p = 0; p < nPts; ++p)
795 {
796 NekDouble divTmp = 0;
797 for (unsigned short j = 0; j < nDim; ++j)
798 {
799 divTmp += pVarDer[j][j][p];
800 }
801 div[p] = divTmp;
802 }
803
804 // |curl velocity| ** 2
805 if (nDim > 2)
806 {
807 for (size_t p = 0; p < nPts; ++p)
808 {
809 // curl[0] 3/2 - 2/3
810 NekDouble curl032 = pVarDer[2][1][p]; // load 1x
811 NekDouble curl023 = pVarDer[1][2][p]; // load 1x
812 NekDouble curl0 = curl032 - curl023;
813 // square curl[0]
814 NekDouble curl0sqr = curl0 * curl0;
815
816 // curl[1] 3/1 - 1/3
817 NekDouble curl131 = pVarDer[2][0][p]; // load 1x
818 NekDouble curl113 = pVarDer[0][2][p]; // load 1x
819 NekDouble curl1 = curl131 - curl113;
820 // square curl[1]
821 NekDouble curl1sqr = curl1 * curl1;
822
823 // curl[2] 1/2 - 2/1
824 NekDouble curl212 = pVarDer[0][1][p]; // load 1x
825 NekDouble curl221 = pVarDer[1][0][p]; // load 1x
826 NekDouble curl2 = curl212 - curl221;
827 // square curl[2]
828 NekDouble curl2sqr = curl2 * curl2;
829
830 // reduce
831 curl0sqr += curl1sqr + curl2sqr;
832 // store
833 curlSquare[p] = curl0sqr; // store 1x
834 }
835 }
836 else if (nDim > 1)
837 {
838 for (size_t p = 0; p < nPts; ++p)
839 {
840 // curl[2] 1/2
841 NekDouble c212 = pVarDer[0][1][p]; // load 1x
842 // curl[2] 2/1
843 NekDouble c221 = pVarDer[1][0][p]; // load 1x
844 // curl[2] 1/2 - 2/1
845 NekDouble curl = c212 - c221;
846 // square curl[2]
847 curlSquare[p] = curl * curl; // store 1x
848 }
849 }
850 else
851 {
852 Vmath::Fill(nPts, 0.0, curlSquare, 1);
853 }
854}
855
857 std::vector<Array<OneD, NekDouble>> &fieldcoeffs,
858 std::vector<std::string> &variables)
859{
860 bool extraFields;
861 m_session->MatchSolverInfo("OutputExtraFields", "True", extraFields, true);
862 if (extraFields)
863 {
864 const int nPhys = m_fields[0]->GetNpoints();
865 const int nCoeffs = m_fields[0]->GetNcoeffs();
867
868 for (size_t i = 0; i < m_fields.size(); ++i)
869 {
870 cnsVar[i] = m_fields[i]->GetPhys();
871 }
872
875 for (int i = 0; i < m_spacedim; ++i)
876 {
877 velocity[i] = Array<OneD, NekDouble>(nPhys);
878 velFwd[i] = Array<OneD, NekDouble>(nCoeffs);
879 }
880
881 Array<OneD, NekDouble> pressure(nPhys), temperature(nPhys);
882 Array<OneD, NekDouble> entropy(nPhys);
883 Array<OneD, NekDouble> soundspeed(nPhys), mach(nPhys);
884 Array<OneD, NekDouble> sensor(nPhys), SensorKappa(nPhys);
885
886 m_varConv->GetVelocityVector(cnsVar, velocity);
887 m_varConv->GetPressure(cnsVar, pressure);
888 m_varConv->GetTemperature(cnsVar, temperature);
889 m_varConv->GetEntropy(cnsVar, entropy);
890 m_varConv->GetSoundSpeed(cnsVar, soundspeed);
891 m_varConv->GetMach(cnsVar, soundspeed, mach);
892
893 int sensorOffset;
894 m_session->LoadParameter("SensorOffset", sensorOffset, 1);
895 m_varConv->GetSensor(m_fields[0], cnsVar, sensor, SensorKappa,
896 sensorOffset);
897
898 Array<OneD, NekDouble> pFwd(nCoeffs), TFwd(nCoeffs);
899 Array<OneD, NekDouble> sFwd(nCoeffs);
900 Array<OneD, NekDouble> aFwd(nCoeffs), mFwd(nCoeffs);
901 Array<OneD, NekDouble> sensFwd(nCoeffs);
902
903 std::string velNames[3] = {"u", "v", "w"};
904 for (int i = 0; i < m_spacedim; ++i)
905 {
906 m_fields[0]->FwdTransLocalElmt(velocity[i], velFwd[i]);
907 variables.push_back(velNames[i]);
908 fieldcoeffs.push_back(velFwd[i]);
909 }
910
911 m_fields[0]->FwdTransLocalElmt(pressure, pFwd);
912 m_fields[0]->FwdTransLocalElmt(temperature, TFwd);
913 m_fields[0]->FwdTransLocalElmt(entropy, sFwd);
914 m_fields[0]->FwdTransLocalElmt(soundspeed, aFwd);
915 m_fields[0]->FwdTransLocalElmt(mach, mFwd);
916 m_fields[0]->FwdTransLocalElmt(sensor, sensFwd);
917
918 variables.push_back("p");
919 variables.push_back("T");
920 variables.push_back("s");
921 variables.push_back("a");
922 variables.push_back("Mach");
923 variables.push_back("Sensor");
924 fieldcoeffs.push_back(pFwd);
925 fieldcoeffs.push_back(TFwd);
926 fieldcoeffs.push_back(sFwd);
927 fieldcoeffs.push_back(aFwd);
928 fieldcoeffs.push_back(mFwd);
929 fieldcoeffs.push_back(sensFwd);
930
932 {
933 // reuse pressure
934 Array<OneD, NekDouble> sensorFwd(nCoeffs);
935 m_artificialDiffusion->GetArtificialViscosity(cnsVar, pressure);
936 m_fields[0]->FwdTransLocalElmt(pressure, sensorFwd);
937
938 variables.push_back("ArtificialVisc");
939 fieldcoeffs.push_back(sensorFwd);
940 }
941
943 {
944
946 cnsVarBwd(m_fields.size());
947
948 for (size_t i = 0; i < m_fields.size(); ++i)
949 {
952 m_fields[i]->GetFwdBwdTracePhys(cnsVar[i], cnsVarFwd[i],
953 cnsVarBwd[i]);
954 }
955
956 Array<OneD, NekDouble> div(nPhys), curlSquare(nPhys);
957 GetDivCurlSquared(m_fields, cnsVar, div, curlSquare, cnsVarFwd,
958 cnsVarBwd);
959
960 Array<OneD, NekDouble> divFwd(nCoeffs, 0.0);
961 m_fields[0]->FwdTransLocalElmt(div, divFwd);
962 variables.push_back("div");
963 fieldcoeffs.push_back(divFwd);
964
965 Array<OneD, NekDouble> curlFwd(nCoeffs, 0.0);
966 m_fields[0]->FwdTransLocalElmt(curlSquare, curlFwd);
967 variables.push_back("curl^2");
968 fieldcoeffs.push_back(curlFwd);
969
970 m_varConv->SetAv(m_fields, cnsVar, div, curlSquare);
971
972 Array<OneD, NekDouble> muavFwd(nCoeffs);
973 m_fields[0]->FwdTransLocalElmt(m_varConv->GetAv(), muavFwd);
974 variables.push_back("ArtificialVisc");
975 fieldcoeffs.push_back(muavFwd);
976 }
977
978 if (m_ALESolver)
979 {
980 ExtraFldOutputGrid(fieldcoeffs, variables);
981 ExtraFldOutputGridVelocity(fieldcoeffs, variables);
982 }
983 }
984}
985
986bool NavierStokesCFE::v_SupportsShockCaptType(const std::string type) const
987{
988 if (type == "NonSmooth" || type == "Physical" || type == "Off")
989 {
990 return true;
991 }
992 else
993 {
994 return false;
995 }
996}
997
998} // namespace Nektar
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
SolverUtils::DiffusionSharedPtr m_diffusion
void v_InitObject(bool DeclareFields=true) override
Initialization object for CompressibleFlowSystem class.
VariableConverterSharedPtr m_varConv
void SetBoundaryConditionsBwdWeight()
Set up a weight on physical boundaries for boundary condition applications.
ArtificialDiffusionSharedPtr m_artificialDiffusion
tBasePtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::string className
Name of class.
NavierStokesCFE(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
void SpecialBndTreat(Array< OneD, Array< OneD, NekDouble > > &consvar)
For very special treatment. For general boundaries it does nothing But for WallViscous and WallAdiaba...
void GetDivCurlFromDvelT(const TensorOfArray3D< NekDouble > &pVarDer, Array< OneD, NekDouble > &div, Array< OneD, NekDouble > &curlSquare)
Get divergence and curl from velocity derivative tensor.
static SolverUtils::EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
void v_InitObject(bool DeclareField=true) override
Initialization object for CompressibleFlowSystem class.
void GetDivCurlSquared(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &cnsVar, Array< OneD, NekDouble > &div, Array< OneD, NekDouble > &curlSquare, const Array< OneD, Array< OneD, NekDouble > > &cnsVarFwd, const Array< OneD, Array< OneD, NekDouble > > &cnsVarBwd)
Get divergence and curl squared.
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
bool m_is_mu_variable
flag to switch between constant viscosity and Sutherland an enum could be added for more options
void v_ExtraFldOutput(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables) override
bool m_is_shockCaptPhys
flag for shock capturing switch on/off an enum could be added for more options
bool v_SupportsShockCaptType(const std::string type) const override
void GetViscousSymmtrFluxConservVar(const size_t nSpaceDim, const Array< OneD, Array< OneD, NekDouble > > &inaverg, const Array< OneD, Array< OneD, NekDouble > > &inarray, TensorOfArray3D< NekDouble > &outarray, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, NekDouble > > &normals)
Calculate and return the Symmetric flux in IP method.
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_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_GetFluxPenalty(const Array< OneD, const Array< OneD, NekDouble > > &uFwd, const Array< OneD, const Array< OneD, NekDouble > > &uBwd, Array< OneD, Array< OneD, NekDouble > > &penaltyCoeff)
Return the penalty vector for the LDGNS diffusion problem.
bool m_is_diffIP
flag to switch between IP and LDG an enum could be added for more options
void GetViscousFluxBilinearFormKernel(const unsigned short nDim, const unsigned short FluxDirection, const unsigned short DerivDirection, const T *inaverg, const T *injumpp, const T &mu, T *outarray)
Calculate diffusion flux using the Jacobian form.
void GetViscosityAndThermalCondFromTempKernel(const T &temperature, T &mu, T &thermalCond)
virtual void v_GetViscousFluxVectorDeAlias(const Array< OneD, const Array< OneD, NekDouble > > &physfield, TensorOfArray3D< NekDouble > &derivatives, TensorOfArray3D< NekDouble > &viscousTensor)
Return the flux vector for the LDG diffusion problem.
SOLVER_UTILS_EXPORT void ExtraFldOutputGrid(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables)
Array< OneD, Array< OneD, NekDouble > > m_gridVelocityTrace
Definition ALEHelper.h:142
SOLVER_UTILS_EXPORT void ExtraFldOutputGridVelocity(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables)
int m_spacedim
Spatial dimension (>= expansion dim).
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT int GetNpoints()
SOLVER_UTILS_EXPORT int GetNcoeffs()
bool m_specHP_dealiasing
Flag to determine if dealisising is usde for the Spectral/hp element discretisation.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT int GetTraceTotPoints()
Base class for unsteady solvers.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DiffusionFactory & GetDiffusionFactory()
Definition Diffusion.cpp:39
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:287
bool IEquals(std::string_view a, std::string_view b)
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
Svtsvtp (scalar times vector plus scalar times vector):
Definition Vmath.hpp:475
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.hpp:74
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.hpp:368
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.hpp:182
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.hpp:102
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition Vmath.hpp:56
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828
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.hpp:222