Nektar++
Loading...
Searching...
No Matches
TestMath.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestMath.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
39
42
45
46#include <algorithm>
47#include <cmath>
48#include <cstdio>
49#include <cstdlib>
50#include <cstring>
51#include <iostream>
52#include <limits>
53#include <memory>
54#include <numeric>
55#include <string>
56#include <vector>
57
58#if defined(_MSC_VER)
59#undef max
60#undef min
61#endif
62
63using namespace Nektar;
64using namespace Nektar::LibUtilities;
65using namespace Nektar::MultiRegions;
66
68
69template <typename TData> class TestMath
70{
71public:
73 {
74 m_meshName = "run/segment.xml";
75 }
76
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 }
98
99 void Configure()
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 }
146
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 }
160
161 void abs()
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 }
181
182 void neg()
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 }
202
203 void sqrt()
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 }
226
227 void add()
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 }
250
251 void sub()
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 }
274
275 void mul()
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 }
298
299 void div()
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 }
323
324 void daxpy(TData alpha)
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 }
348
349 void daxpby(TData alpha, TData beta)
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 }
373
374 /// w = alpha x + beta y + gamma z, with z = x.
375 void daxpbypcz(TData alpha, TData beta, TData gamma)
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 }
399
400 TData sum()
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 }
419
420 TData max()
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 }
439
440 TData min()
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 }
459
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 }
481
482 TData l1norm()
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 }
504
505 TData l2norm()
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 }
527
528 TData linfnorm()
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 }
550
551 /**
552 * @brief Compare this field to another field, with absolute
553 * tolerance tol. Two fields must have same storage shape
554 * and same components.
555 *
556 * @return bool
557 */
558 bool Compare(TData tol)
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 }
658
659protected:
660 std::string m_meshName = "";
668
669 /**
670 * @brief Fills every component of @p field with the session function
671 * @p name evaluated for the variable of that component.
672 */
673 void Evaluate(const std::string &name,
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 }
695};
696
SpatialDomains::MeshGraphSharedPtr graph
#define NEKTAR_TEST_GLOBAL_CONFIGURATION(args)
SpatialDomains::Geometry * el
A Field represents expansion data to be operated on.
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
void SetTestCase()
Definition TestMath.hpp:147
ExpListSharedPtr m_expList
Definition TestMath.hpp:665
TData l1norm()
Definition TestMath.hpp:482
void Configure()
Definition TestMath.hpp:99
void add()
Definition TestMath.hpp:227
SessionReaderSharedPtr m_session
Definition TestMath.hpp:666
void daxpbypcz(TData alpha, TData beta, TData gamma)
w = alpha x + beta y + gamma z, with z = x.
Definition TestMath.hpp:375
TData min()
Definition TestMath.hpp:440
void div()
Definition TestMath.hpp:299
TData sum()
Definition TestMath.hpp:400
Field< TData, FieldState::Phys > * m_expected
Definition TestMath.hpp:664
Math::MathHelper m_math
Definition TestMath.hpp:667
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
void daxpy(TData alpha)
Definition TestMath.hpp:324
void abs()
Definition TestMath.hpp:161
void mul()
Definition TestMath.hpp:275
bool Compare(TData tol)
Compare this field to another field, with absolute tolerance tol. Two fields must have same storage s...
Definition TestMath.hpp:558
Field< TData, FieldState::Phys > * m_in1
Definition TestMath.hpp:661
TData inner_product()
Definition TestMath.hpp:460
void daxpby(TData alpha, TData beta)
Definition TestMath.hpp:349
TData l2norm()
Definition TestMath.hpp:505
Field< TData, FieldState::Phys > * m_out
Definition TestMath.hpp:663
std::string m_meshName
Definition TestMath.hpp:660
TData linfnorm()
Definition TestMath.hpp:528
TData max()
Definition TestMath.hpp:420
void sub()
Definition TestMath.hpp:251
void sqrt()
Definition TestMath.hpp:203
Field< TData, FieldState::Phys > * m_in2
Definition TestMath.hpp:662
void neg()
Definition TestMath.hpp:182
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.