51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_GlobalMPISession.hpp"
56 using namespace Intrepid;
58 int main(
int argc,
char *argv[]) {
60 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 int iprint = argc - 1;
65 Teuchos::RCP<std::ostream> outStream;
66 Teuchos::oblackholestream bhs;
69 outStream = Teuchos::rcp(&std::cout,
false);
71 outStream = Teuchos::rcp(&bhs,
false);
74 Teuchos::oblackholestream oldFormatState;
75 oldFormatState.copyfmt(std::cout);
78 <<
"===============================================================================\n" \
80 <<
"| Unit Test FieldContainer |\n" \
82 <<
"| 1) Value accesss by multi-index and enumeration, setting values |\n" \
84 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
85 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
87 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
88 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
90 <<
"===============================================================================\n";
95 Teuchos::Array<double> dataArray;
96 Teuchos::Array<int> dimension;
97 Teuchos::Array<int> multiIndex;
98 int dim0, dim1, dim2, dim3, dim4;
107 <<
"===============================================================================\n"\
108 <<
"| TEST 1: Rank-1 FieldContainer |\n"\
109 <<
"===============================================================================\n";
113 multiIndex.resize(1);
120 dataSize = dimension[0];
121 dataArray.resize(dataSize);
125 for(
int i=0; i < dimension[0]; i++){
126 dataArray[counter] = (double)counter;
132 <<
"===============================================================================\n"\
133 <<
"| TEST 1-a: Compare constructors with array and list of dimensions |\n"\
134 <<
"===============================================================================\n";
144 containerSize = rank1Container.size();
145 containerRank = rank1Container.rank();
146 multiIndex.resize(containerRank);
148 if( rank1Container.size() != rank1ContainerAlt.size() ) {
150 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
151 *outStream <<
" Size using ctor with array of dimensions = " << rank1Container.size() <<
"\n";
152 *outStream <<
" Size using ctor with list of dimensions = " << rank1ContainerAlt.size() <<
"\n";
155 if( rank1Container.rank() != rank1ContainerAlt.rank() ) {
157 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
158 *outStream <<
" Rank using ctor with array of dimensions = " << rank1Container.rank() <<
"\n";
159 *outStream <<
" Rank using ctor with list of dimensions = " << rank1ContainerAlt.rank() <<
"\n";
162 for(
int dim = 0; dim < rank1Container.rank(); dim ++ ) {
163 if( rank1Container.dimension(dim) != rank1ContainerAlt.dimension(dim) ) {
165 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
166 *outStream <<
" Dimension " << dim <<
" using ctor with array of dimensions = " << rank1Container.dimension(dim) <<
"\n";
167 *outStream <<
" Dimension " << dim <<
" using ctor with list of dimensions = " << rank1ContainerAlt.dimension(dim) <<
"\n";
173 <<
"===============================================================================\n"\
174 <<
"| TEST 1-b: Access by enumeration, multi-index array and multi-index list |\n"\
175 <<
"===============================================================================\n";
178 for(
int enumeration = 0; enumeration < containerSize; enumeration++) {
182 rank1Container.getMultiIndex(multiIndex, enumeration);
183 rank1Container.getMultiIndex(i0, enumeration);
184 if( (multiIndex[0] != i0) ) {
186 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
187 *outStream <<
" Multi-index as array = ["
188 << multiIndex[0] <<
"]\n";
189 *outStream <<
" Multi-index as list = (" << i0 <<
")\n";
193 if( rank1Container[enumeration] != rank1Container.getValue(multiIndex) ) {
195 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
196 *outStream <<
" Value by enumeration = " << rank1Container[enumeration] <<
"\n";
197 *outStream <<
" Value by multi-index array = " << rank1Container.getValue(multiIndex) <<
"\n";
201 if( rank1Container(i0) != rank1Container.getValue(multiIndex) ) {
203 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
204 *outStream <<
" Value by multi-index list = " << rank1Container(i0) <<
"\n";
205 *outStream <<
" Value by multi-index array = " << rank1Container.getValue(multiIndex) <<
"\n";
209 if( rank1Container(i0) != rank1Container[i0] ) {
211 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
212 *outStream <<
" Value by multi-index list = " << rank1Container(i0) <<
"\n";
213 *outStream <<
" Value by overloaded [] = " << rank1Container[i0] <<
"\n";
219 <<
"===============================================================================\n"\
220 <<
"| TEST 1-c: Access by multi-index array and list & compare with data array |\n"\
221 <<
"===============================================================================\n";
224 for(
int i=0; i < dimension[0]; i++){
228 int enumeration = rank1Container.getEnumeration(multiIndex);
231 if( enumeration != rank1Container.getEnumeration(i) ) {
233 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
234 *outStream <<
" Enumeration from multi-index array = " << enumeration <<
"\n";
235 *outStream <<
" Enumeration from multi-index list = " << rank1Container.getEnumeration(i) <<
"\n";
239 if(dataArray[enumeration] != rank1Container.getValue(multiIndex)) {
241 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
242 *outStream <<
" Value by multi-index array = " << rank1Container.getValue(multiIndex) <<
"\n";
243 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
247 if(dataArray[enumeration] != rank1Container(i)) {
249 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
250 *outStream <<
" Value by multi-index list = " << rank1Container(i) <<
"\n";
251 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
255 if( rank1Container(i) != rank1Container.getValue(multiIndex)) {
257 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
258 *outStream <<
" Value by multi-index array = " << rank1Container.getValue(multiIndex) <<
"\n";
259 *outStream <<
" Value by multi-index list = " << rank1Container(i) <<
"\n";
265 <<
"===============================================================================\n"\
266 <<
"| TEST 1-d: Store zeroes and empty container |\n"\
267 <<
"===============================================================================\n";
269 rank1Container.initialize();
271 for (
int i=0; i<rank1Container.size(); i++) {
272 sum += rank1Container[i];
276 *outStream <<
" Container size = " << rank1Container.size() <<
"\n";
277 *outStream <<
" Container rank = " << rank1Container.rank() <<
"\n";
280 rank1Container.clear();
281 if( !(rank1Container.size() == 0 && rank1Container.rank() == 0)) {
283 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
284 *outStream <<
" Container size = " << rank1Container.size() <<
"\n";
285 *outStream <<
" Container rank = " << rank1Container.rank() <<
"\n";
289 catch (std::logic_error err) {
290 *outStream << err.what() <<
"\n";
297 <<
"===============================================================================\n"\
298 <<
"| TEST 2: Rank-2 FieldContainer |\n"\
299 <<
"===============================================================================\n";
303 multiIndex.resize(2);
312 dataSize = dimension[0];
313 for(
int r = 1; r < (int)dimension.size(); r++){
314 dataSize *= dimension[r];
316 dataArray.resize(dataSize);
320 for(
int i=0; i < dimension[0]; i++){
321 for(
int j=0; j < dimension[1]; j++){
322 dataArray[counter] = (double)counter;
329 <<
"===============================================================================\n"\
330 <<
"| TEST 2-a: Compare constructors with array and list of dimensions |\n"\
331 <<
"===============================================================================\n";
341 containerSize = rank2Container.size();
342 containerRank = rank2Container.rank();
343 multiIndex.resize(containerRank);
345 if( rank2Container.size() != rank2ContainerAlt.size() ) {
347 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
348 *outStream <<
" Size using ctor with array of dimensions = " << rank2Container.size() <<
"\n";
349 *outStream <<
" Size using ctor with list of dimensions = " << rank2ContainerAlt.size() <<
"\n";
352 if( rank2Container.rank() != rank2ContainerAlt.rank() ) {
354 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
355 *outStream <<
" Rank using ctor with array of dimensions = " << rank2Container.rank() <<
"\n";
356 *outStream <<
" Rank using ctor with list of dimensions = " << rank2ContainerAlt.rank() <<
"\n";
359 for(
int dim = 0; dim < rank2Container.rank(); dim ++ ) {
360 if( rank2Container.dimension(dim) != rank2ContainerAlt.dimension(dim) ) {
362 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
363 *outStream <<
" Dimension " << dim <<
" using ctor with array of dimensions = " << rank2Container.dimension(dim) <<
"\n";
364 *outStream <<
" Dimension " << dim <<
" using ctor with list of dimensions = " << rank2ContainerAlt.dimension(dim) <<
"\n";
370 <<
"===============================================================================\n"\
371 <<
"| TEST 2-b: Access by enumeration, multi-index array and multi-index list |\n"\
372 <<
"===============================================================================\n";
375 for(
int enumeration = 0; enumeration < containerSize; enumeration++) {
379 rank2Container.getMultiIndex(multiIndex, enumeration);
380 rank2Container.getMultiIndex(i0, i1, enumeration);
381 if( (multiIndex[0] != i0) ||
382 (multiIndex[1] != i1) ) {
384 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
385 *outStream <<
" Multi-index as array = ["
386 << multiIndex[0] << multiIndex[1] <<
"]\n";
387 *outStream <<
" Multi-index as list = (" << i0 <<
"," << i1 <<
")\n";
391 if( rank2Container[enumeration] != rank2Container.getValue(multiIndex) ) {
393 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
394 *outStream <<
" Value by enumeration = " << rank2Container[enumeration] <<
"\n";
395 *outStream <<
" Value by multi-index array = " << rank2Container.getValue(multiIndex) <<
"\n";
399 if( rank2Container(i0,i1) != rank2Container.getValue(multiIndex) ) {
401 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
402 *outStream <<
" Value by multi-index list = " << rank2Container(i0,i1) <<
"\n";
403 *outStream <<
" Value by multi-index array = " << rank2Container.getValue(multiIndex) <<
"\n";
409 <<
"===============================================================================\n"\
410 <<
"| TEST 2-c: Access by multi-index array and list & compare with data array |\n"\
411 <<
"===============================================================================\n";
414 for(
int i=0; i < dimension[0]; i++){
416 for(
int j=0; j < dimension[1]; j++){
420 int enumeration = rank2Container.getEnumeration(multiIndex);
423 if( enumeration != rank2Container.getEnumeration(i,j) ) {
425 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
426 *outStream <<
" Enumeration from multi-index array = " << enumeration <<
"\n";
427 *outStream <<
" Enumeration from multi-index list = " << rank2Container.getEnumeration(i,j) <<
"\n";
431 if(dataArray[enumeration] != rank2Container.getValue(multiIndex)) {
433 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
434 *outStream <<
" Value by multi-index array = " << rank2Container.getValue(multiIndex) <<
"\n";
435 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
439 if(dataArray[enumeration] != rank2Container(i,j)) {
441 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
442 *outStream <<
" Value by multi-index list = " << rank2Container(i,j) <<
"\n";
443 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
447 if( rank2Container(i,j) != rank2Container.getValue(multiIndex)) {
449 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
450 *outStream <<
" Value by multi-index array = " << rank2Container.getValue(multiIndex) <<
"\n";
451 *outStream <<
" Value by multi-index list = " << rank2Container(i,j) <<
"\n";
458 <<
"===============================================================================\n"\
459 <<
"| TEST 2-d: Store zeroes and empty container |\n"\
460 <<
"===============================================================================\n";
462 rank2Container.initialize();
464 for (
int i=0; i<rank2Container.size(); i++) {
465 sum += rank2Container[i];
469 *outStream <<
" Container size = " << rank2Container.size() <<
"\n";
470 *outStream <<
" Container rank = " << rank2Container.rank() <<
"\n";
473 rank2Container.clear();
474 if( !(rank2Container.size() == 0 && rank2Container.rank() == 0)) {
476 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
477 *outStream <<
" Container size = " << rank2Container.size() <<
"\n";
478 *outStream <<
" Container rank = " << rank2Container.rank() <<
"\n";
482 catch (std::logic_error err) {
483 *outStream << err.what() <<
"\n";
491 <<
"===============================================================================\n"\
492 <<
"| TEST 3: Rank-3 FieldContainer |\n"\
493 <<
"===============================================================================\n";
497 multiIndex.resize(3);
508 dataSize = dimension[0];
509 for(
int r = 1; r < (int)dimension.size(); r++){
510 dataSize *= dimension[r];
512 dataArray.resize(dataSize);
516 for(
int i=0; i < dimension[0]; i++){
517 for(
int j=0; j < dimension[1]; j++){
518 for(
int k=0; k < dimension[2]; k++){
519 dataArray[counter] = (double)counter;
527 <<
"===============================================================================\n"\
528 <<
"| TEST 3-a: Compare constructors with array and list of dimensions |\n"\
529 <<
"===============================================================================\n";
539 containerSize = rank3Container.size();
540 containerRank = rank3Container.rank();
541 multiIndex.resize(containerRank);
543 if( rank3Container.size() != rank3ContainerAlt.size() ) {
545 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
546 *outStream <<
" Size using ctor with array of dimensions = " << rank3Container.size() <<
"\n";
547 *outStream <<
" Size using ctor with list of dimensions = " << rank3ContainerAlt.size() <<
"\n";
550 if( rank3Container.rank() != rank3ContainerAlt.rank() ) {
552 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
553 *outStream <<
" Rank using ctor with array of dimensions = " << rank3Container.rank() <<
"\n";
554 *outStream <<
" Rank using ctor with list of dimensions = " << rank3ContainerAlt.rank() <<
"\n";
557 for(
int dim = 0; dim < rank3Container.rank(); dim ++ ) {
558 if( rank3Container.dimension(dim) != rank3ContainerAlt.dimension(dim) ) {
560 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
561 *outStream <<
" Dimension " << dim <<
" using ctor with array of dimensions = " << rank3Container.dimension(dim) <<
"\n";
562 *outStream <<
" Dimension " << dim <<
" using ctor with list of dimensions = " << rank3ContainerAlt.dimension(dim) <<
"\n";
568 <<
"===============================================================================\n"\
569 <<
"| TEST 3-b: Access by enumeration, multi-index array and multi-index list |\n"\
570 <<
"===============================================================================\n";
573 for(
int enumeration = 0; enumeration < containerSize; enumeration++) {
577 rank3Container.getMultiIndex(multiIndex, enumeration);
578 rank3Container.getMultiIndex(i0, i1, i2, enumeration);
579 if( (multiIndex[0] != i0) ||
580 (multiIndex[1] != i1) ||
581 (multiIndex[2] != i2) ) {
583 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
584 *outStream <<
" Multi-index as array = ["
585 << multiIndex[0] << multiIndex[1] << multiIndex[2] <<
"]\n";
586 *outStream <<
" Multi-index as list = (" << i0 <<
"," << i1 <<
"," << i2 <<
")\n";
590 if( rank3Container[enumeration] != rank3Container.getValue(multiIndex) ) {
592 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
593 *outStream <<
" Value by enumeration = " << rank3Container[enumeration] <<
"\n";
594 *outStream <<
" Value by multi-index array = " << rank3Container.getValue(multiIndex) <<
"\n";
598 if( rank3Container(i0,i1,i2) != rank3Container.getValue(multiIndex) ) {
600 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
601 *outStream <<
" Value by multi-index list = " << rank3Container(i0,i1,i2) <<
"\n";
602 *outStream <<
" Value by multi-index array = " << rank3Container.getValue(multiIndex) <<
"\n";
608 <<
"===============================================================================\n"\
609 <<
"| TEST 3-c: Access by multi-index array and list & compare with data array |\n"\
610 <<
"===============================================================================\n";
613 for(
int i=0; i < dimension[0]; i++){
615 for(
int j=0; j < dimension[1]; j++){
617 for(
int k=0; k < dimension[2]; k++){
621 int enumeration = rank3Container.getEnumeration(multiIndex);
624 if( enumeration != rank3Container.getEnumeration(i,j,k) ) {
626 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
627 *outStream <<
" Enumeration from multi-index array = " << enumeration <<
"\n";
628 *outStream <<
" Enumeration from multi-index list = " << rank3Container.getEnumeration(i,j,k) <<
"\n";
632 if(dataArray[enumeration] != rank3Container.getValue(multiIndex)) {
634 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
635 *outStream <<
" Value by multi-index array = " << rank3Container.getValue(multiIndex) <<
"\n";
636 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
640 if(dataArray[enumeration] != rank3Container(i,j,k)) {
642 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
643 *outStream <<
" Value by multi-index list = " << rank3Container(i,j,k) <<
"\n";
644 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
648 if( rank3Container(i,j,k) != rank3Container.getValue(multiIndex)) {
650 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
651 *outStream <<
" Value by multi-index array = " << rank3Container.getValue(multiIndex) <<
"\n";
652 *outStream <<
" Value by multi-index list = " << rank3Container(i,j,k) <<
"\n";
660 <<
"===============================================================================\n"\
661 <<
"| TEST 3-d: Store zeroes and empty container |\n"\
662 <<
"===============================================================================\n";
664 rank3Container.initialize();
666 for (
int i=0; i<rank3Container.size(); i++) {
667 sum += rank3Container[i];
671 *outStream <<
" Container size = " << rank3Container.size() <<
"\n";
672 *outStream <<
" Container rank = " << rank3Container.rank() <<
"\n";
675 rank3Container.clear();
676 if( !(rank3Container.size() == 0 && rank3Container.rank() == 0)) {
678 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
679 *outStream <<
" Container size = " << rank3Container.size() <<
"\n";
680 *outStream <<
" Container rank = " << rank3Container.rank() <<
"\n";
684 catch (std::logic_error err) {
685 *outStream << err.what() <<
"\n";
693 <<
"===============================================================================\n"\
694 <<
"| TEST 4: Rank-4 FieldContainer |\n"\
695 <<
"===============================================================================\n";
699 multiIndex.resize(4);
712 dataSize = dimension[0];
713 for(
int r = 1; r < (int)dimension.size(); r++){
714 dataSize *= dimension[r];
716 dataArray.resize(dataSize);
720 for(
int i=0; i < dimension[0]; i++){
721 for(
int j=0; j < dimension[1]; j++){
722 for(
int k=0; k < dimension[2]; k++){
723 for(
int l = 0; l < dimension[3]; l++){
724 dataArray[counter] = (double)counter;
733 <<
"===============================================================================\n"\
734 <<
"| TEST 4-a: Compare constructors with array and list of dimensions |\n"\
735 <<
"===============================================================================\n";
745 containerSize = rank4Container.size();
746 containerRank = rank4Container.rank();
747 multiIndex.resize(containerRank);
749 if( rank4Container.size() != rank4ContainerAlt.size() ) {
751 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
752 *outStream <<
" Size using ctor with array of dimensions = " << rank4Container.size() <<
"\n";
753 *outStream <<
" Size using ctor with list of dimensions = " << rank4ContainerAlt.size() <<
"\n";
756 if( rank4Container.rank() != rank4ContainerAlt.rank() ) {
758 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
759 *outStream <<
" Rank using ctor with array of dimensions = " << rank4Container.rank() <<
"\n";
760 *outStream <<
" Rank using ctor with list of dimensions = " << rank4ContainerAlt.rank() <<
"\n";
763 for(
int dim = 0; dim < rank4Container.rank(); dim ++ ) {
764 if( rank4Container.dimension(dim) != rank4ContainerAlt.dimension(dim) ) {
766 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
767 *outStream <<
" Dimension " << dim <<
" using ctor with array of dimensions = " << rank4Container.dimension(dim) <<
"\n";
768 *outStream <<
" Dimension " << dim <<
" using ctor with list of dimensions = " << rank4ContainerAlt.dimension(dim) <<
"\n";
774 <<
"===============================================================================\n"\
775 <<
"| TEST 4-b: Access by enumeration, multi-index array and multi-index list |\n"\
776 <<
"===============================================================================\n";
779 for(
int enumeration = 0; enumeration < containerSize; enumeration++) {
783 rank4Container.getMultiIndex(multiIndex, enumeration);
784 rank4Container.getMultiIndex(i0, i1, i2, i3, enumeration);
785 if( (multiIndex[0] != i0) ||
786 (multiIndex[1] != i1) ||
787 (multiIndex[2] != i2) ||
788 (multiIndex[3] != i3) ) {
790 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
791 *outStream <<
" Multi-index as array = ["
792 << multiIndex[0] << multiIndex[1] << multiIndex[2] << multiIndex[3] <<
"]\n";
793 *outStream <<
" Multi-index as list = (" << i0 <<
"," << i1 <<
"," << i2 <<
"," << i3 <<
")\n";
797 if( rank4Container[enumeration] != rank4Container.getValue(multiIndex) ) {
799 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
800 *outStream <<
" Value by enumeration = " << rank4Container[enumeration] <<
"\n";
801 *outStream <<
" Value by multi-index array = " << rank4Container.getValue(multiIndex) <<
"\n";
805 if( rank4Container(i0,i1,i2,i3) != rank4Container.getValue(multiIndex) ) {
807 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
808 *outStream <<
" Value by multi-index list = " << rank4Container(i0,i1,i2,i3) <<
"\n";
809 *outStream <<
" Value by multi-index array = " << rank4Container.getValue(multiIndex) <<
"\n";
815 <<
"===============================================================================\n"\
816 <<
"| TEST 4-c: Access by multi-index array and list & compare with data array |\n"\
817 <<
"===============================================================================\n";
820 for(
int i=0; i < dimension[0]; i++){
822 for(
int j=0; j < dimension[1]; j++){
824 for(
int k=0; k < dimension[2]; k++){
826 for(
int l = 0; l < dimension[3]; l++){
830 int enumeration = rank4Container.getEnumeration(multiIndex);
833 if( enumeration != rank4Container.getEnumeration(i,j,k,l) ) {
835 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
836 *outStream <<
" Enumeration from multi-index array = " << enumeration <<
"\n";
837 *outStream <<
" Enumeration from multi-index list = " << rank4Container.getEnumeration(i,j,k,l) <<
"\n";
841 if(dataArray[enumeration] != rank4Container.getValue(multiIndex)) {
843 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
844 *outStream <<
" Value by multi-index array = " << rank4Container.getValue(multiIndex) <<
"\n";
845 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
849 if(dataArray[enumeration] != rank4Container(i,j,k,l)) {
851 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
852 *outStream <<
" Value by multi-index list = " << rank4Container(i,j,k,l) <<
"\n";
853 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
857 if( rank4Container(i,j,k,l) != rank4Container.getValue(multiIndex)) {
859 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
860 *outStream <<
" Value by multi-index array = " << rank4Container.getValue(multiIndex) <<
"\n";
861 *outStream <<
" Value by multi-index list = " << rank4Container(i,j,k,l) <<
"\n";
870 <<
"===============================================================================\n"\
871 <<
"| TEST 4-d: Store zeroes and empty container |\n"\
872 <<
"===============================================================================\n";
874 rank4Container.initialize();
876 for (
int i=0; i<rank4Container.size(); i++) {
877 sum += rank4Container[i];
881 *outStream <<
" Container size = " << rank4Container.size() <<
"\n";
882 *outStream <<
" Container rank = " << rank4Container.rank() <<
"\n";
885 rank4Container.clear();
886 if( !(rank4Container.size() == 0 && rank4Container.rank() == 0)) {
888 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
889 *outStream <<
" Container size = " << rank4Container.size() <<
"\n";
890 *outStream <<
" Container rank = " << rank4Container.rank() <<
"\n";
894 catch (std::logic_error err) {
895 *outStream << err.what() <<
"\n";
902 <<
"===============================================================================\n"\
903 <<
"| TEST 5: Rank-5 FieldContainer |\n"\
904 <<
"===============================================================================\n";
908 multiIndex.resize(5);
923 dataSize = dimension[0];
924 for(
int r = 1; r < (int)dimension.size(); r++){
925 dataSize *= dimension[r];
927 dataArray.resize(dataSize);
931 for(
int i=0; i < dimension[0]; i++){
932 for(
int j=0; j < dimension[1]; j++){
933 for(
int k=0; k < dimension[2]; k++){
934 for(
int l = 0; l < dimension[3]; l++){
935 for(
int m = 0; m < dimension[4]; m++){
936 dataArray[counter] = (double)counter;
946 <<
"===============================================================================\n"\
947 <<
"| TEST 5-a: Compare constructors with array and list of dimensions |\n"\
948 <<
"===============================================================================\n";
958 containerSize = rank5Container.size();
959 containerRank = rank5Container.rank();
960 multiIndex.resize(containerRank);
962 if( rank5Container.size() != rank5ContainerAlt.size() ) {
964 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
965 *outStream <<
" Size using ctor with array of dimensions = " << rank5Container.size() <<
"\n";
966 *outStream <<
" Size using ctor with list of dimensions = " << rank5ContainerAlt.size() <<
"\n";
969 if( rank5Container.rank() != rank5ContainerAlt.rank() ) {
971 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
972 *outStream <<
" Rank using ctor with array of dimensions = " << rank5Container.rank() <<
"\n";
973 *outStream <<
" Rank using ctor with list of dimensions = " << rank5ContainerAlt.rank() <<
"\n";
976 for(
int dim = 0; dim < rank5Container.rank(); dim ++ ) {
977 if( rank5Container.dimension(dim) != rank5ContainerAlt.dimension(dim) ) {
979 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
980 *outStream <<
" Dimension " << dim <<
" using ctor with array of dimensions = " << rank5Container.dimension(dim) <<
"\n";
981 *outStream <<
" Dimension " << dim <<
" using ctor with list of dimensions = " << rank5ContainerAlt.dimension(dim) <<
"\n";
987 <<
"===============================================================================\n"\
988 <<
"| TEST 5-b: Access by enumeration, multi-index array and multi-index list |\n"\
989 <<
"===============================================================================\n";
992 for(
int enumeration = 0; enumeration < containerSize; enumeration++) {
996 rank5Container.getMultiIndex(multiIndex, enumeration);
997 rank5Container.getMultiIndex(i0, i1, i2, i3, i4, enumeration);
998 if( (multiIndex[0] != i0) ||
999 (multiIndex[1] != i1) ||
1000 (multiIndex[2] != i2) ||
1001 (multiIndex[3] != i3) ||
1002 (multiIndex[4] != i4) ) {
1004 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1005 *outStream <<
" Multi-index as array = ["
1006 << multiIndex[0] << multiIndex[1] << multiIndex[2] << multiIndex[3] << multiIndex[4] <<
"]\n";
1007 *outStream <<
" Multi-index as list = (" << i0 <<
"," << i1 <<
"," << i2 <<
"," << i3 <<
"," << i4 <<
")\n";
1011 if( rank5Container[enumeration] != rank5Container.getValue(multiIndex) ) {
1013 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1014 *outStream <<
" Value by enumeration = " << rank5Container[enumeration] <<
"\n";
1015 *outStream <<
" Value by multi-index array = " << rank5Container.getValue(multiIndex) <<
"\n";
1019 if( rank5Container(i0,i1,i2,i3,i4) != rank5Container.getValue(multiIndex) ) {
1021 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1022 *outStream <<
" Value by multi-index list = " << rank5Container(i0,i1,i2,i3,i4) <<
"\n";
1023 *outStream <<
" Value by multi-index array = " << rank5Container.getValue(multiIndex) <<
"\n";
1029 <<
"===============================================================================\n"\
1030 <<
"| TEST 5-c: Access by multi-index array and list & compare with data array |\n"\
1031 <<
"===============================================================================\n";
1034 for(
int i=0; i < dimension[0]; i++){
1036 for(
int j=0; j < dimension[1]; j++){
1038 for(
int k=0; k < dimension[2]; k++){
1040 for(
int l = 0; l < dimension[3]; l++){
1042 for(
int m = 0; m < dimension[4]; m++){
1046 int enumeration = rank5Container.getEnumeration(multiIndex);
1049 if( enumeration != rank5Container.getEnumeration(i,j,k,l,m) ) {
1051 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1052 *outStream <<
" Enumeration from multi-index array = " << enumeration <<
"\n";
1053 *outStream <<
" Enumeration from multi-index list = " << rank5Container.getEnumeration(i,j,k,l,m) <<
"\n";
1057 if(dataArray[enumeration] != rank5Container.getValue(multiIndex)) {
1059 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1060 *outStream <<
" Value by multi-index array = " << rank5Container.getValue(multiIndex) <<
"\n";
1061 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
1065 if(dataArray[enumeration] != rank5Container(i,j,k,l,m)) {
1067 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1068 *outStream <<
" Value by multi-index list = " << rank5Container(i,j,k,l,m) <<
"\n";
1069 *outStream <<
" Value from data array = " << dataArray[enumeration] <<
"\n";
1073 if( rank5Container(i,j,k,l,m) != rank5Container.getValue(multiIndex)) {
1075 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1076 *outStream <<
" Value by multi-index array = " << rank5Container.getValue(multiIndex) <<
"\n";
1077 *outStream <<
" Value by multi-index list = " << rank5Container(i,j,k,l,m) <<
"\n";
1087 <<
"===============================================================================\n"\
1088 <<
"| TEST 5-d: Store zeroes and empty container |\n"\
1089 <<
"===============================================================================\n";
1091 rank5Container.initialize();
1093 for (
int i=0; i<rank5Container.size(); i++) {
1094 sum += rank5Container[i];
1096 if( (sum != 0.0) ) {
1098 *outStream <<
" Container size = " << rank5Container.size() <<
"\n";
1099 *outStream <<
" Container rank = " << rank5Container.rank() <<
"\n";
1102 rank5Container.clear();
1103 if( !(rank5Container.size() == 0 && rank5Container.rank() == 0)) {
1105 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1106 *outStream <<
" Container size = " << rank5Container.size() <<
"\n";
1107 *outStream <<
" Container rank = " << rank5Container.rank() <<
"\n";
1111 catch (std::logic_error err) {
1112 *outStream << err.what() <<
"\n";
1118 <<
"===============================================================================\n"\
1119 <<
"| TEST 6: Resize container based on another container |\n"\
1120 <<
"===============================================================================\n";
1126 hisContainer.resize(myContainer);
1127 if ( hisContainer.rank() != myContainer.rank() ) {
1129 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1130 *outStream <<
" Rank of target container = " << hisContainer.rank() <<
"\n";
1131 *outStream <<
" Rank of argument container = " << myContainer.rank() <<
"\n";
1134 for(
int dim = 0; dim < myContainer.rank(); dim++){
1135 if ( hisContainer.dimension(dim) != myContainer.dimension(dim) ) {
1137 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
1138 *outStream <<
" Dimension " << dim <<
" of target container = " << hisContainer.dimension(dim) <<
"\n";
1139 *outStream <<
" Dimension " << dim <<
" of argument container = " << myContainer.dimension(dim) <<
"\n";
1144 catch (std::logic_error err) {
1145 *outStream << err.what() <<
"\n";
1155 std::cout <<
"End Result: TEST FAILED\n";
1157 std::cout <<
"End Result: TEST PASSED\n";
1160 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.