Intrepid
test_02.cpp
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
51 #include "Intrepid_CellTools.hpp"
54 #include "Intrepid_Utils.hpp"
55 #include "Teuchos_oblackholestream.hpp"
56 #include "Teuchos_RCP.hpp"
57 #include "Teuchos_GlobalMPISession.hpp"
58 
59 using namespace std;
60 using namespace Intrepid;
61 
62 #define INTREPID_TEST_COMMAND( S ) \
63 { \
64  try { \
65  S ; \
66  } \
67  catch (const std::logic_error & err) { \
68  *outStream << "Expected Error ----------------------------------------------------------------\n"; \
69  *outStream << err.what() << '\n'; \
70  *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
71  }; \
72 }
73 
74 
75 int main(int argc, char *argv[]) {
76 
77  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
78 
79  // This little trick lets us print to std::cout only if
80  // a (dummy) command-line argument is provided.
81  int iprint = argc - 1;
82  Teuchos::RCP<std::ostream> outStream;
83  Teuchos::oblackholestream bhs; // outputs nothing
84  if (iprint > 0)
85  outStream = Teuchos::rcp(&std::cout, false);
86  else
87  outStream = Teuchos::rcp(&bhs, false);
88 
89  // Save the format state of the original std::cout.
90  Teuchos::oblackholestream oldFormatState;
91  oldFormatState.copyfmt(std::cout);
92 
93  *outStream \
94  << "===============================================================================\n" \
95  << "| |\n" \
96  << "| Unit Test (TensorProductSpaceTools) |\n" \
97  << "| |\n" \
98  << "| 1) exception testing |\n" \
99  << "| |\n" \
100  << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
101  << "| Denis Ridzal (dridzal@sandia.gov). |\n" \
102  << "| |\n" \
103  << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
104  << "| Trilinos website: http://trilinos.sandia.gov |\n" \
105  << "| |\n" \
106  << "===============================================================================\n";
107 
108  int errorFlag = 0;
109 #ifdef HAVE_INTREPID_DEBUG
110  const int numTotalExceptions = 7;
111  int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
112  int endThrowNumber = beginThrowNumber + numTotalExceptions;
113 #endif
114 
115  *outStream \
116  << "\n"
117  << "===============================================================================\n"\
118  << "| TEST 1: exceptions |\n"\
119  << "===============================================================================\n";
120 
121  try{
122 #ifdef HAVE_INTREPID_DEBUG
123  typedef TensorProductSpaceTools tpst;
124 
125  FieldContainer<double> a_2_2(2,2);
126  FieldContainer<double> a_2(2);
127  FieldContainer<double> a_4(4);
128  FieldContainer<double> a_4_4(4,4);
129  FieldContainer<double> a_4_1_4(4,1,4);
130  FieldContainer<double> a_4_2(4,2);
131  Array<RCP<FieldContainer<double> > > bases_2(2);
132  Array<RCP<FieldContainer<double> > > bases_1(1);
133  bases_2[0] = Teuchos::rcp( &a_2_2 , false );
134  bases_2[1] = Teuchos::rcp( &a_2_2 , false );
135  bases_1[0] = Teuchos::rcp( &a_2_2 , false );
136 
137  // work with evaluate
138 
139  // first arg wrong shape
140  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4 , a_4_1_4 , bases_2 ) );
141  // second arg wrong shape
142  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4 , bases_2 ) );
143  // bases wrong length
144  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4, bases_1 ) );
145  // internal bases wrong shape
146  bases_2[1] = Teuchos::rcp( & a_2 , false );
147  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_4, bases_2 ) );
148  // different number of cells in first two arguments
149  bases_2[1] = Teuchos::rcp( &a_2_2 , false );
150  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_2_2 , a_4_4, bases_2 ) );
151  // points and bases incompatible
152  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_2 , a_4_4 , bases_2 ) );
153  // coeffs and bases incompatible
154  INTREPID_TEST_COMMAND( tpst::evaluate<double>( a_4_4 , a_4_2 , bases_2 ) );
155 
156  // need to test gradients and other methods, too
157 
158 
159 #endif
160  }
161  catch (const std::logic_error & err) {
162  *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
163  *outStream << err.what() << '\n';
164  *outStream << "-------------------------------------------------------------------------------" << "\n\n";
165  errorFlag = -1000;
166  };
167 
168 #ifdef HAVE_INTREPID_DEBUG
169  if (Teuchos::TestForException_getThrowNumber() != endThrowNumber)
170  errorFlag++;
171 #endif
172 
173  if (errorFlag != 0)
174  std::cout << "End Result: TEST FAILED\n";
175  else
176  std::cout << "End Result: TEST PASSED\n";
177 
178  // reset format state of std::cout
179  std::cout.copyfmt(oldFormatState);
180 
181  return errorFlag;
182 }
Defines expert-level interfaces for the evaluation, differentiation and integration of finite element...
Header file for the Intrepid::CellTools class.
Header file for utility class to provide multidimensional containers.
Intrepid utilities.
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
Header file for the Intrepid::HGRAD_QUAD_Cn_FEM class.
Header file for the Intrepid::TensorProductSpaceTools class.