51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_GlobalMPISession.hpp"
56 using namespace Intrepid;
58 int main(
int argc,
char *argv[]) {
60 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 int iprint = argc - 1;
65 Teuchos::RCP<std::ostream> outStream;
66 Teuchos::oblackholestream bhs;
69 outStream = Teuchos::rcp(&std::cout,
false);
71 outStream = Teuchos::rcp(&bhs,
false);
74 Teuchos::oblackholestream oldFormatState;
75 oldFormatState.copyfmt(std::cout);
78 <<
"===============================================================================\n" \
80 <<
"| Unit Test FieldContainer |\n" \
82 <<
"| 1) Testing exception handling |\n" \
83 <<
"| requires intrepid to be configured with --enable-intrepid-debug |\n" \
85 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
86 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
88 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
89 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
91 <<
"===============================================================================\n";
97 Teuchos::Array<int> dimensions;
98 Teuchos::Array<int> multiIndex;
101 dimensions.resize(4);
113 #ifdef HAVE_INTREPID_DEBUG
116 <<
"===============================================================================\n"\
117 <<
"| TEST 1: Catching exceptions |\n"\
118 <<
"===============================================================================\n\n";
120 int numTestException =16;
121 int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
122 int endThrowNumber = beginThrowNumber + numTestException;
131 <<
"===============================================================================\n"\
132 <<
" Trying to get enumeration using multi-index with the wrong rank: \n";
133 multiIndex.resize(5);
139 myContainer.getEnumeration(multiIndex);
141 catch (std::logic_error err) {
142 *outStream << err.what() <<
"\n";
151 <<
"===============================================================================\n"\
152 <<
" Trying to get enumeration using multi-index that is out of bounds: \n";
153 multiIndex.resize(4);
158 myContainer.getEnumeration(multiIndex);
160 catch (std::logic_error err) {
161 *outStream << err.what() <<
"\n";
170 <<
"===============================================================================\n"\
171 <<
" Trying to set values from array whose size is less than FieldContainer's size: \n";
177 Teuchos::Array<double> dataTeuchosArray(4*3*2*7);
181 for(
int i=0; i < dimensions[0]; i++){
182 for(
int j=0; j < dimensions[1]; j++){
183 for(
int k=0; k < dimensions[2]; k++){
184 for(
int l = 0; l < dimensions[3]; l++){
185 dataTeuchosArray[counter] = (double)counter;
193 myContainer.setValues(dataTeuchosArray);
195 catch (std::logic_error err) {
196 *outStream << err.what() <<
"\n";
205 <<
"===============================================================================\n"\
206 <<
" Trying to set values from array whose size is greater than FieldContainer's size: \n";
214 Teuchos::ArrayRCP<double> dataTeuchosArray(5*3*3*7);
218 for(
int i=0; i < dimensions[0]; i++){
219 for(
int j=0; j < dimensions[1]; j++){
220 for(
int k=0; k < dimensions[2]; k++){
221 for(
int l = 0; l < dimensions[3]; l++){
222 dataTeuchosArray[counter] = (double)counter;
230 myContainer.setValues(dataTeuchosArray());
232 catch (std::logic_error err) {
233 *outStream << err.what() <<
"\n";
242 <<
"===============================================================================\n"\
243 <<
" Trying to use [] with enumeration that is out of range: \n";
246 catch (std::logic_error err) {
247 *outStream << err.what() <<
"\n";
256 <<
"===============================================================================\n"\
257 <<
" Trying to get multi-index from enumeration that is out of bounds: \n";
258 myContainer.getMultiIndex(multiIndex,10000);
260 catch(std::logic_error err) {
261 *outStream << err.what() <<
"\n";
270 <<
"===============================================================================\n"\
271 <<
" Trying to self-assign FieldContainer \n";
272 myContainer = myContainer;
274 catch(std::logic_error err) {
275 *outStream << err.what() <<
"\n";
285 <<
"===============================================================================\n"\
286 <<
" using a method for rank-2 container \n";
287 rank1Container.getEnumeration(1,1);
289 catch(std::logic_error err){
290 *outStream << err.what() <<
"\n";
296 <<
"===============================================================================\n"\
297 <<
" using a method for rank-3 container \n";
298 rank1Container.getEnumeration(1,1,1);
300 catch(std::logic_error err){
301 *outStream << err.what() <<
"\n";
307 <<
"===============================================================================\n"\
308 <<
" using a method for rank-4 container \n";
309 rank1Container.getEnumeration(1,1,1,1);
311 catch(std::logic_error err){
312 *outStream << err.what() <<
"\n";
318 <<
"===============================================================================\n"\
319 <<
" using a method for rank-5 container \n";
320 rank1Container.getEnumeration(1,1,1,1,1);
322 catch(std::logic_error err){
323 *outStream << err.what() <<
"\n";
329 <<
"===============================================================================\n"\
330 <<
" The specified enumeration is out of bounds \n";
332 rank1Container.getMultiIndex(i0,4);
334 catch(std::logic_error err){
335 *outStream << err.what() <<
"\n";
341 <<
"===============================================================================\n"\
342 <<
" Using a method for rank-2 containers \n";
344 rank1Container.getMultiIndex(i0,i1,2);
346 catch(std::logic_error err){
347 *outStream << err.what() <<
"\n";
353 <<
"===============================================================================\n"\
354 <<
" Using a method for rank-2 containers \n";
356 rank1Container.getMultiIndex(i0,i1,i2,2);
358 catch(std::logic_error err){
359 *outStream << err.what() <<
"\n";
366 <<
"===============================================================================\n"\
367 <<
" Using a method for rank-4 containers \n";
369 rank1Container.getMultiIndex(i0,i1,i2,i3,2);
371 catch(std::logic_error err){
372 *outStream << err.what() <<
"\n";
379 <<
"===============================================================================\n"\
380 <<
" Using a method for rank-5 containers \n";
382 rank1Container.getMultiIndex(i0,i1,i2,i3,i4,2);
384 catch(std::logic_error err){
385 *outStream << err.what() <<
"\n";
390 if (Teuchos::TestForException_getThrowNumber() != endThrowNumber) {
395 catch (std::logic_error err) {
396 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
397 *outStream << err.what() <<
"\n";
398 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
404 std::cout <<
"End Result: TEST FAILED\n";
406 std::cout <<
"End Result: TEST PASSED\n";
409 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.