51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_ScalarTraits.hpp"
54 #include "Teuchos_GlobalMPISession.hpp"
55 #include <Kokkos_Core.hpp>
59 using namespace Intrepid;
61 int main(
int argc,
char *argv[]) {
63 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
68 int iprint = argc - 1;
69 Teuchos::RCP<std::ostream> outStream;
70 Teuchos::oblackholestream bhs;
72 outStream = Teuchos::rcp(&std::cout,
false);
74 outStream = Teuchos::rcp(&bhs,
false);
77 Teuchos::oblackholestream oldFormatState;
78 oldFormatState.copyfmt(std::cout);
81 <<
"===============================================================================\n" \
83 <<
"| Unit Test (RealSpaceTools) |\n" \
85 <<
"| 1) Vector operations in 1D, 2D, and 3D real space |\n" \
86 <<
"| 2) Matrix / matrix-vector operations in 1D, 2D, and 3D real space |\n" \
88 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
89 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
91 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
92 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
94 <<
"===============================================================================\n";
101 #ifdef HAVE_INTREPID_DEBUG
102 int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
103 int endThrowNumber = beginThrowNumber + 49;
104 #ifndef HAVE_INTREPID_DEBUG_INF_CHECK
105 endThrowNumber = beginThrowNumber + 44;
111 <<
"===============================================================================\n"\
112 <<
"| TEST 1: vector exceptions |\n"\
113 <<
"===============================================================================\n";
117 Kokkos::View<double**> a_2_2(
"a_2_2",2, 2);
118 Kokkos::View<double**> a_10_2(
"a_10_2",10, 2);
119 Kokkos::View<double**> a_10_3(
"a_10_3",10, 3);
120 Kokkos::View<double***> a_10_2_2(
"a_10_2_2",10, 2, 2);
121 Kokkos::View<double***> a_10_2_3(
"a_10_2_3",10, 2, 3);
122 Kokkos::View<double****> a_10_2_2_3(
"a_10_2_2_3",10, 2, 2, 3);
124 #ifdef HAVE_INTREPID_DEBUG
126 *outStream <<
"-> vector norm with multidimensional arrays:\n";
129 rst::vectorNorm(a_2_2, NORM_TWO);
131 catch (std::logic_error err) {
132 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
133 *outStream << err.what() <<
'\n';
134 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
137 rst::vectorNorm(a_10_2_2, a_10_2_2, NORM_TWO);
139 catch (std::logic_error err) {
140 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
141 *outStream << err.what() <<
'\n';
142 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
145 rst::vectorNorm(a_10_2_2, a_10_2_2_3, NORM_TWO);
147 catch (std::logic_error err) {
148 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
149 *outStream << err.what() <<
'\n';
150 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
153 rst::vectorNorm(a_10_3, a_10_2_2, NORM_TWO);
155 catch (std::logic_error err) {
156 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
157 *outStream << err.what() <<
'\n';
158 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
161 *outStream <<
"-> add with multidimensional arrays:\n";
164 rst::add(a_10_2_2, a_10_2, a_2_2);
166 catch (std::logic_error err) {
167 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
168 *outStream << err.what() <<
'\n';
169 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
172 rst::add(a_10_2_3, a_10_2_2, a_10_2_2);
174 catch (std::logic_error err) {
175 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
176 *outStream << err.what() <<
'\n';
177 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
180 rst::add(a_10_2_2, a_10_2_2_3);
182 catch (std::logic_error err) {
183 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
184 *outStream << err.what() <<
'\n';
185 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
188 rst::add(a_10_2_3, a_10_2_2);
190 catch (std::logic_error err) {
191 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
192 *outStream << err.what() <<
'\n';
193 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
196 *outStream <<
"-> subtract with multidimensional arrays:\n";
199 rst::subtract(a_10_2_2, a_10_2, a_2_2);
201 catch (std::logic_error err) {
202 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
203 *outStream << err.what() <<
'\n';
204 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
207 rst::subtract(a_10_2_3, a_10_2_2, a_10_2_2);
209 catch (std::logic_error err) {
210 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
211 *outStream << err.what() <<
'\n';
212 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
215 rst::subtract(a_10_2_2, a_10_2_2_3);
217 catch (std::logic_error err) {
218 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
219 *outStream << err.what() <<
'\n';
220 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
223 rst::subtract(a_10_2_3, a_10_2_2);
225 catch (std::logic_error err) {
226 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
227 *outStream << err.what() <<
'\n';
228 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
231 *outStream <<
"-> dot product norm with multidimensional arrays:\n";
234 rst::dot(a_10_2, a_10_2_2_3, a_10_2_2_3);
236 catch (std::logic_error err) {
237 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
238 *outStream << err.what() <<
'\n';
239 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
242 rst::dot(a_10_2, a_10_2_2, a_10_2_2_3);
244 catch (std::logic_error err) {
245 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
246 *outStream << err.what() <<
'\n';
247 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
250 rst::dot(a_10_2_2, a_10_2_2_3, a_10_2_2_3);
252 catch (std::logic_error err) {
253 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
254 *outStream << err.what() <<
'\n';
255 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
258 rst::dot(a_10_2, a_10_2_2, a_10_2_3);
260 catch (std::logic_error err) {
261 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
262 *outStream << err.what() <<
'\n';
263 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
266 rst::dot(a_10_3, a_10_2_3, a_10_2_3);
268 catch (std::logic_error err) {
269 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
270 *outStream << err.what() <<
'\n';
271 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
274 *outStream <<
"-> absolute value with multidimensional arrays:\n";
277 rst::absval(a_10_3, a_10_2_3);
279 catch (std::logic_error err) {
280 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
281 *outStream << err.what() <<
'\n';
282 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
285 rst::absval(a_10_2_2, a_10_2_3);
287 catch (std::logic_error err) {
288 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
289 *outStream << err.what() <<
'\n';
290 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
295 catch (std::logic_error err) {
296 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
297 *outStream << err.what() <<
'\n';
298 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
305 <<
"===============================================================================\n"\
306 <<
"| TEST 2: matrix / matrix-vector exceptions |\n"\
307 <<
"===============================================================================\n";
311 Kokkos::View<double*****> a_10_1_2_3_4(
"a_10_1_2_3_4",10, 1, 2, 3, 4);
312 Kokkos::View<double*****> b_10_1_2_3_4(
"b_10_1_2_3_4",10, 1, 2, 3, 4);
313 Kokkos::View<double*> a_10(
"a_10",10);
314 Kokkos::View<double*> a_9(
"a_9",9);
315 Kokkos::View<double*> b_10(
"b_10",10);
316 Kokkos::View<double****> a_10_15_4_4(
"a_10_15_4_4",10, 15, 4, 4);
317 Kokkos::View<double****> b_10_15_4_4(
"b_10_15_4_4",10, 15, 4, 4);
318 Kokkos::View<double***> a_10_2_2(
"a_10_2_2",10, 2, 2);
319 Kokkos::View<double***> a_10_2_3(
"a_10_2_3",10, 2, 3);
320 Kokkos::View<double***> b_10_2_3(
"b_10_2_3",10, 2, 3);
322 Kokkos::View<double**> a_1_1(
"a_1_1",1, 1);
323 Kokkos::View<double**> b_1_1(
"b_1_1",1, 1);
324 Kokkos::View<double**> a_2_2(
"a_2_2",2, 2);
325 Kokkos::View<double**> b_2_2(
"b_2_2",2, 2);
326 Kokkos::View<double**> a_3_3(
"a_3_3",3, 3);
327 Kokkos::View<double**> b_3_3(
"b_3_3",3, 3);
328 Kokkos::View<double**> a_2_3(
"a_2_3",2, 3);
329 Kokkos::View<double**> a_4_4(
"a_4_4",4, 4);
331 Kokkos::View<double****> a_10_15_1_1(
"a_10_15_1_1",10, 15, 1, 1);
332 Kokkos::View<double****> b_10_15_1_1(
"b_10_15_1_1",10, 15, 1, 1);
333 Kokkos::View<double****> a_10_15_2_2(
"a_10_15_2_2",10, 15, 2, 2);
334 Kokkos::View<double****> b_10_15_2_2(
"b_10_15_2_2",10, 15, 2, 2);
335 Kokkos::View<double****> a_10_15_3_3(
"a_10_15_3_3",10, 15, 3, 3);
336 Kokkos::View<double****> a_10_15_3_2(
"a_10_15_3_2",10, 15, 3, 2);
337 Kokkos::View<double****> b_10_15_3_3(
"b_10_15_3_3",10, 15, 3, 3);
338 Kokkos::View<double**> b_10_14(
"b_10_14",10, 14);
339 Kokkos::View<double**> b_10_15(
"b_10_15",10, 15);
340 Kokkos::View<double***> b_10_14_3(
"b_10_14_3",10, 14, 3);
341 Kokkos::View<double***> b_10_15_3(
"b_10_15_3",10, 15, 3);
344 #ifdef HAVE_INTREPID_DEBUG
346 *outStream <<
"-> inverse with multidimensional arrays:\n";
349 rst::inverse(a_2_2, a_10_2_2);
351 catch (std::logic_error err) {
352 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
353 *outStream << err.what() <<
'\n';
354 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
357 rst::inverse(b_10_1_2_3_4, a_10_1_2_3_4);
359 catch (std::logic_error err) {
360 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
361 *outStream << err.what() <<
'\n';
362 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
365 rst::inverse(b_10, a_10);
367 catch (std::logic_error err) {
368 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
369 *outStream << err.what() <<
'\n';
370 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
373 rst::inverse(a_10_2_2, a_10_2_3);
375 catch (std::logic_error err) {
376 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
377 *outStream << err.what() <<
'\n';
378 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
381 rst::inverse(b_10_2_3, a_10_2_3);
383 catch (std::logic_error err) {
384 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
385 *outStream << err.what() <<
'\n';
386 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
389 rst::inverse(b_10_15_4_4, a_10_15_4_4);
391 catch (std::logic_error err) {
392 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
393 *outStream << err.what() <<
'\n';
394 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
397 rst::inverse(b_1_1, a_1_1);
399 catch (std::logic_error err) {
400 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
401 *outStream << err.what() <<
'\n';
402 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
405 rst::inverse(b_2_2, a_2_2);
407 catch (std::logic_error err) {
408 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
409 *outStream << err.what() <<
'\n';
410 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
413 rst::inverse(b_3_3, a_3_3);
415 catch (std::logic_error err) {
416 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
417 *outStream << err.what() <<
'\n';
418 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
423 rst::inverse(b_2_2, a_2_2);
425 catch (std::logic_error err) {
426 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
427 *outStream << err.what() <<
'\n';
428 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
431 rst::inverse(b_3_3, a_3_3);
433 catch (std::logic_error err) {
434 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
435 *outStream << err.what() <<
'\n';
436 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
439 *outStream <<
"-> transpose with multidimensional arrays:\n";
442 rst::transpose(a_2_2, a_10_2_2);
444 catch (std::logic_error err) {
445 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
446 *outStream << err.what() <<
'\n';
447 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
450 rst::transpose(b_10_1_2_3_4, a_10_1_2_3_4);
452 catch (std::logic_error err) {
453 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
454 *outStream << err.what() <<
'\n';
455 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
458 rst::transpose(b_10, a_10);
460 catch (std::logic_error err) {
461 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
462 *outStream << err.what() <<
'\n';
463 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
466 rst::transpose(a_10_2_2, a_10_2_3);
468 catch (std::logic_error err) {
469 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
470 *outStream << err.what() <<
'\n';
471 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
474 rst::transpose(b_10_2_3, a_10_2_3);
476 catch (std::logic_error err) {
477 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
478 *outStream << err.what() <<
'\n';
479 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
482 *outStream <<
"-> determinant with multidimensional arrays:\n";
485 rst::det(a_2_2, a_10_2_2);
487 catch (std::logic_error err) {
488 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
489 *outStream << err.what() <<
'\n';
490 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
493 rst::det(a_10_2_2, a_10_1_2_3_4);
495 catch (std::logic_error err) {
496 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
497 *outStream << err.what() <<
'\n';
498 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
501 rst::det(b_10_14, a_10_15_3_3);
503 catch (std::logic_error err) {
504 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
505 *outStream << err.what() <<
'\n';
506 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
509 rst::det(a_9, a_10_2_2);
511 catch (std::logic_error err) {
512 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
513 *outStream << err.what() <<
'\n';
514 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
517 rst::det(b_10, a_10_2_3);
519 catch (std::logic_error err) {
520 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
521 *outStream << err.what() <<
'\n';
522 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
525 rst::det(b_10_15, a_10_15_4_4);
527 catch (std::logic_error err) {
528 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
529 *outStream << err.what() <<
'\n';
530 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
533 rst::det(a_10_15_4_4);
535 catch (std::logic_error err) {
536 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
537 *outStream << err.what() <<
'\n';
538 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
543 catch (std::logic_error err) {
544 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
545 *outStream << err.what() <<
'\n';
546 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
551 catch (std::logic_error err) {
552 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
553 *outStream << err.what() <<
'\n';
554 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
557 *outStream <<
"-> matrix-vector product with multidimensional arrays:\n";
560 rst::matvec(a_10_2_2, a_10_2_3, b_10_2_3);
562 catch (std::logic_error err) {
563 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
564 *outStream << err.what() <<
'\n';
565 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
568 rst::matvec(a_2_2, a_2_2, a_10);
570 catch (std::logic_error err) {
571 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
572 *outStream << err.what() <<
'\n';
573 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
576 rst::matvec(a_9, a_10_2_2, a_2_2);
578 catch (std::logic_error err) {
579 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
580 *outStream << err.what() <<
'\n';
581 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
584 rst::matvec(b_10_15_3, a_10_15_3_3, b_10_14_3);
586 catch (std::logic_error err) {
587 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
588 *outStream << err.what() <<
'\n';
589 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
592 rst::matvec(b_10_14_3, a_10_15_3_3, b_10_15_3);
594 catch (std::logic_error err) {
595 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
596 *outStream << err.what() <<
'\n';
597 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
600 rst::matvec(b_10_15_3, a_10_15_3_2, b_10_15_3);
602 catch (std::logic_error err) {
603 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
604 *outStream << err.what() <<
'\n';
605 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
611 catch (std::logic_error err) {
612 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
613 *outStream << err.what() <<
'\n';
614 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
617 #ifdef HAVE_INTREPID_DEBUG
618 if (Teuchos::TestForException_getThrowNumber() != endThrowNumber)
624 <<
"===============================================================================\n"\
625 <<
"| TEST 2: correctness of math operations |\n"\
626 <<
"===============================================================================\n";
628 outStream->precision(20);
633 for (
int dim=3; dim>0; dim--) {
635 Kokkos::View<double****> ma_x_x_d_d(
"ma_x_x_d_d",i0, i1, dim, dim);
636 Kokkos::View<double****> mb_x_x_d_d(
"mb_x_x_d_d",i0, i1, dim, dim);
637 Kokkos::View<double****> mc_x_x_d_d(
"mc_x_x_d_d",i0, i1, dim, dim);
638 Kokkos::View<double***> va_x_x_d(
"va_x_x_d",i0, i1, dim);
639 Kokkos::View<double***> vb_x_x_d(
"vb_x_x_d",i0, i1, dim);
640 Kokkos::View<double***> vc_x_x_d(
"vc_x_x_d",i0, i1, dim);
641 Kokkos::View<double**> vdot_x_x(
"vdot_x_x",i0, i1);
642 Kokkos::View<double**> vnorms_x_x(
"vnorms_x_x",i0, i1);
643 Kokkos::View<double*> vnorms_x(
"vnorms_x",i0);
644 double zero = INTREPID_TOL*100.0;
647 for (
unsigned int i=0; i<ma_x_x_d_d.dimension(0); i++) {
648 for (
unsigned int j=0; j<ma_x_x_d_d.dimension(1); j++) {
649 for (
unsigned int k=0; k<ma_x_x_d_d.dimension(2); k++) {
650 for (
unsigned int l=0; l<ma_x_x_d_d.dimension(3); l++) {
651 ma_x_x_d_d(i,j,k,l) = Teuchos::ScalarTraits<double>::random();
657 for (
unsigned int i=0; i<va_x_x_d.dimension(0); i++) {
658 for (
unsigned int j=0; j<va_x_x_d.dimension(1); j++) {
659 for (
unsigned int k=0; k<va_x_x_d.dimension(2); k++) {
660 va_x_x_d(i,j,k) = Teuchos::ScalarTraits<double>::random();
665 *outStream <<
"\n************ Checking vectorNorm ************\n";
667 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_TWO);
668 *outStream <<
"va_x_x_d";
669 *outStream <<
"vnorms_x_x";
670 if ( std::abs(rst::vectorNorm(vnorms_x_x, NORM_TWO) -
671 rst::vectorNorm(va_x_x_d, NORM_TWO)) > zero) {
672 *outStream <<
"\n\nINCORRECT vectorNorm NORM_TWO\n\n";
676 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_ONE);
677 *outStream <<
"va_x_x_d";
678 *outStream <<
"vnorms_x_x";
679 if ( std::abs(rst::vectorNorm(vnorms_x_x, NORM_ONE) -
680 rst::vectorNorm(va_x_x_d, NORM_ONE)) > zero) {
681 *outStream <<
"\n\nINCORRECT vectorNorm NORM_ONE\n\n";
684 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_INF);
685 *outStream <<
"va_x_x_d";
686 *outStream <<
"vnorms_x_x";
687 if ( std::abs(rst::vectorNorm(vnorms_x_x, NORM_INF) -
688 rst::vectorNorm(va_x_x_d, NORM_INF)) > zero) {
689 *outStream <<
"\n\nINCORRECT vectorNorm NORM_INF\n\n";
696 *outStream <<
"\n************ Checking inverse, subtract, and vectorNorm ************\n";
698 rst::inverse(mb_x_x_d_d, ma_x_x_d_d);
699 rst::inverse(mc_x_x_d_d, mb_x_x_d_d);
700 *outStream <<
"ma_x_x_d_d" <<
"mb_x_x_d_d" <<
"mc_x_x_d_d";
702 rst::subtract(mc_x_x_d_d, ma_x_x_d_d);
704 if (rst::vectorNorm(mc_x_x_d_d, NORM_ONE) > zero) {
705 *outStream <<
"\n\nINCORRECT inverse OR subtract OR vectorNorm\n\n";
712 *outStream <<
"\n********** Checking determinant **********\n";
714 Kokkos::View<double**> detA_x_x(
"detA_x_x",i0, i1);
715 Kokkos::View<double**> detB_x_x(
"detB_x_x",i0, i1);
716 Kokkos::View<double*> detA_x_xlinear(
"detA_x_xlinear",i0*i1);
717 Kokkos::View<double*> detB_x_xlinear(
"detB_x_xlinear",i0*i1);
719 rst::det(detA_x_x, ma_x_x_d_d);
720 rst::det(detB_x_x, mb_x_x_d_d);
721 *outStream <<
"detA_x_x" <<
"detB_x_x";
722 for(
int i=0;i<i0;i++){
723 for(
int j=0;j<i1;j++){
724 detA_x_xlinear(i1*i+j)=detA_x_x(i,j);
725 detB_x_xlinear(i1*i+j)=detB_x_x(i,j);
728 if ( (rst::dot(detA_x_xlinear, detB_x_xlinear) - (
double)(i0*i1)) > zero) {
729 *outStream <<
"\n\nINCORRECT det\n\n" ;
758 *outStream <<
"\n************ Checking transpose and subtract ************\n";
760 rst::transpose(mb_x_x_d_d, ma_x_x_d_d);
761 rst::transpose(mc_x_x_d_d, mb_x_x_d_d);
762 *outStream <<
"ma_x_x_d_d" <<
"mb_x_x_d_d" <<
"mc_x_x_d_d";
764 rst::subtract(mc_x_x_d_d, ma_x_x_d_d);
766 if (rst::vectorNorm(mc_x_x_d_d, NORM_ONE) > zero) {
767 *outStream <<
"\n\nINCORRECT transpose OR subtract OR vectorNorm\n\n" ;
774 *outStream <<
"\n************ Checking matvec, vectorNorm, subtract, and inverse ************\n";
776 rst::inverse(mb_x_x_d_d, ma_x_x_d_d);
777 rst::inverse(mc_x_x_d_d, mb_x_x_d_d);
778 rst::matvec(vb_x_x_d, ma_x_x_d_d, va_x_x_d);
779 rst::matvec(vc_x_x_d, mb_x_x_d_d, vb_x_x_d);
780 rst::subtract(vc_x_x_d, va_x_x_d);
781 *outStream <<
"vc_x_x_d";
783 rst::vectorNorm(vnorms_x_x, vc_x_x_d, NORM_ONE);
784 rst::vectorNorm(vnorms_x, vnorms_x_x, NORM_INF);
785 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
786 *outStream <<
"\n\nINCORRECT matvec OR inverse OR subtract OR vectorNorm\n\n";
793 *outStream <<
"\n************ Checking add, subtract, absval, and scale ************\n";
796 rst::add(vc_x_x_d, va_x_x_d, vb_x_x_d);
797 rst::subtract(vc_x_x_d, vb_x_x_d);
798 rst::scale(vb_x_x_d, vc_x_x_d, x);
799 rst::scale(vc_x_x_d, vb_x_x_d, (1.0/x));
800 rst::subtract(vb_x_x_d, vc_x_x_d, va_x_x_d);
801 rst::absval(vc_x_x_d, vb_x_x_d);
802 rst::scale(vb_x_x_d, vc_x_x_d, -1.0);
803 rst::absval(vc_x_x_d, vb_x_x_d);
804 rst::add(vc_x_x_d, vb_x_x_d);
805 *outStream <<
"vc_x_x_d";
807 rst::vectorNorm(vnorms_x_x, vc_x_x_d, NORM_ONE);
808 rst::vectorNorm(vnorms_x, vnorms_x_x, NORM_INF);
809 if (rst::vectorNorm(vnorms_x, NORM_TWO) > (
double)0) {
810 *outStream <<
"\n\nSign flips combined with std::abs might not be invertible on this platform!\n"
811 <<
"Potential IEEE compliance issues!\n\n";
812 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
813 *outStream <<
"\n\nINCORRECT add OR subtract OR scale OR absval OR vectorNorm\n\n";
821 *outStream <<
"\n************ Checking dot and vectorNorm ************\n";
822 for (
unsigned int i=0; i<va_x_x_d.dimension(0); i++) {
823 for (
unsigned int j=0; j<va_x_x_d.dimension(1); j++) {
824 for (
unsigned int k=0; k<va_x_x_d.dimension(2); k++) {
825 va_x_x_d(i,j,k) = 2.0;
831 rst::dot(vdot_x_x, va_x_x_d, va_x_x_d);
832 *outStream <<
"vdot_x_x";
834 rst::vectorNorm(vnorms_x, vdot_x_x, NORM_ONE);
835 if (rst::vectorNorm(vnorms_x, NORM_ONE) - (
double)(4.0*dim*i0*i1) > zero) {
836 *outStream <<
"\n\nINCORRECT dot OR vectorNorm\n\n";
846 for (
int dim=3; dim>0; dim--) {
848 Kokkos::View<double***> ma_x_d_d(
"ma_x_d_d",i0, dim, dim);
849 Kokkos::View<double***> mb_x_d_d(
"mb_x_d_d",i0, dim, dim);
850 Kokkos::View<double***> mc_x_d_d(
"mc_x_d_d",i0, dim, dim);
851 Kokkos::View<double**> va_x_d(
"va_x_d",i0, dim);
852 Kokkos::View<double**> vb_x_d(
"vb_x_d",i0, dim);
853 Kokkos::View<double**> vc_x_d(
"vc_x_d",i0, dim);
854 Kokkos::View<double*> vdot_x(
"vdot_x",i0);
855 Kokkos::View<double*> vnorms_x(
"vnorms_x",i0);
856 double zero = INTREPID_TOL*100.0;
860 for (
unsigned int i=0; i<ma_x_d_d.dimension(0); i++) {
861 for (
unsigned int j=0; j<ma_x_d_d.dimension(1); j++) {
862 for (
unsigned int k=0; k<ma_x_d_d.dimension(2); k++) {
863 ma_x_d_d(i,j,k) = Teuchos::ScalarTraits<double>::random();
868 for (
unsigned int i=0; i<va_x_d.dimension(0); i++) {
869 for (
unsigned int j=0; j<va_x_d.dimension(1); j++) {
870 va_x_d(i,j) = Teuchos::ScalarTraits<double>::random();
876 *outStream <<
"\n************ Checking vectorNorm ************\n";
878 rst::vectorNorm(vnorms_x, va_x_d, NORM_TWO);
879 *outStream <<
"va_x_d";
880 *outStream <<
"vnorms_x";
881 if ( std::abs(rst::vectorNorm(vnorms_x, NORM_TWO) -
882 rst::vectorNorm(va_x_d, NORM_TWO)) > zero) {
883 *outStream <<
"\n\nINCORRECT vectorNorm NORM_TWO\n\n";
887 rst::vectorNorm(vnorms_x, va_x_d, NORM_ONE);
888 *outStream <<
"va_x_d";
889 *outStream <<
"vnorms_x";
890 if ( std::abs(rst::vectorNorm(vnorms_x, NORM_ONE) -
891 rst::vectorNorm(va_x_d, NORM_ONE)) > zero) {
892 *outStream <<
"\n\nINCORRECT vectorNorm NORM_ONE\n\n";
896 rst::vectorNorm(vnorms_x, va_x_d, NORM_INF);
897 *outStream <<
"va_x_d";
898 *outStream <<
"vnorms_x";
899 if ( std::abs(rst::vectorNorm(vnorms_x, NORM_INF) -
900 rst::vectorNorm(va_x_d, NORM_INF)) > zero) {
901 *outStream <<
"\n\nINCORRECT vectorNorm NORM_INF\n\n";
908 *outStream <<
"\n************ Checking inverse, subtract, and vectorNorm ************\n";
910 rst::inverse(mb_x_d_d, ma_x_d_d);
911 rst::inverse(mc_x_d_d, mb_x_d_d);
912 *outStream <<
"ma_x_d_d" <<
"mb_x_d_d" <<
"mc_x_d_d";
914 rst::subtract(mc_x_d_d, ma_x_d_d);
916 if (rst::vectorNorm(mc_x_d_d, NORM_ONE) > zero) {
917 *outStream <<
"\n\nINCORRECT inverse OR subtract OR vectorNorm\n\n";
924 *outStream <<
"\n********** Checking determinant **********\n";
929 rst::det(detA_x, ma_x_d_d);
930 rst::det(detB_x, mb_x_d_d);
931 *outStream <<
"detA_x" <<
"detB_x";
933 if ( (rst::dot(detA_x, detB_x) - (
double)i0) > zero) {
934 *outStream <<
"\n\nINCORRECT det\n\n" ;
951 *outStream <<
"\n************ Checking transpose and subtract ************\n";
953 rst::transpose(mb_x_d_d, ma_x_d_d);
954 rst::transpose(mc_x_d_d, mb_x_d_d);
955 *outStream <<
"ma_x_d_d" <<
"mb_x_d_d" <<
"mc_x_d_d";
957 rst::subtract(mc_x_d_d, ma_x_d_d);
959 if (rst::vectorNorm(mc_x_d_d, NORM_ONE) > zero) {
960 *outStream <<
"\n\nINCORRECT transpose OR subtract OR vectorNorm\n\n" ;
967 *outStream <<
"\n************ Checking matvec, vectorNorm, subtract, and inverse ************\n";
969 rst::inverse(mb_x_d_d, ma_x_d_d);
970 rst::inverse(mc_x_d_d, mb_x_d_d);
971 rst::matvec(vb_x_d, ma_x_d_d, va_x_d);
972 rst::matvec(vc_x_d, mb_x_d_d, vb_x_d);
973 rst::subtract(vc_x_d, va_x_d);
974 *outStream <<
"vc_x_d";
976 rst::vectorNorm(vnorms_x, vc_x_d, NORM_ONE);
977 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
978 *outStream <<
"\n\nINCORRECT matvec OR inverse OR subtract OR vectorNorm\n\n";
985 *outStream <<
"\n************ Checking add, subtract, absval, and scale ************\n";
988 rst::add(vc_x_d, va_x_d, vb_x_d);
989 rst::subtract(vc_x_d, vb_x_d);
990 rst::scale(vb_x_d, vc_x_d, x);
991 rst::scale(vc_x_d, vb_x_d, (1.0/x));
992 rst::subtract(vb_x_d, vc_x_d, va_x_d);
993 rst::absval(vc_x_d, vb_x_d);
994 rst::scale(vb_x_d, vc_x_d, -1.0);
995 rst::absval(vc_x_d, vb_x_d);
996 rst::add(vc_x_d, vb_x_d);
997 *outStream <<
"vc_x_d";
999 rst::vectorNorm(vnorms_x, vc_x_d, NORM_ONE);
1000 if (rst::vectorNorm(vnorms_x, NORM_TWO) > (
double)0) {
1001 *outStream <<
"\n\nSign flips combined with std::abs might not be invertible on this platform!\n"
1002 <<
"Potential IEEE compliance issues!\n\n";
1003 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
1004 *outStream <<
"\n\nINCORRECT add OR subtract OR scale OR absval OR vectorNorm\n\n";
1012 *outStream <<
"\n************ Checking dot and vectorNorm ************\n";
1013 for (
unsigned int i=0; i<va_x_d.dimension(0); i++) {
1014 for (
unsigned int j=0; j<va_x_d.dimension(1); j++) {
1018 rst::dot(vdot_x, va_x_d, va_x_d);
1019 *outStream <<
"vdot_x";
1021 if (rst::vectorNorm(vdot_x, NORM_ONE) - (
double)(4.0*dim*i0) > zero) {
1022 *outStream <<
"\n\nINCORRECT dot OR vectorNorm\n\n";
1031 catch (std::logic_error err) {
1032 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
1033 *outStream << err.what() <<
'\n';
1034 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
1038 std::cout <<
"End Result: TEST FAILED\n";
1040 std::cout <<
"End Result: TEST PASSED\n";
1043 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.