Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
TestPhysLiftProject< TData > Class Template Reference

The lift-and-project operator against the chain it replaces, IProductWRTPhysTrace (appending) + IProductWRTBase without integration + MultiplyByElmtInvMass + BwdTrans, 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 <TestPhysLiftProject.hpp>

Inheritance diagram for TestPhysLiftProject< TData >:
[legend]

Public Member Functions

 TestPhysLiftProject ()=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< TData, 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 (TData 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.
 

Public Attributes

std::set< std::string > m_forms
 The forms and geometry types the cases run so far reached, as "Pointwise/affine" and so on, with "/direct lift" where the Device SumFac and SumFacTOP implementations lift the trace directly (DirectLift()) and "/dense tail" where the Device SumFacTOP implementation applies the dense projector (PhysLiftProjectDenseTail()).
 

Protected Member Functions

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 RecordForms ()
 Note the form and geometry type of every block.
 
bool RunVariant (const bool lift, const bool append, const TData scale, const bool interleaved, const TData tol)
 One variant: the operator and the chain from the same inputs.
 

Static Protected Member Functions

static bool DirectLift (const LocalRegions::ExpansionSharedPtr &exp)
 Whether the Device SumFac and SumFacTOP implementations lift the trace of the block of exp directly at every point: Pointwise blocks whose trace values lie at volume points, segments, and quadrilaterals and hexahedra whose traces have the volume points in every in-trace direction, and triangles, tetrahedra, prisms and pyramids of one point.
 
static std::vector< TData > Values (Field< TData, FieldState::Phys > &field, const TData seed)
 Values for field, element-local and different in every entry and component.
 
static bool Matches (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.
 

Additional Inherited Members

- Static Public Member Functions inherited from TestOp< TData, 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.
 
- Protected Attributes inherited from TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
std::string meshName
 
Field< TData, stateIn > * fixt_in
 
Field< TData, stateOut > * fixt_out
 
Field< TData, stateIn > * fixt_out_2
 
Field< TData, stateOut > * fixt_expected
 
std::shared_ptr< MultiRegions::ExpList > fixt_explist
 
LibUtilities::SessionReaderSharedPtr session
 

Detailed Description

template<typename TData>
class TestPhysLiftProject< TData >

The lift-and-project operator against the chain it replaces, IProductWRTPhysTrace (appending) + IProductWRTBase without integration + MultiplyByElmtInvMass + BwdTrans, 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.

Each case is run with and without the trace, with the scale left at one and overwriting, and with a scale and appending onto a field that already holds values. Where the execution space interleaves, the case is run again with the inputs handed in at the operator's width, which the weak DG right-hand side does, and the inputs are checked to come back intact.

Definition at line 70 of file TestPhysLiftProject.hpp.

Constructor & Destructor Documentation

◆ TestPhysLiftProject()

template<typename TData >
TestPhysLiftProject< TData >::TestPhysLiftProject ( )
default

Member Function Documentation

◆ DirectLift()

template<typename TData >
static bool TestPhysLiftProject< TData >::DirectLift ( const LocalRegions::ExpansionSharedPtr &  exp)
inlinestaticprotected

Whether the Device SumFac and SumFacTOP implementations lift the trace of the block of exp directly at every point: Pointwise blocks whose trace values lie at volume points, segments, and quadrilaterals and hexahedra whose traces have the volume points in every in-trace direction, and triangles, tetrahedra, prisms and pyramids of one point.

Definition at line 150 of file TestPhysLiftProject.hpp.

151 {
153 MultiRegions::detail::PhysLiftProjectForm::Pointwise)
154 {
155 return false;
156 }
157 const auto shape = exp->DetShapeType();
158 if (shape == LibUtilities::Tri || shape == LibUtilities::Tet ||
159 shape == LibUtilities::Prism || shape == LibUtilities::Pyr)
160 {
161 return exp->GetTotPoints() == 1;
162 }
163 if (shape != LibUtilities::Seg && shape != LibUtilities::Quad &&
164 shape != LibUtilities::Hex)
165 {
166 return false;
167 }
168 const unsigned int dim = exp->GetShapeDimension();
169 const auto pointsKeys = exp->GetPointsKeys();
170 for (unsigned int tr = 0; tr < dim; ++tr)
171 {
172 for (unsigned int d = 0; d + 1 < dim; ++d)
173 {
174 if (!(pointsKeys[exp->GetGeom()->GetDir(tr, d)] ==
175 exp->GetTraceBasisKey(tr, d).GetPointsKey()))
176 {
177 return false;
178 }
179 }
180 }
181 return true;
182 }
PhysLiftProjectForm PhysLiftProjectFormOf(const LocalRegions::ExpansionSharedPtr &exp)
The form the block whose representative expansion is exp takes. The square test is on the total count...
std::vector< double > d(NPUPPER *NPUPPER)

References Nektar::LibUtilities::Hex, Nektar::MultiRegions::detail::PhysLiftProjectFormOf(), Nektar::LibUtilities::Prism, Nektar::LibUtilities::Pyr, Nektar::LibUtilities::Quad, Nektar::LibUtilities::Seg, Nektar::LibUtilities::Tet, and Nektar::LibUtilities::Tri.

Referenced by TestPhysLiftProject< TData >::RecordForms().

◆ Matches()

template<typename TData >
static bool TestPhysLiftProject< TData >::Matches ( 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.

Definition at line 324 of file TestPhysLiftProject.hpp.

326 {
327 TData norm = 0, err = 0;
328 for (size_t i = 0; i < out.size(); ++i)
329 {
330 norm = std::max(norm, std::abs(expected[i]));
331 err = std::max(err, std::isfinite(out[i])
332 ? std::abs(out[i] - expected[i])
333 : std::numeric_limits<TData>::max());
334 }
335 if (err > tol * norm)
336 {
337 std::cout << " max error " << err << " against max entry " << norm
338 << std::endl;
339 return false;
340 }
341 return true;
342 }
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
STL namespace.
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:304

Referenced by TestPhysLiftProject< TData >::RunVariant().

◆ RecordForms()

template<typename TData >
void TestPhysLiftProject< TData >::RecordForms ( )
inlineprotected

Note the form and geometry type of every block.

Definition at line 185 of file TestPhysLiftProject.hpp.

186 {
187 const auto nblocks =
188 GetBlockAttributes<TData, FieldState::Phys>(
189 this->fixt_explist,
190 MultiRegions::UnitInterleaveWidths(this->fixt_explist))
191 .size();
192 for (unsigned int blk = 0; blk < nblocks; ++blk)
193 {
194 const auto exp =
195 GetCollection(this->fixt_explist, blk).GetExpVector()[0];
196 const auto form = MultiRegions::detail::PhysLiftProjectFormOf(exp);
197 const std::string name =
198 form == MultiRegions::detail::PhysLiftProjectForm::Pointwise
199 ? "Pointwise"
200 : form == MultiRegions::detail::PhysLiftProjectForm::StdInvMass
201 ? "StdInvMass"
202 : "ElmtInvMass";
203 const bool deformed =
204 exp->GetGeomFactors()->GetGtype() == SpatialDomains::eDeformed;
205 m_forms.insert(name + (deformed ? "/deformed" : "/affine") +
206 (DirectLift(exp) ? "/direct lift" : "") +
207 (MultiRegions::detail::PhysLiftProjectDenseTail(exp)
208 ? "/dense tail"
209 : ""));
210 }
211 }
std::vector< LocalRegions::ExpansionSharedPtr > & GetExpVector()
Definition Collection.h:102
static bool DirectLift(const LocalRegions::ExpansionSharedPtr &exp)
Whether the Device SumFac and SumFacTOP implementations lift the trace of the block of exp directly a...
std::set< std::string > m_forms
The forms and geometry types the cases run so far reached, as "Pointwise/affine" and so on,...
bool PhysLiftProjectDenseTail(const LocalRegions::ExpansionSharedPtr &exp)
Whether the Device SumFacTOP implementation applies the block whose representative expansion is exp t...
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
@ eDeformed
Geometry is curved or has non-constant factors.

References TestPhysLiftProject< TData >::DirectLift(), Nektar::SpatialDomains::eDeformed, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, Nektar::MultiRegions::GetCollection(), Nektar::Collections::Collection::GetExpVector(), TestPhysLiftProject< TData >::m_forms, Nektar::MultiRegions::detail::PhysLiftProjectDenseTail(), and Nektar::MultiRegions::detail::PhysLiftProjectFormOf().

Referenced by TestPhysLiftProject< TData >::RunExpansion().

◆ RunExpansion()

template<typename TData >
bool TestPhysLiftProject< TData >::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 the reference.

Definition at line 84 of file TestPhysLiftProject.hpp.

86 {
87 if (!this->session)
88 {
89 this->SetSession();
90 }
91 SetExpansions(type, nmodes, npts);
92 this->fixt_explist->SetDataWarehouse();
94
95 bool match = true;
96 for (const bool lift : {true, false})
97 {
98 for (const bool append : {false, true})
99 {
100 const TData scale = append ? TData(-0.7) : TData(1.0);
101 match = RunVariant(lift, append, scale, false, tol) && match;
102 if (GlobalConfiguration::ExecStr() == "AVX")
103 {
104 match = RunVariant(lift, append, scale, true, tol) && match;
105 }
106 }
107 }
108 return match;
109 }
bool RunVariant(const bool lift, const bool append, const TData scale, const bool interleaved, const TData tol)
One variant: the operator and the chain from the same inputs.
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...
void RecordForms()
Note the form and geometry type of every block.
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 const bool append

References TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestPhysLiftProject< TData >::RecordForms(), TestPhysLiftProject< TData >::RunVariant(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, TestPhysLiftProject< TData >::SetExpansions(), and TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::SetSession().

◆ RunVariant()

template<typename TData >
bool TestPhysLiftProject< TData >::RunVariant ( const bool  lift,
const bool  append,
const TData  scale,
const bool  interleaved,
const TData  tol 
)
inlineprotected

One variant: the operator and the chain from the same inputs.

Definition at line 228 of file TestPhysLiftProject.hpp.

230 {
231 const auto &explist = this->fixt_explist;
232 const auto ncomp = this->session->GetVariables().size();
233 const std::vector<std::string> comps(this->session->GetVariables());
234 const auto physAttr = GetBlockAttributes<TData, FieldState::Phys>(
235 explist, MultiRegions::UnitInterleaveWidths(explist));
236 const auto coefAttr = GetBlockAttributes<TData, FieldState::Coeff>(
237 explist, MultiRegions::UnitInterleaveWidths(explist));
238 const auto traceAttr =
239 GetLocTraceBlockAttributes<TData, FieldState::Phys>(explist);
240
241 Field<TData, FieldState::Phys> in("in", physAttr, ncomp, 1);
242 Field<TData, FieldState::Phys> trace("trace", traceAttr, ncomp, 1);
243 Field<TData, FieldState::Phys> out("out", physAttr, ncomp, 1);
244 Field<TData, FieldState::Phys> expected("expected", physAttr, ncomp, 1);
245 Field<TData, FieldState::Phys> sum("sum", physAttr, ncomp, 1);
246 Field<TData, FieldState::Coeff> coef("coef", coefAttr, ncomp, 1);
247 Field<TData, FieldState::Coeff> coef2("coef2", coefAttr, ncomp, 1);
248 in.template Initialize<NektarSpaces::HostSpace>(0.0);
249 trace.template Initialize<NektarSpaces::HostSpace>(0.0);
250 out.template Initialize<NektarSpaces::HostSpace>(0.0);
251 expected.template Initialize<NektarSpaces::HostSpace>(0.0);
252
253 const auto inValues = Values(in, 0.1);
254 const auto traceValues = Values(trace, 0.7);
255 const auto outValues = Values(out, 1.9);
256 in.template CopyVector<NektarSpaces::HostSpace>(inValues);
257 trace.template CopyVector<NektarSpaces::HostSpace>(traceValues);
258 sum.template CopyVector<NektarSpaces::HostSpace>(inValues);
259 if (append)
260 {
261 out.template CopyVector<NektarSpaces::HostSpace>(outValues);
262 expected.template CopyVector<NektarSpaces::HostSpace>(outValues);
263 }
264
265 // The chain, in the execution space under test.
266 const std::string exec = GlobalConfiguration::ExecStr();
267 auto liftOp = IProductWRTPhysTraceOp<TData>::Create(explist, comps,
268 exec, "SumFac");
269 auto bTransOp =
270 IProductWRTBaseOp<TData>::Create(explist, comps, exec, "SumFac");
272 explist, comps, exec, "Generic");
273 auto bwdTransOp =
274 BwdTransOp<TData>::Create(explist, comps, exec, "SumFac");
275 liftOp->SetAppend(true);
276 bTransOp->SetIntegration(false);
277 bTransOp->SetScale(scale);
278 bwdTransOp->SetAppend(append);
279 if (lift)
280 {
281 liftOp->Apply(trace, sum);
282 }
283 bTransOp->Apply(sum, coef);
284 invMassOp->Apply(coef, coef2);
285 bwdTransOp->Apply(coef2, expected);
286
287 // The operator.
288 auto op = PhysLiftProjectOp<TData>::Create(explist, comps, exec);
289 op->SetScale(scale);
290 op->SetAppend(append);
291 if (interleaved)
292 {
293 // Interleaved at the SIMD width, the host operators' own.
294 const unsigned int interleaveWidth = tinysimd::simd<TData>::width;
295 in.ReshapeStorage(interleaveWidth, exec);
296 trace.ReshapeStorage(interleaveWidth, exec);
297 }
298 if (lift)
299 {
300 op->Apply(in, trace, out);
301 }
302 else
303 {
304 op->Apply(in, out);
305 }
306
307 bool match = Matches(out.template ToVector<TData>(),
308 expected.template ToVector<TData>(), tol);
309 match =
310 Matches(in.template ToVector<TData>(), inValues, TData(0)) && match;
311 match =
312 Matches(trace.template ToVector<TData>(), traceValues, TData(0)) &&
313 match;
314 if (!match)
315 {
316 std::cout << " mismatch: lift " << lift << ", append " << append
317 << ", interleaved " << interleaved << std::endl;
318 }
319 return match;
320 }
std::map< int64_t, double > sum
A Field represents expansion data to be operated on.
static std::shared_ptr< BwdTransOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a backward-transform operator through the operator and block-operator factories.
static std::shared_ptr< IProductWRTBaseOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete IProductWRTBase operator through the operator and block-operator factories.
static std::shared_ptr< IProductWRTPhysTraceOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a trace inner-product operator through the operator and block-operator factories.
static std::shared_ptr< MultiplyByElmtInvMassOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Build a complete element-wise inverse mass operator through the operator and block-operator factories...
static std::shared_ptr< PhysLiftProjectOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create the operator through the operator and block-operator factories (see ElmtOp::Create()).
static std::vector< TData > Values(Field< TData, FieldState::Phys > &field, const TData seed)
Values for field, element-local and different in every entry and component.
static bool Matches(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.
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 in
typename abi< ScalarType, width >::type simd
Definition tinysimd.hpp:138

References Nektar::MultiRegions::BwdTransOp< TData >::Create(), Nektar::MultiRegions::IProductWRTBaseOp< TData >::Create(), Nektar::MultiRegions::IProductWRTPhysTraceOp< TData >::Create(), Nektar::MultiRegions::MultiplyByElmtInvMassOp< TData >::Create(), Nektar::MultiRegions::PhysLiftProjectOp< TData >::Create(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestPhysLiftProject< TData >::Matches(), Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, sum, and TestPhysLiftProject< TData >::Values().

Referenced by TestPhysLiftProject< TData >::RunExpansion().

◆ SetExpansions()

template<typename TData >
void TestPhysLiftProject< TData >::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 122 of file TestPhysLiftProject.hpp.

124 {
126 for (const auto &var : this->session->GetVariables())
127 {
128 for (const auto &expInfo : graph->GetExpansionInfo(var))
129 {
130 expInfo.second->m_basisKeyVector =
132 expInfo.second->m_geomPtr, type, nmodes, npts);
133 }
134 }
135 const auto &vars = this->session->GetVariables();
136 this->fixt_explist =
138 this->session, graph, vars[0], true, true,
140 }
SpatialDomains::MeshGraphSharedPtr graph
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...
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::SpatialDomains::MeshGraph::DefineBasisKeyFromExpansionType(), Nektar::Collections::eNoCollection, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, graph, Nektar::SpatialDomains::MeshGraphIO::Read(), and TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session.

Referenced by TestPhysLiftProject< TData >::RunExpansion().

◆ Values()

template<typename TData >
static std::vector< TData > TestPhysLiftProject< TData >::Values ( Field< TData, FieldState::Phys > &  field,
const TData  seed 
)
inlinestaticprotected

Values for field, element-local and different in every entry and component.

Definition at line 215 of file TestPhysLiftProject.hpp.

217 {
218 std::vector<TData> values = field.template ToVector<TData>();
219 for (size_t i = 0; i < values.size(); ++i)
220 {
221 values[i] = TData(0.25) + std::sin(seed + TData(0.37) * i) +
222 TData(0.5) * std::cos(TData(1.3) * seed + 0.11 * i);
223 }
224 return values;
225 }

Referenced by TestPhysLiftProject< TData >::RunVariant().

Member Data Documentation

◆ m_forms

template<typename TData >
std::set<std::string> TestPhysLiftProject< TData >::m_forms

The forms and geometry types the cases run so far reached, as "Pointwise/affine" and so on, with "/direct lift" where the Device SumFac and SumFacTOP implementations lift the trace directly (DirectLift()) and "/dense tail" where the Device SumFacTOP implementation applies the dense projector (PhysLiftProjectDenseTail()).

Definition at line 117 of file TestPhysLiftProject.hpp.

Referenced by TestPhysLiftProject< TData >::RecordForms().