39#include <SolverCore/CFL/MaxStdVelocity/MaxStdVelocityOp.hpp>
114 const auto nphys =
m_expList->GetTotPoints();
115 const auto coordim =
m_expList->GetCoordim(0);
126 for (
unsigned int blk = 0; blk <
m_in.
GetBlocks().size(); ++blk)
130 inblock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
134 for (
size_t el = 0, cnt = 0;
el < inblock.GetNumElements();
137 for (
unsigned int phys = 0; phys < inblock.GetNumData();
140 const auto xc =
static_cast<TData
>(x[cnt]);
141 const auto yc =
static_cast<TData
>(y[cnt]);
142 const auto zc =
static_cast<TData
>(z[cnt]);
146 inptr[cnt] =
static_cast<TData
>(0.7 + 0.3 * n) +
147 static_cast<TData
>(0.4) * xc -
148 static_cast<TData
>(0.2) * yc +
149 static_cast<TData
>(0.1) * zc * zc;
153 inptr[cnt] =
static_cast<TData
>(1.3) +
154 static_cast<TData
>(0.2) * xc * xc +
155 static_cast<TData
>(0.05) * yc;
159 inptr += inblock.CompSize();
174 auto op = MaxStdVelocityOp<TData>::Create(
m_expList,
178 op->SetSoundSpeedFactor(TData(0));
181 op->SetSoundSpeedFactor(TData(1));
189 op->SetRootOnly(
true);
190 op->SetSoundSpeedFactor(TData(0));
193 op->SetSoundSpeedFactor(TData(1));
207 const auto report = [&match, tol](
const std::string &desc,
209 const TData expected) {
210 const auto diff = std::abs(actual - expected);
212 diff / (std::max)(std::abs(expected),
static_cast<TData
>(1));
215 std::cout << desc <<
" mismatch: actual=" << actual
216 <<
", expected=" << expected <<
", rel diff=" << rel
222 report(
"Non-interleaved case without wave speed",
m_testNoSound,
236 std::cout <<
"Wave speed made no difference: with="
260 std::string execStr(GlobalConfiguration::ExecStr());
262 BOOST_TEST_MESSAGE(
"Creating input field");
268 char **argv =
new char *[argc];
269 argv[0] = strdup(
"exe_name");
271 argv[2] = strdup((
"--opExecSpace=" + execStr).c_str());
275 for (
int i = 0; i < argc; ++i)
294 const unsigned int ncomp =
m_expList->GetCoordim(0) + 1;
295 auto blockAttr = GetBlockAttributes<TData, FieldState::Phys>(
312 const auto coordim =
m_expList->GetCoordim(0);
313 const auto expdim =
m_expList->GetExp(0)->GetShapeDimension();
314 const auto nElmts =
m_expList->GetExpSize();
317 const auto nphys =
m_expList->GetTotPoints();
322 for (
size_t el = 0;
el < nElmts; ++
el)
326 const auto nqTot = exp->GetTotPoints();
327 const auto &gmat = exp->GetGeomFactors()->GetDerivFactors();
328 const bool deformed =
332 (std::max)(
static_cast<TData
>(exp->EvalBasisNumModesMax()) -
333 static_cast<TData
>(1),
334 static_cast<TData
>(1));
335 const TData weight = order * order;
337 for (
unsigned int q = 0; q < nqTot; ++q)
340 TData sqWithSound = 0;
342 for (
unsigned int i = 0; i < expdim; ++i)
346 for (
unsigned int j = 0; j < coordim; ++j)
348 const TData g =
static_cast<TData
>(
349 gmat[expdim * j + i][deformed ? q : 0]);
350 stdVel += g * in[j * nphys + offset + q];
354 const TData c = in[coordim * nphys + offset + q];
356 const TData velNoSound = std::abs(stdVel);
357 const TData velSound =
358 std::abs(stdVel) + std::abs(stdSound * c);
360 sqNoSound += velNoSound * velNoSound;
361 sqWithSound += velSound * velSound;
365 std::sqrt(sqNoSound) * weight);
374#if defined(NEKTAR_ENABLE_SINGLE_PRECISION)
375#define TESTFLOAT(type, filename) \
376 class type##float : public TestMaxStdVelocity<float> \
381 m_meshName = filename; \
385#define TESTFLOAT(type, filename)
387#if defined(NEKTAR_ENABLE_DOUBLE_PRECISION)
388#define TESTDOUBLE(type, filename) \
389 class type : public TestMaxStdVelocity<double> \
394 m_meshName = filename; \
398#define TESTDOUBLE(type, filename)
400#define TEST(type, filename) \
401 TESTFLOAT(type, filename) \
402 TESTDOUBLE(type, filename)
409TEST(QuadVarP, "run/square_varp.xml")
413TEST(SquareAllElements, "run/square_all_elements.xml")
417TEST(HexVarP, "run/hex_varp.xml")
423TEST(CubeAllElements, "run/cube_all_elements.xml")
425#include <UnitTests/TestBoostTeardown.hpp>
SpatialDomains::MeshGraphSharedPtr graph
#define NEKTAR_TEST_GLOBAL_CONFIGURATION(args)
#define TEST(type, filename)
SpatialDomains::Geometry * el
A Field represents expansion data to be operated on.
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
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 std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Compares MaxStdVelocityOp against the legacy formula.
bool Compare(const TData tol)
Compare both weightings and both storage layouts against the expected values, with relative tolerance...
Field< TData, FieldState::Phys > m_in
TData m_expectedWithSound
void RunTestCase()
Apply the operator with and without the wave speed, once on the non-interleaved storage reduced to ev...
void Configure()
Read the session, build the expansion list and allocate the field the test cases work on.
SessionReaderSharedPtr m_session
ExpListSharedPtr m_expList
~TestMaxStdVelocity()=default
void ExpectedSolution()
The oracle: the legacy computation, element by element on the host.
TestMaxStdVelocity()=default
void SetTestCase()
Fill the velocity components and the wave speed, and record the value the operator is expected to ret...
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
@ eDeformed
Geometry is curved or has non-constant factors.