Intrepid
http://trilinos.sandia.gov/packages/docs/r10.12/packages/intrepid/test/Discretization/TensorProductSpaceTools/test_02.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 
00049 #include "Intrepid_TensorProductSpaceTools.hpp"
00050 #include "Intrepid_FieldContainer.hpp"
00051 #include "Intrepid_CellTools.hpp"
00052 #include "Intrepid_HGRAD_QUAD_Cn_FEM.hpp"
00053 #include "Intrepid_DefaultCubatureFactory.hpp"
00054 #include "Intrepid_Utils.hpp"
00055 #include "Teuchos_oblackholestream.hpp"
00056 #include "Teuchos_RCP.hpp"
00057 #include "Teuchos_GlobalMPISession.hpp"
00058 
00059 using namespace std;
00060 using namespace Intrepid;
00061 
00062 #define INTREPID_TEST_COMMAND( S )                                                                                  \
00063 {                                                                                                                   \
00064   try {                                                                                                             \
00065     S ;                                                                                                             \
00066   }                                                                                                                 \
00067   catch (std::logic_error err) {                                                                                    \
00068       *outStream << "Expected Error ----------------------------------------------------------------\n";            \
00069       *outStream << err.what() << '\n';                                                                             \
00070       *outStream << "-------------------------------------------------------------------------------" << "\n\n";    \
00071   };                                                                                                                \
00072 }
00073 
00074 
00075 int main(int argc, char *argv[]) {
00076 
00077   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00078 
00079   // This little trick lets us print to std::cout only if
00080   // a (dummy) command-line argument is provided.
00081   int iprint     = argc - 1;
00082   Teuchos::RCP<std::ostream> outStream;
00083   Teuchos::oblackholestream bhs; // outputs nothing
00084   if (iprint > 0)
00085     outStream = Teuchos::rcp(&std::cout, false);
00086   else
00087     outStream = Teuchos::rcp(&bhs, false);
00088 
00089   // Save the format state of the original std::cout.
00090   Teuchos::oblackholestream oldFormatState;
00091   oldFormatState.copyfmt(std::cout);
00092 
00093   *outStream \
00094   << "===============================================================================\n" \
00095   << "|                                                                             |\n" \
00096   << "|                      Unit Test (TensorProductSpaceTools)                    |\n" \
00097   << "|                                                                             |\n" \
00098   << "|     1) exception testing                                                    |\n" \
00099   << "|                                                                             |\n" \
00100   << "|  Questions? Contact  Pavel Bochev (pbboche@sandia.gov) or                   |\n" \
00101   << "|                      Denis Ridzal (dridzal@sandia.gov).                     |\n" \
00102   << "|                                                                             |\n" \
00103   << "|  Intrepid's website: http://trilinos.sandia.gov/packages/intrepid           |\n" \
00104   << "|  Trilinos website:   http://trilinos.sandia.gov                             |\n" \
00105   << "|                                                                             |\n" \
00106   << "===============================================================================\n";
00107 
00108   int errorFlag = 0;
00109 #ifdef HAVE_INTREPID_DEBUG
00110   const int numTotalExceptions = 7;
00111   int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
00112   int endThrowNumber = beginThrowNumber + numTotalExceptions;
00113 #endif
00114 
00115   typedef TensorProductSpaceTools tpst; 
00116 
00117   *outStream \
00118   << "\n"
00119   << "===============================================================================\n"\
00120   << "| TEST 1: exceptions                                                          |\n"\
00121   << "===============================================================================\n";
00122 
00123   try{
00124 #ifdef HAVE_INTREPID_DEBUG
00125     FieldContainer<double> a_2_2(2,2);
00126     FieldContainer<double> a_2(2);
00127     FieldContainer<double> a_4(4);
00128     FieldContainer<double> a_4_4(4,4);
00129     FieldContainer<double> a_4_1_4(4,1,4);
00130     FieldContainer<double> a_4_2(4,2);
00131     Array<RCP<FieldContainer<double> > > bases_2(2);
00132     Array<RCP<FieldContainer<double> > > bases_1(1);
00133     bases_2[0] = Teuchos::rcp( &a_2_2 , false );
00134     bases_2[1] = Teuchos::rcp( &a_2_2 , false );
00135     bases_1[0] = Teuchos::rcp( &a_2_2 , false );
00136 
00137     // work with evaluate
00138 
00139     // first arg wrong shape
00140     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4 , a_4_1_4 , bases_2 ) );
00141     // second arg wrong shape
00142     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4 , bases_2 ) );
00143     // bases wrong length
00144     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4, bases_1 ) );
00145     // internal bases wrong shape
00146     bases_2[1] = Teuchos::rcp( & a_2 , false );
00147     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4, bases_2 ) );
00148     // different number of cells in first two arguments
00149     bases_2[1] = Teuchos::rcp( &a_2_2 , false );
00150     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_2_2 , a_4_4, bases_2 ) );
00151     // points and bases incompatible
00152     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_2 , a_4_4 , bases_2 ) );
00153     // coeffs and bases incompatible
00154     INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_2 , bases_2 ) );
00155 
00156     // need to test gradients and other methods, too
00157     
00158 
00159 #endif
00160   }
00161   catch (std::logic_error err) {
00162     *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00163     *outStream << err.what() << '\n';
00164     *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00165     errorFlag = -1000;
00166   };
00167 
00168 #ifdef HAVE_INTREPID_DEBUG
00169   if (Teuchos::TestForException_getThrowNumber() != endThrowNumber)
00170     errorFlag++;
00171 #endif
00172 
00173   if (errorFlag != 0)
00174     std::cout << "End Result: TEST FAILED\n";
00175   else
00176     std::cout << "End Result: TEST PASSED\n";
00177 
00178   // reset format state of std::cout
00179   std::cout.copyfmt(oldFormatState);
00180 
00181   return errorFlag;
00182 }