52 #include "Shards_Array.hpp"
53 #include "Teuchos_oblackholestream.hpp"
54 #include "Teuchos_RCP.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
58 using namespace Intrepid;
60 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( Cell )
61 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( Cell )
63 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( Field )
64 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( Field )
66 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( Point )
67 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( Point )
69 SHARDS_ARRAY_DIM_TAG_SIMPLE_DECLARATION( Dim )
70 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( Dim )
72 #define INTREPID_TEST_COMMAND( S ) \
77 catch (std::logic_error err) { \
78 *outStream << "Expected Error ----------------------------------------------------------------\n"; \
79 *outStream << err.what() << '\n'; \
80 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
85 int main(
int argc,
char *argv[]) {
87 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
90 int iprint = argc - 1;
92 Teuchos::RCP<std::ostream> outStream;
93 Teuchos::oblackholestream bhs;
96 outStream = Teuchos::rcp(&std::cout,
false);
98 outStream = Teuchos::rcp(&bhs,
false);
101 Teuchos::oblackholestream oldFormatState;
102 oldFormatState.copyfmt(std::cout);
105 <<
"===============================================================================\n" \
107 <<
"| Unit Test FieldContainer |\n" \
109 <<
"| 1) Testing usage of various constructors / wrappers |\n" \
110 <<
"| 2) Testing usage of resize |\n" \
112 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
113 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
115 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
116 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
118 <<
"===============================================================================\n";
124 double zero = INTREPID_TOL;
129 Teuchos::Array<int> dimensions;
132 <<
"===============================================================================\n"\
133 <<
"| TEST 1: Constructors / Wrappers for a particular rank-4 container |\n"\
134 <<
"===============================================================================\n\n";
139 dimensions.resize(4);
146 Teuchos::Array<double> data(dimensions[0]*dimensions[1]*dimensions[2]*dimensions[3]);
152 fc_array(1,1,1,1) = 1.0;
154 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1]) > zero) {
155 *outStream <<
"\n\nError in constructor using Array (ArrayView) and deep copy.\n\n";
160 if (std::abs((fc_array.getData())[dimensions[1]*dimensions[2]*dimensions[3] +
161 dimensions[2]*dimensions[3] + dimensions[3] + 1] - fc_array(1,1,1,1)) > zero) {
162 *outStream <<
"\n\nError in getData() member of FieldContainer.\n\n";
167 Teuchos::RCP< Teuchos::Array<double> > rcp_to_data = rcpFromRef(data);
168 Teuchos::ArrayRCP<double> arrayrcp = Teuchos::arcp(rcp_to_data);
172 fc_arrayrcp_deep(1,1,1,1) = 1.0;
174 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1]) > zero) {
175 *outStream <<
"\n\nError in constructor using ArrayRCP (ArrayView) and deep copy.\n\n";
182 fc_arrayrcp_shallow(1,1,1,1) = 1.0;
184 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1] - fc_arrayrcp_shallow(1,1,1,1)) > zero) {
185 *outStream <<
"\n\nError in constructor using ArrayRCP and shallow copy.\n\n";
192 fc_scalarptr_deep(1,1,1,1) = 2.0;
194 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1] - 1.0) > zero) {
195 *outStream <<
"\n\nError in constructor using Scalar* and deep copy.\n\n";
202 fc_scalarptr_shallow(1,1,1,1) = 2.0;
204 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1] - fc_scalarptr_shallow(1,1,1,1)) > zero) {
205 *outStream <<
"\n\nError in constructor using Scalar* and shallow copy.\n\n";
210 shards::Array<double,shards::NaturalOrder,Cell,Field,Point,Dim> shards_array(data.getRawPtr(),dimensions[0],dimensions[1],dimensions[2],dimensions[3]);
213 fc_shards_deep(1,1,1,1) = 3.0;
215 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1] - 2.0) > zero) {
216 *outStream <<
"\n\nError in constructor using shards::Array and deep copy.\n\n";
223 fc_shards_shallow(1,1,1,1) = 3.0;
225 if (std::abs(data[dimensions[1]*dimensions[2]*dimensions[3] + dimensions[2]*dimensions[3] + dimensions[3] + 1] - fc_shards_shallow(1,1,1,1)) > zero) {
226 *outStream <<
"\n\nError in constructor using shards::Array and shallow copy.\n\n";
234 <<
"===============================================================================\n"\
235 <<
"| TEST 1 cont'd: Run through constructors / wrappers of various ranks |\n"\
236 <<
"===============================================================================\n\n";
238 for (
int rank=0; rank<10; rank++) {
239 dimensions.resize(rank);
244 for (
int dim=0; dim<rank; dim++) {
246 total_size *= dimensions[dim];
250 Teuchos::Array<double> data(total_size);
255 Teuchos::RCP< Teuchos::Array<double> > rcp_to_data = rcpFromRef(data);
256 Teuchos::ArrayRCP<double> arrayrcp = Teuchos::arcp(rcp_to_data);
269 Teuchos::Array<double> data(2*2*2*2*2*2);
270 shards::Array<double,shards::NaturalOrder,Cell> shards_array_c(&data[0],2);
271 shards::Array<double,shards::NaturalOrder,Cell,Field> shards_array_cf(&data[0],2,2);
272 shards::Array<double,shards::NaturalOrder,Cell,Field,Point> shards_array_cfp(&data[0],2,2,2);
273 shards::Array<double,shards::NaturalOrder,Cell,Field,Point,Dim> shards_array_cfpd(&data[0],2,2,2,2);
274 shards::Array<double,shards::NaturalOrder,Cell,Field,Point,Dim,Dim> shards_array_cfpdd(&data[0],2,2,2,2,2);
275 shards::Array<double,shards::NaturalOrder,Cell,Field,Point,Dim,Dim,Dim> shards_array_cfpddd(&data[0],2,2,2,2,2,2);
293 <<
"===============================================================================\n"\
294 <<
"| TEST 2: Usage of resize |\n"\
295 <<
"===============================================================================\n\n";
299 dimensions.resize(5);
310 Teuchos::Array<double> data(dimensions[0]*dimensions[1]*dimensions[2]*dimensions[3]*dimensions[4]);
315 double mod_entry = 1.0;
316 fc_array(1,1,1,1,1) = mod_entry;
317 int enumeration = fc_array.getEnumeration(1,1,1,1,1);
321 fc_array.resize(dimensions[0]*dimensions[1], dimensions[2], dimensions[3], dimensions[4]);
323 fc_array.getMultiIndex(d0,d1,d2,d3, enumeration);
324 if (std::abs(fc_array(d0,d1,d2,d3) - mod_entry) > zero) {
325 *outStream <<
"\n\nError in resize.\n\n";
331 fc_array.resize(dimensions[0]*dimensions[1]*dimensions[2], dimensions[3], dimensions[4]);
333 fc_array.getMultiIndex(d0,d1,d2, enumeration);
334 if (std::abs(fc_array(d0,d1,d2) - mod_entry) > zero) {
335 *outStream <<
"\n\nError in resize.\n\n";
341 fc_array.resize(dimensions[0]*dimensions[1]*dimensions[2]*dimensions[3], dimensions[4]);
343 fc_array.getMultiIndex(d0,d1, enumeration);
344 if (std::abs(fc_array(d0,d1) - mod_entry) > zero) {
345 *outStream <<
"\n\nError in resize.\n\n";
351 fc_array.resize(dimensions[0]*dimensions[1]*dimensions[2]*dimensions[3]*dimensions[4]);
353 fc_array.getMultiIndex(d0, enumeration);
354 if (std::abs(fc_array(d0) - mod_entry) > zero) {
355 *outStream <<
"\n\nError in resize.\n\n";
360 data.assign(dimensions[0]*dimensions[1]*dimensions[2]*dimensions[3]*dimensions[4], 3.0);
361 shards::Array<double,shards::NaturalOrder,Cell,Field,Point,Dim,Dim>
362 shards_array(data.getRawPtr(),dimensions[0],dimensions[1],dimensions[2],dimensions[3],dimensions[4]);
365 fc_shards_shallow.resize(4,4,4,4,4);
366 fc_shards_shallow.resize(4*4*4*4*4);
369 *outStream <<
"\n\nError in resize.\n\n";
378 catch (std::logic_error err) {
379 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
380 *outStream << err.what() <<
"\n";
381 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
386 std::cout <<
"End Result: TEST FAILED\n";
388 std::cout <<
"End Result: TEST PASSED\n";
391 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.