52 #include "Teuchos_oblackholestream.hpp"
53 #include "Teuchos_RCP.hpp"
54 #include "Teuchos_ScalarTraits.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
58 using namespace Intrepid;
60 #define INTREPID_TEST_COMMAND( S ) \
65 catch (std::logic_error err) { \
66 *outStream << "Expected Error ----------------------------------------------------------------\n"; \
67 *outStream << err.what() << '\n'; \
68 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
73 int main(
int argc,
char *argv[]) {
75 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
79 int iprint = argc - 1;
80 Teuchos::RCP<std::ostream> outStream;
81 Teuchos::oblackholestream bhs;
83 outStream = Teuchos::rcp(&std::cout,
false);
85 outStream = Teuchos::rcp(&bhs,
false);
88 Teuchos::oblackholestream oldFormatState;
89 oldFormatState.copyfmt(std::cout);
92 <<
"===============================================================================\n" \
94 <<
"| Unit Test (ArrayTools) |\n" \
96 <<
"| 1) Array operations: dot multiply |\n" \
98 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
99 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
101 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
102 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
104 <<
"===============================================================================\n";
108 #ifdef HAVE_INTREPID_DEBUG
109 int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
110 int endThrowNumber = beginThrowNumber + 36;
115 #ifdef HAVE_INTREPID_DEBUG
121 <<
"===============================================================================\n"\
122 <<
"| TEST 1: exceptions |\n"\
123 <<
"===============================================================================\n";
127 #ifdef HAVE_INTREPID_DEBUG
146 *outStream <<
"-> dotMultiplyDataField:\n";
153 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_10_2_2, a_10_2_2_3, a_10_2_2_2_2) );
154 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_2_2_2, a_10_2_2_2, a_10_2_2_2_2) );
155 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_10_3_2, a_10_2_2_2, a_10_2_2_2_2) );
156 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_10_2_3, a_10_2_2_2, a_10_2_2_2_2) );
157 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_10_2_2, a_10_2_2_2, a_10_2_2_2_2) );
158 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataField<
double>(a_10_2_2, a_10_1_2_2, a_10_2_2_2_2) );
172 *outStream <<
"-> dotMultiplyDataData:\n";
179 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataData<
double>(a_10_2, a_10_2_2_2, a_10_2_2_3) );
184 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataData<
double>(a_10_2, a_10_2_2_2, a_10_2_2_2) );
187 INTREPID_TEST_COMMAND( atools.
dotMultiplyDataData<
double>(a_10_2, a_10_1_2_2, a_10_2_2_2) );
206 catch (std::logic_error err) {
207 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
208 *outStream << err.what() <<
'\n';
209 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
213 #ifdef HAVE_INTREPID_DEBUG
214 if (Teuchos::TestForException_getThrowNumber() != endThrowNumber)
220 <<
"===============================================================================\n"\
221 <<
"| TEST 2: correctness of math operations |\n"\
222 <<
"===============================================================================\n";
224 outStream->precision(20);
228 *outStream <<
"\n************ Checking dotMultiplyDataField, (branch 1) ************\n";
230 int c=5, p=9, f=7, d1=6, d2=14;
244 double zero = INTREPID_TOL*10000.0;
247 for (
int i=0; i<in_c_f_p.size(); i++) {
248 in_c_f_p[i] = Teuchos::ScalarTraits<double>::random();
251 for (
int i=0; i<in_c_f_p_d.size(); i++) {
252 in_c_f_p_d[i] = std::pow((
double)-1.0, (
int)i);
255 for (
int i=0; i<in_c_f_p_d_d.size(); i++) {
256 in_c_f_p_d_d[i] = 1.0;
259 for (
int i=0; i<data_c_p.size(); i++) {
260 data_c_p[i] = Teuchos::ScalarTraits<double>::random();
263 for (
int i=0; i<data_c_1.size(); i++) {
264 data_c_1[i] = Teuchos::ScalarTraits<double>::random();
267 for (
int i=0; i<data_c_p_d.size(); i++) {
271 for (
int i=0; i<data_c_1_d.size(); i++) {
275 for (
int i=0; i<data_c_p_d_d.size(); i++) {
276 data_c_p_d_d[i] = 1.0;
279 for (
int i=0; i<data_c_1_d_d.size(); i++) {
280 data_c_1_d_d[i] = 1.0;
283 art::scalarMultiplyDataField<double>(outSM_c_f_p, data_c_p, in_c_f_p);
284 art::dotMultiplyDataField<double>(outDM_c_f_p, data_c_p, in_c_f_p);
285 rst::subtract(out_c_f_p, outSM_c_f_p, outDM_c_f_p);
286 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
287 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (1): check dot multiply for scalars vs. scalar multiply\n\n";
290 art::dotMultiplyDataField<double>(out_c_f_p, data_c_p_d, in_c_f_p_d);
291 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
292 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (2): check dot multiply of orthogonal vectors\n\n";
295 art::dotMultiplyDataField<double>(out_c_f_p, data_c_p_d_d, in_c_f_p_d_d);
296 if ((rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_INF) - d1*d2) > zero) {
297 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (3): check dot multiply for tensors of 1s\n\n";
300 art::scalarMultiplyDataField<double>(outSM_c_f_p, data_c_1, in_c_f_p);
301 art::dotMultiplyDataField<double>(outDM_c_f_p, data_c_1, in_c_f_p);
302 rst::subtract(out_c_f_p, outSM_c_f_p, outDM_c_f_p);
303 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
304 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (4): check dot multiply for scalars vs. scalar multiply\n\n";
307 art::dotMultiplyDataField<double>(out_c_f_p, data_c_1_d, in_c_f_p_d);
308 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
309 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (5): check dot multiply of orthogonal vectors\n\n";
312 art::dotMultiplyDataField<double>(out_c_f_p, data_c_1_d_d, in_c_f_p_d_d);
313 if ((rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_INF) - d1*d2) > zero) {
314 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (6): check dot multiply for tensors of 1s\n\n";
321 *outStream <<
"\n************ Checking dotMultiplyDataField, (branch 2) ************\n";
323 int c=5, p=9, f=7, d1=6, d2=14;
337 double zero = INTREPID_TOL*10000.0;
340 for (
int i=0; i<in_f_p.size(); i++) {
341 in_f_p[i] = Teuchos::ScalarTraits<double>::random();
344 for (
int i=0; i<in_f_p_d.size(); i++) {
345 in_f_p_d[i] = std::pow((
double)-1.0, (
int)i);
348 for (
int i=0; i<in_f_p_d_d.size(); i++) {
352 for (
int i=0; i<data_c_p.size(); i++) {
353 data_c_p[i] = Teuchos::ScalarTraits<double>::random();
356 for (
int i=0; i<data_c_1.size(); i++) {
357 data_c_1[i] = Teuchos::ScalarTraits<double>::random();
360 for (
int i=0; i<data_c_p_d.size(); i++) {
364 for (
int i=0; i<data_c_1_d.size(); i++) {
368 for (
int i=0; i<data_c_p_d_d.size(); i++) {
369 data_c_p_d_d[i] = 1.0;
372 for (
int i=0; i<data_c_1_d_d.size(); i++) {
373 data_c_1_d_d[i] = 1.0;
376 art::scalarMultiplyDataField<double>(outSM_c_f_p, data_c_p, in_f_p);
377 art::dotMultiplyDataField<double>(outDM_c_f_p, data_c_p, in_f_p);
378 rst::subtract(out_c_f_p, outSM_c_f_p, outDM_c_f_p);
379 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
380 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (7): check dot multiply for scalars vs. scalar multiply\n\n";
383 art::dotMultiplyDataField<double>(out_c_f_p, data_c_p_d, in_f_p_d);
384 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
385 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (8): check dot multiply of orthogonal vectors\n\n";
388 art::dotMultiplyDataField<double>(out_c_f_p, data_c_p_d_d, in_f_p_d_d);
389 if ((rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_INF) - d1*d2) > zero) {
390 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (9): check dot multiply for tensors of 1s\n\n";
393 art::scalarMultiplyDataField<double>(outSM_c_f_p, data_c_1, in_f_p);
394 art::dotMultiplyDataField<double>(outDM_c_f_p, data_c_1, in_f_p);
395 rst::subtract(out_c_f_p, outSM_c_f_p, outDM_c_f_p);
396 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
397 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (10): check dot multiply for scalars vs. scalar multiply\n\n";
400 art::dotMultiplyDataField<double>(out_c_f_p, data_c_1_d, in_f_p_d);
401 if (rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_ONE) > zero) {
402 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (11): check dot multiply of orthogonal vectors\n\n";
405 art::dotMultiplyDataField<double>(out_c_f_p, data_c_1_d_d, in_f_p_d_d);
406 if ((rst::vectorNorm(&out_c_f_p[0], out_c_f_p.size(), NORM_INF) - d1*d2) > zero) {
407 *outStream <<
"\n\nINCORRECT dotMultiplyDataField (12): check dot multiply for tensors of 1s\n\n";
416 *outStream <<
"\n************ Checking dotMultiplyDataData, (branch 1) ************\n";
418 int c=5, p=9, d1=6, d2=14;
432 double zero = INTREPID_TOL*10000.0;
435 for (
int i=0; i<in_c_p.size(); i++) {
436 in_c_p[i] = Teuchos::ScalarTraits<double>::random();
439 for (
int i=0; i<in_c_p_d.size(); i++) {
440 in_c_p_d[i] = std::pow((
double)-1.0, (
int)i);
443 for (
int i=0; i<in_c_p_d_d.size(); i++) {
447 for (
int i=0; i<data_c_p.size(); i++) {
448 data_c_p[i] = Teuchos::ScalarTraits<double>::random();
451 for (
int i=0; i<data_c_1.size(); i++) {
452 data_c_1[i] = Teuchos::ScalarTraits<double>::random();
455 for (
int i=0; i<data_c_p_d.size(); i++) {
459 for (
int i=0; i<data_c_1_d.size(); i++) {
463 for (
int i=0; i<data_c_p_d_d.size(); i++) {
464 data_c_p_d_d[i] = 1.0;
467 for (
int i=0; i<data_c_1_d_d.size(); i++) {
468 data_c_1_d_d[i] = 1.0;
471 art::scalarMultiplyDataData<double>(outSM_c_p, data_c_p, in_c_p);
472 art::dotMultiplyDataData<double>(outDM_c_p, data_c_p, in_c_p);
473 rst::subtract(out_c_p, outSM_c_p, outDM_c_p);
474 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
475 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (1): check dot multiply for scalars vs. scalar multiply\n\n";
478 art::dotMultiplyDataData<double>(out_c_p, data_c_p_d, in_c_p_d);
479 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
480 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (2): check dot multiply of orthogonal vectors\n\n";
483 art::dotMultiplyDataData<double>(out_c_p, data_c_p_d_d, in_c_p_d_d);
484 if ((rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_INF) - d1*d2) > zero) {
485 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (3): check dot multiply for tensors of 1s\n\n";
488 art::scalarMultiplyDataData<double>(outSM_c_p, data_c_1, in_c_p);
489 art::dotMultiplyDataData<double>(outDM_c_p, data_c_1, in_c_p);
490 rst::subtract(out_c_p, outSM_c_p, outDM_c_p);
491 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
492 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (4): check dot multiply for scalars vs. scalar multiply\n\n";
495 art::dotMultiplyDataData<double>(out_c_p, data_c_1_d, in_c_p_d);
496 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
497 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (5): check dot multiply of orthogonal vectors\n\n";
500 art::dotMultiplyDataData<double>(out_c_p, data_c_1_d_d, in_c_p_d_d);
501 if ((rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_INF) - d1*d2) > zero) {
502 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (6): check dot multiply for tensors of 1s\n\n";
509 *outStream <<
"\n************ Checking dotMultiplyDataData, (branch 2) ************\n";
511 int c=5, p=9, d1=6, d2=14;
525 double zero = INTREPID_TOL*10000.0;
528 for (
int i=0; i<in_p.size(); i++) {
529 in_p[i] = Teuchos::ScalarTraits<double>::random();
532 for (
int i=0; i<in_p_d.size(); i++) {
533 in_p_d[i] = std::pow((
double)-1.0, (
int)i);
536 for (
int i=0; i<in_p_d_d.size(); i++) {
540 for (
int i=0; i<data_c_p.size(); i++) {
541 data_c_p[i] = Teuchos::ScalarTraits<double>::random();
544 for (
int i=0; i<data_c_1.size(); i++) {
545 data_c_1[i] = Teuchos::ScalarTraits<double>::random();
548 for (
int i=0; i<data_c_p_d.size(); i++) {
552 for (
int i=0; i<data_c_1_d.size(); i++) {
556 for (
int i=0; i<data_c_p_d_d.size(); i++) {
557 data_c_p_d_d[i] = 1.0;
560 for (
int i=0; i<data_c_1_d_d.size(); i++) {
561 data_c_1_d_d[i] = 1.0;
564 art::scalarMultiplyDataData<double>(outSM_c_p, data_c_p, in_p);
565 art::dotMultiplyDataData<double>(outDM_c_p, data_c_p, in_p);
566 rst::subtract(out_c_p, outSM_c_p, outDM_c_p);
567 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
568 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (7): check dot multiply for scalars vs. scalar multiply\n\n";
571 art::dotMultiplyDataData<double>(out_c_p, data_c_p_d, in_p_d);
572 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
573 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (8): check dot multiply of orthogonal vectors\n\n";
576 art::dotMultiplyDataData<double>(out_c_p, data_c_p_d_d, in_p_d_d);
577 if ((rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_INF) - d1*d2) > zero) {
578 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (9): check dot multiply for tensors of 1s\n\n";
581 art::scalarMultiplyDataData<double>(outSM_c_p, data_c_1, in_p);
582 art::dotMultiplyDataData<double>(outDM_c_p, data_c_1, in_p);
583 rst::subtract(out_c_p, outSM_c_p, outDM_c_p);
584 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
585 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (10): check dot multiply for scalars vs. scalar multiply\n\n";
588 art::dotMultiplyDataData<double>(out_c_p, data_c_1_d, in_p_d);
589 if (rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_ONE) > zero) {
590 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (11): check dot multiply of orthogonal vectors\n\n";
593 art::dotMultiplyDataData<double>(out_c_p, data_c_1_d_d, in_p_d_d);
594 if ((rst::vectorNorm(&out_c_p[0], out_c_p.size(), NORM_INF) - d1*d2) > zero) {
595 *outStream <<
"\n\nINCORRECT dotMultiplyDataData (12): check dot multiply for tensors of 1s\n\n";
603 catch (std::logic_error err) {
604 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
605 *outStream << err.what() <<
'\n';
606 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
612 std::cout <<
"End Result: TEST FAILED\n";
614 std::cout <<
"End Result: TEST PASSED\n";
617 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.