Nektar++
Loading...
Searching...
No Matches
Classes | Macros | Functions
TestRiemann.cpp File Reference
#include <LibUtilities/BasicUtils/VmathArray.hpp>
#include <MultiRegions/DisContField.h>
#include <SpatialDomains/MeshGraphIO.h>
#include <LibUtilities/BasicUtils/Field/Field.hpp>
#include <LibUtilities/BasicUtils/Utils/UtilsKernels.hpp>
#include <CompressibleFlowSolverRedesign/AdvTraceFluxCFE/AdvTraceFluxCFEOp.hpp>
#include <SolverCore/TraceFlux/TraceFluxOp.hpp>
#include <UnitTests/TestBoostSetup.hpp>
#include <UnitTests/TestGlobalConfiguration.hpp>
#include <UnitTests/TestBoostTeardown.hpp>

Go to the source code of this file.

Classes

struct  PrimState
 
struct  Case
 

Macros

#define BOOST_TEST_MODULE   TestRiemann
 

Functions

 NEKTAR_TEST_GLOBAL_CONFIGURATION (Nektar::UnitTests::TestArgs::None)
 
template<typename TData >
static Array< OneD, TData > FlattenCompMajor (const Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
 
template<typename TData >
static void UnflattenCompMajor (const Array< OneD, TData > &flat, Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
 
static void PrimToCons (const PrimState &W, unsigned int spaceDim, Array< OneD, double > &U, double gamma)
 
static double ConsToPressure (const Array< OneD, const double > &U, unsigned int spaceDim, double gamma)
 
static void PhysicalFluxDotN (const Array< OneD, const double > &U, const Array< OneD, const double > &n, unsigned int spaceDim, double gamma, Array< OneD, double > &fluxDotN)
 
static void FillTraceFromPrimStates (unsigned int spaceDim, size_t npts, const PrimState &WL, const PrimState &WR, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, double gamma)
 
static void FillTraceNormals (unsigned int spaceDim, size_t npts, const Array< OneD, const double > &n, Array< OneD, Array< OneD, double > > &normals)
 
static double SoundSpeedFromRhoP (double rho, double p, double gamma)
 
static PrimState MakeStateFromMach (double rho, double p, double M, double cRef)
 
static Array< OneD, double > PhysicalFlux (const PrimState &W, unsigned int spaceDim, double gamma)
 
static void CheckCloseRel (const Array< OneD, const double > &a, const Array< OneD, const double > &b, double tol)
 
static void CheckFinite (const Array< OneD, const double > &f)
 
static LibUtilities::SessionReaderSharedPtr SetSession (const std::string &xml, const std::string &exec="Serial")
 
static MultiRegions::DisContFieldSharedPtr SetExpList (const LibUtilities::SessionReaderSharedPtr &session)
 
template<typename TData >
static void ApplyRiemannOperator (const LibUtilities::SessionReaderSharedPtr &session, const std::string &method, const std::string &execStr, const MultiRegions::DisContFieldSharedPtr &dg, unsigned int spaceDim, size_t npts, unsigned int nFields, const Array< OneD, Array< OneD, TData > > &normals, const Array< OneD, Array< OneD, TData > > &fwd, const Array< OneD, Array< OneD, TData > > &bwd, Array< OneD, Array< OneD, TData > > &flx)
 
static void FillConstStateAndReferenceFlux (unsigned int spaceDim, size_t npts, const Array< OneD, Array< OneD, double > > &normals, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, Array< OneD, Array< OneD, double > > &fluxRef, double gamma)
 
static void RunConstStateRiemannTest (const std::string &xml, const std::string &method, const std::string &execStr, unsigned int normalDir, double gamma=1.4)
 
static void RunOneRiemannCase (const std::string &xml, const std::string &method, const std::string &execStr, const PrimState &WL, const PrimState &WR, const Array< OneD, const double > &n, Array< OneD, double > &flux, double gamma=1.4)
 
static void CheckNormalFlipAntisymmetry (const std::string &xml, const std::string &method, const std::string &execStr, const PrimState &WL, const PrimState &WR, unsigned int spaceDim, double gamma, double tol)
 
static void RunMachTest (const std::string &xml, const std::vector< std::string > &ops, const std::string &execStr, double gamma=1.4)
 
static void RunCasesForOp (const std::string &method, const std::string &execStr, const std::vector< Case > &cases)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   TestRiemann

Function Documentation

◆ ApplyRiemannOperator()

template<typename TData >
static void ApplyRiemannOperator ( const LibUtilities::SessionReaderSharedPtr &  session,
const std::string &  method,
const std::string &  execStr,
const MultiRegions::DisContFieldSharedPtr &  dg,
unsigned int  spaceDim,
size_t  npts,
unsigned int  nFields,
const Array< OneD, Array< OneD, TData > > &  normals,
const Array< OneD, Array< OneD, TData > > &  fwd,
const Array< OneD, Array< OneD, TData > > &  bwd,
Array< OneD, Array< OneD, TData > > &  flx 
)
static

Definition at line 318 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

327{
328 auto traceAttr =
329 GetBlockAttributes<TData, FieldState::Phys>(dg->GetTrace());
330
331 LibUtilities::Field<TData, FieldState::Phys> fwdField("fwd", traceAttr,
332 nFields, 1);
333 LibUtilities::Field<TData, FieldState::Phys> bwdField("bwd", traceAttr,
334 nFields, 1);
335 LibUtilities::Field<TData, FieldState::Phys> flxField("flux", traceAttr,
336 nFields, 1);
337
339 "traceNormals", traceAttr, spaceDim, 1);
340
341 fwdField.template CopyArray<NektarSpaces::HostSpace>(
342 FlattenCompMajor(fwd, nFields, npts));
343 bwdField.template CopyArray<NektarSpaces::HostSpace>(
344 FlattenCompMajor(bwd, nFields, npts));
345 normalsField.template CopyArray<NektarSpaces::HostSpace>(
346 FlattenCompMajor(normals, spaceDim, npts));
347
348 auto vars = session->GetVariables();
349
350 auto op = AdvTraceFluxCFEOp<double>::Create(dg, vars, method, execStr);
351 op->ApplyUnitTest(normalsField, fwdField, bwdField, flxField);
352
353 UnflattenCompMajor(flxField.ToArray(), flx, nFields, npts);
354}
LibUtilities::SessionReaderSharedPtr session
static std::shared_ptr< AdvTraceFluxCFEOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &solverType="", const std::string &execStr="")
Create the implementation registered for solverType.
A Field represents expansion data to be operated on.
static void UnflattenCompMajor(const Array< OneD, TData > &flat, Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
static Array< OneD, TData > FlattenCompMajor(const Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)

References Nektar::AdvTraceFluxCFEOp< TData >::Create(), FlattenCompMajor(), session, Nektar::LibUtilities::Field< TData, TState >::ToArray(), and UnflattenCompMajor().

◆ CheckCloseRel()

static void CheckCloseRel ( const Array< OneD, const double > &  a,
const Array< OneD, const double > &  b,
double  tol 
)
static

Definition at line 266 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

268{
269 BOOST_REQUIRE_EQUAL(a.size(), b.size());
270 for (size_t i = 0; i < a.size(); ++i)
271 {
272 const double denom = std::max({1.0, std::abs(a[i]), std::abs(b[i])});
273 BOOST_CHECK_SMALL((a[i] - b[i]) / denom, tol);
274 }
275}

Referenced by CheckNormalFlipAntisymmetry(), and RunMachTest().

◆ CheckFinite()

static void CheckFinite ( const Array< OneD, const double > &  f)
static

Definition at line 277 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

278{
279 for (size_t i = 0; i < f.size(); ++i)
280 {
281 BOOST_CHECK(std::isfinite(f[i]));
282 }
283}

Referenced by RunMachTest().

◆ CheckNormalFlipAntisymmetry()

static void CheckNormalFlipAntisymmetry ( const std::string &  xml,
const std::string &  method,
const std::string &  execStr,
const PrimState &  WL,
const PrimState &  WR,
unsigned int  spaceDim,
double  gamma,
double  tol 
)
static

Definition at line 530 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

534{
535 Array<OneD, double> normals(spaceDim, 0.0);
536 normals[0] = 1.0;
537
538 Array<OneD, double> negNormals(spaceDim, 0.0);
539 negNormals[0] = -1.0;
540
541 Array<OneD, double> f_plus, f_minus;
542
543 // F(L,R; +n)
544 RunOneRiemannCase(xml, method, execStr, WL, WR, normals, f_plus, gamma);
545
546 // F(R,L; -n)
547 RunOneRiemannCase(xml, method, execStr, WR, WL, negNormals, f_minus, gamma);
548
549 // Check f_plus + f_minus == 0
550 BOOST_REQUIRE_EQUAL(f_plus.size(), f_minus.size());
551
552 Array<OneD, double> sum(f_plus.size(), 0.0);
553 for (size_t i = 0; i < f_plus.size(); ++i)
554 {
555 sum[i] = f_plus[i] + f_minus[i];
556 }
557
558 Array<OneD, double> zero(f_plus.size(), 0.0);
559 CheckCloseRel(sum, zero, tol);
560}
std::map< int64_t, double > sum
static void CheckCloseRel(const Array< OneD, const double > &a, const Array< OneD, const double > &b, double tol)
static void RunOneRiemannCase(const std::string &xml, const std::string &method, const std::string &execStr, const PrimState &WL, const PrimState &WR, const Array< OneD, const double > &n, Array< OneD, double > &flux, double gamma=1.4)
void zero(LibUtilities::MemoryRegion< TData > &x)
Definition Math.hpp:206

References CheckCloseRel(), RunOneRiemannCase(), and sum.

Referenced by RunMachTest().

◆ ConsToPressure()

static double ConsToPressure ( const Array< OneD, const double > &  U,
unsigned int  spaceDim,
double  gamma 
)
inlinestatic

Definition at line 129 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

131{
132 const unsigned int nFields = spaceDim + 2;
133 const double rho = U[0];
134
135 double mom2_over_rho = 0.0;
136 for (unsigned int d = 0; d < spaceDim; ++d)
137 {
138 const double m = U[1 + d];
139 mom2_over_rho += (m * m) / rho;
140 }
141
142 const double E = U[nFields - 1];
143 const double p = (gamma - 1.0) * (E - 0.5 * mom2_over_rho);
144 return p;
145}
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)

Referenced by PhysicalFluxDotN().

◆ FillConstStateAndReferenceFlux()

static void FillConstStateAndReferenceFlux ( unsigned int  spaceDim,
size_t  npts,
const Array< OneD, Array< OneD, double > > &  normals,
Array< OneD, Array< OneD, double > > &  fwd,
Array< OneD, Array< OneD, double > > &  bwd,
Array< OneD, Array< OneD, double > > &  fluxRef,
double  gamma 
)
static

Definition at line 358 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

364{
365 const unsigned int nFields = spaceDim + 2;
366
367 const double rho = 0.9;
368 const double p = 1.0;
369 double u[3] = {1.0, 2.0, 3.0};
370
371 for (size_t i = 0; i < npts; ++i)
372 {
373 // density
374 fwd[0][i] = rho;
375 bwd[0][i] = rho;
376
377 // momentum
378 double mom[3] = {0, 0, 0};
379 for (unsigned int d = 0; d < spaceDim; ++d)
380 {
381 mom[d] = rho * u[d];
382 fwd[1 + d][i] = mom[d];
383 bwd[1 + d][i] = mom[d];
384 }
385
386 // energy
387 const double rhoe = p / (gamma - 1.0);
388 double kin = 0.0;
389 for (unsigned int d = 0; d < spaceDim; ++d)
390 {
391 kin += 0.5 * mom[d] * mom[d] / rho;
392 }
393 const double E = rhoe + kin;
394 fwd[nFields - 1][i] = E;
395 bwd[nFields - 1][i] = E;
396
397 // normal velocity u_n = u dot n
398 double un = 0.0;
399 for (unsigned int d = 0; d < spaceDim; ++d)
400 {
401 un += u[d] * normals[d][i];
402 }
403
404 // reference flux F·n
405 // mass flux is rho * u_n
406 fluxRef[0][i] = rho * un; // mass
407
408 // momentum flux is rho * u * u_n + p * n
409 for (unsigned int k = 0; k < spaceDim; ++k)
410 {
411 fluxRef[1 + k][i] = mom[k] * un + p * normals[k][i];
412 }
413
414 // energy flux is (E + p) * u_n
415 fluxRef[nFields - 1][i] = (E + p) * un;
416 }
417}

Referenced by RunConstStateRiemannTest().

◆ FillTraceFromPrimStates()

static void FillTraceFromPrimStates ( unsigned int  spaceDim,
size_t  npts,
const PrimState &  WL,
const PrimState &  WR,
Array< OneD, Array< OneD, double > > &  fwd,
Array< OneD, Array< OneD, double > > &  bwd,
double  gamma 
)
static

Definition at line 201 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

206{
207 const unsigned int nFields = spaceDim + 2;
208
209 Array<OneD, double> UL(nFields, 0.0), UR(nFields, 0.0);
210 PrimToCons(WL, spaceDim, UL, gamma);
211 PrimToCons(WR, spaceDim, UR, gamma);
212
213 for (size_t i = 0; i < npts; ++i)
214 {
215 for (unsigned int c = 0; c < nFields; ++c)
216 {
217 fwd[c][i] = UL[c];
218 bwd[c][i] = UR[c];
219 }
220 }
221}
static void PrimToCons(const PrimState &W, unsigned int spaceDim, Array< OneD, double > &U, double gamma)

References PrimToCons().

Referenced by RunOneRiemannCase().

◆ FillTraceNormals()

static void FillTraceNormals ( unsigned int  spaceDim,
size_t  npts,
const Array< OneD, const double > &  n,
Array< OneD, Array< OneD, double > > &  normals 
)
static

Definition at line 223 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

226{
227 for (unsigned int d = 0; d < spaceDim; ++d)
228 {
229 Vmath::Fill((int)npts, n[d], normals[d], 1);
230 }
231}
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition Vmath.hpp:56

References Vmath::Fill().

Referenced by RunOneRiemannCase().

◆ FlattenCompMajor()

template<typename TData >
static Array< OneD, TData > FlattenCompMajor ( const Array< OneD, Array< OneD, TData > > &  a,
unsigned int  ncomp,
size_t  npts 
)
static

Definition at line 66 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

68{
69 Array<OneD, TData> flat(ncomp * npts, 0.0);
70 for (unsigned int c = 0; c < ncomp; ++c)
71 {
72 for (size_t i = 0; i < npts; ++i)
73 {
74 flat[c * npts + i] = a[c][i];
75 }
76 }
77 return flat;
78}

Referenced by ApplyRiemannOperator().

◆ MakeStateFromMach()

static PrimState MakeStateFromMach ( double  rho,
double  p,
double  M,
double  cRef 
)
inlinestatic

Definition at line 239 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

241{
242 PrimState W;
243 W.rho = rho;
244 W.p = p;
245 // x-normal velocity only
246 W.u[0] = M * cRef;
247 W.u[1] = 0.0;
248 W.u[2] = 0.0;
249 return W;
250}

Referenced by RunMachTest().

◆ NEKTAR_TEST_GLOBAL_CONFIGURATION()

NEKTAR_TEST_GLOBAL_CONFIGURATION ( Nektar::UnitTests::TestArgs::None  )

◆ PhysicalFlux()

static Array< OneD, double > PhysicalFlux ( const PrimState &  W,
unsigned int  spaceDim,
double  gamma 
)
inlinestatic

Definition at line 252 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

255{
256 Array<OneD, double> U(spaceDim + 2, 0.0), F(spaceDim + 2, 0.0);
257 PrimToCons(W, spaceDim, U, gamma);
258
259 Array<OneD, double> normals(spaceDim, 0.0);
260 // x-normal
261 normals[0] = 1.0;
262 PhysicalFluxDotN(U, normals, spaceDim, gamma, F);
263 return F;
264}
static void PhysicalFluxDotN(const Array< OneD, const double > &U, const Array< OneD, const double > &n, unsigned int spaceDim, double gamma, Array< OneD, double > &fluxDotN)

References PhysicalFluxDotN(), and PrimToCons().

Referenced by RunMachTest().

◆ PhysicalFluxDotN()

static void PhysicalFluxDotN ( const Array< OneD, const double > &  U,
const Array< OneD, const double > &  n,
unsigned int  spaceDim,
double  gamma,
Array< OneD, double > &  fluxDotN 
)
inlinestatic

Definition at line 157 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

161{
162 // Euler physical flux in normal direction
163 // layout: [rho, rhou..., E] length = spaceDim + 2
164 const unsigned int nFields = spaceDim + 2;
165 ASSERTL0(U.size() == nFields, "PhysicalFluxDotN: wrong U size");
166 ASSERTL0(n.size() == spaceDim, "PhysicalFluxDotN: wrong n size");
167 ASSERTL0(fluxDotN.size() == nFields,
168 "PhysicalFluxDotN: wrong fluxDotN size");
169
170 const double rho = U[0];
171 double u[3] = {0.0, 0.0, 0.0};
172
173 for (unsigned int d = 0; d < spaceDim; ++d)
174 {
175 u[d] = U[1 + d] / rho;
176 }
177
178 double un = 0.0;
179 for (unsigned int d = 0; d < spaceDim; ++d)
180 {
181 un += u[d] * n[d];
182 }
183
184 const double p = ConsToPressure(U, spaceDim, gamma);
185 const double E = U[nFields - 1];
186
187 // mass
188 fluxDotN[0] = rho * un;
189
190 // momentum
191 for (unsigned int k = 0; k < spaceDim; ++k)
192 {
193 const double momk = U[1 + k];
194 fluxDotN[1 + k] = momk * un + p * n[k];
195 }
196
197 // energy
198 fluxDotN[nFields - 1] = (E + p) * un;
199}
#define ASSERTL0(condition, msg)
static double ConsToPressure(const Array< OneD, const double > &U, unsigned int spaceDim, double gamma)

References ASSERTL0, and ConsToPressure().

Referenced by PhysicalFlux().

◆ PrimToCons()

static void PrimToCons ( const PrimState &  W,
unsigned int  spaceDim,
Array< OneD, double > &  U,
double  gamma 
)
inlinestatic

Definition at line 109 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

111{
112 // U layout: [rho, rhou..., E] length = spaceDim + 2
113 const unsigned int nFields = spaceDim + 2;
114 ASSERTL0(U.size() == nFields, "PrimToCons: wrong U size");
115
116 U[0] = W.rho;
117
118 double kin = 0.0;
119 for (unsigned int d = 0; d < spaceDim; ++d)
120 {
121 U[1 + d] = W.rho * W.u[d];
122 kin += 0.5 * W.rho * W.u[d] * W.u[d];
123 }
124
125 const double rhoe = W.p / (gamma - 1.0);
126 U[nFields - 1] = rhoe + kin;
127}

References ASSERTL0.

Referenced by FillTraceFromPrimStates(), and PhysicalFlux().

◆ RunCasesForOp()

static void RunCasesForOp ( const std::string &  method,
const std::string &  execStr,
const std::vector< Case > &  cases 
)
static

Definition at line 788 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

791{
792 for (const auto &tc : cases)
793 {
794 BOOST_TEST_CONTEXT("method=" << method << " exec=" << execStr << " xml="
795 << tc.xml << " normalDir=" << tc.normalDir)
796 {
797 RunConstStateRiemannTest(tc.xml, method, execStr, tc.normalDir);
798 }
799 }
800}
static void RunConstStateRiemannTest(const std::string &xml, const std::string &method, const std::string &execStr, unsigned int normalDir, double gamma=1.4)

References RunConstStateRiemannTest().

◆ RunConstStateRiemannTest()

static void RunConstStateRiemannTest ( const std::string &  xml,
const std::string &  method,
const std::string &  execStr,
unsigned int  normalDir,
double  gamma = 1.4 
)
static

Definition at line 422 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

426{
427 auto session = SetSession(xml, execStr);
428 auto dg = SetExpList(session);
429
430 dg->SetDataWarehouse();
431 dg->GetTrace()->SetDataWarehouse();
432
433 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
434 const size_t npts = dg->GetTrace()->GetTotPoints();
435 const unsigned int nFields = spaceDim + 2;
436
437 // If user listed a normalDir that doesn't exist for this mesh dimension,
438 // just skip (use ASSERT if you prefer strict behaviour).
439 if (normalDir >= spaceDim)
440 {
441 return;
442 }
443
444 // normals: unit along normalDir
445 Array<OneD, Array<OneD, double>> normals(spaceDim);
446 for (unsigned int d = 0; d < spaceDim; ++d)
447 {
448 normals[d] = Array<OneD, double>(npts, 0.0);
449 }
450 for (size_t i = 0; i < npts; ++i)
451 {
452 normals[normalDir][i] = 1.0;
453 }
454
455 // arrays
456 Array<OneD, Array<OneD, double>> fwd(nFields), bwd(nFields), flux(nFields),
457 fluxRef(nFields);
458 for (unsigned int c = 0; c < nFields; ++c)
459 {
460 fwd[c] = Array<OneD, double>(npts, 0.0);
461 bwd[c] = Array<OneD, double>(npts, 0.0);
462 flux[c] = Array<OneD, double>(npts, 0.0);
463 fluxRef[c] = Array<OneD, double>(npts, 0.0);
464 }
465
466 FillConstStateAndReferenceFlux(spaceDim, npts, normals, fwd, bwd, fluxRef,
467 gamma);
468
469 ApplyRiemannOperator<double>(session, method, execStr, dg, spaceDim, npts,
470 nFields, normals, fwd, bwd, flux);
471
472 // check
473 for (unsigned int c = 0; c < nFields; ++c)
474 {
475 for (size_t i = 0; i < npts; ++i)
476 {
477 BOOST_CHECK_CLOSE(fluxRef[c][i], flux[c][i], 1e-10);
478 }
479 }
480}
static void FillConstStateAndReferenceFlux(unsigned int spaceDim, size_t npts, const Array< OneD, Array< OneD, double > > &normals, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, Array< OneD, Array< OneD, double > > &fluxRef, double gamma)
static MultiRegions::DisContFieldSharedPtr SetExpList(const LibUtilities::SessionReaderSharedPtr &session)
static LibUtilities::SessionReaderSharedPtr SetSession(const std::string &xml, const std::string &exec="Serial")

References FillConstStateAndReferenceFlux(), session, SetExpList(), and SetSession().

Referenced by RunCasesForOp().

◆ RunMachTest()

static void RunMachTest ( const std::string &  xml,
const std::vector< std::string > &  ops,
const std::string &  execStr,
double  gamma = 1.4 
)
static

Definition at line 562 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

566{
567 // Determine dimension from the mesh.
568 auto session = SetSession(xml, execStr);
569 auto dg = SetExpList(session);
570 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
571 BOOST_REQUIRE(spaceDim == 2 || spaceDim == 3);
572
573 const double tol = 1e-10;
574
575 Array<OneD, double> n(spaceDim, 0.0);
576 n[0] = 1.0;
577
578 //--------------------------------------------------------------------
579 // Equation of state string - currently only setup for Ideal Gas
580 //---------------------------------------------------------------------
581 const std::vector<std::string> EoS = {"IDEALGAS"};
582
583 // ---------------------------------------------------------------------
584 // Case family 1: Consistency for WL==WR across Mach list (ALL ops).
585 // ---------------------------------------------------------------------
586 const std::vector<double> Machs = {-3.0, -1.01, -0.99, -0.2, 0.0,
587 0.2, 0.99, 1.01, 3.0};
588
589 // Pick a base state.
590 const double rho0 = 1.0;
591 const double p0 = 1.0;
592 const double a0 = SoundSpeedFromRhoP(rho0, p0, gamma);
593
594 for (double M : Machs)
595 {
596 PrimState W = MakeStateFromMach(rho0, p0, M, a0);
597 Array<OneD, double> fluxRef = PhysicalFlux(W, spaceDim, gamma);
598
599 for (auto &method : ops)
600 {
601 BOOST_TEST_CONTEXT("Case family 1 Riemann method: "
602 << method << ", SpaceDim=" << spaceDim
603 << ", Mach=" << M)
604 {
606 RunOneRiemannCase(xml, method, execStr, W, W, n, flux, gamma);
607 CheckFinite(flux);
608
609 CheckCloseRel(flux, fluxRef, tol);
610 }
611 }
612 }
613
614 // ---------------------------------------------------------------------
615 // Case family 2: Supersonic upwind limit (upwind solvers only).
616 // Exclude "Average". LaxFriedrichs might not be exact depending on alpha.
617 // ---------------------------------------------------------------------
618 const std::vector<std::string> upwindOps = {
619 "HLL", "HLLC", "AUSM0", "AUSM1", "AUSM2", "AUSM3", "Roe"};
620
621 // Make different left/right states, but same-sign supersonic
622 // Mach. Use cRef based on code-consistent cA for AUSM to hit |M|>=1
623 // reliably:
624 const double rhoL = 1.0, pL = 1.0;
625 const double rhoR = 0.4, pR = 0.7;
626 const double cL = SoundSpeedFromRhoP(rhoL, pL, gamma);
627 const double cR = SoundSpeedFromRhoP(rhoR, pR, gamma);
628 const double cA = 0.5 * (cL + cR);
629
630 auto DoSupersonic = [&](double ML, double MR) {
631 PrimState WL = MakeStateFromMach(rhoL, pL, ML, cA);
632 PrimState WR = MakeStateFromMach(rhoR, pR, MR, cA);
633
634 // Expected: + => left physical flux, - => right physical flux
635 Array<OneD, double> fluxRef = (ML > 0.0 && MR > 0.0)
636 ? PhysicalFlux(WL, spaceDim, gamma)
637 : PhysicalFlux(WR, spaceDim, gamma);
638
639 for (auto &method : upwindOps)
640 {
641 BOOST_TEST_CONTEXT("Case family 2 Riemann method: "
642 << method << ", SpaceDim=" << spaceDim
643 << ", ML=" << ML << ", MR=" << MR)
644 {
646 RunOneRiemannCase(xml, method + EoS[0], execStr, WL, WR, n,
647 flux, gamma);
648 CheckFinite(flux);
649 CheckCloseRel(flux, fluxRef, tol);
650 }
651 }
652 };
653
654 DoSupersonic(+2.5, +2.0);
655 DoSupersonic(-2.5, -2.0);
656
657 // ---------------------------------------------------------------------
658 // Case family 3: Near-sonic / subsonic mixed cases: verify antisymmetry
659 // ---------------------------------------------------------------------
660 struct Pair
661 {
662 double ML, MR;
663 };
664 const std::vector<Pair> transonicPairs = {{+0.99, +1.01},
665 {-0.99, -1.01},
666 {+0.2, -0.2},
667 {-0.2, +0.2},
668 {+0.8, +0.3}};
669
670 for (auto pr : transonicPairs)
671 {
672 PrimState WL = MakeStateFromMach(rhoL, pL, pr.ML, cA);
673 PrimState WR = MakeStateFromMach(rhoR, pR, pr.MR, cA);
674
675 for (auto &method : ops)
676 {
677 BOOST_TEST_CONTEXT("Case family 3 Riemann method: "
678 << method << ", SpaceDim=" << spaceDim
679 << ", ML=" << pr.ML << ", MR=" << pr.MR)
680 {
682 RunOneRiemannCase(xml, method, execStr, WL, WR, n, flux, gamma);
683 CheckFinite(flux);
684 CheckNormalFlipAntisymmetry(xml, method, execStr, WL, WR,
685 spaceDim, gamma, tol);
686 }
687 }
688 }
689
690 // ---------------------------------------------------------------------
691 // Case family 4: M=0 with pressure jump
692 // AUSM0/1: pressure-only (mass=0, energy=0, mom=pbar)
693 // AUSM2/3: include Mp correction (nonzero mass & energy possible)
694 // ---------------------------------------------------------------------
695 const std::vector<std::string> ausmOps = {"AUSM0", "AUSM1", "AUSM2",
696 "AUSM3"};
697
698 {
699 auto ExpectAUSM0or1M0 = [&]() {
700 const unsigned int nFields = spaceDim + 2;
701 Array<OneD, double> fluxRef(nFields, 0.0);
702 const double pbar = 0.5 * (pL + pR);
703 fluxRef[0] = 0.0; // mass
704 fluxRef[1] = pbar; // x-momentum
705 if (spaceDim > 1)
706 {
707 fluxRef[2] = 0.0;
708 }
709 if (spaceDim > 2)
710 {
711 fluxRef[3] = 0.0;
712 }
713 fluxRef[nFields - 1] = 0.0; // energy
714 return fluxRef;
715 };
716
717 auto ExpectAUSM2or3M0 = [&](bool ausm3) {
718 const double rhoA = 0.5 * (rhoL + rhoR);
719 const double pbar = 0.5 * (pL + pR);
720
721 const double Kp = 0.25;
722 double fa = 1.0;
723 if (ausm3)
724 {
725 const double Mco = 0.01;
726 fa = Mco * (2.0 - Mco);
727 }
728
729 const double Mp = -(Kp / fa) * ((pR - pL) / (rhoA * cA * cA));
730 const bool cond = (Mp >= 0.0);
731
732 const double rhoUp = cond ? rhoL : rhoR;
733 const double pUp = cond ? pL : pR;
734
735 const unsigned int nFields = spaceDim + 2;
736 Array<OneD, double> fluxRef(nFields, 0.0);
737
738 // uUp=0 so momentum convective part is 0
739 fluxRef[0] = cA * Mp * rhoUp; // mass
740 fluxRef[1] = pbar; // x-momentum
741 if (spaceDim > 1)
742 {
743 fluxRef[2] = 0.0;
744 }
745 if (spaceDim > 2)
746 {
747 fluxRef[3] = 0.0;
748 }
749
750 // EUp + pUp = gamma/(gamma-1) * pUp (since u=0)
751 fluxRef[nFields - 1] =
752 cA * Mp * (gamma / (gamma - 1.0)) * pUp; // energy
753 return fluxRef;
754 };
755
756 PrimState WL = MakeStateFromMach(rhoL, pL, 0.0, cA);
757 PrimState WR = MakeStateFromMach(rhoR, pR, 0.0, cA);
758
759 for (auto &method : ausmOps)
760 {
761 BOOST_TEST_CONTEXT("Case family 4 Riemann method: "
762 << method << ", SpaceDim=" << spaceDim)
763 {
765 RunOneRiemannCase(xml, method + EoS[0], execStr, WL, WR, n,
766 flux, gamma);
767 CheckFinite(flux);
768
769 Array<OneD, double> fluxRef =
770 (method == "AUSM0" || method == "AUSM1")
771 ? ExpectAUSM0or1M0()
772 : (method == "AUSM2" ? ExpectAUSM2or3M0(false)
773 : ExpectAUSM2or3M0(true));
774 CheckCloseRel(flux, fluxRef, tol);
775 }
776 }
777 }
778}
static PrimState MakeStateFromMach(double rho, double p, double M, double cRef)
static void CheckNormalFlipAntisymmetry(const std::string &xml, const std::string &method, const std::string &execStr, const PrimState &WL, const PrimState &WR, unsigned int spaceDim, double gamma, double tol)
static Array< OneD, double > PhysicalFlux(const PrimState &W, unsigned int spaceDim, double gamma)
static double SoundSpeedFromRhoP(double rho, double p, double gamma)
static void CheckFinite(const Array< OneD, const double > &f)
detail::IdealGasEoS< double > EoS

References CheckCloseRel(), CheckFinite(), CheckNormalFlipAntisymmetry(), MakeStateFromMach(), PhysicalFlux(), RunOneRiemannCase(), session, SetExpList(), SetSession(), and SoundSpeedFromRhoP().

◆ RunOneRiemannCase()

static void RunOneRiemannCase ( const std::string &  xml,
const std::string &  method,
const std::string &  execStr,
const PrimState &  WL,
const PrimState &  WR,
const Array< OneD, const double > &  n,
Array< OneD, double > &  flux,
double  gamma = 1.4 
)
static

Definition at line 482 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

487{
488 auto session = SetSession(xml, execStr);
489 auto dg = SetExpList(session);
490
491 dg->SetDataWarehouse();
492 dg->GetTrace()->SetDataWarehouse();
493
494 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
495 const size_t npts = dg->GetTrace()->GetTotPoints();
496 const unsigned int nFields = spaceDim + 2;
497
498 ASSERTL0(n.size() == spaceDim, "RunOneRiemannCase: wrong normal size");
499
500 Array<OneD, Array<OneD, double>> normals(spaceDim);
501 for (unsigned int d = 0; d < spaceDim; ++d)
502 {
503 normals[d] = Array<OneD, double>(npts, 0.0);
504 }
505 FillTraceNormals(spaceDim, npts, n, normals);
506
507 Array<OneD, Array<OneD, double>> fwdArr(nFields), bwdArr(nFields),
508 fluxArr(nFields);
509 for (unsigned int c = 0; c < nFields; ++c)
510 {
511 fwdArr[c] = Array<OneD, double>(npts, 0.0);
512 bwdArr[c] = Array<OneD, double>(npts, 0.0);
513 fluxArr[c] = Array<OneD, double>(npts, 0.0);
514 }
515
516 FillTraceFromPrimStates(spaceDim, npts, WL, WR, fwdArr, bwdArr, gamma);
517
518 ApplyRiemannOperator<double>(session, method, execStr, dg, spaceDim, npts,
519 nFields, normals, fwdArr, bwdArr, fluxArr);
520
521 flux = Array<OneD, double>(nFields, 0.0);
522 for (unsigned int c = 0; c < nFields; ++c)
523 {
524 flux[c] = fluxArr[c][0];
525 }
526}
static void FillTraceFromPrimStates(unsigned int spaceDim, size_t npts, const PrimState &WL, const PrimState &WR, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, double gamma)
static void FillTraceNormals(unsigned int spaceDim, size_t npts, const Array< OneD, const double > &n, Array< OneD, Array< OneD, double > > &normals)

References ASSERTL0, FillTraceFromPrimStates(), FillTraceNormals(), session, SetExpList(), and SetSession().

Referenced by CheckNormalFlipAntisymmetry(), and RunMachTest().

◆ SetExpList()

static MultiRegions::DisContFieldSharedPtr SetExpList ( const LibUtilities::SessionReaderSharedPtr &  session)
static

Definition at line 308 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

310{
313 session, graph, "DefaultVar", true, true, Collections::eNoCollection);
314}
SpatialDomains::MeshGraphSharedPtr graph
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::Collections::eNoCollection, graph, Nektar::SpatialDomains::MeshGraphIO::Read(), and session.

Referenced by RunConstStateRiemannTest(), RunMachTest(), and RunOneRiemannCase().

◆ SetSession()

static LibUtilities::SessionReaderSharedPtr SetSession ( const std::string &  xml,
const std::string &  exec = "Serial" 
)
static

Definition at line 286 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

288{
289 BOOST_TEST_MESSAGE("Creating input and output fields");
290
291 int argc = 3;
292 char **argv = new char *[argc];
293 argv[0] = strdup("TestRiemannOperator");
294 argv[1] = strdup(xml.c_str());
295 argv[2] = strdup(("--opExecSpace=" + exec).c_str());
296
298
299 for (int i = 0; i < argc; ++i)
300 {
301 free(argv[i]);
302 }
303 delete[] argv;
304
305 return session;
306}
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.

References Nektar::LibUtilities::SessionReader::CreateInstance(), and session.

Referenced by RunConstStateRiemannTest(), RunMachTest(), and RunOneRiemannCase().

◆ SoundSpeedFromRhoP()

static double SoundSpeedFromRhoP ( double  rho,
double  p,
double  gamma 
)
inlinestatic

Definition at line 233 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

234{
235 return std::sqrt(gamma * p / rho);
236}

Referenced by RunMachTest().

◆ UnflattenCompMajor()

template<typename TData >
static void UnflattenCompMajor ( const Array< OneD, TData > &  flat,
Array< OneD, Array< OneD, TData > > &  a,
unsigned int  ncomp,
size_t  npts 
)
static

Definition at line 81 of file edesign/RiemannSolvers/UnitTests/TestRiemann.cpp.

84{
85 for (unsigned int c = 0; c < ncomp; ++c)
86 {
87 for (size_t i = 0; i < npts; ++i)
88 {
89 a[c][i] = flat[c * npts + i];
90 }
91 }
92}

Referenced by ApplyRiemannOperator().