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_HCURL_HEX_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_HCURL_HEX_I1_FEM) |\n" \
00080 << "| |\n" \
00081 << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" \
00082 << "| 2) Basis values for VALUE and CURL operators |\n" \
00083 << "| |\n" \
00084 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
00085 << "| Denis Ridzal (dridzal@sandia.gov), |\n" \
00086 << "| Kara Peterson (kjpeter@sandia.gov). |\n" \
00087 << "| |\n" \
00088 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
00089 << "| Trilinos website: http://trilinos.sandia.gov |\n" \
00090 << "| |\n" \
00091 << "===============================================================================\n"\
00092 << "| TEST 1: Basis creation, exception testing |\n"\
00093 << "===============================================================================\n";
00094
00095
00096 Basis_HCURL_HEX_I1_FEM<double, FieldContainer<double> > hexBasis;
00097 int errorFlag = 0;
00098
00099
00100 int nException = 0;
00101 int throwCounter = 0;
00102
00103
00104 FieldContainer<double> hexNodes(15, 3);
00105 hexNodes(0,0) = -1.0; hexNodes(0,1) = -1.0; hexNodes(0,2) = -1.0;
00106 hexNodes(1,0) = 1.0; hexNodes(1,1) = -1.0; hexNodes(1,2) = -1.0;
00107 hexNodes(2,0) = 1.0; hexNodes(2,1) = 1.0; hexNodes(2,2) = -1.0;
00108 hexNodes(3,0) = -1.0; hexNodes(3,1) = 1.0; hexNodes(3,2) = -1.0;
00109
00110 hexNodes(4,0) = -1.0; hexNodes(4,1) = -1.0; hexNodes(4,2) = 1.0;
00111 hexNodes(5,0) = 1.0; hexNodes(5,1) = -1.0; hexNodes(5,2) = 1.0;
00112 hexNodes(6,0) = 1.0; hexNodes(6,1) = 1.0; hexNodes(6,2) = 1.0;
00113 hexNodes(7,0) = -1.0; hexNodes(7,1) = 1.0; hexNodes(7,2) = 1.0;
00114
00115 hexNodes(8,0) = 0.0; hexNodes(8,1) = 0.0; hexNodes(8,2) = 0.0;
00116
00117 hexNodes(9,0) = 1.0; hexNodes(9,1) = 0.0; hexNodes(9,2) = 0.0;
00118 hexNodes(10,0)= -1.0; hexNodes(10,1)= 0.0; hexNodes(10,2)= 0.0;
00119
00120 hexNodes(11,0)= 0.0; hexNodes(11,1)= 1.0; hexNodes(11,2)= 0.0;
00121 hexNodes(12,0)= 0.0; hexNodes(12,1)= -1.0; hexNodes(12,2)= 0.0;
00122
00123 hexNodes(13,0)= 0.0; hexNodes(13,1)= 0.0; hexNodes(13,2)= 1.0;
00124 hexNodes(14,0)= 0.0; hexNodes(14,1)= 0.0; hexNodes(14,2)= -1.0;
00125
00126
00127
00128 FieldContainer<double> vals;
00129
00130 try{
00131
00132
00133 vals.resize(hexBasis.getCardinality(), hexNodes.dimension(0), 4 );
00134 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_GRAD), throwCounter, nException );
00135
00136
00137
00138 vals.resize(hexBasis.getCardinality(), hexNodes.dimension(0) );
00139 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_DIV), throwCounter, nException );
00140
00141
00142
00143
00144 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(3,0,0), throwCounter, nException );
00145
00146 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(1,1,1), throwCounter, nException );
00147
00148 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(0,4,1), throwCounter, nException );
00149
00150 INTREPID_TEST_COMMAND( hexBasis.getDofTag(12), throwCounter, nException );
00151
00152 INTREPID_TEST_COMMAND( hexBasis.getDofTag(-1), throwCounter, nException );
00153
00154 #ifdef HAVE_INTREPID_DEBUG
00155
00156
00157 FieldContainer<double> badPoints1(4, 5, 3);
00158 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
00159
00160
00161 FieldContainer<double> badPoints2(4, 2);
00162 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
00163
00164
00165 FieldContainer<double> badVals1(4, 3);
00166 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals1, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00167
00168
00169 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals1, hexNodes, OPERATOR_CURL), throwCounter, nException );
00170
00171
00172 FieldContainer<double> badVals2(hexBasis.getCardinality() + 1, hexNodes.dimension(0), 3);
00173 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals2, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00174
00175
00176 FieldContainer<double> badVals3(hexBasis.getCardinality(), hexNodes.dimension(0) + 1, 3);
00177 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals3, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00178
00179
00180 FieldContainer<double> badVals4(hexBasis.getCardinality(), hexNodes.dimension(0), 4);
00181 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals4, hexNodes, OPERATOR_VALUE), throwCounter, nException ) ;
00182
00183
00184 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals4, hexNodes, OPERATOR_CURL), throwCounter, nException ) ;
00185
00186
00187
00188 vals.resize(hexBasis.getCardinality(),
00189 hexNodes.dimension(0),
00190 Intrepid::getDkCardinality(OPERATOR_D2, hexBasis.getBaseCellTopology().getDimension()));
00191 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_D2), throwCounter, nException );
00192
00193 #endif
00194
00195 }
00196 catch (std::logic_error err) {
00197 *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00198 *outStream << err.what() << '\n';
00199 *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00200 errorFlag = -1000;
00201 };
00202
00203
00204
00205 if (throwCounter != nException) {
00206 errorFlag++;
00207 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00208 }
00209
00210
00211 *outStream \
00212 << "\n"
00213 << "===============================================================================\n"\
00214 << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
00215 << "===============================================================================\n";
00216
00217 try{
00218 std::vector<std::vector<int> > allTags = hexBasis.getAllDofTags();
00219
00220
00221 for (unsigned i = 0; i < allTags.size(); i++) {
00222 int bfOrd = hexBasis.getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
00223
00224 std::vector<int> myTag = hexBasis.getDofTag(bfOrd);
00225 if( !( (myTag[0] == allTags[i][0]) &&
00226 (myTag[1] == allTags[i][1]) &&
00227 (myTag[2] == allTags[i][2]) &&
00228 (myTag[3] == allTags[i][3]) ) ) {
00229 errorFlag++;
00230 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00231 *outStream << " getDofOrdinal( {"
00232 << allTags[i][0] << ", "
00233 << allTags[i][1] << ", "
00234 << allTags[i][2] << ", "
00235 << allTags[i][3] << "}) = " << bfOrd <<" but \n";
00236 *outStream << " getDofTag(" << bfOrd << ") = { "
00237 << myTag[0] << ", "
00238 << myTag[1] << ", "
00239 << myTag[2] << ", "
00240 << myTag[3] << "}\n";
00241 }
00242 }
00243
00244
00245 for( int bfOrd = 0; bfOrd < hexBasis.getCardinality(); bfOrd++) {
00246 std::vector<int> myTag = hexBasis.getDofTag(bfOrd);
00247 int myBfOrd = hexBasis.getDofOrdinal(myTag[0], myTag[1], myTag[2]);
00248 if( bfOrd != myBfOrd) {
00249 errorFlag++;
00250 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00251 *outStream << " getDofTag(" << bfOrd << ") = { "
00252 << myTag[0] << ", "
00253 << myTag[1] << ", "
00254 << myTag[2] << ", "
00255 << myTag[3] << "} but getDofOrdinal({"
00256 << myTag[0] << ", "
00257 << myTag[1] << ", "
00258 << myTag[2] << ", "
00259 << myTag[3] << "} ) = " << myBfOrd << "\n";
00260 }
00261 }
00262 }
00263 catch (std::logic_error err){
00264 *outStream << err.what() << "\n\n";
00265 errorFlag = -1000;
00266 };
00267
00268 *outStream \
00269 << "\n"
00270 << "===============================================================================\n"\
00271 << "| TEST 3: correctness of basis function values |\n"\
00272 << "===============================================================================\n";
00273
00274 outStream -> precision(20);
00275
00276
00277 double basisValues[] = {
00278
00279 0.5,0.,0., 0.,0.,0., 0.,0.,0., 0.,-0.5,0., 0.,0.,0., 0.,0.,0.,
00280 0.,0.,0., 0.,0.,0., 0.,0.,0.5, 0.,0.,0., 0.,0.,0., 0.,0.,0.,
00281
00282 0.5,0.,0., 0.,0.5,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.,
00283 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5, 0.,0.,0., 0.,0.,0.,
00284
00285 0.,0.,0., 0.,0.5,0., -0.5,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.,
00286 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5, 0.,0.,0.,
00287
00288 0.,0.,0., 0.,0.,0., -0.5,0.,0., 0.,-0.5,0., 0.,0.,0., 0.,0.,0.,
00289 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5,
00290
00291
00292 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.5,0.,0., 0.,0.,0.,
00293 0.,0.,0., 0.,-0.5,0., 0.,0.,0.5, 0.,0.,0., 0.,0.,0., 0.,0.,0.,
00294
00295 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.5,0.,0., 0.,0.5,0.,
00296 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5, 0.,0.,0., 0.,0.,0.,
00297
00298 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.5,0.,
00299 -0.5,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5, 0.,0.,0.,
00300
00301 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.,
00302 -0.5,0.,0., 0.,-0.5,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.5,
00303
00304
00305 0.125,0.,0., 0.,0.125,0., -0.125,0.,0., 0.,-0.125,0., 0.125,0.,0., 0.,0.125,0.,
00306 -0.125,0.,0., 0.,-0.125,0., 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125,
00307
00308
00309 0.125,0.,0., 0.,0.25,0., -0.125,0.,0., 0.,0.,0., 0.125,0.,0., 0.,0.25,0.,
00310 -0.125,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.25, 0.,0.,0.25, 0.,0.,0.,
00311
00312 0.125,0.,0., 0.,0.,0., -0.125,0.,0., 0.,-0.25,0., 0.125,0.,0., 0.,0.,0.,
00313 -0.125,0.,0., 0.,-0.25,0., 0.,0.,0.25, 0.,0.,0., 0.,0.,0., 0.,0.,0.25,
00314
00315
00316 0.,0.,0., 0.,0.125,0., -0.25,0.,0., 0.,-0.125,0., 0.,0.,0., 0.,0.125,0.,
00317 -0.25,0.,0., 0.,-0.125,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.25, 0.,0.,0.25,
00318
00319 0.25,0.,0., 0.,0.125,0., 0.,0.,0., 0.,-0.125,0., 0.25,0.,0., 0.,0.125,0.,
00320 0.,0.,0., 0.,-0.125,0., 0.,0.,0.25, 0.,0.,0.25, 0.,0.,0., 0.,0.,0.,
00321
00322
00323 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.25,0.,0., 0.,0.25,0.,
00324 -0.25,0.,0., 0.,-0.25,0., 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125,
00325
00326 0.25,0.,0., 0.,0.25,0., -0.25,0.,0., 0.,-0.25,0., 0.,0.,0., 0.,0.,0.,
00327 0.0,0.,0., 0.,0.,0.0, 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125, 0.,0.,0.125
00328 };
00329
00330
00331 double basisCurls[] = {
00332
00333 0.,-0.25,0.25, 0.,0.,0.25, 0.,0.,0.25, -0.25,0.,0.25, 0.,0.25,0., 0.,0.,0.,
00334 0.,0.,0., 0.25,0.,0., -0.25,0.25,0., 0.,-0.25,0., 0.,0.,0., 0.25,0.,0.,
00335
00336 0.,-0.25,0.25, 0.25,0.,0.25, 0.,0.,0.25, 0.,0.,0.25, 0.,0.25,0., -0.25,0.,0.,
00337 0.,0.,0., 0.,0.,0., 0.,0.25,0., -0.25,-0.25,0., 0.25,0.,0., 0.,0.,0.,
00338
00339 0.,0.,0.25, 0.25,0.,0.25, 0.,0.25,0.25, 0.,0.,0.25, 0.,0.,0., -0.25,0.,0.,
00340 0.,-0.25,0., 0.,0.,0., 0.,0.,0., -0.25,0.,0., 0.25,-0.25,0., 0.,0.25,0.,
00341
00342 0.,0.,0.25, 0.,0.,0.25, 0.,0.25,0.25, -0.25,0.,0.25, 0.,0.,0., 0.,0.,0.,
00343 0.,-0.25,0., 0.25,0.,0., -0.25,0.,0., 0.,0.,0., 0.,-0.25,0., 0.25,0.25,0.,
00344
00345
00346 0.,-0.25,0., 0.,0.,0., 0.,0.,0., -0.25,0.,0., 0.,0.25,0.25, 0.,0.,0.25,
00347 0.,0.,0.25, 0.25,0.,0.25, -0.25,0.25,0., 0.,-0.25,0., 0.,0.,0., 0.25,0.,0.,
00348
00349 0.,-0.25,0., 0.25,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.25,0.25, -0.25,0.,0.25,
00350 0.,0.,0.25, 0.,0.,0.25, 0.,0.25,0., -0.25,-0.25,0., 0.25,0.,0., 0.,0.,0.,
00351
00352 0.,0.,0., 0.25,0.,0., 0.,0.25,0., 0.,0.,0., 0.,0.,0.25, -0.25,0.,0.25,
00353 0.,-0.25,0.25, 0.,0.,0.25, 0.,0.,0., -0.25,0.,0., 0.25,-0.25,0., 0.,0.25,0.,
00354
00355 0.,0.,0., 0.,0.,0., 0.,0.25,0., -0.25,0.,0., 0.,0.,0.25, 0.,0.,0.25,
00356 0.,-0.25,0.25, 0.25,0.,0.25, -0.25,0.,0., 0.,0.,0., 0.,-0.25,0., 0.25,0.25,0.,
00357
00358
00359 0.,-0.125,0.125, 0.125,0.,0.125, 0.,0.125,0.125, -0.125,0.,0.125, 0.,0.125,0.125, -0.125,0.,0.125,
00360 0.,-0.125,0.125, 0.125,0.,0.125, -0.125,0.125,0., -0.125,-0.125,0., 0.125,-0.125,0., 0.125,0.125,0.,
00361
00362
00363 0.,-0.125,0.125, 0.25,0.,0.125, 0.,0.125,0.125, 0.,0.,0.125, 0.,0.125,0.125, -0.25,0.,0.125,
00364 0.,-0.125,0.125, 0.,0.,0.125, 0.,0.125,0., -0.25,-0.125,0., 0.25,-0.125,0., 0.,0.125,0.,
00365
00366 0.,-0.125,0.125, 0.,0.,0.125, 0.,0.125,0.125, -0.25,0.,0.125, 0.,0.125,0.125, 0.,0.,0.125,
00367 0.,-0.125,0.125, 0.25,0.,0.125, -0.25,0.125,0., 0.,-0.125,0., 0.,-0.125,0., 0.25,0.125,0.,
00368
00369
00370 0.,0.,0.125, 0.125,0.,0.125, 0.,0.25,0.125, -0.125,0.,0.125, 0.,0.,0.125, -0.125,0.,0.125,
00371 0.,-0.25,0.125, 0.125,0.,0.125, -0.125,0.,0., -0.125,0.,0., 0.125,-0.25,0., 0.125,0.25,0.,
00372
00373 0.,-0.25,0.125, 0.125,0.,0.125, 0.,0.,0.125, -0.125,0.,0.125, 0.,0.25,0.125, -0.125,0.,0.125,
00374 0.,0.,0.125, 0.125,0.,0.125, -0.125,0.25,0., -0.125,-0.25,0., 0.125,0.,0., 0.125,0.,0.,
00375
00376
00377 0.,-0.125,0., 0.125,0.,0., 0.,0.125,0., -0.125,0.,0., 0.,0.125,0.25, -0.125,0.,0.25,
00378 0.,-0.125,0.25, 0.125,0.,0.25, -0.125,0.125,0., -0.125,-0.125,0., 0.125,-0.125,0., 0.125,0.125,0.,
00379
00380 0.,-0.125,0.25, 0.125,0.,0.25, 0.,0.125,0.25, -0.125,0.,0.25, 0.,0.125,0., -0.125,0.,0.,
00381 0.,-0.125,0., 0.125,0.,0., -0.125,0.125,0., -0.125,-0.125,0., 0.125,-0.125,0., 0.125,0.125,0.
00382 };
00383
00384
00385 try{
00386
00387
00388 int numFields = hexBasis.getCardinality();
00389 int numPoints = hexNodes.dimension(0);
00390 int spaceDim = hexBasis.getBaseCellTopology().getDimension();
00391
00392
00393 FieldContainer<double> vals;
00394
00395
00396 vals.resize(numFields, numPoints, spaceDim);
00397 hexBasis.getValues(vals, hexNodes, OPERATOR_VALUE);
00398 for (int i = 0; i < numFields; i++) {
00399 for (int j = 0; j < numPoints; j++) {
00400 for (int k = 0; k < spaceDim; k++) {
00401
00402
00403 int l = k + i * spaceDim + j * spaceDim * numFields;
00404 if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
00405 errorFlag++;
00406 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00407
00408
00409 *outStream << " At multi-index { ";
00410 *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00411 *outStream << "} computed value: " << vals(i,j,k)
00412 << " but reference value: " << basisValues[l] << "\n";
00413 }
00414 }
00415 }
00416 }
00417
00418
00419 vals.resize(numFields, numPoints, spaceDim);
00420 hexBasis.getValues(vals, hexNodes, OPERATOR_CURL);
00421 for (int i = 0; i < numFields; i++) {
00422 for (int j = 0; j < numPoints; j++) {
00423 for (int k = 0; k < spaceDim; k++) {
00424
00425
00426 int l = k + i * spaceDim + j * spaceDim * numFields;
00427 if (std::abs(vals(i,j,k) - basisCurls[l]) > INTREPID_TOL) {
00428 errorFlag++;
00429 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00430
00431
00432 *outStream << " At multi-index { ";
00433 *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00434 *outStream << "} computed curl component: " << vals(i,j,k)
00435 << " but reference curl component: " << basisCurls[l] << "\n";
00436 }
00437 }
00438 }
00439 }
00440
00441 }
00442
00443
00444 catch (std::logic_error err) {
00445 *outStream << err.what() << "\n\n";
00446 errorFlag = -1000;
00447 };
00448
00449 if (errorFlag != 0)
00450 std::cout << "End Result: TEST FAILED\n";
00451 else
00452 std::cout << "End Result: TEST PASSED\n";
00453
00454
00455 std::cout.copyfmt(oldFormatState);
00456
00457 return errorFlag;
00458 }