00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "Intrepid_FieldContainer.hpp"
00036 #include "Intrepid_HDIV_TET_I1_FEM.hpp"
00037 #include "Teuchos_oblackholestream.hpp"
00038 #include "Teuchos_RCP.hpp"
00039 #include "Teuchos_GlobalMPISession.hpp"
00040
00041 using namespace std;
00042 using namespace Intrepid;
00043
00044 #define INTREPID_TEST_COMMAND( S , throwCounter, nException ) \
00045 { \
00046 ++nException; \
00047 try { \
00048 S ; \
00049 } \
00050 catch (std::logic_error err) { \
00051 ++throwCounter; \
00052 *outStream << "Expected Error " << nException << " -------------------------------------------------------------\n"; \
00053 *outStream << err.what() << '\n'; \
00054 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
00055 }; \
00056 }
00057
00058 int main(int argc, char *argv[]) {
00059
00060 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00061
00062
00063
00064 int iprint = argc - 1;
00065 Teuchos::RCP<std::ostream> outStream;
00066 Teuchos::oblackholestream bhs;
00067 if (iprint > 0)
00068 outStream = Teuchos::rcp(&std::cout, false);
00069 else
00070 outStream = Teuchos::rcp(&bhs, false);
00071
00072
00073 Teuchos::oblackholestream oldFormatState;
00074 oldFormatState.copyfmt(std::cout);
00075
00076 *outStream \
00077 << "===============================================================================\n" \
00078 << "| |\n" \
00079 << "| Unit Test (Basis_HDIV_TET_I1_FEM) |\n" \
00080 << "| |\n" \
00081 << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" \
00082 << "| 3) Exception tests on input arguments and invalid operators |\n" \
00083 << "| 2) Basis values for VALUE and DIV operators |\n" \
00084 << "| |\n" \
00085 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
00086 << "| Denis Ridzal (dridzal@sandia.gov), |\n" \
00087 << "| Kara Peterson (kjpeter@sandia.gov). |\n" \
00088 << "| |\n" \
00089 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
00090 << "| Trilinos website: http://trilinos.sandia.gov |\n" \
00091 << "| |\n" \
00092 << "===============================================================================\n"\
00093 << "| TEST 1: Basis creation, exception testing |\n"\
00094 << "===============================================================================\n";
00095
00096
00097 Basis_HDIV_TET_I1_FEM<double, FieldContainer<double> > tetBasis;
00098 int errorFlag = 0;
00099
00100
00101 int nException = 0;
00102 int throwCounter = 0;
00103
00104
00105 FieldContainer<double> tetNodes(10, 3);
00106 tetNodes(0,0) = 0.0; tetNodes(0,1) = 0.0; tetNodes(0,2) = 0.0;
00107 tetNodes(1,0) = 1.0; tetNodes(1,1) = 0.0; tetNodes(1,2) = 0.0;
00108 tetNodes(2,0) = 0.0; tetNodes(2,1) = 1.0; tetNodes(2,2) = 0.0;
00109 tetNodes(3,0) = 0.0; tetNodes(3,1) = 0.0; tetNodes(3,2) = 1.0;
00110 tetNodes(4,0) = 0.5; tetNodes(4,1) = 0.0; tetNodes(4,2) = 0.0;
00111 tetNodes(5,0) = 0.5; tetNodes(5,1) = 0.5; tetNodes(5,2) = 0.0;
00112 tetNodes(6,0) = 0.0; tetNodes(6,1) = 0.5; tetNodes(6,2) = 0.0;
00113 tetNodes(7,0) = 0.0; tetNodes(7,1) = 0.0; tetNodes(7,2) = 0.5;
00114 tetNodes(8,0) = 0.5; tetNodes(8,1) = 0.0; tetNodes(8,2) = 0.5;
00115 tetNodes(9,0) = 0.0; tetNodes(9,1) = 0.5; tetNodes(9,2) = 0.5;
00116
00117
00118 FieldContainer<double> vals;
00119
00120 try{
00121
00122
00123 vals.resize(tetBasis.getCardinality(), tetNodes.dimension(0), 3 );
00124 INTREPID_TEST_COMMAND( tetBasis.getValues(vals, tetNodes, OPERATOR_GRAD), throwCounter, nException );
00125
00126
00127 INTREPID_TEST_COMMAND( tetBasis.getValues(vals, tetNodes, OPERATOR_CURL), throwCounter, nException );
00128
00129
00130
00131
00132 INTREPID_TEST_COMMAND( tetBasis.getDofOrdinal(3,0,0), throwCounter, nException );
00133
00134 INTREPID_TEST_COMMAND( tetBasis.getDofOrdinal(1,1,1), throwCounter, nException );
00135
00136 INTREPID_TEST_COMMAND( tetBasis.getDofOrdinal(0,4,1), throwCounter, nException );
00137
00138 INTREPID_TEST_COMMAND( tetBasis.getDofTag(7), throwCounter, nException );
00139
00140 INTREPID_TEST_COMMAND( tetBasis.getDofTag(-1), throwCounter, nException );
00141
00142 #ifdef HAVE_INTREPID_DEBUG
00143
00144
00145 FieldContainer<double> badPoints1(4, 5, 3);
00146 INTREPID_TEST_COMMAND( tetBasis.getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
00147
00148
00149 FieldContainer<double> badPoints2(4, 2);
00150 INTREPID_TEST_COMMAND( tetBasis.getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
00151
00152
00153 FieldContainer<double> badVals1(4, 3);
00154 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals1, tetNodes, OPERATOR_VALUE), throwCounter, nException );
00155
00156
00157 FieldContainer<double> badVals2(4, 3, 1);
00158 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals2, tetNodes, OPERATOR_VALUE), throwCounter, nException );
00159
00160
00161 FieldContainer<double> badVals3(tetBasis.getCardinality() + 1, tetNodes.dimension(0), 3);
00162 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals3, tetNodes, OPERATOR_VALUE), throwCounter, nException );
00163
00164
00165 FieldContainer<double> badVals4(tetBasis.getCardinality() + 1, tetNodes.dimension(0));
00166 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals4, tetNodes, OPERATOR_DIV), throwCounter, nException );
00167
00168
00169 FieldContainer<double> badVals5(tetBasis.getCardinality(), tetNodes.dimension(0) + 1, 3);
00170 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals5, tetNodes, OPERATOR_VALUE), throwCounter, nException );
00171
00172
00173 FieldContainer<double> badVals6(tetBasis.getCardinality(), tetNodes.dimension(0) + 1);
00174 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals6, tetNodes, OPERATOR_DIV), throwCounter, nException );
00175
00176
00177 FieldContainer<double> badVals7(tetBasis.getCardinality(), tetNodes.dimension(0), 4);
00178 INTREPID_TEST_COMMAND( tetBasis.getValues(badVals7, tetNodes, OPERATOR_VALUE), throwCounter, nException );
00179 #endif
00180
00181 }
00182 catch (std::logic_error err) {
00183 *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00184 *outStream << err.what() << '\n';
00185 *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00186 errorFlag = -1000;
00187 };
00188
00189
00190 if (throwCounter != nException) {
00191 errorFlag++;
00192 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00193 }
00194
00195 *outStream \
00196 << "\n"
00197 << "===============================================================================\n"\
00198 << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
00199 << "===============================================================================\n";
00200
00201 try{
00202 std::vector<std::vector<int> > allTags = tetBasis.getAllDofTags();
00203
00204
00205 for (unsigned i = 0; i < allTags.size(); i++) {
00206 int bfOrd = tetBasis.getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
00207
00208 std::vector<int> myTag = tetBasis.getDofTag(bfOrd);
00209 if( !( (myTag[0] == allTags[i][0]) &&
00210 (myTag[1] == allTags[i][1]) &&
00211 (myTag[2] == allTags[i][2]) &&
00212 (myTag[3] == allTags[i][3]) ) ) {
00213 errorFlag++;
00214 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00215 *outStream << " getDofOrdinal( {"
00216 << allTags[i][0] << ", "
00217 << allTags[i][1] << ", "
00218 << allTags[i][2] << ", "
00219 << allTags[i][3] << "}) = " << bfOrd <<" but \n";
00220 *outStream << " getDofTag(" << bfOrd << ") = { "
00221 << myTag[0] << ", "
00222 << myTag[1] << ", "
00223 << myTag[2] << ", "
00224 << myTag[3] << "}\n";
00225 }
00226 }
00227
00228
00229 for( int bfOrd = 0; bfOrd < tetBasis.getCardinality(); bfOrd++) {
00230 std::vector<int> myTag = tetBasis.getDofTag(bfOrd);
00231 int myBfOrd = tetBasis.getDofOrdinal(myTag[0], myTag[1], myTag[2]);
00232 if( bfOrd != myBfOrd) {
00233 errorFlag++;
00234 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00235 *outStream << " getDofTag(" << bfOrd << ") = { "
00236 << myTag[0] << ", "
00237 << myTag[1] << ", "
00238 << myTag[2] << ", "
00239 << myTag[3] << "} but getDofOrdinal({"
00240 << myTag[0] << ", "
00241 << myTag[1] << ", "
00242 << myTag[2] << ", "
00243 << myTag[3] << "} ) = " << myBfOrd << "\n";
00244 }
00245 }
00246 }
00247 catch (std::logic_error err){
00248 *outStream << err.what() << "\n\n";
00249 errorFlag = -1000;
00250 };
00251
00252 *outStream \
00253 << "\n"
00254 << "===============================================================================\n"\
00255 << "| TEST 3: correctness of basis function values |\n"\
00256 << "===============================================================================\n";
00257
00258 outStream -> precision(20);
00259
00260
00261
00262 double basisValues[] = {
00263
00264 0.,-2.0,0., 0.,0.,0., -2.0,0.,0., 0.,0.,-2.0,
00265 2.0,-2.0,0., 2.0,0.,0., 0.,0.,0., 2.0,0.,-2.0,
00266 0.,0.,0., 0.,2.0,0., -2.0,2.0,0., 0,2.0,-2.0,
00267 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, 0.,0.,0.,
00268
00269 1.0,-2.0,0., 1.0,0.,0., -1.0,0.,0., 1.0,0.,-2.0,
00270 1.0,-1.0,0., 1.0,1.0,0., -1.0,1.0,0., 1.0,1.0,-2.0,
00271 0.,-1.0,0., 0.,1.0,0., -2.0,1.0,0., 0.,1.0,-2.0,
00272 0.,-2.0,1.0, 0.,0.,1.0, -2.0,0.,1.0, 0.,0.,-1.0,
00273 1.0,-2.0,1.0, 1.0,0.,1.0, -1.0,0.,1.0, 1.0,0.,-1.0,
00274 0.,-1.0,1.0, 0.,1.0,1.0, -2.0,1.0,1.0, 0.,1.0,-1.0
00275
00276 };
00277
00278
00279 double basisDivs[] = {
00280
00281 6.0, 6.0, 6.0, 6.0,
00282 6.0, 6.0, 6.0, 6.0,
00283 6.0, 6.0, 6.0, 6.0,
00284 6.0, 6.0, 6.0, 6.0,
00285
00286 6.0, 6.0, 6.0, 6.0,
00287 6.0, 6.0, 6.0, 6.0,
00288 6.0, 6.0, 6.0, 6.0,
00289 6.0, 6.0, 6.0, 6.0,
00290 6.0, 6.0, 6.0, 6.0,
00291 6.0, 6.0, 6.0, 6.0
00292 };
00293
00294 try{
00295
00296
00297 int numFields = tetBasis.getCardinality();
00298 int numPoints = tetNodes.dimension(0);
00299 int spaceDim = tetBasis.getBaseCellTopology().getDimension();
00300
00301
00302 FieldContainer<double> vals;
00303
00304
00305 vals.resize(numFields, numPoints, spaceDim);
00306 tetBasis.getValues(vals, tetNodes, OPERATOR_VALUE);
00307 for (int i = 0; i < numFields; i++) {
00308 for (int j = 0; j < numPoints; j++) {
00309 for (int k = 0; k < spaceDim; k++) {
00310
00311 int l = k + i * spaceDim + j * spaceDim * numFields;
00312 if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
00313 errorFlag++;
00314 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00315
00316
00317 *outStream << " At (Field,Point,Dim) multi-index { ";
00318 *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00319 *outStream << "} computed value: " << vals(i,j,k)
00320 << " but reference value: " << basisValues[l] << "\n";
00321 }
00322 }
00323 }
00324 }
00325
00326
00327
00328 vals.resize(numFields, numPoints);
00329 tetBasis.getValues(vals, tetNodes, OPERATOR_DIV);
00330 for (int i = 0; i < numFields; i++) {
00331 for (int j = 0; j < numPoints; j++) {
00332 int l = i + j * numFields;
00333 if (std::abs(vals(i,j) - basisDivs[l]) > INTREPID_TOL) {
00334 errorFlag++;
00335 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00336
00337
00338 *outStream << " At multi-index { ";
00339 *outStream << i << " ";*outStream << j << " ";
00340 *outStream << "} computed divergence component: " << vals(i,j)
00341 << " but reference divergence component: " << basisDivs[l] << "\n";
00342 }
00343 }
00344 }
00345
00346 }
00347
00348
00349 catch (std::logic_error err) {
00350 *outStream << err.what() << "\n\n";
00351 errorFlag = -1000;
00352 };
00353
00354 if (errorFlag != 0)
00355 std::cout << "End Result: TEST FAILED\n";
00356 else
00357 std::cout << "End Result: TEST PASSED\n";
00358
00359
00360 std::cout.copyfmt(oldFormatState);
00361
00362 return errorFlag;
00363 }