35#define BOOST_TEST_MODULE TestRiemann
45#include <SolverCore/TraceFlux/TraceFluxOp.hpp>
65template <
typename TData>
70 for (
unsigned int c = 0; c < ncomp; ++c)
72 for (
size_t i = 0; i < npts; ++i)
74 flat[c * npts + i] = a[c][i];
80template <
typename TData>
83 unsigned int ncomp,
size_t npts)
85 for (
unsigned int c = 0; c < ncomp; ++c)
87 for (
size_t i = 0; i < npts; ++i)
89 a[c][i] = flat[c * npts + i];
113 const unsigned int nFields = spaceDim + 2;
114 ASSERTL0(U.size() == nFields,
"PrimToCons: wrong U size");
119 for (
unsigned int d = 0; d < spaceDim; ++d)
121 U[1 + d] = W.rho * W.u[d];
122 kin += 0.5 * W.rho * W.u[d] * W.u[d];
125 const double rhoe = W.p / (gamma - 1.0);
126 U[nFields - 1] = rhoe + kin;
130 unsigned int spaceDim,
double gamma)
132 const unsigned int nFields = spaceDim + 2;
133 const double rho = U[0];
135 double mom2_over_rho = 0.0;
136 for (
unsigned int d = 0; d < spaceDim; ++d)
138 const double m = U[1 + d];
139 mom2_over_rho += (m * m) / rho;
142 const double E = U[nFields - 1];
143 const double p = (gamma - 1.0) * (E - 0.5 * mom2_over_rho);
159 unsigned int spaceDim,
double gamma,
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");
170 const double rho = U[0];
171 double u[3] = {0.0, 0.0, 0.0};
173 for (
unsigned int d = 0; d < spaceDim; ++d)
175 u[d] = U[1 + d] / rho;
179 for (
unsigned int d = 0; d < spaceDim; ++d)
185 const double E = U[nFields - 1];
188 fluxDotN[0] = rho * un;
191 for (
unsigned int k = 0; k < spaceDim; ++k)
193 const double momk = U[1 + k];
194 fluxDotN[1 + k] = momk * un + p * n[k];
198 fluxDotN[nFields - 1] = (E + p) * un;
207 const unsigned int nFields = spaceDim + 2;
213 for (
size_t i = 0; i < npts; ++i)
215 for (
unsigned int c = 0; c < nFields; ++c)
227 for (
unsigned int d = 0; d < spaceDim; ++d)
235 return std::sqrt(gamma * p / rho);
253 unsigned int spaceDim,
269 BOOST_REQUIRE_EQUAL(a.size(), b.size());
270 for (
size_t i = 0; i < a.size(); ++i)
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);
279 for (
size_t i = 0; i < f.size(); ++i)
281 BOOST_CHECK(std::isfinite(f[i]));
287 const std::string &xml,
const std::string &exec =
"Serial")
289 BOOST_TEST_MESSAGE(
"Creating input and output fields");
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());
299 for (
int i = 0; i < argc; ++i)
317template <
typename TData>
320 const std::string &method,
const std::string &execStr,
322 size_t npts,
unsigned int nFields,
329 GetBlockAttributes<TData, FieldState::Phys>(dg->GetTrace());
339 "traceNormals", traceAttr, spaceDim, 1);
341 fwdField.template CopyArray<NektarSpaces::HostSpace>(
343 bwdField.template CopyArray<NektarSpaces::HostSpace>(
345 normalsField.template CopyArray<NektarSpaces::HostSpace>(
348 auto vars =
session->GetVariables();
351 op->ApplyUnitTest(normalsField, fwdField, bwdField, flxField);
359 unsigned int spaceDim,
size_t npts,
365 const unsigned int nFields = spaceDim + 2;
367 const double rho = 0.9;
368 const double p = 1.0;
369 double u[3] = {1.0, 2.0, 3.0};
371 for (
size_t i = 0; i < npts; ++i)
378 double mom[3] = {0, 0, 0};
379 for (
unsigned int d = 0; d < spaceDim; ++d)
382 fwd[1 + d][i] = mom[d];
383 bwd[1 + d][i] = mom[d];
387 const double rhoe = p / (gamma - 1.0);
389 for (
unsigned int d = 0; d < spaceDim; ++d)
391 kin += 0.5 * mom[d] * mom[d] / rho;
393 const double E = rhoe + kin;
394 fwd[nFields - 1][i] = E;
395 bwd[nFields - 1][i] = E;
399 for (
unsigned int d = 0; d < spaceDim; ++d)
401 un += u[d] * normals[d][i];
406 fluxRef[0][i] = rho * un;
409 for (
unsigned int k = 0; k < spaceDim; ++k)
411 fluxRef[1 + k][i] = mom[k] * un + p * normals[k][i];
415 fluxRef[nFields - 1][i] = (E + p) * un;
423 const std::string &method,
424 const std::string &execStr,
425 unsigned int normalDir,
double gamma = 1.4)
430 dg->SetDataWarehouse();
431 dg->GetTrace()->SetDataWarehouse();
433 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
434 const size_t npts = dg->GetTrace()->GetTotPoints();
435 const unsigned int nFields = spaceDim + 2;
439 if (normalDir >= spaceDim)
446 for (
unsigned int d = 0; d < spaceDim; ++d)
450 for (
size_t i = 0; i < npts; ++i)
452 normals[normalDir][i] = 1.0;
458 for (
unsigned int c = 0; c < nFields; ++c)
469 ApplyRiemannOperator<double>(
session, method, execStr, dg, spaceDim, npts,
470 nFields, normals, fwd, bwd, flux);
473 for (
unsigned int c = 0; c < nFields; ++c)
475 for (
size_t i = 0; i < npts; ++i)
477 BOOST_CHECK_CLOSE(fluxRef[c][i], flux[c][i], 1e-10);
483 const std::string &execStr,
const PrimState &WL,
491 dg->SetDataWarehouse();
492 dg->GetTrace()->SetDataWarehouse();
494 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
495 const size_t npts = dg->GetTrace()->GetTotPoints();
496 const unsigned int nFields = spaceDim + 2;
498 ASSERTL0(n.size() == spaceDim,
"RunOneRiemannCase: wrong normal size");
501 for (
unsigned int d = 0; d < spaceDim; ++d)
509 for (
unsigned int c = 0; c < nFields; ++c)
518 ApplyRiemannOperator<double>(
session, method, execStr, dg, spaceDim, npts,
519 nFields, normals, fwdArr, bwdArr, fluxArr);
522 for (
unsigned int c = 0; c < nFields; ++c)
524 flux[c] = fluxArr[c][0];
531 const std::string &xml,
const std::string &method,
533 unsigned int spaceDim,
double gamma,
double tol)
539 negNormals[0] = -1.0;
550 BOOST_REQUIRE_EQUAL(f_plus.size(), f_minus.size());
553 for (
size_t i = 0; i < f_plus.size(); ++i)
555 sum[i] = f_plus[i] + f_minus[i];
563 const std::vector<std::string> &ops,
564 const std::string &execStr,
570 const unsigned int spaceDim = dg->GetExp(0)->GetShapeDimension();
571 BOOST_REQUIRE(spaceDim == 2 || spaceDim == 3);
573 const double tol = 1e-10;
581 const std::vector<std::string> EoS = {
"IDEALGAS"};
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};
590 const double rho0 = 1.0;
591 const double p0 = 1.0;
594 for (
double M : Machs)
599 for (
auto &method : ops)
601 BOOST_TEST_CONTEXT(
"Case family 1 Riemann method: "
602 << method <<
", SpaceDim=" << spaceDim
618 const std::vector<std::string> upwindOps = {
619 "HLL",
"HLLC",
"AUSM0",
"AUSM1",
"AUSM2",
"AUSM3",
"Roe"};
624 const double rhoL = 1.0, pL = 1.0;
625 const double rhoR = 0.4, pR = 0.7;
628 const double cA = 0.5 * (cL + cR);
630 auto DoSupersonic = [&](
double ML,
double MR) {
639 for (
auto &method : upwindOps)
641 BOOST_TEST_CONTEXT(
"Case family 2 Riemann method: "
642 << method <<
", SpaceDim=" << spaceDim
643 <<
", ML=" << ML <<
", MR=" << MR)
654 DoSupersonic(+2.5, +2.0);
655 DoSupersonic(-2.5, -2.0);
664 const std::vector<Pair> transonicPairs = {{+0.99, +1.01},
670 for (
auto pr : transonicPairs)
675 for (
auto &method : ops)
677 BOOST_TEST_CONTEXT(
"Case family 3 Riemann method: "
678 << method <<
", SpaceDim=" << spaceDim
679 <<
", ML=" << pr.ML <<
", MR=" << pr.MR)
685 spaceDim, gamma, tol);
695 const std::vector<std::string> ausmOps = {
"AUSM0",
"AUSM1",
"AUSM2",
699 auto ExpectAUSM0or1M0 = [&]() {
700 const unsigned int nFields = spaceDim + 2;
702 const double pbar = 0.5 * (pL + pR);
713 fluxRef[nFields - 1] = 0.0;
717 auto ExpectAUSM2or3M0 = [&](
bool ausm3) {
718 const double rhoA = 0.5 * (rhoL + rhoR);
719 const double pbar = 0.5 * (pL + pR);
721 const double Kp = 0.25;
725 const double Mco = 0.01;
726 fa = Mco * (2.0 - Mco);
729 const double Mp = -(Kp / fa) * ((pR - pL) / (rhoA * cA * cA));
730 const bool cond = (Mp >= 0.0);
732 const double rhoUp = cond ? rhoL : rhoR;
733 const double pUp = cond ? pL : pR;
735 const unsigned int nFields = spaceDim + 2;
739 fluxRef[0] = cA * Mp * rhoUp;
751 fluxRef[nFields - 1] =
752 cA * Mp * (gamma / (gamma - 1.0)) * pUp;
759 for (
auto &method : ausmOps)
761 BOOST_TEST_CONTEXT(
"Case family 4 Riemann method: "
762 << method <<
", SpaceDim=" << spaceDim)
770 (method ==
"AUSM0" || method ==
"AUSM1")
772 : (method ==
"AUSM2" ? ExpectAUSM2or3M0(
false)
773 : ExpectAUSM2or3M0(
true));
789 const std::string &execStr,
790 const std::vector<Case> &cases)
792 for (
const auto &tc : cases)
794 BOOST_TEST_CONTEXT(
"method=" << method <<
" exec=" << execStr <<
" xml="
795 << tc.xml <<
" normalDir=" << tc.normalDir)
802BOOST_AUTO_TEST_SUITE(TestSuiteRiemann)
804#if defined(NEKTAR_ENABLE_DOUBLE_PRECISION)
808 boost::unit_test::framework::master_test_suite().argv[1]);
810 const std::vector<Case> cases = {
811 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
812 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
813 {
"run/hex_Euler.xml", 2},
822 boost::unit_test::framework::master_test_suite().argv[1]);
824 const std::vector<Case> cases = {
825 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
826 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
827 {
"run/hex_Euler.xml", 2},
836 boost::unit_test::framework::master_test_suite().argv[1]);
838 const std::vector<Case> cases = {
839 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
840 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
841 {
"run/hex_Euler.xml", 2},
850 boost::unit_test::framework::master_test_suite().argv[1]);
852 const std::vector<Case> cases = {
853 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
854 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
855 {
"run/hex_Euler.xml", 2},
864 boost::unit_test::framework::master_test_suite().argv[1]);
866 const std::vector<Case> cases = {
867 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
868 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
869 {
"run/hex_Euler.xml", 2},
878 boost::unit_test::framework::master_test_suite().argv[1]);
880 const std::vector<Case> cases = {
881 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
882 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
883 {
"run/hex_Euler.xml", 2},
892 boost::unit_test::framework::master_test_suite().argv[1]);
894 const std::vector<Case> cases = {
895 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
896 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
897 {
"run/hex_Euler.xml", 2},
906 boost::unit_test::framework::master_test_suite().argv[1]);
908 const std::vector<Case> cases = {
909 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
910 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
911 {
"run/hex_Euler.xml", 2},
920 boost::unit_test::framework::master_test_suite().argv[1]);
922 const std::vector<Case> cases = {
923 {
"run/square_Euler.xml", 0}, {
"run/square_Euler.xml", 1},
924 {
"run/hex_Euler.xml", 0}, {
"run/hex_Euler.xml", 1},
925 {
"run/hex_Euler.xml", 2},
931BOOST_AUTO_TEST_SUITE_END()
933BOOST_AUTO_TEST_SUITE(TestSuiteRiemannMach)
938 boost::unit_test::framework::master_test_suite().argv[1]);
940 const std::vector<std::string> ops = {
941 "AverageIDEALGAS",
"LaxFriedrichsIDEALGAS",
"HLLIDEALGAS",
942 "HLLCIDEALGAS",
"AUSM0IDEALGAS",
"AUSM1IDEALGAS",
943 "AUSM2IDEALGAS",
"AUSM3IDEALGAS",
"RoeIDEALGAS"};
945 RunMachTest(
"run/square_Euler.xml", ops, execStr, 1.4);
951 boost::unit_test::framework::master_test_suite().argv[1]);
953 const std::vector<std::string> ops = {
954 "AverageIDEALGAS",
"LaxFriedrichsIDEALGAS",
"HLLIDEALGAS",
955 "HLLCIDEALGAS",
"AUSM0IDEALGAS",
"AUSM1IDEALGAS",
956 "AUSM2IDEALGAS",
"AUSM3IDEALGAS",
"RoeIDEALGAS"};
958 RunMachTest(
"run/hex_Euler.xml", ops, execStr, 1.4);
962BOOST_AUTO_TEST_SUITE_END()
#define ASSERTL0(condition, msg)
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
#define NEKTAR_TEST_GLOBAL_CONFIGURATION(args)
std::map< int64_t, double > sum
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.
Nektar::Array< Nektar::OneD, TDataOut > ToArray()
Copy the data to a Nektar::Array, component by component and element by element, without padding,...
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
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)
static void PrimToCons(const PrimState &W, unsigned int spaceDim, Array< OneD, double > &U, double gamma)
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 void CheckCloseRel(const Array< OneD, const double > &a, const Array< OneD, const double > &b, double tol)
static PrimState MakeStateFromMach(double rho, double p, double M, double cRef)
static void UnflattenCompMajor(const Array< OneD, TData > &flat, Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
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 RunMachTest(const std::string &xml, const std::vector< std::string > &ops, const std::string &execStr, double gamma=1.4)
static double ConsToPressure(const Array< OneD, const double > &U, unsigned int spaceDim, double gamma)
static void RunCasesForOp(const std::string &method, const std::string &execStr, const std::vector< Case > &cases)
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 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 RunConstStateRiemannTest(const std::string &xml, const std::string &method, const std::string &execStr, unsigned int normalDir, double gamma=1.4)
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 Array< OneD, double > PhysicalFlux(const PrimState &W, unsigned int spaceDim, double gamma)
static double SoundSpeedFromRhoP(double rho, double p, double gamma)
static void FillTraceNormals(unsigned int spaceDim, size_t npts, const Array< OneD, const double > &n, Array< OneD, Array< OneD, double > > &normals)
static Array< OneD, TData > FlattenCompMajor(const Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
static LibUtilities::SessionReaderSharedPtr SetSession(const std::string &xml, const std::string &exec="Serial")
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 CheckFinite(const Array< OneD, const double > &f)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< DisContField > DisContFieldSharedPtr
BOOST_AUTO_TEST_CASE(TestCanGetRawPtr)
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.