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

#include <TestMath.hpp>

Public Member Functions

 TestMath ()
 
 ~TestMath ()
 
void Configure ()
 
void SetTestCase ()
 
void abs ()
 
void neg ()
 
void sqrt ()
 
void add ()
 
void sub ()
 
void mul ()
 
void div ()
 
void daxpy (TData alpha)
 
void daxpby (TData alpha, TData beta)
 
void daxpbypcz (TData alpha, TData beta, TData gamma)
 w = alpha x + beta y + gamma z, with z = x.
 
TData sum ()
 
TData max ()
 
TData min ()
 
TData inner_product ()
 
TData l1norm ()
 
TData l2norm ()
 
TData linfnorm ()
 
bool Compare (TData tol)
 Compare this field to another field, with absolute tolerance tol. Two fields must have same storage shape and same components.
 

Protected Member Functions

void Evaluate (const std::string &name, Field< TData, FieldState::Phys > &field, Array< OneD, double > &x, Array< OneD, double > &y, Array< OneD, double > &z, Array< OneD, double > &fce)
 Fills every component of field with the session function name evaluated for the variable of that component.
 

Protected Attributes

std::string m_meshName = ""
 
Field< TData, FieldState::Phys > * m_in1 = nullptr
 
Field< TData, FieldState::Phys > * m_in2 = nullptr
 
Field< TData, FieldState::Phys > * m_out = nullptr
 
Field< TData, FieldState::Phys > * m_expected = nullptr
 
ExpListSharedPtr m_expList
 
SessionReaderSharedPtr m_session
 
Math::MathHelper m_math
 

Detailed Description

template<typename TData>
class TestMath< TData >

Definition at line 69 of file TestMath.hpp.

Constructor & Destructor Documentation

◆ TestMath()

template<typename TData >
TestMath< TData >::TestMath ( )
inline

Definition at line 72 of file TestMath.hpp.

73 {
74 m_meshName = "run/segment.xml";
75 }
std::string m_meshName
Definition TestMath.hpp:660

References TestMath< TData >::m_meshName.

◆ ~TestMath()

template<typename TData >
TestMath< TData >::~TestMath ( )
inline

Definition at line 77 of file TestMath.hpp.

78 {
79 BOOST_TEST_MESSAGE("teardown this->fixture");
80
81 if (this->m_in1)
82 {
83 delete this->m_in1;
84 }
85 if (this->m_in2)
86 {
87 delete this->m_in2;
88 }
89 if (this->m_out)
90 {
91 delete this->m_out;
92 }
93 if (this->m_expected)
94 {
95 delete this->m_expected;
96 }
97 }
Field< TData, FieldState::Phys > * m_expected
Definition TestMath.hpp:664
Field< TData, FieldState::Phys > * m_in1
Definition TestMath.hpp:661
Field< TData, FieldState::Phys > * m_out
Definition TestMath.hpp:663
Field< TData, FieldState::Phys > * m_in2
Definition TestMath.hpp:662

References TestMath< TData >::m_expected, TestMath< TData >::m_in1, TestMath< TData >::m_in2, and TestMath< TData >::m_out.

Member Function Documentation

◆ abs()

template<typename TData >
void TestMath< TData >::abs ( )
inline

Definition at line 161 of file TestMath.hpp.

162 {
163 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
164 {
165 auto x = this->m_in1->GetBlocks()[blk]
166 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
167 auto y = this->m_expected->GetBlocks()[blk]
168 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
169 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
170 this->m_in1->GetBlocks()[blk].GetNumData();
171 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
172
173 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
174 ++nc, x += stride, y += stride)
175 {
176 std::transform(x, x + size, y,
177 [](const TData &xi) { return std::abs(xi); });
178 }
179 }
180 }
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, and TestMath< TData >::m_in1.

◆ add()

template<typename TData >
void TestMath< TData >::add ( )
inline

Definition at line 227 of file TestMath.hpp.

228 {
229 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
230 {
231 auto x = this->m_in1->GetBlocks()[blk]
232 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
233 auto y = this->m_in2->GetBlocks()[blk]
234 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
235 auto z = this->m_expected->GetBlocks()[blk]
236 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
237 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
238 this->m_in1->GetBlocks()[blk].GetNumData();
239 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
240
241 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
242 ++nc, x += stride, y += stride, z += stride)
243 {
244 std::transform(
245 x, x + size, y, z,
246 [](const TData &xi, const TData &yi) { return xi + yi; });
247 }
248 }
249 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ Compare()

template<typename TData >
bool TestMath< TData >::Compare ( TData  tol)
inline

Compare this field to another field, with absolute tolerance tol. Two fields must have same storage shape and same components.

Returns
bool

Definition at line 558 of file TestMath.hpp.

559 {
560 auto rank = this->m_session->GetComm()->GetRank();
561
562 if (this->m_expected->GetNumComponents() !=
563 this->m_out->GetNumComponents())
564 {
565 std::cout << "Mismatch of number of components." << std::endl;
566 return false;
567 }
568
569 if (this->m_expected->GetNumHomoModes() !=
570 this->m_out->GetNumHomoModes())
571 {
572 std::cout << "Mismatch of number of homogeneous modes."
573 << std::endl;
574 return false;
575 }
576
577 if (this->m_expected->GetBlocks().size() !=
578 this->m_out->GetBlocks().size())
579 {
580 std::cout << "Mismatch of block size." << std::endl;
581 return false;
582 }
583
584 bool isMatch = true;
585
586 if (rank == 0)
587 {
588 printf("#elm #pts output expected "
589 "difference\n");
590 }
591 for (unsigned int blk = 0; blk < this->m_out->GetBlocks().size(); ++blk)
592 {
593 const TData *outptr =
594 this->m_out->GetBlocks()[blk]
595 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
596 const TData *expptr =
597 this->m_expected->GetBlocks()[blk]
598 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
599
600 if ((this->m_out->GetBlocks()[blk].GetNumElements() !=
601 this->m_expected->GetBlocks()[blk].GetNumElements()) ||
602 (this->m_out->GetBlocks()[blk].GetNumData() !=
603 this->m_expected->GetBlocks()[blk].GetNumData()))
604 {
605 std::cout << "Mismatch of block structure." << std::endl;
606 return false;
607 }
608
609 for (unsigned int n = 0; n < this->m_out->GetNumComponents() *
610 this->m_out->GetNumHomoModes();
611 ++n)
612 {
613 size_t MisMatchcnt = 0, total = 0;
614
615 for (size_t el = 0, cnt = 0;
616 el < this->m_out->GetBlocks()[blk].GetNumElements(); ++el)
617 {
618 for (unsigned int pts = 0;
619 pts < this->m_out->GetBlocks()[blk].GetNumData();
620 ++pts, ++cnt)
621 {
622 if (std::isnan(outptr[cnt]) ||
623 std::isinf(outptr[cnt]) ||
624 std::abs(outptr[cnt] - expptr[cnt]) > tol)
625 {
626 printf("%04lu %04u %20.16f %20.16f %20.16f\n", el,
627 pts, outptr[cnt], expptr[cnt],
628 std::abs(outptr[cnt] - expptr[cnt]));
629 MisMatchcnt++;
630 }
631 total++;
632 }
633 }
634
635 outptr += this->m_out->GetBlocks()[blk].CompSize();
636 expptr += this->m_expected->GetBlocks()[blk].CompSize();
637
638 if (MisMatchcnt)
639 {
640 std::cout << "Number of mismatches in component " << n
641 << " on block " << blk << " is " << MisMatchcnt
642 << " out of " << total << " on rank: " << rank
643 << std::endl;
644 isMatch = false;
645 }
646 }
647 }
648
649 if (isMatch)
650 {
651 return true;
652 }
653 else
654 {
655 return false;
656 }
657 }
SpatialDomains::Geometry * el
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
SessionReaderSharedPtr m_session
Definition TestMath.hpp:666

References el, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestMath< TData >::m_expected, TestMath< TData >::m_out, TestMath< TData >::m_session, and rank.

◆ Configure()

template<typename TData >
void TestMath< TData >::Configure ( )
inline

Definition at line 99 of file TestMath.hpp.

100 {
101 BOOST_TEST_MESSAGE("Creating input and output fields");
102
103 // Construct a fake command-line argument array to be fed to
104 // Session::Reader::CreateInstance. The first element stands for
105 // the name of the executable which, in our case, doesn't matter.
106 int argc = 2;
107 char **argv = new char *[argc];
108 argv[0] = strdup("exe_name");
109 argv[1] = strdup(m_meshName.data());
110
111 this->m_session = SessionReader::CreateInstance(argc, argv);
113
114 for (int i = 0; i < argc; ++i)
115 {
116 free(argv[i]);
117 }
118 delete[] argv;
119
121 this->m_session, graph, true, "u", Collections::eNoCollection);
122
123 // One component per session variable, so the kernels are exercised
124 // over a field wider than a single component.
125 const auto &components = this->m_session->GetVariables();
126 auto blockAttr = GetBlockAttributes<TData, FieldState::Phys>(
127 m_expList, MultiRegions::UnitInterleaveWidths(m_expList));
128 auto f_in1 =
129 Field<TData, FieldState::Phys>("f_in1", blockAttr, components, 1);
130 auto f_in2 =
131 Field<TData, FieldState::Phys>("f_in2", blockAttr, components, 1);
132 auto f_out =
133 Field<TData, FieldState::Phys>("f_out", blockAttr, components, 1);
134 auto f_expected = Field<TData, FieldState::Phys>(
135 "f_expected", blockAttr, components, 1);
136 this->m_in1 = new Field<TData, FieldState::Phys>(std::move(f_in1));
137 this->m_in2 = new Field<TData, FieldState::Phys>(std::move(f_in2));
138 this->m_out = new Field<TData, FieldState::Phys>(std::move(f_out));
139 this->m_expected =
140 new Field<TData, FieldState::Phys>(std::move(f_expected));
141
142 std::string execName(
143 boost::unit_test::framework::master_test_suite().argv[1]);
144 m_math = Math::MathHelper(execName);
145 }
SpatialDomains::MeshGraphSharedPtr graph
A Field represents expansion data to be operated on.
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)
ExpListSharedPtr m_expList
Definition TestMath.hpp:665
Math::MathHelper m_math
Definition TestMath.hpp:667

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::Collections::eNoCollection, graph, TestMath< TData >::m_expected, TestMath< TData >::m_expList, TestMath< TData >::m_in1, TestMath< TData >::m_in2, TestMath< TData >::m_math, TestMath< TData >::m_meshName, TestMath< TData >::m_out, TestMath< TData >::m_session, and Nektar::SpatialDomains::MeshGraphIO::Read().

◆ daxpby()

template<typename TData >
void TestMath< TData >::daxpby ( TData  alpha,
TData  beta 
)
inline

Definition at line 349 of file TestMath.hpp.

350 {
351 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
352 {
353 auto x = this->m_in1->GetBlocks()[blk]
354 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
355 auto y = this->m_in2->GetBlocks()[blk]
356 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
357 auto z = this->m_expected->GetBlocks()[blk]
358 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
359 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
360 this->m_in1->GetBlocks()[blk].GetNumData();
361 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
362
363 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
364 ++nc, x += stride, y += stride, z += stride)
365 {
366 std::transform(x, x + size, y, z,
367 [=](const TData &xi, const TData &yi) {
368 return alpha * xi + beta * yi;
369 });
370 }
371 }
372 }
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59

References Nektar::LibUtilities::beta, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ daxpbypcz()

template<typename TData >
void TestMath< TData >::daxpbypcz ( TData  alpha,
TData  beta,
TData  gamma 
)
inline

w = alpha x + beta y + gamma z, with z = x.

Definition at line 375 of file TestMath.hpp.

376 {
377 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
378 {
379 auto x = this->m_in1->GetBlocks()[blk]
380 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
381 auto y = this->m_in2->GetBlocks()[blk]
382 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
383 auto z = this->m_expected->GetBlocks()[blk]
384 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
385 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
386 this->m_in1->GetBlocks()[blk].GetNumData();
387 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
388
389 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
390 ++nc, x += stride, y += stride, z += stride)
391 {
392 std::transform(x, x + size, y, z,
393 [=](const TData &xi, const TData &yi) {
394 return alpha * xi + beta * yi + gamma * xi;
395 });
396 }
397 }
398 }

References Nektar::LibUtilities::beta, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ daxpy()

template<typename TData >
void TestMath< TData >::daxpy ( TData  alpha)
inline

Definition at line 324 of file TestMath.hpp.

325 {
326 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
327 {
328 auto x = this->m_in1->GetBlocks()[blk]
329 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
330 auto y = this->m_in2->GetBlocks()[blk]
331 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
332 auto z = this->m_expected->GetBlocks()[blk]
333 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
334 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
335 this->m_in1->GetBlocks()[blk].GetNumData();
336 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
337
338 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
339 ++nc, x += stride, y += stride, z += stride)
340 {
341 std::transform(x, x + size, y, z,
342 [=](const TData &xi, const TData &yi) {
343 return alpha * xi + yi;
344 });
345 }
346 }
347 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ div()

template<typename TData >
void TestMath< TData >::div ( )
inline

Definition at line 299 of file TestMath.hpp.

300 {
301 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
302 {
303 auto x = this->m_in1->GetBlocks()[blk]
304 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
305 auto y = this->m_in2->GetBlocks()[blk]
306 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
307 auto z = this->m_expected->GetBlocks()[blk]
308 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
309 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
310 this->m_in1->GetBlocks()[blk].GetNumData();
311 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
312
313 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
314 ++nc, x += stride, y += stride, z += stride)
315 {
316 std::transform(x, x + size, y, z,
317 [](const TData &xi, const TData &yi) {
318 return (yi == TData(0)) ? TData(0) : xi / yi;
319 });
320 }
321 }
322 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ Evaluate()

template<typename TData >
void TestMath< TData >::Evaluate ( const std::string &  name,
Field< TData, FieldState::Phys > &  field,
Array< OneD, double > &  x,
Array< OneD, double > &  y,
Array< OneD, double > &  z,
Array< OneD, double > &  fce 
)
inlineprotected

Fills every component of field with the session function name evaluated for the variable of that component.

Definition at line 673 of file TestMath.hpp.

677 {
678 for (unsigned int nc = 0; nc < field.GetNumComponents(); ++nc)
679 {
680 auto func = this->m_session->GetFunction(name, nc);
681 func->Evaluate(x, y, z, fce);
682
683 auto ptr = fce.data();
684 for (unsigned int blk = 0; blk < field.GetBlocks().size(); ++blk)
685 {
686 auto &block = field.GetBlocks()[blk];
687 auto inptr =
688 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
689 auto size = block.GetNumElements() * block.GetNumData();
690 std::copy(ptr, ptr + size, inptr + nc * block.CompSize());
691 ptr += size;
692 }
693 }
694 }

Referenced by TestMath< TData >::SetTestCase().

◆ inner_product()

template<typename TData >
TData TestMath< TData >::inner_product ( )
inline

Definition at line 460 of file TestMath.hpp.

461 {
462 TData out = 0;
463 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
464 {
465 auto x = this->m_in1->GetBlocks()[blk]
466 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
467 auto y = this->m_in2->GetBlocks()[blk]
468 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
469 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
470 this->m_in1->GetBlocks()[blk].GetNumData();
471 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
472
473 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
474 ++nc, x += stride, y += stride)
475 {
476 out = std::inner_product(x, x + size, y, out);
477 }
478 }
479 return out;
480 }
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

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ l1norm()

template<typename TData >
TData TestMath< TData >::l1norm ( )
inline

Definition at line 482 of file TestMath.hpp.

483 {
484 TData out = 0;
485 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
486 {
487 auto x = this->m_in1->GetBlocks()[blk]
488 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
489 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
490 this->m_in1->GetBlocks()[blk].GetNumData();
491 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
492
493 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
494 ++nc, x += stride)
495 {
496 out = std::accumulate(x, x + size, out,
497 [](const TData &acc, const TData &val) {
498 return acc + std::abs(val);
499 });
500 }
501 }
502 return out;
503 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

◆ l2norm()

template<typename TData >
TData TestMath< TData >::l2norm ( )
inline

Definition at line 505 of file TestMath.hpp.

506 {
507 TData out = 0;
508 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
509 {
510 auto x = this->m_in1->GetBlocks()[blk]
511 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
512 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
513 this->m_in1->GetBlocks()[blk].GetNumData();
514 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
515
516 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
517 ++nc, x += stride)
518 {
519 out = std::accumulate(x, x + size, out,
520 [](const TData &acc, const TData &val) {
521 return acc + val * val;
522 });
523 }
524 }
525 return out;
526 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

◆ linfnorm()

template<typename TData >
TData TestMath< TData >::linfnorm ( )
inline

Definition at line 528 of file TestMath.hpp.

529 {
530 TData out = 0.0;
531 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
532 {
533 auto x = this->m_in1->GetBlocks()[blk]
534 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
535 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
536 this->m_in1->GetBlocks()[blk].GetNumData();
537 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
538
539 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
540 ++nc, x += stride)
541 {
542 out = std::accumulate(
543 x, x + size, out, [](const TData &acc, const TData &val) {
544 return std::max(std::abs(acc), std::abs(val));
545 });
546 }
547 }
548 return out;
549 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

◆ max()

template<typename TData >
TData TestMath< TData >::max ( )
inline

Definition at line 420 of file TestMath.hpp.

421 {
422 TData out = std::numeric_limits<TData>::lowest();
423 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
424 {
425 auto x = this->m_in1->GetBlocks()[blk]
426 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
427 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
428 this->m_in1->GetBlocks()[blk].GetNumData();
429 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
430
431 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
432 ++nc, x += stride)
433 {
434 out = std::max(out, *(std::max_element(x, x + size)));
435 }
436 }
437 return out;
438 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

◆ min()

template<typename TData >
TData TestMath< TData >::min ( )
inline

Definition at line 440 of file TestMath.hpp.

441 {
442 TData out = std::numeric_limits<TData>::max();
443 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
444 {
445 auto x = this->m_in1->GetBlocks()[blk]
446 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
447 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
448 this->m_in1->GetBlocks()[blk].GetNumData();
449 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
450
451 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
452 ++nc, x += stride)
453 {
454 out = std::min(out, *(std::min_element(x, x + size)));
455 }
456 }
457 return out;
458 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

◆ mul()

template<typename TData >
void TestMath< TData >::mul ( )
inline

Definition at line 275 of file TestMath.hpp.

276 {
277 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
278 {
279 auto x = this->m_in1->GetBlocks()[blk]
280 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
281 auto y = this->m_in2->GetBlocks()[blk]
282 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
283 auto z = this->m_expected->GetBlocks()[blk]
284 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
285 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
286 this->m_in1->GetBlocks()[blk].GetNumData();
287 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
288
289 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
290 ++nc, x += stride, y += stride, z += stride)
291 {
292 std::transform(
293 x, x + size, y, z,
294 [](const TData &xi, const TData &yi) { return xi * yi; });
295 }
296 }
297 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ neg()

template<typename TData >
void TestMath< TData >::neg ( )
inline

Definition at line 182 of file TestMath.hpp.

183 {
184 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
185 {
186 auto x = this->m_in1->GetBlocks()[blk]
187 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
188 auto y = this->m_expected->GetBlocks()[blk]
189 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
190 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
191 this->m_in1->GetBlocks()[blk].GetNumData();
192 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
193
194 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
195 ++nc, x += stride, y += stride)
196 {
197 std::transform(x, x + size, y,
198 [](const TData &xi) { return -xi; });
199 }
200 }
201 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, and TestMath< TData >::m_in1.

◆ SetTestCase()

template<typename TData >
void TestMath< TData >::SetTestCase ( )
inline

Definition at line 147 of file TestMath.hpp.

148 {
149 // GetCoords() and Equation::Evaluate() take double arrays, whatever
150 // TData is; the values are narrowed when copied into the field.
151 Array<OneD, double> x(this->m_expList->GetTotPoints(), 0.0);
152 Array<OneD, double> y(this->m_expList->GetTotPoints(), 0.0);
153 Array<OneD, double> z(this->m_expList->GetTotPoints(), 0.0);
154 Array<OneD, double> fce(this->m_expList->GetTotPoints());
155 this->m_expList->GetCoords(x, y, z);
156
157 Evaluate("Forcing", *this->m_in1, x, y, z, fce);
158 Evaluate("ExactSolution", *this->m_in2, x, y, z, fce);
159 }
void Evaluate(const std::string &name, Field< TData, FieldState::Phys > &field, Array< OneD, double > &x, Array< OneD, double > &y, Array< OneD, double > &z, Array< OneD, double > &fce)
Fills every component of field with the session function name evaluated for the variable of that comp...
Definition TestMath.hpp:673

References TestMath< TData >::Evaluate(), TestMath< TData >::m_expList, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ sqrt()

template<typename TData >
void TestMath< TData >::sqrt ( )
inline

Definition at line 203 of file TestMath.hpp.

204 {
205 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
206 {
207 auto x = this->m_in1->GetBlocks()[blk]
208 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
209 auto y = this->m_expected->GetBlocks()[blk]
210 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
211 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
212 this->m_in1->GetBlocks()[blk].GetNumData();
213 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
214
215 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
216 ++nc, x += stride, y += stride)
217 {
218 // If inputs might be negative and want to avoid NaNs,
219 // replace std::sqrt(xi) with std::sqrt(std::abs(xi)).
220 std::transform(x, x + size, y, [](const TData &xi) {
221 return std::sqrt(std::abs(xi));
222 });
223 }
224 }
225 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, and TestMath< TData >::m_in1.

◆ sub()

template<typename TData >
void TestMath< TData >::sub ( )
inline

Definition at line 251 of file TestMath.hpp.

252 {
253 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
254 {
255 auto x = this->m_in1->GetBlocks()[blk]
256 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
257 auto y = this->m_in2->GetBlocks()[blk]
258 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
259 auto z = this->m_expected->GetBlocks()[blk]
260 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
261 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
262 this->m_in1->GetBlocks()[blk].GetNumData();
263 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
264
265 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
266 ++nc, x += stride, y += stride, z += stride)
267 {
268 std::transform(
269 x, x + size, y, z,
270 [](const TData &xi, const TData &yi) { return xi - yi; });
271 }
272 }
273 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestMath< TData >::m_expected, TestMath< TData >::m_in1, and TestMath< TData >::m_in2.

◆ sum()

template<typename TData >
TData TestMath< TData >::sum ( )
inline

Definition at line 400 of file TestMath.hpp.

401 {
402 TData out = 0;
403 for (unsigned int blk = 0; blk < this->m_in1->GetBlocks().size(); ++blk)
404 {
405 auto x = this->m_in1->GetBlocks()[blk]
406 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
407 auto size = this->m_in1->GetBlocks()[blk].GetNumElements() *
408 this->m_in1->GetBlocks()[blk].GetNumData();
409 auto stride = this->m_in1->GetBlocks()[blk].CompSize();
410
411 for (unsigned int nc = 0; nc < this->m_in1->GetNumComponents();
412 ++nc, x += stride)
413 {
414 out = std::accumulate(x, x + size, out);
415 }
416 }
417 return out;
418 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestMath< TData >::m_in1.

Member Data Documentation

◆ m_expected

template<typename TData >
Field<TData, FieldState::Phys>* TestMath< TData >::m_expected = nullptr
protected

◆ m_expList

template<typename TData >
ExpListSharedPtr TestMath< TData >::m_expList
protected

Definition at line 665 of file TestMath.hpp.

Referenced by TestMath< TData >::Configure(), and TestMath< TData >::SetTestCase().

◆ m_in1

template<typename TData >
Field<TData, FieldState::Phys>* TestMath< TData >::m_in1 = nullptr
protected

◆ m_in2

template<typename TData >
Field<TData, FieldState::Phys>* TestMath< TData >::m_in2 = nullptr
protected

◆ m_math

template<typename TData >
Math::MathHelper TestMath< TData >::m_math
protected

Definition at line 667 of file TestMath.hpp.

Referenced by TestMath< TData >::Configure().

◆ m_meshName

template<typename TData >
std::string TestMath< TData >::m_meshName = ""
protected

Definition at line 660 of file TestMath.hpp.

Referenced by TestMath< TData >::Configure(), and TestMath< TData >::TestMath().

◆ m_out

template<typename TData >
Field<TData, FieldState::Phys>* TestMath< TData >::m_out = nullptr
protected

◆ m_session

template<typename TData >
SessionReaderSharedPtr TestMath< TData >::m_session
protected

Definition at line 666 of file TestMath.hpp.

Referenced by TestMath< TData >::Compare(), and TestMath< TData >::Configure().