|
Intrepid
|
00001 // @HEADER 00002 // ************************************************************************ 00003 // 00004 // Intrepid Package 00005 // Copyright (2007) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Pavel Bochev (pbboche@sandia.gov) 00038 // Denis Ridzal (dridzal@sandia.gov), or 00039 // Kara Peterson (kjpeter@sandia.gov) 00040 // 00041 // ************************************************************************ 00042 // @HEADER 00043 00044 00050 #include "Intrepid_FieldContainer.hpp" 00051 #include "Teuchos_oblackholestream.hpp" 00052 #include "Teuchos_RCP.hpp" 00053 #include "Teuchos_GlobalMPISession.hpp" 00054 00055 00056 using namespace Intrepid; 00057 00058 int main(int argc, char *argv[]) { 00059 00060 Teuchos::GlobalMPISession mpiSession(&argc, &argv); 00061 00062 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. 00063 int iprint = argc - 1; 00064 00065 Teuchos::RCP<std::ostream> outStream; 00066 Teuchos::oblackholestream bhs; // outputs nothing 00067 00068 if (iprint > 0) 00069 outStream = Teuchos::rcp(&std::cout, false); 00070 else 00071 outStream = Teuchos::rcp(&bhs, false); 00072 00073 // Save the format state of the original std::cout. 00074 Teuchos::oblackholestream oldFormatState; 00075 oldFormatState.copyfmt(std::cout); 00076 00077 *outStream \ 00078 << "===============================================================================\n" \ 00079 << "| |\n" \ 00080 << "| Unit Test FieldContainer |\n" \ 00081 << "| |\n" \ 00082 << "| 1) Value accesss by multi-index and enumeration, setting values |\n" \ 00083 << "| |\n" \ 00084 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \ 00085 << "| Denis Ridzal (dridzal@sandia.gov). |\n" \ 00086 << "| |\n" \ 00087 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ 00088 << "| Trilinos website: http://trilinos.sandia.gov |\n" \ 00089 << "| |\n" \ 00090 << "===============================================================================\n"; 00091 00092 int errorFlag = 0; 00093 00094 // Define variables to construct and use FieldContainer: 00095 Teuchos::Array<double> dataArray; 00096 Teuchos::Array<int> dimension; 00097 Teuchos::Array<int> multiIndex; 00098 int dim0, dim1, dim2, dim3, dim4; 00099 int containerSize; 00100 int containerRank; 00101 int dataSize; 00102 int counter; 00103 00104 00105 *outStream \ 00106 << "\n" 00107 << "===============================================================================\n"\ 00108 << "| TEST 1: Rank-1 FieldContainer |\n"\ 00109 << "===============================================================================\n"; 00110 00111 // Adjust for rank-1 containers 00112 dimension.resize(1); 00113 multiIndex.resize(1); 00114 dim0 = 267; 00115 00116 // Set dimensions 00117 dimension[0] = dim0; 00118 00119 // Define Teuchos::Array with dimension equal to FieldContainer capacity (determined from dimension) 00120 dataSize = dimension[0]; 00121 dataArray.resize(dataSize); 00122 00123 // Fill with data 00124 counter = 0; 00125 for(int i=0; i < dimension[0]; i++){ 00126 dataArray[counter] = (double)counter; 00127 counter++; 00128 } 00129 00130 *outStream \ 00131 << "\n" 00132 << "===============================================================================\n"\ 00133 << "| TEST 1-a: Compare constructors with array and list of dimensions |\n"\ 00134 << "===============================================================================\n"; 00135 try{ 00136 00137 // Using ctor with array of dimensions and array of data 00138 FieldContainer<double> rank1Container(dimension, dataArray); 00139 00140 // Using ctor with list of dimensions and no data 00141 FieldContainer<double> rank1ContainerAlt(dim0); 00142 00143 // Initialize variables 00144 containerSize = rank1Container.size(); 00145 containerRank = rank1Container.rank(); 00146 multiIndex.resize(containerRank); 00147 00148 if( rank1Container.size() != rank1ContainerAlt.size() ) { 00149 errorFlag++; 00150 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00151 *outStream << " Size using ctor with array of dimensions = " << rank1Container.size() << "\n"; 00152 *outStream << " Size using ctor with list of dimensions = " << rank1ContainerAlt.size() << "\n"; 00153 } 00154 00155 if( rank1Container.rank() != rank1ContainerAlt.rank() ) { 00156 errorFlag++; 00157 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00158 *outStream << " Rank using ctor with array of dimensions = " << rank1Container.rank() << "\n"; 00159 *outStream << " Rank using ctor with list of dimensions = " << rank1ContainerAlt.rank() << "\n"; 00160 } 00161 00162 for(int dim = 0; dim < rank1Container.rank(); dim ++ ) { 00163 if( rank1Container.dimension(dim) != rank1ContainerAlt.dimension(dim) ) { 00164 errorFlag++; 00165 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00166 *outStream << " Dimension " << dim << " using ctor with array of dimensions = " << rank1Container.dimension(dim) << "\n"; 00167 *outStream << " Dimension " << dim << " using ctor with list of dimensions = " << rank1ContainerAlt.dimension(dim) << "\n"; 00168 } 00169 } 00170 00171 *outStream \ 00172 << "\n" 00173 << "===============================================================================\n"\ 00174 << "| TEST 1-b: Access by enumeration, multi-index array and multi-index list |\n"\ 00175 << "===============================================================================\n"; 00176 00177 // Loop over container by enumeration 00178 for(int enumeration = 0; enumeration < containerSize; enumeration++) { 00179 int i0; 00180 00181 // Convert enumeration to multi-index array and multi-index list and compare values 00182 rank1Container.getMultiIndex(multiIndex, enumeration); 00183 rank1Container.getMultiIndex(i0, enumeration); 00184 if( (multiIndex[0] != i0) ) { 00185 errorFlag++; 00186 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00187 *outStream << " Multi-index as array = [" 00188 << multiIndex[0] << "]\n"; 00189 *outStream << " Multi-index as list = (" << i0 << ")\n"; 00190 } 00191 00192 // Check if access by enumeration gives the same value as access by multi-index array 00193 if( rank1Container[enumeration] != rank1Container.getValue(multiIndex) ) { 00194 errorFlag++; 00195 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00196 *outStream << " Value by enumeration = " << rank1Container[enumeration] << "\n"; 00197 *outStream << " Value by multi-index array = " << rank1Container.getValue(multiIndex) << "\n"; 00198 } 00199 00200 // Check if access by multi-index list gives the same value as access by multi-index array 00201 if( rank1Container(i0) != rank1Container.getValue(multiIndex) ) { 00202 errorFlag++; 00203 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00204 *outStream << " Value by multi-index list = " << rank1Container(i0) << "\n"; 00205 *outStream << " Value by multi-index array = " << rank1Container.getValue(multiIndex) << "\n"; 00206 } 00207 00208 // Check if access by multi-index list gives the same value as access by [] (only for rank-1!) 00209 if( rank1Container(i0) != rank1Container[i0] ) { 00210 errorFlag++; 00211 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00212 *outStream << " Value by multi-index list = " << rank1Container(i0) << "\n"; 00213 *outStream << " Value by overloaded [] = " << rank1Container[i0] << "\n"; 00214 } 00215 } 00216 00217 *outStream \ 00218 << "\n" 00219 << "===============================================================================\n"\ 00220 << "| TEST 1-c: Access by multi-index array and list & compare with data array |\n"\ 00221 << "===============================================================================\n"; 00222 00223 // Loop over container by multi-index 00224 for(int i=0; i < dimension[0]; i++){ 00225 multiIndex[0] = i; 00226 00227 // Method that takes array of multi-indices 00228 int enumeration = rank1Container.getEnumeration(multiIndex); 00229 00230 // Compare with method that takes a list of multi-indices 00231 if( enumeration != rank1Container.getEnumeration(i) ) { 00232 errorFlag++; 00233 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00234 *outStream << " Enumeration from multi-index array = " << enumeration << "\n"; 00235 *outStream << " Enumeration from multi-index list = " << rank1Container.getEnumeration(i) << "\n"; 00236 } 00237 00238 // Check if access by multi-index array matches values in original dataArray 00239 if(dataArray[enumeration] != rank1Container.getValue(multiIndex)) { 00240 errorFlag++; 00241 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00242 *outStream << " Value by multi-index array = " << rank1Container.getValue(multiIndex) << "\n"; 00243 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00244 } 00245 00246 // Check if access by multi-index list matches values in original dataArray 00247 if(dataArray[enumeration] != rank1Container(i)) { 00248 errorFlag++; 00249 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00250 *outStream << " Value by multi-index list = " << rank1Container(i) << "\n"; 00251 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00252 } 00253 00254 // Check if access by multi-index array matches access by multi-index list 00255 if( rank1Container(i) != rank1Container.getValue(multiIndex)) { 00256 errorFlag++; 00257 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00258 *outStream << " Value by multi-index array = " << rank1Container.getValue(multiIndex) << "\n"; 00259 *outStream << " Value by multi-index list = " << rank1Container(i) << "\n"; 00260 } 00261 } 00262 00263 *outStream \ 00264 << "\n" 00265 << "===============================================================================\n"\ 00266 << "| TEST 1-d: Store zeroes and empty container |\n"\ 00267 << "===============================================================================\n"; 00268 00269 rank1Container.initialize(); 00270 double sum = 0.0; 00271 for (int i=0; i<rank1Container.size(); i++) { 00272 sum += rank1Container[i]; 00273 } 00274 if( (sum != 0.0) ) { 00275 errorFlag++; 00276 *outStream << " Container size = " << rank1Container.size() << "\n"; 00277 *outStream << " Container rank = " << rank1Container.rank() << "\n"; 00278 } 00279 00280 rank1Container.clear(); 00281 if( !(rank1Container.size() == 0 && rank1Container.rank() == 0)) { 00282 errorFlag++; 00283 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00284 *outStream << " Container size = " << rank1Container.size() << "\n"; 00285 *outStream << " Container rank = " << rank1Container.rank() << "\n"; 00286 } 00287 } //try 00288 00289 catch (std::logic_error err) { 00290 *outStream << err.what() << "\n"; 00291 errorFlag = -1000; 00292 }; 00293 00294 00295 *outStream \ 00296 << "\n" 00297 << "===============================================================================\n"\ 00298 << "| TEST 2: Rank-2 FieldContainer |\n"\ 00299 << "===============================================================================\n"; 00300 00301 // Adjust for rank-2 containers 00302 dimension.resize(2); 00303 multiIndex.resize(2); 00304 dim0 = 1; 00305 dim1 = 55; 00306 00307 // Set dimensions 00308 dimension[0] = dim0; 00309 dimension[1] = dim1; 00310 00311 // Define Teuchos::Array with dimension equal to FieldContainer capacity (determined from dimension) 00312 dataSize = dimension[0]; 00313 for(int r = 1; r < (int)dimension.size(); r++){ 00314 dataSize *= dimension[r]; 00315 } 00316 dataArray.resize(dataSize); 00317 00318 // Fill with data 00319 counter = 0; 00320 for(int i=0; i < dimension[0]; i++){ 00321 for(int j=0; j < dimension[1]; j++){ 00322 dataArray[counter] = (double)counter; 00323 counter++; 00324 } 00325 } 00326 00327 *outStream \ 00328 << "\n" 00329 << "===============================================================================\n"\ 00330 << "| TEST 2-a: Compare constructors with array and list of dimensions |\n"\ 00331 << "===============================================================================\n"; 00332 try{ 00333 00334 // Using ctor with array of dimensions and array of data 00335 FieldContainer<double> rank2Container(dimension, dataArray); 00336 00337 // Using ctor with list of dimensions and no data 00338 FieldContainer<double> rank2ContainerAlt(dim0, dim1); 00339 00340 // Initialize variables 00341 containerSize = rank2Container.size(); 00342 containerRank = rank2Container.rank(); 00343 multiIndex.resize(containerRank); 00344 00345 if( rank2Container.size() != rank2ContainerAlt.size() ) { 00346 errorFlag++; 00347 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00348 *outStream << " Size using ctor with array of dimensions = " << rank2Container.size() << "\n"; 00349 *outStream << " Size using ctor with list of dimensions = " << rank2ContainerAlt.size() << "\n"; 00350 } 00351 00352 if( rank2Container.rank() != rank2ContainerAlt.rank() ) { 00353 errorFlag++; 00354 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00355 *outStream << " Rank using ctor with array of dimensions = " << rank2Container.rank() << "\n"; 00356 *outStream << " Rank using ctor with list of dimensions = " << rank2ContainerAlt.rank() << "\n"; 00357 } 00358 00359 for(int dim = 0; dim < rank2Container.rank(); dim ++ ) { 00360 if( rank2Container.dimension(dim) != rank2ContainerAlt.dimension(dim) ) { 00361 errorFlag++; 00362 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00363 *outStream << " Dimension " << dim << " using ctor with array of dimensions = " << rank2Container.dimension(dim) << "\n"; 00364 *outStream << " Dimension " << dim << " using ctor with list of dimensions = " << rank2ContainerAlt.dimension(dim) << "\n"; 00365 } 00366 } 00367 00368 *outStream \ 00369 << "\n" 00370 << "===============================================================================\n"\ 00371 << "| TEST 2-b: Access by enumeration, multi-index array and multi-index list |\n"\ 00372 << "===============================================================================\n"; 00373 00374 // Loop over container by enumeration 00375 for(int enumeration = 0; enumeration < containerSize; enumeration++) { 00376 int i0,i1; 00377 00378 // Convert enumeration to multi-index array and multi-index list and compare values 00379 rank2Container.getMultiIndex(multiIndex, enumeration); 00380 rank2Container.getMultiIndex(i0, i1, enumeration); 00381 if( (multiIndex[0] != i0) || 00382 (multiIndex[1] != i1) ) { 00383 errorFlag++; 00384 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00385 *outStream << " Multi-index as array = [" 00386 << multiIndex[0] << multiIndex[1] << "]\n"; 00387 *outStream << " Multi-index as list = (" << i0 << "," << i1 << ")\n"; 00388 } 00389 00390 // Check if access by enumeration gives the same value as access by multi-index array 00391 if( rank2Container[enumeration] != rank2Container.getValue(multiIndex) ) { 00392 errorFlag++; 00393 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00394 *outStream << " Value by enumeration = " << rank2Container[enumeration] << "\n"; 00395 *outStream << " Value by multi-index array = " << rank2Container.getValue(multiIndex) << "\n"; 00396 } 00397 00398 // Check if access by multi-index list gives the same value as access by multi-index array 00399 if( rank2Container(i0,i1) != rank2Container.getValue(multiIndex) ) { 00400 errorFlag++; 00401 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00402 *outStream << " Value by multi-index list = " << rank2Container(i0,i1) << "\n"; 00403 *outStream << " Value by multi-index array = " << rank2Container.getValue(multiIndex) << "\n"; 00404 } 00405 } 00406 00407 *outStream \ 00408 << "\n" 00409 << "===============================================================================\n"\ 00410 << "| TEST 2-c: Access by multi-index array and list & compare with data array |\n"\ 00411 << "===============================================================================\n"; 00412 00413 // Loop over container by multi-index 00414 for(int i=0; i < dimension[0]; i++){ 00415 multiIndex[0] = i; 00416 for(int j=0; j < dimension[1]; j++){ 00417 multiIndex[1] = j; 00418 00419 // Method that takes array of multi-indices 00420 int enumeration = rank2Container.getEnumeration(multiIndex); 00421 00422 // Compare with method that takes a list of multi-indices 00423 if( enumeration != rank2Container.getEnumeration(i,j) ) { 00424 errorFlag++; 00425 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00426 *outStream << " Enumeration from multi-index array = " << enumeration << "\n"; 00427 *outStream << " Enumeration from multi-index list = " << rank2Container.getEnumeration(i,j) << "\n"; 00428 } 00429 00430 // Check if access by multi-index array matches values in original dataArray 00431 if(dataArray[enumeration] != rank2Container.getValue(multiIndex)) { 00432 errorFlag++; 00433 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00434 *outStream << " Value by multi-index array = " << rank2Container.getValue(multiIndex) << "\n"; 00435 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00436 } 00437 00438 // Check if access by multi-index list matches values in original dataArray 00439 if(dataArray[enumeration] != rank2Container(i,j)) { 00440 errorFlag++; 00441 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00442 *outStream << " Value by multi-index list = " << rank2Container(i,j) << "\n"; 00443 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00444 } 00445 00446 // Check if access by multi-index array matches access by multi-index list 00447 if( rank2Container(i,j) != rank2Container.getValue(multiIndex)) { 00448 errorFlag++; 00449 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00450 *outStream << " Value by multi-index array = " << rank2Container.getValue(multiIndex) << "\n"; 00451 *outStream << " Value by multi-index list = " << rank2Container(i,j) << "\n"; 00452 } 00453 } 00454 } 00455 00456 *outStream \ 00457 << "\n" 00458 << "===============================================================================\n"\ 00459 << "| TEST 2-d: Store zeroes and empty container |\n"\ 00460 << "===============================================================================\n"; 00461 00462 rank2Container.initialize(); 00463 double sum = 0.0; 00464 for (int i=0; i<rank2Container.size(); i++) { 00465 sum += rank2Container[i]; 00466 } 00467 if( (sum != 0.0) ) { 00468 errorFlag++; 00469 *outStream << " Container size = " << rank2Container.size() << "\n"; 00470 *outStream << " Container rank = " << rank2Container.rank() << "\n"; 00471 } 00472 00473 rank2Container.clear(); 00474 if( !(rank2Container.size() == 0 && rank2Container.rank() == 0)) { 00475 errorFlag++; 00476 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00477 *outStream << " Container size = " << rank2Container.size() << "\n"; 00478 *outStream << " Container rank = " << rank2Container.rank() << "\n"; 00479 } 00480 } //try 00481 00482 catch (std::logic_error err) { 00483 *outStream << err.what() << "\n"; 00484 errorFlag = -1000; 00485 }; 00486 00487 00488 00489 *outStream \ 00490 << "\n" 00491 << "===============================================================================\n"\ 00492 << "| TEST 3: Rank-3 FieldContainer |\n"\ 00493 << "===============================================================================\n"; 00494 00495 // Adjust for rank-3 containers 00496 dimension.resize(3); 00497 multiIndex.resize(3); 00498 dim0 = 17; 00499 dim1 = 55; 00500 dim2 = 10; 00501 00502 // Set dimensions 00503 dimension[0] = dim0; 00504 dimension[1] = dim1; 00505 dimension[2] = dim2; 00506 00507 // Define Teuchos::Array with dimension equal to FieldContainer capacity (determined from dimension) 00508 dataSize = dimension[0]; 00509 for(int r = 1; r < (int)dimension.size(); r++){ 00510 dataSize *= dimension[r]; 00511 } 00512 dataArray.resize(dataSize); 00513 00514 // Fill with data 00515 counter = 0; 00516 for(int i=0; i < dimension[0]; i++){ 00517 for(int j=0; j < dimension[1]; j++){ 00518 for(int k=0; k < dimension[2]; k++){ 00519 dataArray[counter] = (double)counter; 00520 counter++; 00521 } 00522 } 00523 } 00524 00525 *outStream \ 00526 << "\n" 00527 << "===============================================================================\n"\ 00528 << "| TEST 3-a: Compare constructors with array and list of dimensions |\n"\ 00529 << "===============================================================================\n"; 00530 try{ 00531 00532 // Using ctor with array of dimensions and array of data 00533 FieldContainer<double> rank3Container(dimension, dataArray); 00534 00535 // Using ctor with list of dimensions and no data 00536 FieldContainer<double> rank3ContainerAlt(dim0, dim1, dim2); 00537 00538 // Initialize variables 00539 containerSize = rank3Container.size(); 00540 containerRank = rank3Container.rank(); 00541 multiIndex.resize(containerRank); 00542 00543 if( rank3Container.size() != rank3ContainerAlt.size() ) { 00544 errorFlag++; 00545 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00546 *outStream << " Size using ctor with array of dimensions = " << rank3Container.size() << "\n"; 00547 *outStream << " Size using ctor with list of dimensions = " << rank3ContainerAlt.size() << "\n"; 00548 } 00549 00550 if( rank3Container.rank() != rank3ContainerAlt.rank() ) { 00551 errorFlag++; 00552 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00553 *outStream << " Rank using ctor with array of dimensions = " << rank3Container.rank() << "\n"; 00554 *outStream << " Rank using ctor with list of dimensions = " << rank3ContainerAlt.rank() << "\n"; 00555 } 00556 00557 for(int dim = 0; dim < rank3Container.rank(); dim ++ ) { 00558 if( rank3Container.dimension(dim) != rank3ContainerAlt.dimension(dim) ) { 00559 errorFlag++; 00560 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00561 *outStream << " Dimension " << dim << " using ctor with array of dimensions = " << rank3Container.dimension(dim) << "\n"; 00562 *outStream << " Dimension " << dim << " using ctor with list of dimensions = " << rank3ContainerAlt.dimension(dim) << "\n"; 00563 } 00564 } 00565 00566 *outStream \ 00567 << "\n" 00568 << "===============================================================================\n"\ 00569 << "| TEST 3-b: Access by enumeration, multi-index array and multi-index list |\n"\ 00570 << "===============================================================================\n"; 00571 00572 // Loop over container by enumeration 00573 for(int enumeration = 0; enumeration < containerSize; enumeration++) { 00574 int i0,i1,i2; 00575 00576 // Convert enumeration to multi-index array and multi-index list and compare values 00577 rank3Container.getMultiIndex(multiIndex, enumeration); 00578 rank3Container.getMultiIndex(i0, i1, i2, enumeration); 00579 if( (multiIndex[0] != i0) || 00580 (multiIndex[1] != i1) || 00581 (multiIndex[2] != i2) ) { 00582 errorFlag++; 00583 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00584 *outStream << " Multi-index as array = [" 00585 << multiIndex[0] << multiIndex[1] << multiIndex[2] << "]\n"; 00586 *outStream << " Multi-index as list = (" << i0 << "," << i1 << "," << i2 << ")\n"; 00587 } 00588 00589 // Check if access by enumeration gives the same value as access by multi-index array 00590 if( rank3Container[enumeration] != rank3Container.getValue(multiIndex) ) { 00591 errorFlag++; 00592 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00593 *outStream << " Value by enumeration = " << rank3Container[enumeration] << "\n"; 00594 *outStream << " Value by multi-index array = " << rank3Container.getValue(multiIndex) << "\n"; 00595 } 00596 00597 // Check if access by multi-index list gives the same value as access by multi-index array 00598 if( rank3Container(i0,i1,i2) != rank3Container.getValue(multiIndex) ) { 00599 errorFlag++; 00600 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00601 *outStream << " Value by multi-index list = " << rank3Container(i0,i1,i2) << "\n"; 00602 *outStream << " Value by multi-index array = " << rank3Container.getValue(multiIndex) << "\n"; 00603 } 00604 } 00605 00606 *outStream \ 00607 << "\n" 00608 << "===============================================================================\n"\ 00609 << "| TEST 3-c: Access by multi-index array and list & compare with data array |\n"\ 00610 << "===============================================================================\n"; 00611 00612 // Loop over container by multi-index 00613 for(int i=0; i < dimension[0]; i++){ 00614 multiIndex[0] = i; 00615 for(int j=0; j < dimension[1]; j++){ 00616 multiIndex[1] = j; 00617 for(int k=0; k < dimension[2]; k++){ 00618 multiIndex[2] = k; 00619 00620 // Method that takes array of multi-indices 00621 int enumeration = rank3Container.getEnumeration(multiIndex); 00622 00623 // Compare with method that takes a list of multi-indices 00624 if( enumeration != rank3Container.getEnumeration(i,j,k) ) { 00625 errorFlag++; 00626 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00627 *outStream << " Enumeration from multi-index array = " << enumeration << "\n"; 00628 *outStream << " Enumeration from multi-index list = " << rank3Container.getEnumeration(i,j,k) << "\n"; 00629 } 00630 00631 // Check if access by multi-index array matches values in original dataArray 00632 if(dataArray[enumeration] != rank3Container.getValue(multiIndex)) { 00633 errorFlag++; 00634 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00635 *outStream << " Value by multi-index array = " << rank3Container.getValue(multiIndex) << "\n"; 00636 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00637 } 00638 00639 // Check if access by multi-index list matches values in original dataArray 00640 if(dataArray[enumeration] != rank3Container(i,j,k)) { 00641 errorFlag++; 00642 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00643 *outStream << " Value by multi-index list = " << rank3Container(i,j,k) << "\n"; 00644 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00645 } 00646 00647 // Check if access by multi-index array matches access by multi-index list 00648 if( rank3Container(i,j,k) != rank3Container.getValue(multiIndex)) { 00649 errorFlag++; 00650 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00651 *outStream << " Value by multi-index array = " << rank3Container.getValue(multiIndex) << "\n"; 00652 *outStream << " Value by multi-index list = " << rank3Container(i,j,k) << "\n"; 00653 } 00654 } 00655 } 00656 } 00657 00658 *outStream \ 00659 << "\n" 00660 << "===============================================================================\n"\ 00661 << "| TEST 3-d: Store zeroes and empty container |\n"\ 00662 << "===============================================================================\n"; 00663 00664 rank3Container.initialize(); 00665 double sum = 0.0; 00666 for (int i=0; i<rank3Container.size(); i++) { 00667 sum += rank3Container[i]; 00668 } 00669 if( (sum != 0.0) ) { 00670 errorFlag++; 00671 *outStream << " Container size = " << rank3Container.size() << "\n"; 00672 *outStream << " Container rank = " << rank3Container.rank() << "\n"; 00673 } 00674 00675 rank3Container.clear(); 00676 if( !(rank3Container.size() == 0 && rank3Container.rank() == 0)) { 00677 errorFlag++; 00678 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00679 *outStream << " Container size = " << rank3Container.size() << "\n"; 00680 *outStream << " Container rank = " << rank3Container.rank() << "\n"; 00681 } 00682 } //try 00683 00684 catch (std::logic_error err) { 00685 *outStream << err.what() << "\n"; 00686 errorFlag = -1000; 00687 }; 00688 00689 00690 00691 *outStream \ 00692 << "\n" 00693 << "===============================================================================\n"\ 00694 << "| TEST 4: Rank-4 FieldContainer |\n"\ 00695 << "===============================================================================\n"; 00696 00697 // Adjust for rank-4 containers 00698 dimension.resize(4); 00699 multiIndex.resize(4); 00700 dim0 = 27; 00701 dim1 = 4; 00702 dim2 = 11; 00703 dim3 = 6; 00704 00705 // Set dimensions 00706 dimension[0] = dim0; 00707 dimension[1] = dim1; 00708 dimension[2] = dim2; 00709 dimension[3] = dim3; 00710 00711 // Define Teuchos::Array with dimension equal to FieldContainer capacity (determined from dimension) 00712 dataSize = dimension[0]; 00713 for(int r = 1; r < (int)dimension.size(); r++){ 00714 dataSize *= dimension[r]; 00715 } 00716 dataArray.resize(dataSize); 00717 00718 // Fill with data 00719 counter = 0; 00720 for(int i=0; i < dimension[0]; i++){ 00721 for(int j=0; j < dimension[1]; j++){ 00722 for(int k=0; k < dimension[2]; k++){ 00723 for(int l = 0; l < dimension[3]; l++){ 00724 dataArray[counter] = (double)counter; 00725 counter++; 00726 } 00727 } 00728 } 00729 } 00730 00731 *outStream \ 00732 << "\n" 00733 << "===============================================================================\n"\ 00734 << "| TEST 4-a: Compare constructors with array and list of dimensions |\n"\ 00735 << "===============================================================================\n"; 00736 try{ 00737 00738 // Using ctor with array of dimensions and array of data 00739 FieldContainer<double> rank4Container(dimension, dataArray); 00740 00741 // Using ctor with list of dimensions and no data 00742 FieldContainer<double> rank4ContainerAlt(dim0, dim1, dim2, dim3); 00743 00744 // Initialize variables 00745 containerSize = rank4Container.size(); 00746 containerRank = rank4Container.rank(); 00747 multiIndex.resize(containerRank); 00748 00749 if( rank4Container.size() != rank4ContainerAlt.size() ) { 00750 errorFlag++; 00751 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00752 *outStream << " Size using ctor with array of dimensions = " << rank4Container.size() << "\n"; 00753 *outStream << " Size using ctor with list of dimensions = " << rank4ContainerAlt.size() << "\n"; 00754 } 00755 00756 if( rank4Container.rank() != rank4ContainerAlt.rank() ) { 00757 errorFlag++; 00758 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00759 *outStream << " Rank using ctor with array of dimensions = " << rank4Container.rank() << "\n"; 00760 *outStream << " Rank using ctor with list of dimensions = " << rank4ContainerAlt.rank() << "\n"; 00761 } 00762 00763 for(int dim = 0; dim < rank4Container.rank(); dim ++ ) { 00764 if( rank4Container.dimension(dim) != rank4ContainerAlt.dimension(dim) ) { 00765 errorFlag++; 00766 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00767 *outStream << " Dimension " << dim << " using ctor with array of dimensions = " << rank4Container.dimension(dim) << "\n"; 00768 *outStream << " Dimension " << dim << " using ctor with list of dimensions = " << rank4ContainerAlt.dimension(dim) << "\n"; 00769 } 00770 } 00771 00772 *outStream \ 00773 << "\n" 00774 << "===============================================================================\n"\ 00775 << "| TEST 4-b: Access by enumeration, multi-index array and multi-index list |\n"\ 00776 << "===============================================================================\n"; 00777 00778 // Loop over container by enumeration 00779 for(int enumeration = 0; enumeration < containerSize; enumeration++) { 00780 int i0,i1,i2,i3; 00781 00782 // Convert enumeration to multi-index array and multi-index list and compare values 00783 rank4Container.getMultiIndex(multiIndex, enumeration); 00784 rank4Container.getMultiIndex(i0, i1, i2, i3, enumeration); 00785 if( (multiIndex[0] != i0) || 00786 (multiIndex[1] != i1) || 00787 (multiIndex[2] != i2) || 00788 (multiIndex[3] != i3) ) { 00789 errorFlag++; 00790 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00791 *outStream << " Multi-index as array = [" 00792 << multiIndex[0] << multiIndex[1] << multiIndex[2] << multiIndex[3] << "]\n"; 00793 *outStream << " Multi-index as list = (" << i0 << "," << i1 << "," << i2 << "," << i3 << ")\n"; 00794 } 00795 00796 // Check if access by enumeration gives the same value as access by multi-index array 00797 if( rank4Container[enumeration] != rank4Container.getValue(multiIndex) ) { 00798 errorFlag++; 00799 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00800 *outStream << " Value by enumeration = " << rank4Container[enumeration] << "\n"; 00801 *outStream << " Value by multi-index array = " << rank4Container.getValue(multiIndex) << "\n"; 00802 } 00803 00804 // Check if access by multi-index list gives the same value as access by multi-index array 00805 if( rank4Container(i0,i1,i2,i3) != rank4Container.getValue(multiIndex) ) { 00806 errorFlag++; 00807 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00808 *outStream << " Value by multi-index list = " << rank4Container(i0,i1,i2,i3) << "\n"; 00809 *outStream << " Value by multi-index array = " << rank4Container.getValue(multiIndex) << "\n"; 00810 } 00811 } 00812 00813 *outStream \ 00814 << "\n" 00815 << "===============================================================================\n"\ 00816 << "| TEST 4-c: Access by multi-index array and list & compare with data array |\n"\ 00817 << "===============================================================================\n"; 00818 00819 // Loop over container by multi-index 00820 for(int i=0; i < dimension[0]; i++){ 00821 multiIndex[0] = i; 00822 for(int j=0; j < dimension[1]; j++){ 00823 multiIndex[1] = j; 00824 for(int k=0; k < dimension[2]; k++){ 00825 multiIndex[2] = k; 00826 for(int l = 0; l < dimension[3]; l++){ 00827 multiIndex[3] = l; 00828 00829 // Method that takes array of multi-indices 00830 int enumeration = rank4Container.getEnumeration(multiIndex); 00831 00832 // Compare with method that takes a list of multi-indices 00833 if( enumeration != rank4Container.getEnumeration(i,j,k,l) ) { 00834 errorFlag++; 00835 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00836 *outStream << " Enumeration from multi-index array = " << enumeration << "\n"; 00837 *outStream << " Enumeration from multi-index list = " << rank4Container.getEnumeration(i,j,k,l) << "\n"; 00838 } 00839 00840 // Check if access by multi-index array matches values in original dataArray 00841 if(dataArray[enumeration] != rank4Container.getValue(multiIndex)) { 00842 errorFlag++; 00843 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00844 *outStream << " Value by multi-index array = " << rank4Container.getValue(multiIndex) << "\n"; 00845 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00846 } 00847 00848 // Check if access by multi-index list matches values in original dataArray 00849 if(dataArray[enumeration] != rank4Container(i,j,k,l)) { 00850 errorFlag++; 00851 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00852 *outStream << " Value by multi-index list = " << rank4Container(i,j,k,l) << "\n"; 00853 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 00854 } 00855 00856 // Check if access by multi-index array matches access by multi-index list 00857 if( rank4Container(i,j,k,l) != rank4Container.getValue(multiIndex)) { 00858 errorFlag++; 00859 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00860 *outStream << " Value by multi-index array = " << rank4Container.getValue(multiIndex) << "\n"; 00861 *outStream << " Value by multi-index list = " << rank4Container(i,j,k,l) << "\n"; 00862 } 00863 } 00864 } 00865 } 00866 } 00867 00868 *outStream \ 00869 << "\n" 00870 << "===============================================================================\n"\ 00871 << "| TEST 4-d: Store zeroes and empty container |\n"\ 00872 << "===============================================================================\n"; 00873 00874 rank4Container.initialize(); 00875 double sum = 0.0; 00876 for (int i=0; i<rank4Container.size(); i++) { 00877 sum += rank4Container[i]; 00878 } 00879 if( (sum != 0.0) ) { 00880 errorFlag++; 00881 *outStream << " Container size = " << rank4Container.size() << "\n"; 00882 *outStream << " Container rank = " << rank4Container.rank() << "\n"; 00883 } 00884 00885 rank4Container.clear(); 00886 if( !(rank4Container.size() == 0 && rank4Container.rank() == 0)) { 00887 errorFlag++; 00888 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00889 *outStream << " Container size = " << rank4Container.size() << "\n"; 00890 *outStream << " Container rank = " << rank4Container.rank() << "\n"; 00891 } 00892 } //try 00893 00894 catch (std::logic_error err) { 00895 *outStream << err.what() << "\n"; 00896 errorFlag = -1000; 00897 }; 00898 00899 00900 *outStream \ 00901 << "\n" 00902 << "===============================================================================\n"\ 00903 << "| TEST 5: Rank-5 FieldContainer |\n"\ 00904 << "===============================================================================\n"; 00905 00906 // Adjust for rank-5 containers 00907 dimension.resize(5); 00908 multiIndex.resize(5); 00909 dim0 = 3; 00910 dim1 = 7; 00911 dim2 = 11; 00912 dim3 = 5; 00913 dim4 = 6; 00914 00915 // Set dimensions 00916 dimension[0] = dim0; 00917 dimension[1] = dim1; 00918 dimension[2] = dim2; 00919 dimension[3] = dim3; 00920 dimension[4] = dim4; 00921 00922 // Define Teuchos::Array with dimension equal to FieldContainer capacity (determined from dimension) 00923 dataSize = dimension[0]; 00924 for(int r = 1; r < (int)dimension.size(); r++){ 00925 dataSize *= dimension[r]; 00926 } 00927 dataArray.resize(dataSize); 00928 00929 // Fill with data 00930 counter = 0; 00931 for(int i=0; i < dimension[0]; i++){ 00932 for(int j=0; j < dimension[1]; j++){ 00933 for(int k=0; k < dimension[2]; k++){ 00934 for(int l = 0; l < dimension[3]; l++){ 00935 for(int m = 0; m < dimension[4]; m++){ 00936 dataArray[counter] = (double)counter; 00937 counter++; 00938 } 00939 } 00940 } 00941 } 00942 } 00943 00944 *outStream \ 00945 << "\n" 00946 << "===============================================================================\n"\ 00947 << "| TEST 5-a: Compare constructors with array and list of dimensions |\n"\ 00948 << "===============================================================================\n"; 00949 try{ 00950 00951 // Using ctor with array of dimensions and array of data 00952 FieldContainer<double> rank5Container(dimension, dataArray); 00953 00954 // Using ctor with list of dimensions and no data 00955 FieldContainer<double> rank5ContainerAlt(dim0, dim1, dim2, dim3, dim4); 00956 00957 // Initialize variables 00958 containerSize = rank5Container.size(); 00959 containerRank = rank5Container.rank(); 00960 multiIndex.resize(containerRank); 00961 00962 if( rank5Container.size() != rank5ContainerAlt.size() ) { 00963 errorFlag++; 00964 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00965 *outStream << " Size using ctor with array of dimensions = " << rank5Container.size() << "\n"; 00966 *outStream << " Size using ctor with list of dimensions = " << rank5ContainerAlt.size() << "\n"; 00967 } 00968 00969 if( rank5Container.rank() != rank5ContainerAlt.rank() ) { 00970 errorFlag++; 00971 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00972 *outStream << " Rank using ctor with array of dimensions = " << rank5Container.rank() << "\n"; 00973 *outStream << " Rank using ctor with list of dimensions = " << rank5ContainerAlt.rank() << "\n"; 00974 } 00975 00976 for(int dim = 0; dim < rank5Container.rank(); dim ++ ) { 00977 if( rank5Container.dimension(dim) != rank5ContainerAlt.dimension(dim) ) { 00978 errorFlag++; 00979 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00980 *outStream << " Dimension " << dim << " using ctor with array of dimensions = " << rank5Container.dimension(dim) << "\n"; 00981 *outStream << " Dimension " << dim << " using ctor with list of dimensions = " << rank5ContainerAlt.dimension(dim) << "\n"; 00982 } 00983 } 00984 00985 *outStream \ 00986 << "\n" 00987 << "===============================================================================\n"\ 00988 << "| TEST 5-b: Access by enumeration, multi-index array and multi-index list |\n"\ 00989 << "===============================================================================\n"; 00990 00991 // Loop over container by enumeration 00992 for(int enumeration = 0; enumeration < containerSize; enumeration++) { 00993 int i0,i1,i2,i3,i4; 00994 00995 // Convert enumeration to multi-index array and multi-index list and compare values 00996 rank5Container.getMultiIndex(multiIndex, enumeration); 00997 rank5Container.getMultiIndex(i0, i1, i2, i3, i4, enumeration); 00998 if( (multiIndex[0] != i0) || 00999 (multiIndex[1] != i1) || 01000 (multiIndex[2] != i2) || 01001 (multiIndex[3] != i3) || 01002 (multiIndex[4] != i4) ) { 01003 errorFlag++; 01004 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01005 *outStream << " Multi-index as array = [" 01006 << multiIndex[0] << multiIndex[1] << multiIndex[2] << multiIndex[3] << multiIndex[4] << "]\n"; 01007 *outStream << " Multi-index as list = (" << i0 << "," << i1 << "," << i2 << "," << i3 << "," << i4 << ")\n"; 01008 } 01009 01010 // Check if access by enumeration gives the same value as access by multi-index array 01011 if( rank5Container[enumeration] != rank5Container.getValue(multiIndex) ) { 01012 errorFlag++; 01013 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01014 *outStream << " Value by enumeration = " << rank5Container[enumeration] << "\n"; 01015 *outStream << " Value by multi-index array = " << rank5Container.getValue(multiIndex) << "\n"; 01016 } 01017 01018 // Check if access by multi-index list gives the same value as access by multi-index array 01019 if( rank5Container(i0,i1,i2,i3,i4) != rank5Container.getValue(multiIndex) ) { 01020 errorFlag++; 01021 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01022 *outStream << " Value by multi-index list = " << rank5Container(i0,i1,i2,i3,i4) << "\n"; 01023 *outStream << " Value by multi-index array = " << rank5Container.getValue(multiIndex) << "\n"; 01024 } 01025 } 01026 01027 *outStream \ 01028 << "\n" 01029 << "===============================================================================\n"\ 01030 << "| TEST 5-c: Access by multi-index array and list & compare with data array |\n"\ 01031 << "===============================================================================\n"; 01032 01033 // Loop over container by multi-index 01034 for(int i=0; i < dimension[0]; i++){ 01035 multiIndex[0] = i; 01036 for(int j=0; j < dimension[1]; j++){ 01037 multiIndex[1] = j; 01038 for(int k=0; k < dimension[2]; k++){ 01039 multiIndex[2] = k; 01040 for(int l = 0; l < dimension[3]; l++){ 01041 multiIndex[3] = l; 01042 for(int m = 0; m < dimension[4]; m++){ 01043 multiIndex[4] = m; 01044 01045 // Method that takes array of multi-indices 01046 int enumeration = rank5Container.getEnumeration(multiIndex); 01047 01048 // Compare with method that takes a list of multi-indices 01049 if( enumeration != rank5Container.getEnumeration(i,j,k,l,m) ) { 01050 errorFlag++; 01051 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01052 *outStream << " Enumeration from multi-index array = " << enumeration << "\n"; 01053 *outStream << " Enumeration from multi-index list = " << rank5Container.getEnumeration(i,j,k,l,m) << "\n"; 01054 } 01055 01056 // Check if access by multi-index array matches values in original dataArray 01057 if(dataArray[enumeration] != rank5Container.getValue(multiIndex)) { 01058 errorFlag++; 01059 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01060 *outStream << " Value by multi-index array = " << rank5Container.getValue(multiIndex) << "\n"; 01061 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 01062 } 01063 01064 // Check if access by multi-index list matches values in original dataArray 01065 if(dataArray[enumeration] != rank5Container(i,j,k,l,m)) { 01066 errorFlag++; 01067 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01068 *outStream << " Value by multi-index list = " << rank5Container(i,j,k,l,m) << "\n"; 01069 *outStream << " Value from data array = " << dataArray[enumeration] << "\n"; 01070 } 01071 01072 // Check if access by multi-index array matches access by multi-index list 01073 if( rank5Container(i,j,k,l,m) != rank5Container.getValue(multiIndex)) { 01074 errorFlag++; 01075 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01076 *outStream << " Value by multi-index array = " << rank5Container.getValue(multiIndex) << "\n"; 01077 *outStream << " Value by multi-index list = " << rank5Container(i,j,k,l,m) << "\n"; 01078 } 01079 } 01080 } 01081 } 01082 } 01083 } 01084 01085 *outStream \ 01086 << "\n" 01087 << "===============================================================================\n"\ 01088 << "| TEST 5-d: Store zeroes and empty container |\n"\ 01089 << "===============================================================================\n"; 01090 01091 rank5Container.initialize(); 01092 double sum = 0.0; 01093 for (int i=0; i<rank5Container.size(); i++) { 01094 sum += rank5Container[i]; 01095 } 01096 if( (sum != 0.0) ) { 01097 errorFlag++; 01098 *outStream << " Container size = " << rank5Container.size() << "\n"; 01099 *outStream << " Container rank = " << rank5Container.rank() << "\n"; 01100 } 01101 01102 rank5Container.clear(); 01103 if( !(rank5Container.size() == 0 && rank5Container.rank() == 0)) { 01104 errorFlag++; 01105 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01106 *outStream << " Container size = " << rank5Container.size() << "\n"; 01107 *outStream << " Container rank = " << rank5Container.rank() << "\n"; 01108 } 01109 } //try 01110 01111 catch (std::logic_error err) { 01112 *outStream << err.what() << "\n"; 01113 errorFlag = -1000; 01114 }; 01115 01116 *outStream \ 01117 << "\n" 01118 << "===============================================================================\n"\ 01119 << "| TEST 6: Resize container based on another container |\n"\ 01120 << "===============================================================================\n"; 01121 01122 try{ 01123 FieldContainer<double> myContainer(1,2,3); 01124 FieldContainer<double> hisContainer(5,4,3,2); 01125 01126 hisContainer.resize(myContainer); 01127 if ( hisContainer.rank() != myContainer.rank() ) { 01128 errorFlag++; 01129 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01130 *outStream << " Rank of target container = " << hisContainer.rank() << "\n"; 01131 *outStream << " Rank of argument container = " << myContainer.rank() << "\n"; 01132 } 01133 01134 for(int dim = 0; dim < myContainer.rank(); dim++){ 01135 if ( hisContainer.dimension(dim) != myContainer.dimension(dim) ) { 01136 errorFlag++; 01137 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 01138 *outStream << " Dimension " << dim << " of target container = " << hisContainer.dimension(dim) << "\n"; 01139 *outStream << " Dimension " << dim << " of argument container = " << myContainer.dimension(dim) << "\n"; 01140 } 01141 } 01142 }// try 01143 01144 catch (std::logic_error err) { 01145 *outStream << err.what() << "\n"; 01146 errorFlag = -1000; 01147 }; 01148 01149 01150 01151 01152 01153 01154 if (errorFlag != 0) 01155 std::cout << "End Result: TEST FAILED\n"; 01156 else 01157 std::cout << "End Result: TEST PASSED\n"; 01158 01159 // reset format state of std::cout 01160 std::cout.copyfmt(oldFormatState); 01161 01162 return errorFlag; 01163 }
1.7.6.1