Nektar++
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
TestFusedElmt< Policy, VISCOUS > Class Template Reference

A fused element-local operator against the separate operators it replaces, for the flux policy Policy, on the mesh of the derived fixture with its expansions replaced: every element of the given expansion type, number of modes and number of points per direction. More...

#include <TestFusedElmt.hpp>

Inheritance diagram for TestFusedElmt< Policy, VISCOUS >:
[legend]

Public Types

using TData = double
 
using PhysField = Field< TData, FieldState::Phys >
 
using FusedElmtOp = std::conditional_t< VISCOUS, SolverCore::AdvDiffFusedElmtOp< TData >, SolverCore::AdvectionFusedElmtOp< TData > >
 

Public Member Functions

 TestFusedElmt ()=default
 
bool RunExpansion (const SpatialDomains::ExpansionType type, const int nmodes, const int npts, const TData tol)
 Run one expansion: type with nmodes modes and, when positive, npts points per direction (the type's own otherwise).
 
- Public Member Functions inherited from TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
 TestOp ()=default
 
virtual ~TestOp ()
 
void Configure (void)
 
void Configure3DH1 (const unsigned int nhomo=1)
 
void Configure3DH2 (const unsigned int nhomoY=1, const unsigned int nhomoZ=1)
 
void SetSession (void)
 
void SetExpList (void)
 
void SetExpList3DH1 (const unsigned int nhomo=1)
 
void SetExpList3DH2 (const unsigned int nhomoY=1, const unsigned int nhomoZ=1)
 
virtual void SetFixture (const unsigned int nhomo)
 
virtual bool Compare (double tol)
 Compare this field to another field, with absolute tolerance tol. The two must have the same blocks and components; their interleave widths may differ.
 

Static Public Attributes

static constexpr unsigned int NDIM = Policy::NDIM
 
static constexpr unsigned int NVAR = Policy::NVAR
 
static constexpr unsigned int NAUX = Policy::NAUX
 

Protected Types

enum class  GradTraceList { None , EveryOther , All }
 Which elements of each block a variant writes the gradient trace of. More...
 

Protected Member Functions

bool HasDeformedQuad ()
 Whether the mesh has a deformed quadrilateral element.
 
bool DefaultImplementation (const SpatialDomains::ExpansionType type, const int nmodes)
 Whether the operator, created on a session that names no implementation, takes the default of each block (MultiRegions::ElmtOp::GetOpImpl()): it exists exactly where the default of every block, read from the default implementation table, has a block operator of this family, which is SumFac on Serial and AVX and SumFacTOP on Device.
 
bool FitsDeviceBlock (const std::string &exec) const
 Whether every element has no more points than a fused thread block may have threads on exec (SolverCore::fusedElmtMaxBlockSize).
 
void SetExpansions (const SpatialDomains::ExpansionType type, const int nmodes, const int npts)
 Read the mesh and give every element type with nmodes modes and npts points, then build the expansion list.
 
void StateValues (const size_t npts)
 The state and the auxiliary fields, every entry different: a positive density and pressure, a velocity of order one and an auxiliary field near one, so that the fluxes are those of a physical state. npts entries per component.
 
void Reference ()
 The separate chain, in the execution space under test, from the inputs StateValues() makes.
 
std::vector< std::vector< unsigned int > > GradTraceElements (const GradTraceList list) const
 The listed elements of each block for list.
 
bool RunVariant (FusedElmtOp &op, const bool interleaved, const GradTraceList list, const TData tol)
 One variant: the fused operator from the inputs the chain took.
 
std::vector< TData > GradTraceExpected (const std::vector< std::vector< unsigned int > > &elements, const std::vector< BlockAttributes< FieldState::Phys > > &traceAttr, PhysField &gradTrace) const
 The chain's gradient trace of the listed elements, laid out as the compact gradient trace field's ToVector() returns it.
 

Static Protected Member Functions

static std::vector< std::string > Components ()
 
static bool Matches (const std::string &what, const std::vector< TData > &out, const std::vector< TData > &expected, const TData tol)
 Whether out matches expected within tol times the largest entry of expected, or times machine epsilon when that is smaller: the inputs are of order one, so an output below epsilon is zero up to round-off (the gradient of a one-mode expansion on a collapsed shape).
 

Protected Attributes

std::vector< TData > m_stateValues
 The inputs, laid out as Field::ToVector() returns them.
 
std::vector< TData > m_auxValues
 
std::vector< TData > m_traceRef
 The chain's outputs, laid out likewise.
 
std::vector< TData > m_normViscRef
 
std::vector< TData > m_outRef
 
std::vector< TData > m_gradTraceRef
 
- Protected Attributes inherited from TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
std::string meshName
 
Field< double, stateIn > * fixt_in
 
Field< double, stateOut > * fixt_out
 
Field< double, stateIn > * fixt_out_2
 
Field< double, stateOut > * fixt_expected
 
std::shared_ptr< MultiRegions::ExpList > fixt_explist
 
LibUtilities::SessionReaderSharedPtr session
 

Additional Inherited Members

- Static Public Member Functions inherited from TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
static void MixInterleaveWidths (TField &field)
 Put the blocks of field at alternating interleave widths, the execution space's vector width on even blocks and 1 on odd ones, reshaping the data in place: a field whose blocks differ in width, for an operator that must read any mix, such as the trace flux, which addresses each trace at the width of the element block it lies in. On Serial every width is 1 and nothing changes.
 

Detailed Description

template<typename Policy, bool VISCOUS>
class TestFusedElmt< Policy, VISCOUS >

A fused element-local operator against the separate operators it replaces, for the flux policy Policy, on the mesh of the derived fixture with its expansions replaced: every element of the given expansion type, number of modes and number of points per direction.

The operator is the advection one (SolverCore::AdvectionFusedElmtOp) or, for VISCOUS, the advection-diffusion one (SolverCore::AdvDiffFusedElmtOp). The separate chain is PhysTraceExtract for the state trace; for the advection-diffusion operator PhysDeriv for the gradient; the policy evaluated point by point for the fluxes; IProductWRTDerivBase with scale -1 for the derivative inner products; and for the advection-diffusion operator PhysTraceExtract::ApplyNormalComponent() of the viscous flux for the normal viscous flux on the traces, and PhysTraceExtract of the gradient for the gradient trace. Each case is run with the fields at width 1 and, where the execution space interleaves, at its vector width, and for the advection-diffusion operator with a gradient trace on every other element and on every element.

Template Parameters
PolicyThe flux policy (TestFusedElmtPolicies.hpp).
VISCOUSTest the advection-diffusion operator rather than the advection one.

Definition at line 81 of file TestFusedElmt.hpp.

Member Typedef Documentation

◆ FusedElmtOp

template<typename Policy , bool VISCOUS>
using TestFusedElmt< Policy, VISCOUS >::FusedElmtOp = std::conditional_t<VISCOUS, SolverCore::AdvDiffFusedElmtOp<TData>, SolverCore::AdvectionFusedElmtOp<TData> >

Definition at line 92 of file TestFusedElmt.hpp.

◆ PhysField

template<typename Policy , bool VISCOUS>
using TestFusedElmt< Policy, VISCOUS >::PhysField = Field<TData, FieldState::Phys>

Definition at line 86 of file TestFusedElmt.hpp.

◆ TData

template<typename Policy , bool VISCOUS>
using TestFusedElmt< Policy, VISCOUS >::TData = double

Definition at line 85 of file TestFusedElmt.hpp.

Member Enumeration Documentation

◆ GradTraceList

template<typename Policy , bool VISCOUS>
enum class TestFusedElmt::GradTraceList
strongprotected

Which elements of each block a variant writes the gradient trace of.

Enumerator
None 
EveryOther 
All 

Definition at line 148 of file TestFusedElmt.hpp.

Constructor & Destructor Documentation

◆ TestFusedElmt()

template<typename Policy , bool VISCOUS>
TestFusedElmt< Policy, VISCOUS >::TestFusedElmt ( )
default

Member Function Documentation

◆ Components()

template<typename Policy , bool VISCOUS>
static std::vector< std::string > TestFusedElmt< Policy, VISCOUS >::Components ( )
inlinestaticprotected

Definition at line 160 of file TestFusedElmt.hpp.

161 {
162 std::vector<std::string> comps;
163 for (unsigned int n = 0; n < NVAR; ++n)
164 {
165 comps.push_back("q" + std::to_string(n));
166 }
167 return comps;
168 }
static constexpr unsigned int NVAR

References TestFusedElmt< Policy, VISCOUS >::NVAR.

Referenced by TestFusedElmt< Policy, VISCOUS >::DefaultImplementation(), TestFusedElmt< Policy, VISCOUS >::Reference(), and TestFusedElmt< Policy, VISCOUS >::RunExpansion().

◆ DefaultImplementation()

template<typename Policy , bool VISCOUS>
bool TestFusedElmt< Policy, VISCOUS >::DefaultImplementation ( const SpatialDomains::ExpansionType  type,
const int  nmodes 
)
inlineprotected

Whether the operator, created on a session that names no implementation, takes the default of each block (MultiRegions::ElmtOp::GetOpImpl()): it exists exactly where the default of every block, read from the default implementation table, has a block operator of this family, which is SumFac on Serial and AVX and SumFacTOP on Device.

Parameters
typeThe expansion type of every element.
nmodesThe number of modes of every element.

Definition at line 208 of file TestFusedElmt.hpp.

210 {
211 const std::string exec = GlobalConfiguration::ExecStr();
212
213 // The fixture's session names the implementation on the command
214 // line, which overrides the default: build one that does not.
215 int argc = 3;
216 char **argv = new char *[argc];
217 argv[0] = strdup("exe_name");
218 argv[1] = strdup(this->meshName.data());
219 argv[2] = strdup(("--opExecSpace=" + exec).c_str());
221 for (int i = 0; i < argc; ++i)
222 {
223 free(argv[i]);
224 }
225 delete[] argv;
226
227 SetExpansions(type, nmodes, -1);
228 this->fixt_explist->SetDataWarehouse();
229
230 const std::string familyImpl =
231 exec == "Device" ? "SumFacTOP" : "SumFac";
232 bool expected = FitsDeviceBlock(exec);
233 for (auto &coll : MultiRegions::GetCollections(this->fixt_explist))
234 {
235 expected =
237 coll.GetExpVector()[0], exec) == familyImpl;
238 }
239 const bool created = static_cast<bool>(FusedElmtOp::Create(
240 this->fixt_explist, Components(), Policy::name, exec));
241 if (created != expected)
242 {
243 std::cout << " modes " << nmodes << ": operator "
244 << (created ? "created" : "not created")
245 << " where the default implementation "
246 << (expected ? "has" : "has no") << " block operator"
247 << std::endl;
248 }
249 return created == expected;
250 }
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::string GetDefaultOpImpl(const StdRegions::StdExpansionSharedPtr &exp, const std::string &execSpace)
Return the implementation a block of elements takes when neither the command line nor the session nam...
Definition Operator.hpp:255
static std::vector< std::string > Components()
void SetExpansions(const SpatialDomains::ExpansionType type, const int nmodes, const int npts)
Read the mesh and give every element type with nmodes modes and npts points, then build the expansion...
bool FitsDeviceBlock(const std::string &exec) const
Whether every element has no more points than a fused thread block may have threads on exec (SolverCo...
Collections::CollectionVector GetCollections(MultiRegions::ExpListSharedPtr expansionList)
STL namespace.

References TestFusedElmt< Policy, VISCOUS >::Components(), Nektar::LibUtilities::SessionReader::CreateInstance(), TestFusedElmt< Policy, VISCOUS >::FitsDeviceBlock(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, Nektar::MultiRegions::GetCollections(), Nektar::MultiRegions::Operator< TData >::GetDefaultOpImpl(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::meshName, TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, and TestFusedElmt< Policy, VISCOUS >::SetExpansions().

◆ FitsDeviceBlock()

template<typename Policy , bool VISCOUS>
bool TestFusedElmt< Policy, VISCOUS >::FitsDeviceBlock ( const std::string &  exec) const
inlineprotected

Whether every element has no more points than a fused thread block may have threads on exec (SolverCore::fusedElmtMaxBlockSize).

Definition at line 254 of file TestFusedElmt.hpp.

255 {
256 bool fits = true;
257 if (exec == "Device")
258 {
259 for (size_t e = 0; e < this->fixt_explist->GetExpSize(); ++e)
260 {
261 fits = fits &&
262 static_cast<unsigned int>(
263 this->fixt_explist->GetExp(e)->GetTotPoints()) <=
264 SolverCore::fusedElmtMaxBlockSize;
265 }
266 }
267 return fits;
268 }

References TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist.

Referenced by TestFusedElmt< Policy, VISCOUS >::DefaultImplementation(), and TestFusedElmt< Policy, VISCOUS >::RunExpansion().

◆ GradTraceElements()

template<typename Policy , bool VISCOUS>
std::vector< std::vector< unsigned int > > TestFusedElmt< Policy, VISCOUS >::GradTraceElements ( const GradTraceList  list) const
inlineprotected

The listed elements of each block for list.

Definition at line 447 of file TestFusedElmt.hpp.

449 {
450 const auto physAttr =
451 GetBlockAttributes<TData, FieldState::Phys>(this->fixt_explist);
452 std::vector<std::vector<unsigned int>> elements(physAttr.size());
453 for (size_t blk = 0; blk < physAttr.size(); ++blk)
454 {
455 for (unsigned int e = 0; e < physAttr[blk].GetNumElements(); ++e)
456 {
457 if (list == GradTraceList::All || e % 2 == 0)
458 {
459 elements[blk].push_back(e);
460 }
461 }
462 }
463 return elements;
464 }

References TestFusedElmt< Policy, VISCOUS >::All, and TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist.

Referenced by TestFusedElmt< Policy, VISCOUS >::RunVariant().

◆ GradTraceExpected()

template<typename Policy , bool VISCOUS>
std::vector< TData > TestFusedElmt< Policy, VISCOUS >::GradTraceExpected ( const std::vector< std::vector< unsigned int > > &  elements,
const std::vector< BlockAttributes< FieldState::Phys > > &  traceAttr,
PhysField &  gradTrace 
) const
inlineprotected

The chain's gradient trace of the listed elements, laid out as the compact gradient trace field's ToVector() returns it.

Definition at line 590 of file TestFusedElmt.hpp.

594 {
595 size_t fullCompSize = 0;
596 for (const auto &attr : traceAttr)
597 {
598 fullCompSize += attr.GetNumElements() * attr.GetNumData();
599 }
600 const size_t compactCompSize =
601 gradTrace.template ToVector<TData>().size() / (NVAR * NDIM);
602
603 std::vector<TData> expected(NVAR * NDIM * compactCompSize, 0.0);
604 for (unsigned int c = 0; c < NVAR * NDIM; ++c)
605 {
606 size_t fullOffset = c * fullCompSize;
607 size_t compactOffset = c * compactCompSize;
608 for (size_t blk = 0; blk < traceAttr.size(); ++blk)
609 {
610 const unsigned int ndata = traceAttr[blk].GetNumData();
611 for (size_t k = 0; k < elements[blk].size(); ++k)
612 {
613 for (unsigned int i = 0; i < ndata; ++i)
614 {
615 expected[compactOffset + k * ndata + i] =
616 m_gradTraceRef[fullOffset +
617 elements[blk][k] * ndata + i];
618 }
619 }
620 fullOffset += traceAttr[blk].GetNumElements() * ndata;
621 compactOffset += elements[blk].size() * ndata;
622 }
623 }
624 return expected;
625 }
std::vector< TData > m_gradTraceRef
static constexpr unsigned int NDIM

References TestFusedElmt< Policy, VISCOUS >::m_gradTraceRef, TestFusedElmt< Policy, VISCOUS >::NDIM, TestFusedElmt< Policy, VISCOUS >::NVAR, and Nektar::LibUtilities::Field< TData, TState >::size().

Referenced by TestFusedElmt< Policy, VISCOUS >::RunVariant().

◆ HasDeformedQuad()

template<typename Policy , bool VISCOUS>
bool TestFusedElmt< Policy, VISCOUS >::HasDeformedQuad ( )
inlineprotected

Whether the mesh has a deformed quadrilateral element.

Order 0 skips such meshes: with one Gauss point per direction the trace normals of a deformed quadrilateral are wrong in LocalRegions::QuadExp::v_ComputeTraceNormal, which reads past its edge array.

Definition at line 178 of file TestFusedElmt.hpp.

179 {
180 if (!this->session)
181 {
182 this->SetSession();
183 }
186 for (auto [id, quad] : graph->GetGeomMap<SpatialDomains::QuadGeom>())
187 {
188 if (graph->GetMeshDimension() == 2 &&
189 quad->CalcGeomType() == SpatialDomains::eDeformed)
190 {
191 return true;
192 }
193 }
194 return false;
195 }
SpatialDomains::MeshGraphSharedPtr graph
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:287

References Nektar::SpatialDomains::eDeformed, graph, Nektar::SpatialDomains::MeshGraphIO::Read(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, and TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::SetSession().

◆ Matches()

template<typename Policy , bool VISCOUS>
static bool TestFusedElmt< Policy, VISCOUS >::Matches ( const std::string &  what,
const std::vector< TData > &  out,
const std::vector< TData > &  expected,
const TData  tol 
)
inlinestaticprotected

Whether out matches expected within tol times the largest entry of expected, or times machine epsilon when that is smaller: the inputs are of order one, so an output below epsilon is zero up to round-off (the gradient of a one-mode expansion on a collapsed shape).

Definition at line 632 of file TestFusedElmt.hpp.

634 {
635 if (out.size() != expected.size())
636 {
637 std::cout << " " << what << ": " << out.size()
638 << " entries against " << expected.size() << std::endl;
639 return false;
640 }
641 TData norm = std::numeric_limits<TData>::epsilon(), err = 0;
642 for (size_t i = 0; i < out.size(); ++i)
643 {
644 norm = std::max(norm, std::abs(expected[i]));
645 err = std::max(err, std::isfinite(out[i])
646 ? std::abs(out[i] - expected[i])
647 : std::numeric_limits<TData>::max());
648 }
649 if (err > tol * norm)
650 {
651 std::cout << " " << what << ": max error " << err
652 << " against max entry " << norm << std::endl;
653 return false;
654 }
655 return true;
656 }
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:304

Referenced by TestFusedElmt< Policy, VISCOUS >::RunVariant().

◆ Reference()

template<typename Policy , bool VISCOUS>
void TestFusedElmt< Policy, VISCOUS >::Reference ( )
inlineprotected

The separate chain, in the execution space under test, from the inputs StateValues() makes.

Definition at line 327 of file TestFusedElmt.hpp.

328 {
329 const auto &explist = this->fixt_explist;
330 const auto comps = Components();
331 const auto physAttr =
332 GetBlockAttributes<TData, FieldState::Phys>(explist);
333 const auto traceAttr =
334 GetLocTraceBlockAttributes<TData, FieldState::Phys>(explist);
335 const std::string exec = GlobalConfiguration::ExecStr();
336
337 PhysField state("state", physAttr, NVAR, 1);
338 PhysField flux("flux", physAttr, NVAR * NDIM, 1);
339 PhysField trace("trace", traceAttr, NVAR, 1);
340 PhysField out("out", physAttr, NVAR, 1);
341 size_t npts = 0;
342 for (const auto &attr : physAttr)
343 {
344 npts += attr.GetNumElements() * attr.GetNumData();
345 }
346 state.template Initialize<NektarSpaces::HostSpace>(0.0);
347 flux.template Initialize<NektarSpaces::HostSpace>(0.0);
348 trace.template Initialize<NektarSpaces::HostSpace>(0.0);
349 out.template Initialize<NektarSpaces::HostSpace>(0.0);
350 StateValues(npts);
351 state.template CopyVector<NektarSpaces::HostSpace>(m_stateValues);
352
353 auto traceOp =
354 PhysTraceExtractOp<TData>::Create(explist, comps, exec, "SumFac");
355 traceOp->Apply(state, trace);
356 m_traceRef = trace.template ToVector<TData>();
357
358 // The gradient, direction-major per variable as PhysDeriv lays it
359 // out, component n * NDIM + d.
360 std::vector<TData> gradValues(NVAR * NDIM * npts, 0.0);
361 if constexpr (VISCOUS)
362 {
363 PhysField grad("grad", physAttr, NVAR * NDIM, 1);
364 grad.template Initialize<NektarSpaces::HostSpace>(0.0);
365 PhysDerivOp<TData>::Create(explist, comps, exec, "SumFac")
366 ->Apply(state, grad);
367 gradValues = grad.template ToVector<TData>();
368
369 std::vector<std::string> gradComps(NVAR * NDIM, "g");
370 PhysField gradTrace("gradTrace", traceAttr, NVAR * NDIM, 1);
371 gradTrace.template Initialize<NektarSpaces::HostSpace>(0.0);
372 PhysTraceExtractOp<TData>::Create(explist, gradComps, exec,
373 "SumFac")
374 ->Apply(grad, gradTrace);
375 m_gradTraceRef = gradTrace.template ToVector<TData>();
376 }
377
378 // The policy point by point.
379 Policy policy(this->session);
380 std::vector<TData> fluxValues(NVAR * NDIM * npts, 0.0);
381 std::vector<TData> viscValues(NVAR * NDIM * npts, 0.0);
382 for (size_t q = 0; q < npts; ++q)
383 {
384 // The advection operator has no viscous flux, and reads no
385 // gradient.
386 TData statePt[NVAR], fluxPt[NDIM][NVAR],
387 viscFluxPt[NDIM][NVAR] = {}, auxPt[NAUX > 0 ? NAUX : 1];
388 [[maybe_unused]] TData gradPt[NDIM][NVAR];
389 for (unsigned int n = 0; n < NVAR; ++n)
390 {
391 statePt[n] = m_stateValues[n * npts + q];
392 for (unsigned int d = 0; d < NDIM; ++d)
393 {
394 gradPt[d][n] = gradValues[(n * NDIM + d) * npts + q];
395 }
396 }
397 for (unsigned int a = 0; a < NAUX; ++a)
398 {
399 auxPt[a] = m_auxValues[a * npts + q];
400 }
401 // The policy's fluxes, combined here rather than through the
402 // operator's own wrappers: flux = viscFlux - advFlux.
403 const TData *auxArg = NAUX > 0 ? auxPt : nullptr;
404 policy.AdvFlux(statePt, auxArg, fluxPt);
405 if constexpr (VISCOUS)
406 {
407 policy.ViscFlux(statePt, gradPt, auxArg, viscFluxPt);
408 }
409 for (unsigned int d = 0; d < NDIM; ++d)
410 {
411 for (unsigned int n = 0; n < NVAR; ++n)
412 {
413 fluxPt[d][n] =
414 (VISCOUS ? viscFluxPt[d][n] : TData(0)) - fluxPt[d][n];
415 }
416 }
417 for (unsigned int n = 0; n < NVAR; ++n)
418 {
419 for (unsigned int d = 0; d < NDIM; ++d)
420 {
421 fluxValues[(n * NDIM + d) * npts + q] = fluxPt[d][n];
422 viscValues[(n * NDIM + d) * npts + q] = viscFluxPt[d][n];
423 }
424 }
425 }
426
427 flux.template CopyVector<NektarSpaces::HostSpace>(fluxValues);
429 explist, comps, exec, "SumFac");
430 iprodOp->SetScale(-1.0);
431 iprodOp->Apply(flux, out);
432 m_outRef = out.template ToVector<TData>();
433
434 if constexpr (VISCOUS)
435 {
436 PhysField visc("visc", physAttr, NVAR * NDIM, 1);
437 PhysField normVisc("normVisc", traceAttr, NVAR, 1);
438 visc.template Initialize<NektarSpaces::HostSpace>(0.0);
439 normVisc.template Initialize<NektarSpaces::HostSpace>(0.0);
440 visc.template CopyVector<NektarSpaces::HostSpace>(viscValues);
441 traceOp->ApplyNormalComponent(visc, normVisc);
442 m_normViscRef = normVisc.template ToVector<TData>();
443 }
444 }
std::vector< NekDouble > grad
static std::shared_ptr< IProductWRTDerivBaseOp< TFieldOut, TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete IProductWRTDerivBase operator through the operator and block-operator factories.
static std::shared_ptr< PhysDerivOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a physical-derivative operator, its per-block operators and, for a multi-plane 3DH1 expansion,...
static std::shared_ptr< PhysTraceExtractOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a trace extraction operator through the operator and block-operator factories.
std::vector< TData > m_stateValues
The inputs, laid out as Field::ToVector() returns them.
void StateValues(const size_t npts)
The state and the auxiliary fields, every entry different: a positive density and pressure,...
std::vector< TData > m_outRef
static constexpr unsigned int NAUX
Field< TData, FieldState::Phys > PhysField
std::vector< TData > m_traceRef
The chain's outputs, laid out likewise.
std::vector< TData > m_auxValues
std::vector< TData > m_normViscRef
std::vector< double > d(NPUPPER *NPUPPER)

References TestFusedElmt< Policy, VISCOUS >::Components(), Nektar::MultiRegions::IProductWRTDerivBaseOp< TFieldOut, TData >::Create(), Nektar::MultiRegions::PhysDerivOp< TData >::Create(), Nektar::MultiRegions::PhysTraceExtractOp< TData >::Create(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, grad, TestFusedElmt< Policy, VISCOUS >::m_auxValues, TestFusedElmt< Policy, VISCOUS >::m_gradTraceRef, TestFusedElmt< Policy, VISCOUS >::m_normViscRef, TestFusedElmt< Policy, VISCOUS >::m_outRef, TestFusedElmt< Policy, VISCOUS >::m_stateValues, TestFusedElmt< Policy, VISCOUS >::m_traceRef, TestFusedElmt< Policy, VISCOUS >::NAUX, TestFusedElmt< Policy, VISCOUS >::NDIM, TestFusedElmt< Policy, VISCOUS >::NVAR, TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, and TestFusedElmt< Policy, VISCOUS >::StateValues().

Referenced by TestFusedElmt< Policy, VISCOUS >::RunExpansion().

◆ RunExpansion()

template<typename Policy , bool VISCOUS>
bool TestFusedElmt< Policy, VISCOUS >::RunExpansion ( const SpatialDomains::ExpansionType  type,
const int  nmodes,
const int  npts,
const TData  tol 
)
inline

Run one expansion: type with nmodes modes and, when positive, npts points per direction (the type's own otherwise).

Returns
Whether every variant matched the chain within tol, relative to the largest entry of each reference.

Definition at line 105 of file TestFusedElmt.hpp.

107 {
108 if (!this->session)
109 {
110 this->SetSession();
111 }
112 SetExpansions(type, nmodes, npts);
113 this->fixt_explist->SetDataWarehouse();
114 Reference();
115
116 const std::string exec = GlobalConfiguration::ExecStr();
117 auto op =
118 FusedElmtOp::Create(this->fixt_explist, Components(), Policy::name,
119 exec, GlobalConfiguration::ImplStr());
120 if (!op)
121 {
122 // Refused rightly only when an element has more points than a
123 // fused thread block may have threads.
124 std::cout << " no fused operator for this mesh" << std::endl;
125 return !FitsDeviceBlock(exec);
126 }
127
128 const bool interleaves = NektarSpaces::GetVectorWidth<TData>(exec) > 1;
129 bool match = RunVariant(*op, false, GradTraceList::None, tol);
130 if (interleaves)
131 {
132 match = RunVariant(*op, true, GradTraceList::None, tol) && match;
133 }
134 if constexpr (VISCOUS)
135 {
136 match =
137 RunVariant(*op, interleaves, GradTraceList::EveryOther, tol) &&
138 match;
139 match = RunVariant(*op, false, GradTraceList::All, tol) && match;
140 // Without a gradient trace again, after one was written.
141 match = RunVariant(*op, false, GradTraceList::None, tol) && match;
142 }
143 return match;
144 }
void Reference()
The separate chain, in the execution space under test, from the inputs StateValues() makes.
bool RunVariant(FusedElmtOp &op, const bool interleaved, const GradTraceList list, const TData tol)
One variant: the fused operator from the inputs the chain took.

References TestFusedElmt< Policy, VISCOUS >::All, TestFusedElmt< Policy, VISCOUS >::Components(), TestFusedElmt< Policy, VISCOUS >::EveryOther, TestFusedElmt< Policy, VISCOUS >::FitsDeviceBlock(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestFusedElmt< Policy, VISCOUS >::None, TestFusedElmt< Policy, VISCOUS >::Reference(), TestFusedElmt< Policy, VISCOUS >::RunVariant(), TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, TestFusedElmt< Policy, VISCOUS >::SetExpansions(), and TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::SetSession().

◆ RunVariant()

template<typename Policy , bool VISCOUS>
bool TestFusedElmt< Policy, VISCOUS >::RunVariant ( FusedElmtOp &  op,
const bool  interleaved,
const GradTraceList  list,
const TData  tol 
)
inlineprotected

One variant: the fused operator from the inputs the chain took.

Definition at line 467 of file TestFusedElmt.hpp.

469 {
470 const auto &explist = this->fixt_explist;
471 const auto physAttr =
472 GetBlockAttributes<TData, FieldState::Phys>(explist);
473 const auto traceAttr =
474 GetLocTraceBlockAttributes<TData, FieldState::Phys>(explist);
475 const std::string exec = GlobalConfiguration::ExecStr();
476
477 PhysField state("state", physAttr, NVAR, 1);
478 PhysField trace("trace", traceAttr, NVAR, 1);
479 PhysField out("out", physAttr, NVAR, 1);
480 state.template Initialize<NektarSpaces::HostSpace>(0.0);
481 trace.template Initialize<NektarSpaces::HostSpace>(0.0);
482 out.template Initialize<NektarSpaces::HostSpace>(0.0);
483 state.template CopyVector<NektarSpaces::HostSpace>(m_stateValues);
484 PhysField aux;
485 if constexpr (NAUX > 0)
486 {
487 aux = PhysField("aux", physAttr, NAUX, 1);
488 aux.template Initialize<NektarSpaces::HostSpace>(0.0);
489 aux.template CopyVector<NektarSpaces::HostSpace>(m_auxValues);
490 }
491 PhysField normVisc;
492 if constexpr (VISCOUS)
493 {
494 normVisc = PhysField("normVisc", traceAttr, NVAR, 1);
495 normVisc.template Initialize<NektarSpaces::HostSpace>(0.0);
496 }
497
498 // The gradient trace on the listed elements only, in list order.
499 const auto elements = GradTraceElements(list);
500 PhysField gradTrace;
501 if constexpr (VISCOUS)
502 {
503 if (list != GradTraceList::None)
504 {
505 const auto vectorWidth =
507 std::vector<BlockAttributes<FieldState::Phys>> gradTraceAttr;
508 for (size_t blk = 0; blk < traceAttr.size(); ++blk)
509 {
510 const size_t nelmt = elements[blk].size();
511 gradTraceAttr.push_back(
512 {nelmt,
513 ((nelmt + vectorWidth - 1) / vectorWidth) *
514 vectorWidth,
515 traceAttr[blk].GetNumData(), 1});
516 }
517 gradTrace =
518 PhysField("gradTrace", gradTraceAttr, NVAR * NDIM, 1);
519 gradTrace.template Initialize<NektarSpaces::HostSpace>(0.0);
520 op.SetGradientTrace(&gradTrace, &elements);
521 }
522 else
523 {
524 op.SetGradientTrace(nullptr, nullptr);
525 }
526 }
527
528 if (interleaved)
529 {
530 // Interleaved at the execution space's vector width: the SIMD
531 // width, the host operators' own, or the warp size.
532 const unsigned int interleaveWidth =
533 NektarSpaces::GetVectorWidth<TData>(exec);
534 state.ReshapeStorage(interleaveWidth, exec);
535 if constexpr (NAUX > 0)
536 {
537 aux.ReshapeStorage(interleaveWidth, exec);
538 }
539 }
540 if constexpr (VISCOUS && NAUX > 0)
541 {
542 op.Apply(state, aux, trace, normVisc, out);
543 }
544 else if constexpr (VISCOUS)
545 {
546 op.Apply(state, trace, normVisc, out);
547 }
548 else if constexpr (NAUX > 0)
549 {
550 op.Apply(state, aux, trace, out);
551 }
552 else
553 {
554 op.Apply(state, trace, out);
555 }
556
557 bool match =
558 Matches("out", out.template ToVector<TData>(), m_outRef, tol);
559 match = Matches("trace", trace.template ToVector<TData>(), m_traceRef,
560 tol) &&
561 match;
562 if constexpr (VISCOUS)
563 {
564 match =
565 Matches("traceNormVisc", normVisc.template ToVector<TData>(),
566 m_normViscRef, tol) &&
567 match;
568 }
569 if (list != GradTraceList::None)
570 {
571 match = Matches("gradTrace", gradTrace.template ToVector<TData>(),
572 GradTraceExpected(elements, traceAttr, gradTrace),
573 tol) &&
574 match;
575 }
576 match = Matches("state", state.template ToVector<TData>(),
577 m_stateValues, TData(0)) &&
578 match;
579 if (!match)
580 {
581 std::cout << " mismatch: interleaved " << interleaved
582 << ", gradient trace list " << static_cast<int>(list)
583 << std::endl;
584 }
585 return match;
586 }
std::vector< TData > GradTraceExpected(const std::vector< std::vector< unsigned int > > &elements, const std::vector< BlockAttributes< FieldState::Phys > > &traceAttr, PhysField &gradTrace) const
The chain's gradient trace of the listed elements, laid out as the compact gradient trace field's ToV...
static bool Matches(const std::string &what, const std::vector< TData > &out, const std::vector< TData > &expected, const TData tol)
Whether out matches expected within tol times the largest entry of expected, or times machine epsilon...
std::vector< std::vector< unsigned int > > GradTraceElements(const GradTraceList list) const
The listed elements of each block for list.
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt

References TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestFusedElmt< Policy, VISCOUS >::GradTraceElements(), TestFusedElmt< Policy, VISCOUS >::GradTraceExpected(), TestFusedElmt< Policy, VISCOUS >::m_auxValues, TestFusedElmt< Policy, VISCOUS >::m_normViscRef, TestFusedElmt< Policy, VISCOUS >::m_outRef, TestFusedElmt< Policy, VISCOUS >::m_stateValues, TestFusedElmt< Policy, VISCOUS >::m_traceRef, TestFusedElmt< Policy, VISCOUS >::Matches(), TestFusedElmt< Policy, VISCOUS >::NAUX, TestFusedElmt< Policy, VISCOUS >::NDIM, TestFusedElmt< Policy, VISCOUS >::None, TestFusedElmt< Policy, VISCOUS >::NVAR, and Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage().

Referenced by TestFusedElmt< Policy, VISCOUS >::RunExpansion().

◆ SetExpansions()

template<typename Policy , bool VISCOUS>
void TestFusedElmt< Policy, VISCOUS >::SetExpansions ( const SpatialDomains::ExpansionType  type,
const int  nmodes,
const int  npts 
)
inlineprotected

Read the mesh and give every element type with nmodes modes and npts points, then build the expansion list.

Definition at line 272 of file TestFusedElmt.hpp.

274 {
276 for (const auto &var : this->session->GetVariables())
277 {
278 for (const auto &expInfo : graph->GetExpansionInfo(var))
279 {
280 expInfo.second->m_basisKeyVector =
282 expInfo.second->m_geomPtr, type, nmodes, npts);
283 }
284 }
285 const auto &vars = this->session->GetVariables();
286 this->fixt_explist =
288 this->session, graph, vars[0], true, true,
290 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static LibUtilities::BasisKeyVector DefineBasisKeyFromExpansionType(Geometry *in, ExpansionType type, const int order, const int numpoints=-1)
The basis keys of expansion type type at order on in, with numpoints quadrature points in every direc...

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::SpatialDomains::MeshGraph::DefineBasisKeyFromExpansionType(), Nektar::Collections::eNoCollection, TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, graph, Nektar::SpatialDomains::MeshGraphIO::Read(), and TestOp< double, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session.

Referenced by TestFusedElmt< Policy, VISCOUS >::DefaultImplementation(), and TestFusedElmt< Policy, VISCOUS >::RunExpansion().

◆ StateValues()

template<typename Policy , bool VISCOUS>
void TestFusedElmt< Policy, VISCOUS >::StateValues ( const size_t  npts)
inlineprotected

The state and the auxiliary fields, every entry different: a positive density and pressure, a velocity of order one and an auxiliary field near one, so that the fluxes are those of a physical state. npts entries per component.

Definition at line 298 of file TestFusedElmt.hpp.

299 {
300 const TData gamma = 1.4;
301 m_stateValues.assign(NVAR * npts, 0.0);
302 m_auxValues.assign(NAUX * npts, 0.0);
303 for (size_t q = 0; q < npts; ++q)
304 {
305 const TData x = TData(0.37) * q;
306 const TData rho = 1.0 + 0.2 * std::sin(x + 0.3);
307 const TData pressure = 1.0 + 0.1 * std::sin(0.7 * x + 1.1);
308 TData kinetic = 0.0;
309 m_stateValues[q] = rho;
310 for (unsigned int d = 0; d < NDIM; ++d)
311 {
312 const TData velocity = 0.3 * std::cos(1.3 * x + d);
313 m_stateValues[(1 + d) * npts + q] = rho * velocity;
314 kinetic += 0.5 * rho * velocity * velocity;
315 }
316 m_stateValues[(NDIM + 1) * npts + q] =
317 pressure / (gamma - 1.0) + kinetic;
318 for (unsigned int a = 0; a < NAUX; ++a)
319 {
320 m_auxValues[a * npts + q] = 1.0 + 0.3 * std::sin(0.9 * x + a);
321 }
322 }
323 }

References TestFusedElmt< Policy, VISCOUS >::m_auxValues, TestFusedElmt< Policy, VISCOUS >::m_stateValues, TestFusedElmt< Policy, VISCOUS >::NAUX, TestFusedElmt< Policy, VISCOUS >::NDIM, and TestFusedElmt< Policy, VISCOUS >::NVAR.

Referenced by TestFusedElmt< Policy, VISCOUS >::Reference().

Member Data Documentation

◆ m_auxValues

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_auxValues
protected

◆ m_gradTraceRef

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_gradTraceRef
protected

◆ m_normViscRef

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_normViscRef
protected

◆ m_outRef

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_outRef
protected

◆ m_stateValues

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_stateValues
protected

The inputs, laid out as Field::ToVector() returns them.

Definition at line 156 of file TestFusedElmt.hpp.

Referenced by TestFusedElmt< Policy, VISCOUS >::Reference(), TestFusedElmt< Policy, VISCOUS >::RunVariant(), and TestFusedElmt< Policy, VISCOUS >::StateValues().

◆ m_traceRef

template<typename Policy , bool VISCOUS>
std::vector<TData> TestFusedElmt< Policy, VISCOUS >::m_traceRef
protected

The chain's outputs, laid out likewise.

Definition at line 158 of file TestFusedElmt.hpp.

Referenced by TestFusedElmt< Policy, VISCOUS >::Reference(), and TestFusedElmt< Policy, VISCOUS >::RunVariant().

◆ NAUX

template<typename Policy , bool VISCOUS>
constexpr unsigned int TestFusedElmt< Policy, VISCOUS >::NAUX = Policy::NAUX
staticconstexpr

◆ NDIM

template<typename Policy , bool VISCOUS>
constexpr unsigned int TestFusedElmt< Policy, VISCOUS >::NDIM = Policy::NDIM
staticconstexpr

◆ NVAR

template<typename Policy , bool VISCOUS>
constexpr unsigned int TestFusedElmt< Policy, VISCOUS >::NVAR = Policy::NVAR
staticconstexpr