Intrepid
http://trilinos.sandia.gov/packages/docs/r10.12/packages/intrepid/test/Discretization/Basis/HCURL_HEX_I1_FEM/test_01.cpp
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 
00048 #include "Intrepid_FieldContainer.hpp"
00049 #include "Intrepid_HCURL_HEX_I1_FEM.hpp"
00050 #include "Teuchos_oblackholestream.hpp"
00051 #include "Teuchos_RCP.hpp"
00052 #include "Teuchos_GlobalMPISession.hpp"
00053 
00054 using namespace std;
00055 using namespace Intrepid;
00056 
00057 #define INTREPID_TEST_COMMAND( S , throwCounter, nException )                                                              \
00058 {                                                                                                                          \
00059   ++nException;                                                                                                            \
00060   try {                                                                                                                    \
00061     S ;                                                                                                                    \
00062   }                                                                                                                        \
00063   catch (std::logic_error err) {                                                                                           \
00064       ++throwCounter;                                                                                                      \
00065       *outStream << "Expected Error " << nException << " -------------------------------------------------------------\n"; \
00066       *outStream << err.what() << '\n';                                                                                    \
00067       *outStream << "-------------------------------------------------------------------------------" << "\n\n";           \
00068   };                                                                                                                       \
00069 }
00070 
00071 int main(int argc, char *argv[]) {
00072 
00073   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00074 
00075   // This little trick lets us print to std::cout only if
00076   // a (dummy) command-line argument is provided.
00077   int iprint     = argc - 1;
00078   Teuchos::RCP<std::ostream> outStream;
00079   Teuchos::oblackholestream bhs; // outputs nothing
00080   if (iprint > 0)
00081     outStream = Teuchos::rcp(&std::cout, false);
00082   else
00083     outStream = Teuchos::rcp(&bhs, false);
00084   
00085   // Save the format state of the original std::cout.
00086   Teuchos::oblackholestream oldFormatState;
00087   oldFormatState.copyfmt(std::cout);
00088   
00089   *outStream \
00090     << "===============================================================================\n" \
00091     << "|                                                                             |\n" \
00092     << "|                 Unit Test (Basis_HCURL_HEX_I1_FEM)                          |\n" \
00093     << "|                                                                             |\n" \
00094     << "|     1) Conversion of Dof tags into Dof ordinals and back                    |\n" \
00095     << "|     2) Basis values for VALUE and CURL operators                            |\n" \
00096     << "|                                                                             |\n" \
00097     << "|  Questions? Contact  Pavel Bochev  (pbboche@sandia.gov),                    |\n" \
00098     << "|                      Denis Ridzal  (dridzal@sandia.gov),                    |\n" \
00099     << "|                      Kara Peterson (kjpeter@sandia.gov).                    |\n" \
00100     << "|                                                                             |\n" \
00101     << "|  Intrepid's website: http://trilinos.sandia.gov/packages/intrepid           |\n" \
00102     << "|  Trilinos website:   http://trilinos.sandia.gov                             |\n" \
00103     << "|                                                                             |\n" \
00104     << "===============================================================================\n"\
00105     << "| TEST 1: Basis creation, exception testing                                   |\n"\
00106     << "===============================================================================\n";
00107   
00108   // Define basis and error flag
00109   Basis_HCURL_HEX_I1_FEM<double, FieldContainer<double> > hexBasis;
00110   int errorFlag = 0;
00111 
00112   // Initialize throw counter for exception testing
00113   int nException     = 0;
00114   int throwCounter   = 0;
00115 
00116   // Define array containing the 8 vertices of the reference HEX, its center and 6 face centers
00117   FieldContainer<double> hexNodes(15, 3);
00118   hexNodes(0,0) = -1.0;  hexNodes(0,1) = -1.0;  hexNodes(0,2) = -1.0;
00119   hexNodes(1,0) =  1.0;  hexNodes(1,1) = -1.0;  hexNodes(1,2) = -1.0;
00120   hexNodes(2,0) =  1.0;  hexNodes(2,1) =  1.0;  hexNodes(2,2) = -1.0;
00121   hexNodes(3,0) = -1.0;  hexNodes(3,1) =  1.0;  hexNodes(3,2) = -1.0;
00122   
00123   hexNodes(4,0) = -1.0;  hexNodes(4,1) = -1.0;  hexNodes(4,2) =  1.0;
00124   hexNodes(5,0) =  1.0;  hexNodes(5,1) = -1.0;  hexNodes(5,2) =  1.0;
00125   hexNodes(6,0) =  1.0;  hexNodes(6,1) =  1.0;  hexNodes(6,2) =  1.0;
00126   hexNodes(7,0) = -1.0;  hexNodes(7,1) =  1.0;  hexNodes(7,2) =  1.0;  
00127   
00128   hexNodes(8,0) =  0.0;  hexNodes(8,1) =  0.0;  hexNodes(8,2) =  0.0;
00129   
00130   hexNodes(9,0) =  1.0;  hexNodes(9,1) =  0.0;  hexNodes(9,2) =  0.0;
00131   hexNodes(10,0)= -1.0;  hexNodes(10,1)=  0.0;  hexNodes(10,2)=  0.0;
00132   
00133   hexNodes(11,0)=  0.0;  hexNodes(11,1)=  1.0;  hexNodes(11,2)=  0.0;
00134   hexNodes(12,0)=  0.0;  hexNodes(12,1)= -1.0;  hexNodes(12,2)=  0.0;
00135   
00136   hexNodes(13,0)=  0.0;  hexNodes(13,1)=  0.0;  hexNodes(13,2)=  1.0;
00137   hexNodes(14,0)=  0.0;  hexNodes(14,1)=  0.0;  hexNodes(14,2)= -1.0;
00138 
00139   
00140   // Generic array for the output values; needs to be properly resized depending on the operator type
00141   FieldContainer<double> vals;
00142 
00143   try{
00144     // exception #1: GRAD cannot be applied to HCURL functions 
00145     // resize vals to rank-3 container with dimensions (num. basis functions, num. points, arbitrary)
00146     vals.resize(hexBasis.getCardinality(), hexNodes.dimension(0), 4 );
00147     INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_GRAD), throwCounter, nException );
00148 
00149     // exception #2: DIV cannot be applied to HCURL functions
00150     // resize vals to rank-2 container with dimensions (num. points, num. basis functions)
00151     vals.resize(hexBasis.getCardinality(), hexNodes.dimension(0) );
00152     INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_DIV), throwCounter, nException );
00153         
00154     // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and 
00155     // getDofTag() to access invalid array elements thereby causing bounds check exception
00156     // exception #3
00157     INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(3,0,0), throwCounter, nException );
00158     // exception #4
00159     INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(1,1,1), throwCounter, nException );
00160     // exception #5
00161     INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(0,4,1), throwCounter, nException );
00162     // exception #6
00163     INTREPID_TEST_COMMAND( hexBasis.getDofTag(12), throwCounter, nException );
00164     // exception #7
00165     INTREPID_TEST_COMMAND( hexBasis.getDofTag(-1), throwCounter, nException );
00166     
00167 #ifdef HAVE_INTREPID_DEBUG
00168     // Exceptions 8-15 test exception handling with incorrectly dimensioned input/output arrays
00169     // exception #8: input points array must be of rank-2
00170     FieldContainer<double> badPoints1(4, 5, 3);
00171     INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
00172     
00173     // exception #9 dimension 1 in the input point array must equal space dimension of the cell
00174     FieldContainer<double> badPoints2(4, 2);
00175     INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
00176     
00177     // exception #10 output values must be of rank-3 for OPERATOR_VALUE
00178     FieldContainer<double> badVals1(4, 3);
00179     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals1, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00180  
00181     // exception #11 output values must be of rank-3 for OPERATOR_CURL
00182     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals1, hexNodes, OPERATOR_CURL), throwCounter, nException );
00183     
00184     // exception #12 incorrect 0th dimension of output array (must equal number of basis functions)
00185     FieldContainer<double> badVals2(hexBasis.getCardinality() + 1, hexNodes.dimension(0), 3);
00186     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals2, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00187     
00188     // exception #13 incorrect 1st  dimension of output array (must equal number of points)
00189     FieldContainer<double> badVals3(hexBasis.getCardinality(), hexNodes.dimension(0) + 1, 3);
00190     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals3, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00191 
00192     // exception #14: incorrect 2nd dimension of output array (must equal the space dimension)
00193     FieldContainer<double> badVals4(hexBasis.getCardinality(), hexNodes.dimension(0), 4);
00194     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals4, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00195     
00196     // exception #15: incorrect 2nd dimension of output array (must equal the space dimension)
00197     INTREPID_TEST_COMMAND( hexBasis.getValues(badVals4, hexNodes, OPERATOR_CURL), throwCounter, nException ) ;
00198     
00199     // exception #16: D2 cannot be applied to HCURL functions 
00200     // resize vals to rank-3 container with dimensions (num. basis functions, num. points, arbitrary)
00201     vals.resize(hexBasis.getCardinality(), 
00202                 hexNodes.dimension(0),  
00203                 Intrepid::getDkCardinality(OPERATOR_D2, hexBasis.getBaseCellTopology().getDimension()));
00204     INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_D2), throwCounter, nException );
00205     
00206 #endif
00207     
00208   }
00209   catch (std::logic_error err) {
00210     *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00211     *outStream << err.what() << '\n';
00212     *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00213     errorFlag = -1000;
00214   };
00215   
00216   // Check if number of thrown exceptions matches the one we expect 
00217   // Note Teuchos throw number will not pick up exceptions 3-7 and therefore will not match.
00218   if (throwCounter != nException) {
00219     errorFlag++;
00220     *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00221   }
00222 //#endif
00223   
00224   *outStream \
00225     << "\n"
00226     << "===============================================================================\n"\
00227     << "| TEST 2: correctness of tag to enum and enum to tag lookups                  |\n"\
00228     << "===============================================================================\n";
00229   
00230   try{
00231     std::vector<std::vector<int> > allTags = hexBasis.getAllDofTags();
00232     
00233     // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again
00234     for (unsigned i = 0; i < allTags.size(); i++) {
00235       int bfOrd  = hexBasis.getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
00236       
00237       std::vector<int> myTag = hexBasis.getDofTag(bfOrd);
00238        if( !( (myTag[0] == allTags[i][0]) &&
00239               (myTag[1] == allTags[i][1]) &&
00240               (myTag[2] == allTags[i][2]) &&
00241               (myTag[3] == allTags[i][3]) ) ) {
00242         errorFlag++;
00243         *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00244         *outStream << " getDofOrdinal( {" 
00245           << allTags[i][0] << ", " 
00246           << allTags[i][1] << ", " 
00247           << allTags[i][2] << ", " 
00248           << allTags[i][3] << "}) = " << bfOrd <<" but \n";   
00249         *outStream << " getDofTag(" << bfOrd << ") = { "
00250           << myTag[0] << ", " 
00251           << myTag[1] << ", " 
00252           << myTag[2] << ", " 
00253           << myTag[3] << "}\n";        
00254       }
00255     }
00256     
00257     // Now do the same but loop over basis functions
00258     for( int bfOrd = 0; bfOrd < hexBasis.getCardinality(); bfOrd++) {
00259       std::vector<int> myTag  = hexBasis.getDofTag(bfOrd);
00260       int myBfOrd = hexBasis.getDofOrdinal(myTag[0], myTag[1], myTag[2]);
00261       if( bfOrd != myBfOrd) {
00262         errorFlag++;
00263         *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00264         *outStream << " getDofTag(" << bfOrd << ") = { "
00265           << myTag[0] << ", " 
00266           << myTag[1] << ", " 
00267           << myTag[2] << ", " 
00268           << myTag[3] << "} but getDofOrdinal({" 
00269           << myTag[0] << ", " 
00270           << myTag[1] << ", " 
00271           << myTag[2] << ", " 
00272           << myTag[3] << "} ) = " << myBfOrd << "\n";
00273       }
00274     }
00275   }
00276   catch (std::logic_error err){
00277     *outStream << err.what() << "\n\n";
00278     errorFlag = -1000;
00279   };
00280   
00281   *outStream \
00282     << "\n"
00283     << "===============================================================================\n"\
00284     << "| TEST 3: correctness of basis function values                                |\n"\
00285     << "===============================================================================\n";
00286   
00287   outStream -> precision(20);
00288   
00289   // VALUE: Each row pair gives the 12x3 correct basis set values at an evaluation point: (P,F,D) layout
00290   double basisValues[] = {
00291     // bottom 4 vertices
00292       0.5,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,-0.5,0.,  0.,0.,0.,  0.,0.,0.,  
00293       0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,
00294 
00295       0.5,0.,0.,  0.,0.5,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,
00296       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,  0.,0.,0.,  0.,0.,0.,
00297 
00298       0.,0.,0.,  0.,0.5,0.,  -0.5,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,
00299       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,  0.,0.,0.,
00300 
00301       0.,0.,0.,  0.,0.,0.,  -0.5,0.,0.,  0.,-0.5,0.,  0.,0.,0.,  0.,0.,0.,
00302       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,
00303 
00304     // top 4 vertices
00305       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.5,0.,0.,  0.,0.,0.,
00306       0.,0.,0.,  0.,-0.5,0.,  0.,0.,0.5,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,
00307 
00308       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.5,0.,0.,  0.,0.5,0.,
00309       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,  0.,0.,0.,  0.,0.,0.,
00310      
00311       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.5,0.,
00312      -0.5,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,  0.,0.,0.,
00313    
00314       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,
00315      -0.5,0.,0.,  0.,-0.5,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.5,
00316 
00317     // center {0, 0, 0}
00318       0.125,0.,0.,  0.,0.125,0.,  -0.125,0.,0.,  0.,-0.125,0.,  0.125,0.,0.,  0.,0.125,0.,
00319      -0.125,0.,0.,  0.,-0.125,0.,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125,
00320   
00321     // faces { 1, 0, 0} and {-1, 0, 0}
00322       0.125,0.,0.,  0.,0.25,0.,  -0.125,0.,0.,  0.,0.,0.,  0.125,0.,0.,  0.,0.25,0.,
00323      -0.125,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.25,  0.,0.,0.25,  0.,0.,0.,  
00324 
00325       0.125,0.,0.,  0.,0.,0.,  -0.125,0.,0.,  0.,-0.25,0.,  0.125,0.,0.,  0.,0.,0.,
00326      -0.125,0.,0.,  0.,-0.25,0.,  0.,0.,0.25,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.25,
00327 
00328     // faces { 0, 1, 0} and { 0,-1, 0}
00329       0.,0.,0.,  0.,0.125,0.,  -0.25,0.,0.,  0.,-0.125,0.,  0.,0.,0.,  0.,0.125,0.,
00330      -0.25,0.,0.,  0.,-0.125,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.25,  0.,0.,0.25,
00331 
00332       0.25,0.,0.,  0.,0.125,0.,  0.,0.,0.,  0.,-0.125,0.,  0.25,0.,0.,  0.,0.125,0.,
00333       0.,0.,0.,  0.,-0.125,0.,  0.,0.,0.25,  0.,0.,0.25,  0.,0.,0.,  0.,0.,0.,
00334 
00335     // faces {0, 0, 1} and {0, 0, -1}
00336       0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.25,0.,0.,  0.,0.25,0.,
00337      -0.25,0.,0.,  0.,-0.25,0.,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125,
00338 
00339       0.25,0.,0.,  0.,0.25,0.,  -0.25,0.,0.,  0.,-0.25,0.,  0.,0.,0.,  0.,0.,0.,  
00340       0.0,0.,0.,  0.,0.,0.0,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125,  0.,0.,0.125
00341   };
00342   
00343   // CURL: each row pair gives the 3x12 correct values of the curls of the 12 basis functions: (P,F,D) layout
00344   double basisCurls[] = {   
00345     // bottom 4 vertices
00346     0.,-0.25,0.25,  0.,0.,0.25,  0.,0.,0.25,  -0.25,0.,0.25,  0.,0.25,0.,  0.,0.,0.,  
00347     0.,0.,0.,  0.25,0.,0.,  -0.25,0.25,0.,  0.,-0.25,0.,  0.,0.,0.,  0.25,0.,0.,
00348 
00349     0.,-0.25,0.25,  0.25,0.,0.25,  0.,0.,0.25,  0.,0.,0.25,  0.,0.25,0.,  -0.25,0.,0., 
00350     0.,0.,0.,  0.,0.,0.,  0.,0.25,0.,  -0.25,-0.25,0.,  0.25,0.,0.,  0.,0.,0.,  
00351 
00352     0.,0.,0.25,  0.25,0.,0.25,  0.,0.25,0.25,  0.,0.,0.25,  0.,0.,0.,  -0.25,0.,0.,
00353     0.,-0.25,0.,  0.,0.,0.,  0.,0.,0.,  -0.25,0.,0.,  0.25,-0.25,0.,  0.,0.25,0.,
00354 
00355     0.,0.,0.25,  0.,0.,0.25,  0.,0.25,0.25,  -0.25,0.,0.25,  0.,0.,0.,  0.,0.,0.,
00356     0.,-0.25,0.,  0.25,0.,0.,  -0.25,0.,0.,  0.,0.,0.,  0.,-0.25,0.,  0.25,0.25,0.,
00357 
00358     // top 4 vertices
00359     0.,-0.25,0.,  0.,0.,0.,  0.,0.,0.,  -0.25,0.,0.,  0.,0.25,0.25,  0.,0.,0.25,
00360     0.,0.,0.25,  0.25,0.,0.25,  -0.25,0.25,0.,  0.,-0.25,0.,  0.,0.,0.,  0.25,0.,0.,
00361 
00362     0.,-0.25,0.,  0.25,0.,0.,  0.,0.,0.,  0.,0.,0.,  0.,0.25,0.25,  -0.25,0.,0.25,
00363     0.,0.,0.25,  0.,0.,0.25,  0.,0.25,0.,  -0.25,-0.25,0.,  0.25,0.,0.,  0.,0.,0.,
00364 
00365     0.,0.,0.,  0.25,0.,0.,  0.,0.25,0.,  0.,0.,0.,  0.,0.,0.25,  -0.25,0.,0.25,
00366     0.,-0.25,0.25,  0.,0.,0.25,  0.,0.,0.,  -0.25,0.,0.,  0.25,-0.25,0.,  0.,0.25,0.,
00367 
00368     0.,0.,0.,  0.,0.,0.,  0.,0.25,0.,  -0.25,0.,0.,  0.,0.,0.25,  0.,0.,0.25,
00369     0.,-0.25,0.25,  0.25,0.,0.25,  -0.25,0.,0., 0.,0.,0.,  0.,-0.25,0.,  0.25,0.25,0.,
00370 
00371     // center {0, 0, 0}
00372     0.,-0.125,0.125,  0.125,0.,0.125,  0.,0.125,0.125,  -0.125,0.,0.125,  0.,0.125,0.125,  -0.125,0.,0.125,
00373     0.,-0.125,0.125,  0.125,0.,0.125,  -0.125,0.125,0.,  -0.125,-0.125,0.,  0.125,-0.125,0.,  0.125,0.125,0.,
00374 
00375     // faces { 1, 0, 0} and {-1, 0, 0}
00376     0.,-0.125,0.125,  0.25,0.,0.125,  0.,0.125,0.125,  0.,0.,0.125,  0.,0.125,0.125,  -0.25,0.,0.125, 
00377     0.,-0.125,0.125,  0.,0.,0.125,  0.,0.125,0.,  -0.25,-0.125,0.,  0.25,-0.125,0.,  0.,0.125,0., 
00378 
00379     0.,-0.125,0.125,  0.,0.,0.125,  0.,0.125,0.125,  -0.25,0.,0.125,  0.,0.125,0.125,  0.,0.,0.125,
00380     0.,-0.125,0.125,  0.25,0.,0.125,  -0.25,0.125,0.,  0.,-0.125,0.,  0.,-0.125,0.,  0.25,0.125,0.,
00381 
00382     // faces { 0, 1, 0} and { 0,-1, 0}
00383     0.,0.,0.125,  0.125,0.,0.125,  0.,0.25,0.125,  -0.125,0.,0.125,  0.,0.,0.125,  -0.125,0.,0.125,
00384     0.,-0.25,0.125,  0.125,0.,0.125,  -0.125,0.,0.,  -0.125,0.,0.,  0.125,-0.25,0.,  0.125,0.25,0.,
00385 
00386     0.,-0.25,0.125,  0.125,0.,0.125,  0.,0.,0.125,  -0.125,0.,0.125,  0.,0.25,0.125,  -0.125,0.,0.125,
00387     0.,0.,0.125,  0.125,0.,0.125,  -0.125,0.25,0.,  -0.125,-0.25,0.,  0.125,0.,0.,  0.125,0.,0.,
00388 
00389     // faces {0, 0, 1} and {0, 0, -1}
00390     0.,-0.125,0.,  0.125,0.,0.,  0.,0.125,0.,  -0.125,0.,0.,  0.,0.125,0.25,  -0.125,0.,0.25,
00391     0.,-0.125,0.25,  0.125,0.,0.25,  -0.125,0.125,0.,  -0.125,-0.125,0.,  0.125,-0.125,0.,  0.125,0.125,0.,
00392 
00393     0.,-0.125,0.25,  0.125,0.,0.25,  0.,0.125,0.25,  -0.125,0.,0.25,  0.,0.125,0.,  -0.125,0.,0.,
00394     0.,-0.125,0.,  0.125,0.,0.,  -0.125,0.125,0.,  -0.125,-0.125,0.,  0.125,-0.125,0.,  0.125,0.125,0.
00395   };
00396 
00397   
00398   try{
00399         
00400     // Dimensions for the output arrays:
00401     int numFields = hexBasis.getCardinality();
00402     int numPoints = hexNodes.dimension(0);
00403     int spaceDim  = hexBasis.getBaseCellTopology().getDimension();
00404     
00405     // Generic array for values and curls that will be properly sized before each call
00406     FieldContainer<double> vals;
00407     
00408     // Check VALUE of basis functions: resize vals to rank-3 container:
00409     vals.resize(numFields, numPoints, spaceDim);
00410     hexBasis.getValues(vals, hexNodes, OPERATOR_VALUE);
00411     for (int i = 0; i < numFields; i++) {
00412       for (int j = 0; j < numPoints; j++) {
00413         for (int k = 0; k < spaceDim; k++) {
00414           
00415           // compute offset for (P,F,D) data layout: indices are P->j, F->i, D->k
00416           int l = k + i * spaceDim + j * spaceDim * numFields;
00417            if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
00418              errorFlag++;
00419              *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00420         
00421              // Output the multi-index of the value where the error is: 
00422              *outStream << " At multi-index { ";
00423              *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00424              *outStream << "}  computed value: " << vals(i,j,k)
00425                << " but reference value: " << basisValues[l] << "\n";
00426             }
00427          }
00428       }
00429     }
00430     
00431     // Check CURL of basis function: resize vals to rank-3 container
00432     vals.resize(numFields, numPoints, spaceDim);
00433     hexBasis.getValues(vals, hexNodes, OPERATOR_CURL);
00434     for (int i = 0; i < numFields; i++) {
00435       for (int j = 0; j < numPoints; j++) {
00436         for (int k = 0; k < spaceDim; k++) {
00437 
00438           // compute offset for (P,F,D) data layout: indices are P->j, F->i, D->k
00439            int l = k + i * spaceDim + j * spaceDim * numFields;
00440            if (std::abs(vals(i,j,k) - basisCurls[l]) > INTREPID_TOL) {
00441              errorFlag++;
00442              *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00443         
00444              // Output the multi-index of the value where the error is: 
00445              *outStream << " At multi-index { ";
00446              *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00447              *outStream << "}  computed curl component: " << vals(i,j,k) 
00448                << " but reference curl component: " << basisCurls[l] << "\n";
00449             }
00450          }
00451       }
00452     }
00453     
00454    }    
00455   
00456   // Catch unexpected errors
00457   catch (std::logic_error err) {
00458     *outStream << err.what() << "\n\n";
00459     errorFlag = -1000;
00460   };
00461   
00462   if (errorFlag != 0)
00463     std::cout << "End Result: TEST FAILED\n";
00464   else
00465     std::cout << "End Result: TEST PASSED\n";
00466   
00467   // reset format state of std::cout
00468   std::cout.copyfmt(oldFormatState);
00469   
00470   return errorFlag;
00471 }