51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_ScalarTraits.hpp"
54 #include "Teuchos_GlobalMPISession.hpp"
58 using namespace Intrepid;
60 int main(
int argc,
char *argv[]) {
62 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
66 int iprint = argc - 1;
67 Teuchos::RCP<std::ostream> outStream;
68 Teuchos::oblackholestream bhs;
70 outStream = Teuchos::rcp(&std::cout,
false);
72 outStream = Teuchos::rcp(&bhs,
false);
75 Teuchos::oblackholestream oldFormatState;
76 oldFormatState.copyfmt(std::cout);
79 <<
"===============================================================================\n" \
81 <<
"| Unit Test (RealSpaceTools) |\n" \
83 <<
"| 1) Vector operations in 1D, 2D, and 3D real space |\n" \
84 <<
"| 2) Matrix / matrix-vector operations in 1D, 2D, and 3D real space |\n" \
86 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
87 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
89 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
90 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
92 <<
"===============================================================================\n";
99 #ifdef HAVE_INTREPID_DEBUG
100 int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
101 int endThrowNumber = beginThrowNumber + 49;
102 #ifndef HAVE_INTREPID_DEBUG_INF_CHECK
103 endThrowNumber = beginThrowNumber + 44;
110 <<
"===============================================================================\n"\
111 <<
"| TEST 1: vector exceptions |\n"\
112 <<
"===============================================================================\n";
123 #ifdef HAVE_INTREPID_DEBUG
125 *outStream <<
"-> vector norm with multidimensional arrays:\n";
128 rst::vectorNorm(a_2_2, NORM_TWO);
130 catch (std::logic_error err) {
131 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
132 *outStream << err.what() <<
'\n';
133 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
136 rst::vectorNorm(a_10_2_2, a_10_2_2, NORM_TWO);
138 catch (std::logic_error err) {
139 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
140 *outStream << err.what() <<
'\n';
141 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
144 rst::vectorNorm(a_10_2_2, a_10_2_2_3, NORM_TWO);
146 catch (std::logic_error err) {
147 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
148 *outStream << err.what() <<
'\n';
149 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
152 rst::vectorNorm(a_10_3, a_10_2_2, NORM_TWO);
154 catch (std::logic_error err) {
155 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
156 *outStream << err.what() <<
'\n';
157 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
160 *outStream <<
"-> add with multidimensional arrays:\n";
163 rst::add(a_10_2_2, a_10_2, a_2_2);
165 catch (std::logic_error err) {
166 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
167 *outStream << err.what() <<
'\n';
168 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
171 rst::add(a_10_2_3, a_10_2_2, a_10_2_2);
173 catch (std::logic_error err) {
174 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
175 *outStream << err.what() <<
'\n';
176 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
179 rst::add(a_10_2_2, a_10_2_2_3);
181 catch (std::logic_error err) {
182 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
183 *outStream << err.what() <<
'\n';
184 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
187 rst::add(a_10_2_3, a_10_2_2);
189 catch (std::logic_error err) {
190 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
191 *outStream << err.what() <<
'\n';
192 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
195 *outStream <<
"-> subtract with multidimensional arrays:\n";
198 rst::subtract(a_10_2_2, a_10_2, a_2_2);
200 catch (std::logic_error err) {
201 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
202 *outStream << err.what() <<
'\n';
203 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
206 rst::subtract(a_10_2_3, a_10_2_2, a_10_2_2);
208 catch (std::logic_error err) {
209 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
210 *outStream << err.what() <<
'\n';
211 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
214 rst::subtract(a_10_2_2, a_10_2_2_3);
216 catch (std::logic_error err) {
217 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
218 *outStream << err.what() <<
'\n';
219 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
222 rst::subtract(a_10_2_3, a_10_2_2);
224 catch (std::logic_error err) {
225 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
226 *outStream << err.what() <<
'\n';
227 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
230 *outStream <<
"-> dot product norm with multidimensional arrays:\n";
233 rst::dot(a_10_2, a_10_2_2_3, a_10_2_2_3);
235 catch (std::logic_error err) {
236 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
237 *outStream << err.what() <<
'\n';
238 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
241 rst::dot(a_10_2, a_10_2_2, a_10_2_2_3);
243 catch (std::logic_error err) {
244 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
245 *outStream << err.what() <<
'\n';
246 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
249 rst::dot(a_10_2_2, a_10_2_2_3, a_10_2_2_3);
251 catch (std::logic_error err) {
252 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
253 *outStream << err.what() <<
'\n';
254 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
257 rst::dot(a_10_2, a_10_2_2, a_10_2_3);
259 catch (std::logic_error err) {
260 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
261 *outStream << err.what() <<
'\n';
262 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
265 rst::dot(a_10_3, a_10_2_3, a_10_2_3);
267 catch (std::logic_error err) {
268 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
269 *outStream << err.what() <<
'\n';
270 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
273 *outStream <<
"-> absolute value with multidimensional arrays:\n";
276 rst::absval(a_10_3, a_10_2_3);
278 catch (std::logic_error err) {
279 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
280 *outStream << err.what() <<
'\n';
281 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
284 rst::absval(a_10_2_2, a_10_2_3);
286 catch (std::logic_error err) {
287 *outStream <<
"Expected Error ----------------------------------------------------------------\n";
288 *outStream << err.what() <<
'\n';
289 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
294 catch (std::logic_error err) {
295 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
296 *outStream << err.what() <<
'\n';
297 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
305 <<
"===============================================================================\n"\
306 <<
"| TEST 2: matrix / matrix-vector exceptions |\n"\
307 <<
"===============================================================================\n";
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)
625 <<
"===============================================================================\n"\
626 <<
"| TEST 2: correctness of math operations |\n"\
627 <<
"===============================================================================\n";
629 outStream->precision(20);
634 for (
int dim=3; dim>0; dim--) {
645 double zero = INTREPID_TOL*100.0;
648 for (
int i=0; i<ma_x_x_d_d.size(); i++) {
649 ma_x_x_d_d[i] = Teuchos::ScalarTraits<double>::random();
651 for (
int i=0; i<va_x_x_d.size(); i++) {
652 va_x_x_d[i] = Teuchos::ScalarTraits<double>::random();
655 *outStream <<
"\n************ Checking vectorNorm ************\n";
657 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_TWO);
658 *outStream << va_x_x_d;
659 *outStream << vnorms_x_x;
660 if ( std::abs(rst::vectorNorm(&vnorms_x_x[0], vnorms_x_x.size(), NORM_TWO) -
661 rst::vectorNorm(&va_x_x_d[0], va_x_x_d.size(), NORM_TWO)) > zero) {
662 *outStream <<
"\n\nINCORRECT vectorNorm NORM_TWO\n\n";
666 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_ONE);
667 *outStream << va_x_x_d;
668 *outStream << vnorms_x_x;
669 if ( std::abs(rst::vectorNorm(&vnorms_x_x[0], vnorms_x_x.size(), NORM_ONE) -
670 rst::vectorNorm(&va_x_x_d[0], va_x_x_d.size(), NORM_ONE)) > zero) {
671 *outStream <<
"\n\nINCORRECT vectorNorm NORM_ONE\n\n";
675 rst::vectorNorm(vnorms_x_x, va_x_x_d, NORM_INF);
676 *outStream << va_x_x_d;
677 *outStream << vnorms_x_x;
678 if ( std::abs(rst::vectorNorm(&vnorms_x_x[0], vnorms_x_x.size(), NORM_INF) -
679 rst::vectorNorm(&va_x_x_d[0], va_x_x_d.size(), NORM_INF)) > zero) {
680 *outStream <<
"\n\nINCORRECT vectorNorm NORM_INF\n\n";
687 *outStream <<
"\n************ Checking inverse, subtract, and vectorNorm ************\n";
689 rst::inverse(mb_x_x_d_d, ma_x_x_d_d);
690 rst::inverse(mc_x_x_d_d, mb_x_x_d_d);
691 *outStream << ma_x_x_d_d << mb_x_x_d_d << mc_x_x_d_d;
693 rst::subtract(&mc_x_x_d_d[0], &ma_x_x_d_d[0], ma_x_x_d_d.size());
695 if (rst::vectorNorm(&mc_x_x_d_d[0], mc_x_x_d_d.size(), NORM_ONE) > zero) {
696 *outStream <<
"\n\nINCORRECT inverse OR subtract OR vectorNorm\n\n";
703 *outStream <<
"\n********** Checking determinant **********\n";
708 rst::det(detA_x_x, ma_x_x_d_d);
709 rst::det(detB_x_x, mb_x_x_d_d);
710 *outStream << detA_x_x << detB_x_x;
712 if ( (rst::dot(&detA_x_x[0], &detB_x_x[0], detA_x_x.size()) - (
double)(i0*i1)) > zero) {
713 *outStream <<
"\n\nINCORRECT det\n\n" ;
717 *outStream <<
"\n det(A)*det(inv(A)) = " <<
718 rst::det(&ma_x_x_d_d[0], ma_x_x_d_d.dimension(3))*rst::det(&mb_x_x_d_d[0], mb_x_x_d_d.dimension(3))
721 if ( (rst::det(&ma_x_x_d_d[0], ma_x_x_d_d.dimension(3))*
722 rst::det(&mb_x_x_d_d[0], mb_x_x_d_d.dimension(3)) - (
double)1) > zero) {
723 *outStream <<
"\n\nINCORRECT det\n\n" ;
730 *outStream <<
"\n************ Checking transpose and subtract ************\n";
732 rst::transpose(mb_x_x_d_d, ma_x_x_d_d);
733 rst::transpose(mc_x_x_d_d, mb_x_x_d_d);
734 *outStream << ma_x_x_d_d << mb_x_x_d_d << mc_x_x_d_d;
736 rst::subtract(&mc_x_x_d_d[0], &ma_x_x_d_d[0], ma_x_x_d_d.size());
738 if (rst::vectorNorm(&mc_x_x_d_d[0], mc_x_x_d_d.size(), NORM_ONE) > zero) {
739 *outStream <<
"\n\nINCORRECT transpose OR subtract OR vectorNorm\n\n" ;
746 *outStream <<
"\n************ Checking matvec, vectorNorm, subtract, and inverse ************\n";
748 rst::inverse(mb_x_x_d_d, ma_x_x_d_d);
749 rst::inverse(mc_x_x_d_d, mb_x_x_d_d);
750 rst::matvec(vb_x_x_d, ma_x_x_d_d, va_x_x_d);
751 rst::matvec(vc_x_x_d, mb_x_x_d_d, vb_x_x_d);
752 rst::subtract(vc_x_x_d, va_x_x_d);
753 *outStream << vc_x_x_d;
755 rst::vectorNorm(vnorms_x_x, vc_x_x_d, NORM_ONE);
756 rst::vectorNorm(vnorms_x, vnorms_x_x, NORM_INF);
757 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
758 *outStream <<
"\n\nINCORRECT matvec OR inverse OR subtract OR vectorNorm\n\n";
765 *outStream <<
"\n************ Checking add, subtract, absval, and scale ************\n";
768 rst::add(vc_x_x_d, va_x_x_d, vb_x_x_d);
769 rst::subtract(vc_x_x_d, vb_x_x_d);
770 rst::scale(vb_x_x_d, vc_x_x_d, x);
771 rst::scale(vc_x_x_d, vb_x_x_d, (1.0/x));
772 rst::subtract(vb_x_x_d, vc_x_x_d, va_x_x_d);
773 rst::absval(vc_x_x_d, vb_x_x_d);
774 rst::scale(vb_x_x_d, vc_x_x_d, -1.0);
775 rst::absval(vc_x_x_d, vb_x_x_d);
776 rst::add(vc_x_x_d, vb_x_x_d);
777 *outStream << vc_x_x_d;
779 rst::vectorNorm(vnorms_x_x, vc_x_x_d, NORM_ONE);
780 rst::vectorNorm(vnorms_x, vnorms_x_x, NORM_INF);
781 if (rst::vectorNorm(vnorms_x, NORM_TWO) > (
double)0) {
782 *outStream <<
"\n\nSign flips combined with std::abs might not be invertible on this platform!\n"
783 <<
"Potential IEEE compliance issues!\n\n";
784 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
785 *outStream <<
"\n\nINCORRECT add OR subtract OR scale OR absval OR vectorNorm\n\n";
793 *outStream <<
"\n************ Checking dot and vectorNorm ************\n";
795 for (
int i=0; i<va_x_x_d.size(); i++) {
799 rst::dot(vdot_x_x, va_x_x_d, va_x_x_d);
800 *outStream << vdot_x_x;
802 rst::vectorNorm(vnorms_x, vdot_x_x, NORM_ONE);
803 if (rst::vectorNorm(vnorms_x, NORM_ONE) - (
double)(4.0*dim*i0*i1) > zero) {
804 *outStream <<
"\n\nINCORRECT dot OR vectorNorm\n\n";
814 for (
int dim=3; dim>0; dim--) {
824 double zero = INTREPID_TOL*100.0;
827 for (
int i=0; i<ma_x_d_d.size(); i++) {
828 ma_x_d_d[i] = Teuchos::ScalarTraits<double>::random();
830 for (
int i=0; i<va_x_d.size(); i++) {
831 va_x_d[i] = Teuchos::ScalarTraits<double>::random();
834 *outStream <<
"\n************ Checking vectorNorm ************\n";
836 rst::vectorNorm(vnorms_x, va_x_d, NORM_TWO);
837 *outStream << va_x_d;
838 *outStream << vnorms_x;
839 if ( std::abs(rst::vectorNorm(&vnorms_x[0], vnorms_x.size(), NORM_TWO) -
840 rst::vectorNorm(&va_x_d[0], va_x_d.size(), NORM_TWO)) > zero) {
841 *outStream <<
"\n\nINCORRECT vectorNorm NORM_TWO\n\n";
845 rst::vectorNorm(vnorms_x, va_x_d, NORM_ONE);
846 *outStream << va_x_d;
847 *outStream << vnorms_x;
848 if ( std::abs(rst::vectorNorm(&vnorms_x[0], vnorms_x.size(), NORM_ONE) -
849 rst::vectorNorm(&va_x_d[0], va_x_d.size(), NORM_ONE)) > zero) {
850 *outStream <<
"\n\nINCORRECT vectorNorm NORM_ONE\n\n";
854 rst::vectorNorm(vnorms_x, va_x_d, NORM_INF);
855 *outStream << va_x_d;
856 *outStream << vnorms_x;
857 if ( std::abs(rst::vectorNorm(&vnorms_x[0], vnorms_x.size(), NORM_INF) -
858 rst::vectorNorm(&va_x_d[0], va_x_d.size(), NORM_INF)) > zero) {
859 *outStream <<
"\n\nINCORRECT vectorNorm NORM_INF\n\n";
866 *outStream <<
"\n************ Checking inverse, subtract, and vectorNorm ************\n";
868 rst::inverse(mb_x_d_d, ma_x_d_d);
869 rst::inverse(mc_x_d_d, mb_x_d_d);
870 *outStream << ma_x_d_d << mb_x_d_d << mc_x_d_d;
872 rst::subtract(&mc_x_d_d[0], &ma_x_d_d[0], ma_x_d_d.size());
874 if (rst::vectorNorm(&mc_x_d_d[0], mc_x_d_d.size(), NORM_ONE) > zero) {
875 *outStream <<
"\n\nINCORRECT inverse OR subtract OR vectorNorm\n\n";
882 *outStream <<
"\n********** Checking determinant **********\n";
887 rst::det(detA_x, ma_x_d_d);
888 rst::det(detB_x, mb_x_d_d);
889 *outStream << detA_x << detB_x;
891 if ( (rst::dot(&detA_x[0], &detB_x[0], detA_x.size()) - (
double)i0) > zero) {
892 *outStream <<
"\n\nINCORRECT det\n\n" ;
896 *outStream <<
"\n det(A)*det(inv(A)) = " <<
897 rst::det(&ma_x_d_d[0], ma_x_d_d.dimension(2))*rst::det(&mb_x_d_d[0], mb_x_d_d.dimension(2))
900 if ( (rst::det(&ma_x_d_d[0], ma_x_d_d.dimension(2))*
901 rst::det(&mb_x_d_d[0], mb_x_d_d.dimension(2)) - (
double)1) > zero) {
902 *outStream <<
"\n\nINCORRECT det\n\n" ;
909 *outStream <<
"\n************ Checking transpose and subtract ************\n";
911 rst::transpose(mb_x_d_d, ma_x_d_d);
912 rst::transpose(mc_x_d_d, mb_x_d_d);
913 *outStream << ma_x_d_d << mb_x_d_d << mc_x_d_d;
915 rst::subtract(&mc_x_d_d[0], &ma_x_d_d[0], ma_x_d_d.size());
917 if (rst::vectorNorm(&mc_x_d_d[0], mc_x_d_d.size(), NORM_ONE) > zero) {
918 *outStream <<
"\n\nINCORRECT transpose OR subtract OR vectorNorm\n\n" ;
925 *outStream <<
"\n************ Checking matvec, vectorNorm, subtract, and inverse ************\n";
927 rst::inverse(mb_x_d_d, ma_x_d_d);
928 rst::inverse(mc_x_d_d, mb_x_d_d);
929 rst::matvec(vb_x_d, ma_x_d_d, va_x_d);
930 rst::matvec(vc_x_d, mb_x_d_d, vb_x_d);
931 rst::subtract(vc_x_d, va_x_d);
932 *outStream << vc_x_d;
934 rst::vectorNorm(vnorms_x, vc_x_d, NORM_ONE);
935 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
936 *outStream <<
"\n\nINCORRECT matvec OR inverse OR subtract OR vectorNorm\n\n";
943 *outStream <<
"\n************ Checking add, subtract, absval, and scale ************\n";
946 rst::add(vc_x_d, va_x_d, vb_x_d);
947 rst::subtract(vc_x_d, vb_x_d);
948 rst::scale(vb_x_d, vc_x_d, x);
949 rst::scale(vc_x_d, vb_x_d, (1.0/x));
950 rst::subtract(vb_x_d, vc_x_d, va_x_d);
951 rst::absval(vc_x_d, vb_x_d);
952 rst::scale(vb_x_d, vc_x_d, -1.0);
953 rst::absval(vc_x_d, vb_x_d);
954 rst::add(vc_x_d, vb_x_d);
955 *outStream << vc_x_d;
957 rst::vectorNorm(vnorms_x, vc_x_d, NORM_ONE);
958 if (rst::vectorNorm(vnorms_x, NORM_TWO) > (
double)0) {
959 *outStream <<
"\n\nSign flips combined with std::abs might not be invertible on this platform!\n"
960 <<
"Potential IEEE compliance issues!\n\n";
961 if (rst::vectorNorm(vnorms_x, NORM_TWO) > zero) {
962 *outStream <<
"\n\nINCORRECT add OR subtract OR scale OR absval OR vectorNorm\n\n";
970 *outStream <<
"\n************ Checking dot and vectorNorm ************\n";
972 for (
int i=0; i<va_x_d.size(); i++) {
975 rst::dot(vdot_x, va_x_d, va_x_d);
976 *outStream << vdot_x;
978 if (rst::vectorNorm(vdot_x, NORM_ONE) - (
double)(4.0*dim*i0) > zero) {
979 *outStream <<
"\n\nINCORRECT dot OR vectorNorm\n\n";
988 catch (std::logic_error err) {
989 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
990 *outStream << err.what() <<
'\n';
991 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
996 std::cout <<
"End Result: TEST FAILED\n";
998 std::cout <<
"End Result: TEST PASSED\n";
1001 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.