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_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_HDIV_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 DIV 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_HDIV_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), 3 );
00134 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_GRAD), throwCounter, nException );
00135
00136
00137 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, hexNodes, OPERATOR_CURL), throwCounter, nException );
00138
00139
00140
00141
00142 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(3,0,0), throwCounter, nException );
00143
00144 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(1,1,1), throwCounter, nException );
00145
00146 INTREPID_TEST_COMMAND( hexBasis.getDofOrdinal(0,4,1), throwCounter, nException );
00147
00148 INTREPID_TEST_COMMAND( hexBasis.getDofTag(12), throwCounter, nException );
00149
00150 INTREPID_TEST_COMMAND( hexBasis.getDofTag(-1), throwCounter, nException );
00151
00152 #ifdef HAVE_INTREPID_DEBUG
00153
00154
00155 FieldContainer<double> badPoints1(4, 5, 3);
00156 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
00157
00158
00159 FieldContainer<double> badPoints2(4, 2);
00160 INTREPID_TEST_COMMAND( hexBasis.getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
00161
00162
00163 FieldContainer<double> badVals1(4, 3);
00164 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals1, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00165
00166
00167 FieldContainer<double> badVals2(4, 3, 3);
00168 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals2, hexNodes, OPERATOR_DIV), throwCounter, nException );
00169
00170
00171 FieldContainer<double> badVals3(hexBasis.getCardinality() + 1, hexNodes.dimension(0), 3);
00172 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals3, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00173
00174
00175 FieldContainer<double> badVals4(hexBasis.getCardinality() + 1, hexNodes.dimension(0));
00176 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals4, hexNodes, OPERATOR_DIV), throwCounter, nException );
00177
00178
00179 FieldContainer<double> badVals5(hexBasis.getCardinality(), hexNodes.dimension(0) + 1, 3);
00180 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals5, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00181
00182
00183 FieldContainer<double> badVals6(hexBasis.getCardinality(), hexNodes.dimension(0) + 1);
00184 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals6, hexNodes, OPERATOR_DIV), throwCounter, nException );
00185
00186
00187 FieldContainer<double> badVals7(hexBasis.getCardinality(), hexNodes.dimension(0), 4);
00188 INTREPID_TEST_COMMAND( hexBasis.getValues(badVals7, hexNodes, OPERATOR_VALUE), throwCounter, nException );
00189 #endif
00190
00191 }
00192 catch (std::logic_error err) {
00193 *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00194 *outStream << err.what() << '\n';
00195 *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00196 errorFlag = -1000;
00197 };
00198
00199
00200 if (throwCounter != nException) {
00201 errorFlag++;
00202 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00203 }
00204
00205 *outStream \
00206 << "\n"
00207 << "===============================================================================\n"\
00208 << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
00209 << "===============================================================================\n";
00210
00211 try{
00212 std::vector<std::vector<int> > allTags = hexBasis.getAllDofTags();
00213
00214
00215 for (unsigned i = 0; i < allTags.size(); i++) {
00216 int bfOrd = hexBasis.getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
00217
00218 std::vector<int> myTag = hexBasis.getDofTag(bfOrd);
00219 if( !( (myTag[0] == allTags[i][0]) &&
00220 (myTag[1] == allTags[i][1]) &&
00221 (myTag[2] == allTags[i][2]) &&
00222 (myTag[3] == allTags[i][3]) ) ) {
00223 errorFlag++;
00224 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00225 *outStream << " getDofOrdinal( {"
00226 << allTags[i][0] << ", "
00227 << allTags[i][1] << ", "
00228 << allTags[i][2] << ", "
00229 << allTags[i][3] << "}) = " << bfOrd <<" but \n";
00230 *outStream << " getDofTag(" << bfOrd << ") = { "
00231 << myTag[0] << ", "
00232 << myTag[1] << ", "
00233 << myTag[2] << ", "
00234 << myTag[3] << "}\n";
00235 }
00236 }
00237
00238
00239 for( int bfOrd = 0; bfOrd < hexBasis.getCardinality(); bfOrd++) {
00240 std::vector<int> myTag = hexBasis.getDofTag(bfOrd);
00241 int myBfOrd = hexBasis.getDofOrdinal(myTag[0], myTag[1], myTag[2]);
00242 if( bfOrd != myBfOrd) {
00243 errorFlag++;
00244 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00245 *outStream << " getDofTag(" << bfOrd << ") = { "
00246 << myTag[0] << ", "
00247 << myTag[1] << ", "
00248 << myTag[2] << ", "
00249 << myTag[3] << "} but getDofOrdinal({"
00250 << myTag[0] << ", "
00251 << myTag[1] << ", "
00252 << myTag[2] << ", "
00253 << myTag[3] << "} ) = " << myBfOrd << "\n";
00254 }
00255 }
00256 }
00257 catch (std::logic_error err){
00258 *outStream << err.what() << "\n\n";
00259 errorFlag = -1000;
00260 };
00261
00262 *outStream \
00263 << "\n"
00264 << "===============================================================================\n"\
00265 << "| TEST 3: correctness of basis function values |\n"\
00266 << "===============================================================================\n";
00267
00268 outStream -> precision(20);
00269
00270
00271 double basisValues[] = {
00272
00273 0.,-0.25,0., 0.,0.,0., 0.,0.,0., -0.25,0.,0., 0.,0.,-0.25, 0.,0.,0.,
00274 0.,-0.25,0., 0.25,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,-0.25, 0.,0.,0.,
00275 0.,0.,0., 0.25,0.,0., 0.,0.25,0., 0.,0.,0., 0.,0.,-0.25, 0.,0.,0.,
00276 0.,0.,0., 0.,0.,0., 0.,0.25,0., -0.25,0.,0., 0.,0.,-0.25, 0.,0.,0.,
00277
00278 0.,-0.25,0., 0.,0.,0., 0.,0.,0., -0.25,0.,0., 0.,0.,0., 0.,0.,0.25,
00279 0.,-0.25,0., 0.25,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.25,
00280 0.,0.,0., 0.25,0.,0., 0.,0.25,0., 0.,0.,0., 0.,0.,0., 0.,0.,0.25,
00281 0.,0.,0., 0.,0.,0., 0.,0.25,0., -0.25,0.,0., 0.,0.,0., 0.,0.,0.25,
00282
00283 0.,-0.125,0., 0.125,0.,0., 0.,0.125,0., -0.125,0.,0., 0.,0.,-0.125, 0.,0.,0.125,
00284
00285 0.,-0.125,0., 0.25,0.,0., 0.,0.125,0., 0.,0.,0., 0.,0.,-0.125, 0.,0.,0.125,
00286 0.,-0.125,0., 0.,0.,0., 0.,0.125,0., -0.25,0.,0., 0.,0.,-0.125, 0.,0.,0.125,
00287
00288 0.,0.,0., 0.125,0.,0., 0.,0.25,0., -0.125,0.,0., 0.,0.,-0.125, 0.,0.,0.125,
00289 0.,-0.25,0., 0.125,0.,0., 0.,0.,0., -0.125,0.,0., 0.,0.,-0.125, 0.,0.,0.125,
00290
00291 0.,-0.125,0., 0.125,0.,0., 0.,0.125,0., -0.125,0.,0., 0.,0.,0., 0.,0.,0.25,
00292 0.,-0.125,0., 0.125,0.,0., 0.,0.125,0., -0.125,0.,0., 0.,0.,-0.25, 0.,0.,0.
00293 };
00294
00295
00296 double basisDivs[] = {
00297
00298 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00299 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00300 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00301 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00302
00303 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00304 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00305 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00306 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00307
00308 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00309
00310 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00311 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00312
00313 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00314 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00315
00316 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00317 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
00318 };
00319
00320 try{
00321
00322
00323 int numPoints = hexNodes.dimension(0);
00324 int numFields = hexBasis.getCardinality();
00325 int spaceDim = hexBasis.getBaseCellTopology().getDimension();
00326
00327
00328 FieldContainer<double> vals;
00329
00330
00331 vals.resize(numFields, numPoints, spaceDim);
00332 hexBasis.getValues(vals, hexNodes, OPERATOR_VALUE);
00333 for (int i = 0; i < numFields; i++) {
00334 for (int j = 0; j < numPoints; j++) {
00335 for (int k = 0; k < spaceDim; k++) {
00336
00337
00338 int l = k + i * spaceDim + j * spaceDim * numFields;
00339 if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
00340 errorFlag++;
00341 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00342
00343
00344 *outStream << " At multi-index { ";
00345 *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00346 *outStream << "} computed value: " << vals(i,j,k)
00347 << " but reference value: " << basisValues[l] << "\n";
00348 }
00349 }
00350 }
00351 }
00352
00353
00354 vals.resize(numFields, numPoints);
00355 hexBasis.getValues(vals, hexNodes, OPERATOR_DIV);
00356 for (int i = 0; i < numFields; i++) {
00357 for (int j = 0; j < numPoints; j++) {
00358 int l = i + j * numFields;
00359 if (std::abs(vals(i,j) - basisDivs[l]) > INTREPID_TOL) {
00360 errorFlag++;
00361 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00362
00363
00364 *outStream << " At multi-index { ";
00365 *outStream << i << " ";*outStream << j << " ";
00366 *outStream << "} computed divergence component: " << vals(i,j)
00367 << " but reference divergence component: " << basisDivs[l] << "\n";
00368 }
00369 }
00370 }
00371
00372 }
00373
00374
00375 catch (std::logic_error err) {
00376 *outStream << err.what() << "\n\n";
00377 errorFlag = -1000;
00378 };
00379
00380 if (errorFlag != 0)
00381 std::cout << "End Result: TEST FAILED\n";
00382 else
00383 std::cout << "End Result: TEST PASSED\n";
00384
00385
00386 std::cout.copyfmt(oldFormatState);
00387
00388 return errorFlag;
00389 }