Nektar++
UnsteadyAdvectionDiffusion.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File UnsteadyAdvectionDiffusion.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: Unsteady advection-diffusion solve routines
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 
37 #include <boost/core/ignore_unused.hpp>
38 
41 
42 namespace Nektar
43 {
44  using namespace LibUtilities;
45 
48  "UnsteadyAdvectionDiffusion",
50 
54  : UnsteadySystem(pSession, pGraph),
55  AdvectionSystem(pSession, pGraph)
56  {
57  m_planeNumber = 0;
58  }
59 
60  /**
61  * @brief Initialisation object for the unsteady linear advection
62  * diffusion equation.
63  */
65  {
67 
68  m_session->LoadParameter("wavefreq", m_waveFreq, 0.0);
69  m_session->LoadParameter("epsilon", m_epsilon, 0.0);
70 
71  // turn on substepping
72  m_session->MatchSolverInfo("Extrapolation", "SubStepping",
73  m_subSteppingScheme, false);
74 
75  // Define Velocity fields
77  std::vector<std::string> vel;
78  vel.push_back("Vx");
79  vel.push_back("Vy");
80  vel.push_back("Vz");
81  vel.resize(m_spacedim);
82 
83  GetFunction("AdvectionVelocity")->Evaluate(vel, m_velocity);
84 
85  m_session->MatchSolverInfo(
86  "SpectralVanishingViscosity", "True", m_useSpecVanVisc, false);
87 
89  {
90  m_session->LoadParameter("SVVCutoffRatio",m_sVVCutoffRatio,0.75);
91  m_session->LoadParameter("SVVDiffCoeff",m_sVVDiffCoeff,0.1);
92  }
93 
94  // Type of advection and diffusion classes to be used
95  switch(m_projectionType)
96  {
97  // Discontinuous field
99  {
100  // Do not forwards transform initial condition
101  m_homoInitialFwd = false;
102 
103  // Advection term
104  std::string advName;
105  std::string riemName;
106  m_session->LoadSolverInfo("AdvectionType", advName, "WeakDG");
108  CreateInstance(advName, advName);
109  m_advObject->SetFluxVector(&UnsteadyAdvectionDiffusion::
110  GetFluxVectorAdv, this);
111  m_session->LoadSolverInfo("UpwindType", riemName, "Upwind");
113  CreateInstance(riemName, m_session);
114  m_riemannSolver->SetScalar("Vn", &UnsteadyAdvectionDiffusion::
115  GetNormalVelocity, this);
116  m_advObject->SetRiemannSolver(m_riemannSolver);
117  m_advObject->InitObject (m_session, m_fields);
118 
119  // Diffusion term
121  {
122  std::string diffName;
123  m_session->LoadSolverInfo("DiffusionType", diffName, "LDG");
125  CreateInstance(diffName, diffName);
126  m_diffusion->SetFluxVector(&UnsteadyAdvectionDiffusion::
127  GetFluxVectorDiff, this);
128  m_diffusion->InitObject(m_session, m_fields);
129  }
130 
131  ASSERTL0(m_subSteppingScheme == false,"SubSteppingScheme is not set up for DG projection");
132  break;
133  }
134  // Continuous field
137  {
138  // Advection term
139  std::string advName;
140  m_session->LoadSolverInfo("AdvectionType", advName,
141  "NonConservative");
143  CreateInstance(advName, advName);
144  m_advObject->SetFluxVector(&UnsteadyAdvectionDiffusion::
145  GetFluxVectorAdv, this);
146 
147  if(advName.compare("WeakDG") == 0)
148  {
149  std::string riemName;
150  m_session->LoadSolverInfo("UpwindType", riemName, "Upwind");
152  CreateInstance(riemName, m_session);
153  m_riemannSolver->SetScalar("Vn",
155  GetNormalVelocity, this);
156  m_advObject->SetRiemannSolver(m_riemannSolver);
157  m_advObject->InitObject (m_session, m_fields);
158  }
159 
160  // In case of Galerkin explicit diffusion gives an error
162  {
163  ASSERTL0(false, "Explicit Galerkin diffusion not set up.");
164  }
165  // In case of Galerkin implicit diffusion: do nothing
166  break;
167  }
168  default:
169  {
170  ASSERTL0(false, "Unsupported projection type.");
171  break;
172  }
173  }
174 
180 
181  if(m_subSteppingScheme) // Substepping
182  {
184  "Projection must be set to Mixed_CG_Discontinuous for "
185  "substepping");
187  }
188  }
189 
190  /**
191  * @brief Unsteady linear advection diffusion equation destructor.
192  */
194  {
195  }
196 
197  /**
198  * @brief Get the normal velocity for the unsteady linear advection
199  * diffusion equation.
200  */
202  {
203  return GetNormalVel(m_velocity);
204  }
205 
206 
208  const Array<OneD, const Array<OneD, NekDouble> > &velfield)
209  {
210  // Number of trace (interface) points
211  int i;
212  int nTracePts = GetTraceNpoints();
213 
214  // Auxiliary variable to compute the normal velocity
215  Array<OneD, NekDouble> tmp(nTracePts);
216  m_traceVn = Array<OneD, NekDouble>(nTracePts, 0.0);
217 
218  // Reset the normal velocity
219  Vmath::Zero(nTracePts, m_traceVn, 1);
220 
221  for (i = 0; i < velfield.size(); ++i)
222  {
223  m_fields[0]->ExtractTracePhys(velfield[i], tmp);
224 
225  Vmath::Vvtvp(nTracePts,
226  m_traceNormals[i], 1,
227  tmp, 1,
228  m_traceVn, 1,
229  m_traceVn, 1);
230  }
231 
232  return m_traceVn;
233  }
234 
235  /**
236  * @brief Compute the right-hand side for the unsteady linear advection
237  * diffusion problem.
238  *
239  * @param inarray Given fields.
240  * @param outarray Calculated solution.
241  * @param time Time.
242  */
244  const Array<OneD, const Array<OneD, NekDouble> >&inarray,
245  Array<OneD, Array<OneD, NekDouble> >&outarray,
246  const NekDouble time)
247  {
248  // Number of fields (variables of the problem)
249  int nVariables = inarray.size();
250 
251  // Number of solution points
252  int nSolutionPts = GetNpoints();
253 
254  // RHS computation using the new advection base class
255  m_advObject->Advect(nVariables, m_fields, m_velocity,
256  inarray, outarray, time);
257 
258  // Negate the RHS
259  for (int i = 0; i < nVariables; ++i)
260  {
261  Vmath::Neg(nSolutionPts, outarray[i], 1);
262  }
263 
265  {
266  Array<OneD, Array<OneD, NekDouble> > outarrayDiff(nVariables);
267  for (int i = 0; i < nVariables; ++i)
268  {
269  outarrayDiff[i] = Array<OneD, NekDouble>(nSolutionPts, 0.0);
270  }
271 
272  m_diffusion->Diffuse(nVariables, m_fields, inarray, outarrayDiff);
273 
274  for (int i = 0; i < nVariables; ++i)
275  {
276  Vmath::Vadd(nSolutionPts, &outarrayDiff[i][0], 1,
277  &outarray[i][0], 1, &outarray[i][0], 1);
278  }
279  }
280 
281  }
282 
283  /**
284  * @brief Compute the projection for the unsteady advection
285  * diffusion problem.
286  *
287  * @param inarray Given fields.
288  * @param outarray Calculated solution.
289  * @param time Time.
290  */
292  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
293  Array<OneD, Array<OneD, NekDouble> > &outarray,
294  const NekDouble time)
295  {
296  int i;
297  int nvariables = inarray.size();
298  SetBoundaryConditions(time);
299  switch(m_projectionType)
300  {
302  {
303  // Just copy over array
304  int npoints = GetNpoints();
305 
306  for(i = 0; i < nvariables; ++i)
307  {
308  Vmath::Vcopy(npoints, inarray[i], 1, outarray[i], 1);
309  }
310  break;
311  }
314  {
316 
317  for(i = 0; i < nvariables; ++i)
318  {
319  m_fields[i]->FwdTrans(inarray[i], coeffs);
320  m_fields[i]->BwdTrans_IterPerExp(coeffs, outarray[i]);
321  }
322  break;
323  }
324  default:
325  {
326  ASSERTL0(false, "Unknown projection scheme");
327  break;
328  }
329  }
330  }
331 
332 
333  /* @brief Compute the diffusion term implicitly.
334  *
335  * @param inarray Given fields.
336  * @param outarray Calculated solution.
337  * @param time Time.
338  * @param lambda Diffusion coefficient.
339  */
341  const Array<OneD, const Array<OneD, NekDouble> >&inarray,
342  Array<OneD, Array<OneD, NekDouble> >&outarray,
343  const NekDouble time,
344  const NekDouble lambda)
345  {
346  int nvariables = inarray.size();
347  int nq = m_fields[0]->GetNpoints();
348 
350  factors[StdRegions::eFactorLambda] = 1.0/lambda/m_epsilon;
351 
352  if(m_useSpecVanVisc)
353  {
356  }
358  {
359  factors[StdRegions::eFactorTau] = 1.0;
360  }
361 
362  Array<OneD, Array< OneD, NekDouble> > F(nvariables);
363  for (int n = 0; n < nvariables; ++n)
364  {
365  F[n] = Array<OneD, NekDouble> (nq);
366  }
367 
368  // We solve ( \nabla^2 - HHlambda ) Y[i] = rhs [i]
369  // inarray = input: \hat{rhs} -> output: \hat{Y}
370  // outarray = output: nabla^2 \hat{Y}
371  // where \hat = modal coeffs
372  for (int i = 0; i < nvariables; ++i)
373  {
374  // Multiply 1.0/timestep/lambda
376  inarray[i], 1, F[i], 1);
377  }
378 
379  //Setting boundary conditions
380  SetBoundaryConditions(time);
381 
382  for (int i = 0; i < nvariables; ++i)
383  {
384  // Solve a system of equations with Helmholtz solver
385  m_fields[i]->HelmSolve(F[i], m_fields[i]->UpdateCoeffs(), factors);
386 
387  m_fields[i]->BwdTrans(m_fields[i]->GetCoeffs(), outarray[i]);
388  }
389  }
390 
391  /**
392  * @brief Return the flux vector for the advection part.
393  *
394  * @param physfield Fields.
395  * @param flux Resulting flux.
396  */
398  const Array<OneD, Array<OneD, NekDouble> > &physfield,
400  {
401  ASSERTL1(flux[0].size() == m_velocity.size(),
402  "Dimension of flux array and velocity array do not match");
403 
404  const int nq = m_fields[0]->GetNpoints();
405 
406  for (int i = 0; i < flux.size(); ++i)
407  {
408  for (int j = 0; j < flux[0].size(); ++j)
409  {
410  Vmath::Vmul(nq, physfield[i], 1, m_velocity[j], 1,
411  flux[i][j], 1);
412  }
413  }
414  }
415 
416  /**
417  * @brief Return the flux vector for the diffusion part.
418  *
419  * @param i Equation number.
420  * @param j Spatial direction.
421  * @param physfield Fields.
422  * @param derivatives First order derivatives.
423  * @param flux Resulting flux.
424  */
426  const Array<OneD, Array<OneD, NekDouble> > &inarray,
427  const Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&qfield,
428  Array<OneD, Array<OneD, Array<OneD, NekDouble> > >&viscousTensor)
429  {
430  boost::ignore_unused(inarray);
431 
432  unsigned int nDim = qfield.size();
433  unsigned int nConvectiveFields = qfield[0].size();
434  unsigned int nPts = qfield[0][0].size();
435  for (unsigned int j = 0; j < nDim; ++j)
436  {
437  for (unsigned int i = 0; i < nConvectiveFields; ++i)
438  {
439  Vmath::Smul(nPts, m_epsilon, qfield[j][i], 1,
440  viscousTensor[j][i], 1 );
441  }
442  }
443  }
444 
447  {
449  }
450 
451 
452  /**
453  * Perform the extrapolation.
454  */
456  {
458  {
459  SubStepAdvance(step,m_time);
460  }
461 
462  return false;
463  }
464 
465 
466  /**
467  *
468  */
470  NekDouble time)
471  {
472  int n;
473  int nsubsteps;
474 
475  NekDouble dt;
476 
477  Array<OneD, Array<OneD, NekDouble> > fields, velfields;
478 
479  static int ncalls = 1;
480  int nint = std::min(ncalls++, m_intSteps);
481 
484 
485  LibUtilities::CommSharedPtr comm = m_session->GetComm();
486 
487  // Get the proper time step with CFL control
488  dt = GetSubstepTimeStep();
489 
490  nsubsteps = (m_timestep > dt)? ((int)(m_timestep/dt)+1):1;
491  nsubsteps = std::max(m_minsubsteps, nsubsteps);
492 
493  dt = m_timestep/nsubsteps;
494 
495  if (m_infosteps && !((nstep+1)%m_infosteps) && comm->GetRank() == 0)
496  {
497  std::cout << "Sub-integrating using "<< nsubsteps
498  << " steps over Dt = " << m_timestep
499  << " (SubStep CFL=" << m_cflSafetyFactor << ")"
500  << std::endl;
501  }
502 
503  const TripleArray &solutionVector = m_intScheme->GetSolutionVector();
504 
505  for (int m = 0; m < nint; ++m)
506  {
507  // We need to update the fields held by the m_intScheme
508  fields = solutionVector[m];
509 
510  // Initialise NS solver which is set up to use a GLM method
511  // with calls to EvaluateAdvection_SetPressureBCs and
512  // SolveUnsteadyStokesSystem
514  InitializeScheme(dt, fields, time, m_subStepIntegrationOps);
515 
516  for(n = 0; n < nsubsteps; ++n)
517  {
518  fields = m_subStepIntegrationScheme->
519  TimeIntegrate(n, dt, m_subStepIntegrationOps);
520  }
521 
522  // Reset time integrated solution in m_intScheme
523  m_intScheme->SetSolutionVector(m, fields);
524  }
525  }
526 
527  /**
528  *
529  */
531  {
532  int n_element = m_fields[0]->GetExpSize();
533 
534  const Array<OneD, int> ExpOrder=m_fields[0]->EvalBasisNumModesMaxPerExp();
535  Array<OneD, int> ExpOrderList (n_element, ExpOrder);
536 
537  const NekDouble cLambda = 0.2; // Spencer book pag. 317
538 
539  Array<OneD, NekDouble> tstep (n_element, 0.0);
540  Array<OneD, NekDouble> stdVelocity(n_element, 0.0);
541 
542  stdVelocity = GetMaxStdVelocity(m_velocity);
543 
544  for(int el = 0; el < n_element; ++el)
545  {
546  tstep[el] = m_cflSafetyFactor /
547  (stdVelocity[el] * cLambda *
548  (ExpOrder[el]-1) * (ExpOrder[el]-1));
549  }
550 
551  NekDouble TimeStep = Vmath::Vmin(n_element, tstep, 1);
552  m_session->GetComm()->AllReduce(TimeStep,LibUtilities::ReduceMin);
553 
554  return TimeStep;
555  }
556 
558  const LibUtilities::TimeIntegrationSchemeSharedPtr &IntegrationScheme)
559  {
560  // Set to 1 for first step and it will then be increased in
561  // time advance routines
562  unsigned int order = IntegrationScheme->GetOrder();
563 
564  // Set to 1 for first step and it will then be increased in
565  // time advance routines
566  if ((IntegrationScheme->GetName() == "Euler" &&
567  IntegrationScheme->GetVariant() == "Backward") ||
568  (IntegrationScheme->GetName() == "BDFImplicit" &&
569  (order == 1 || order == 2)))
570  {
571  // Note RK first order SSP is just Forward Euler.
574  .CreateInstance( "RungeKutta", "SSP", order,
575  std::vector<NekDouble>());
576  }
577  else
578  {
579  NEKERROR(ErrorUtil::efatal, "Integration method not suitable: "
580  "Options include BackwardEuler or BDFImplicitOrder1");
581  }
582 
583  m_intSteps = IntegrationScheme->GetNumIntegrationPhases();
584 
585  // set explicit time-integration class operators
588  }
589 
590  /**
591  * Explicit Advection terms used by SubStepAdvance time integration
592  */
594  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
595  Array<OneD, Array<OneD, NekDouble> > &outarray,
596  const NekDouble time)
597  {
598  int i;
599  int nVariables = inarray.size();
600 
601  /// Get the number of coefficients
602  int ncoeffs = m_fields[0]->GetNcoeffs();
603 
604  /// Define an auxiliary variable to compute the RHS
605  Array<OneD, Array<OneD, NekDouble> > WeakAdv(nVariables);
606  WeakAdv[0] = Array<OneD, NekDouble> (ncoeffs*nVariables);
607  for(i = 1; i < nVariables; ++i)
608  {
609  WeakAdv[i] = WeakAdv[i-1] + ncoeffs;
610  }
611 
612  // Currently assume velocity field is time independent and does not therefore
613  // need extrapolating.
614  // RHS computation using the advection base class
615  m_advObject->Advect(nVariables, m_fields, m_velocity,
616  inarray, outarray, time);
617 
618  for(i = 0; i < nVariables; ++i)
619  {
620  m_fields[i]->IProductWRTBase(outarray[i],WeakAdv[i]);
621  // negation requried due to sign of DoAdvection term to be consistent
622  Vmath::Neg(ncoeffs, WeakAdv[i], 1);
623  }
624 
625  AddAdvectionPenaltyFlux(m_velocity, inarray, WeakAdv);
626 
627 
628  /// Operations to compute the RHS
629  for(i = 0; i < nVariables; ++i)
630  {
631  // Negate the RHS
632  Vmath::Neg(ncoeffs, WeakAdv[i], 1);
633 
634  /// Multiply the flux by the inverse of the mass matrix
635  m_fields[i]->MultiplyByElmtInvMass(WeakAdv[i], WeakAdv[i]);
636 
637  /// Store in outarray the physical values of the RHS
638  m_fields[i]->BwdTrans(WeakAdv[i], outarray[i]);
639  }
640  }
641 
642  /**
643  * Projection used by SubStepAdvance time integration
644  */
646  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
647  Array<OneD, Array<OneD, NekDouble> > &outarray,
648  const NekDouble time)
649  {
650  boost::ignore_unused(time);
651 
652  ASSERTL1(inarray.size() == outarray.size(),"Inarray and outarray of different sizes ");
653 
654  for(int i = 0; i < inarray.size(); ++i)
655  {
656  Vmath::Vcopy(inarray[i].size(),inarray[i],1,outarray[i],1);
657  }
658  }
659 
661  const Array<OneD, const Array<OneD, NekDouble> > &velfield,
662  const Array<OneD, const Array<OneD, NekDouble> > &physfield,
663  Array<OneD, Array<OneD, NekDouble> > &Outarray)
664  {
665  ASSERTL1(physfield.size() == Outarray.size(),
666  "Physfield and outarray are of different dimensions");
667 
668  int i;
669 
670  /// Number of trace points
671  int nTracePts = m_fields[0]->GetTrace()->GetNpoints();
672 
673  /// Forward state array
674  Array<OneD, NekDouble> Fwd(3*nTracePts);
675 
676  /// Backward state array
677  Array<OneD, NekDouble> Bwd = Fwd + nTracePts;
678 
679  /// upwind numerical flux state array
680  Array<OneD, NekDouble> numflux = Bwd + nTracePts;
681 
682  /// Normal velocity array
683  Array<OneD, NekDouble> Vn = GetNormalVel(velfield);
684 
685  for(i = 0; i < physfield.size(); ++i)
686  {
687  /// Extract forwards/backwards trace spaces
688  /// Note: Needs to have correct i value to get boundary conditions
689  m_fields[i]->GetFwdBwdTracePhys(physfield[i], Fwd, Bwd);
690 
691  /// Upwind between elements
692  m_fields[0]->GetTrace()->Upwind(Vn, Fwd, Bwd, numflux);
693 
694  /// Construct difference between numflux and Fwd,Bwd
695  Vmath::Vsub(nTracePts, numflux, 1, Fwd, 1, Fwd, 1);
696  Vmath::Vsub(nTracePts, numflux, 1, Bwd, 1, Bwd, 1);
697 
698  /// Calculate the numerical fluxes multipling Fwd, Bwd and
699  /// numflux by the normal advection velocity
700  Vmath::Vmul(nTracePts, Fwd, 1, Vn, 1, Fwd, 1);
701  Vmath::Vmul(nTracePts, Bwd, 1, Vn, 1, Bwd, 1);
702 
703  m_fields[0]->AddFwdBwdTraceIntegral(Fwd,Bwd,Outarray[i]);
704  }
705  }
706 
707 
709  const Array<OneD, Array<OneD,NekDouble> > inarray)
710  {
711 
712  int n_points_0 = m_fields[0]->GetExp(0)->GetTotPoints();
713  int n_element = m_fields[0]->GetExpSize();
714  int nvel = inarray.size();
715  int cnt;
716 
717  ASSERTL0(nvel >= 2, "Method not implemented for 1D");
718 
719  NekDouble pntVelocity;
720 
721  // Getting the standard velocity vector on the 2D normal space
722  Array<OneD, Array<OneD, NekDouble> > stdVelocity(nvel);
723  Array<OneD, NekDouble> maxV(n_element, 0.0);
725 
726  for (int i = 0; i < nvel; ++i)
727  {
728  stdVelocity[i] = Array<OneD, NekDouble>(n_points_0);
729  }
730 
731  if (nvel == 2)
732  {
733  cnt = 0.0;
734  for (int el = 0; el < n_element; ++el)
735  {
736  int n_points = m_fields[0]->GetExp(el)->GetTotPoints();
737  ptsKeys = m_fields[0]->GetExp(el)->GetPointsKeys();
738 
739  // reset local space if necessary
740  if(n_points != n_points_0)
741  {
742  for (int j = 0; j < nvel; ++j)
743  {
744  stdVelocity[j] = Array<OneD, NekDouble>(n_points);
745  }
746  n_points_0 = n_points;
747  }
748 
750  m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo()->GetDerivFactors(ptsKeys);
751 
752  if (m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo()->GetGtype()
754  {
755  for (int i = 0; i < n_points; i++)
756  {
757  stdVelocity[0][i] = gmat[0][i]*inarray[0][i+cnt]
758  + gmat[2][i]*inarray[1][i+cnt];
759 
760  stdVelocity[1][i] = gmat[1][i]*inarray[0][i+cnt]
761  + gmat[3][i]*inarray[1][i+cnt];
762  }
763  }
764  else
765  {
766  for (int i = 0; i < n_points; i++)
767  {
768  stdVelocity[0][i] = gmat[0][0]*inarray[0][i+cnt]
769  + gmat[2][0]*inarray[1][i+cnt];
770 
771  stdVelocity[1][i] = gmat[1][0]*inarray[0][i+cnt]
772  + gmat[3][0]*inarray[1][i+cnt];
773  }
774  }
775 
776  cnt += n_points;
777 
778 
779  for (int i = 0; i < n_points; i++)
780  {
781  pntVelocity = stdVelocity[0][i]*stdVelocity[0][i]
782  + stdVelocity[1][i]*stdVelocity[1][i];
783 
784  if (pntVelocity>maxV[el])
785  {
786  maxV[el] = pntVelocity;
787  }
788  }
789  maxV[el] = sqrt(maxV[el]);
790  }
791  }
792  else
793  {
794  cnt = 0;
795  for (int el = 0; el < n_element; ++el)
796  {
797 
798  int n_points = m_fields[0]->GetExp(el)->GetTotPoints();
799  ptsKeys = m_fields[0]->GetExp(el)->GetPointsKeys();
800 
801  // reset local space if necessary
802  if(n_points != n_points_0)
803  {
804  for (int j = 0; j < nvel; ++j)
805  {
806  stdVelocity[j] = Array<OneD, NekDouble>(n_points);
807  }
808  n_points_0 = n_points;
809  }
810 
812  m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo()->GetDerivFactors(ptsKeys);
813 
814  if (m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo()->GetGtype()
816  {
817  for (int i = 0; i < n_points; i++)
818  {
819  stdVelocity[0][i] = gmat[0][i]*inarray[0][i+cnt]
820  + gmat[3][i]*inarray[1][i+cnt]
821  + gmat[6][i]*inarray[2][i+cnt];
822 
823  stdVelocity[1][i] = gmat[1][i]*inarray[0][i+cnt]
824  + gmat[4][i]*inarray[1][i+cnt]
825  + gmat[7][i]*inarray[2][i+cnt];
826 
827  stdVelocity[2][i] = gmat[2][i]*inarray[0][i+cnt]
828  + gmat[5][i]*inarray[1][i+cnt]
829  + gmat[8][i]*inarray[2][i+cnt];
830  }
831  }
832  else
833  {
834  for (int i = 0; i < n_points; i++)
835  {
836  stdVelocity[0][i] = gmat[0][0]*inarray[0][i+cnt]
837  + gmat[3][0]*inarray[1][i+cnt]
838  + gmat[6][0]*inarray[2][i+cnt];
839 
840  stdVelocity[1][i] = gmat[1][0]*inarray[0][i+cnt]
841  + gmat[4][0]*inarray[1][i+cnt]
842  + gmat[7][0]*inarray[2][i+cnt];
843 
844  stdVelocity[2][i] = gmat[2][0]*inarray[0][i+cnt]
845  + gmat[5][0]*inarray[1][i+cnt]
846  + gmat[8][0]*inarray[2][i+cnt];
847  }
848  }
849 
850  cnt += n_points;
851 
852  for (int i = 0; i < n_points; i++)
853  {
854  pntVelocity = stdVelocity[0][i]*stdVelocity[0][i]
855  + stdVelocity[1][i]*stdVelocity[1][i]
856  + stdVelocity[2][i]*stdVelocity[2][i];
857 
858  if (pntVelocity > maxV[el])
859  {
860  maxV[el] = pntVelocity;
861  }
862  }
863 
864  maxV[el] = sqrt(maxV[el]);
865  //cout << maxV[el]*maxV[el] << endl;
866  }
867  }
868 
869  return maxV;
870  }
871 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:145
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
A base class for PDEs which include an advection component.
SolverUtils::AdvectionSharedPtr m_advObject
Advection term.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
int m_spacedim
Spatial dimension (>= expansion dim).
SOLVER_UTILS_EXPORT int GetTraceNpoints()
NekDouble m_timestep
Time step size.
NekDouble m_time
Current time of simulation.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT int GetExpSize()
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
Array< OneD, Array< OneD, NekDouble > > m_traceNormals
Array holding trace normals for DG simulations in the forwards direction.
SOLVER_UTILS_EXPORT int GetNpoints()
SOLVER_UTILS_EXPORT int GetNcoeffs()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
SOLVER_UTILS_EXPORT void SetBoundaryConditions(NekDouble time)
Evaluates the boundary conditions at the given time.
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction(std::string name, const MultiRegions::ExpListSharedPtr &field=MultiRegions::NullExpListSharedPtr, bool cache=false)
Get a SessionFunction by name.
Base class for unsteady solvers.
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
LibUtilities::TimeIntegrationSchemeSharedPtr m_intScheme
Wrapper to the time integration scheme.
bool m_explicitDiffusion
Indicates if explicit or implicit treatment of diffusion is used.
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &s)
Print a summary of time stepping parameters.
bool m_homoInitialFwd
Flag to determine if simulation should start in homogeneous forward transformed state.
UnsteadyAdvectionDiffusion(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Session reader.
SolverUtils::DiffusionSharedPtr m_diffusion
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Perform the projection.
Array< OneD, NekDouble > & GetNormalVelocity()
Get the normal velocity based on m_velocity.
virtual void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Compute the RHS.
Array< OneD, Array< OneD, NekDouble > > m_velocity
void SetUpSubSteppingTimeIntegration(const LibUtilities::TimeIntegrationSchemeSharedPtr &IntegrationScheme)
virtual void DoImplicitSolve(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, NekDouble time, NekDouble lambda)
Solve implicitly the diffusion term.
void AddAdvectionPenaltyFlux(const Array< OneD, const Array< OneD, NekDouble > > &velfield, const Array< OneD, const Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, NekDouble > > &Outarray)
Array< OneD, NekDouble > & GetNormalVel(const Array< OneD, const Array< OneD, NekDouble > > &velfield)
Get the normal velocity based on input velfield.
void GetFluxVectorAdv(const Array< OneD, Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &flux)
Evaluate the flux at each solution point for the advection part.
static SolverUtils::EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
void SubStepAdvection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
virtual bool v_PreIntegrate(int step)
PreIntegration step for substepping.
void SubStepAdvance(int nstep, NekDouble time)
static std::string className
Name of class.
Array< OneD, NekDouble > GetMaxStdVelocity(const Array< OneD, Array< OneD, NekDouble > > inarray)
SolverUtils::RiemannSolverSharedPtr m_riemannSolver
void GetFluxVectorDiff(const Array< OneD, Array< OneD, NekDouble > > &inarray, const Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &qfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &viscousTensor)
Evaluate the flux at each solution point for the diffusion part.
void SubStepProjection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
LibUtilities::TimeIntegrationSchemeSharedPtr m_subStepIntegrationScheme
virtual void v_InitObject()
Initialise the object.
virtual void v_GenerateSummary(SolverUtils::SummaryList &s)
Print Summary.
LibUtilities::TimeIntegrationSchemeOperators m_subStepIntegrationOps
TimeIntegrationSchemeFactory & GetTimeIntegrationSchemeFactory()
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::vector< PointsKey > PointsKeyVector
Definition: Points.h:246
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:47
std::vector< std::pair< std::string, std::string > > SummaryList
Definition: Misc.h:46
DiffusionFactory & GetDiffusionFactory()
Definition: Diffusion.cpp:41
EquationSystemFactory & GetEquationSystemFactory()
RiemannSolverFactory & GetRiemannSolverFactory()
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:314
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 Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:461
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.cpp:992
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
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267