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_TRI_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_TRI_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_TRI_I1_FEM<double, FieldContainer<double> > triBasis;
00098 int errorFlag = 0;
00099
00100
00101 int nException = 0;
00102 int throwCounter = 0;
00103
00104
00105 FieldContainer<double> triNodes(6, 2);
00106 triNodes(0,0) = 0.0; triNodes(0,1) = 0.0;
00107 triNodes(1,0) = 1.0; triNodes(1,1) = 0.0;
00108 triNodes(2,0) = 0.0; triNodes(2,1) = 1.0;
00109
00110 triNodes(3,0) = 0.5; triNodes(3,1) = 0.0;
00111 triNodes(4,0) = 0.5; triNodes(4,1) = 0.5;
00112 triNodes(5,0) = 0.0; triNodes(5,1) = 0.5;
00113
00114
00115
00116 FieldContainer<double> vals;
00117
00118 try{
00119
00120
00121 vals.resize(triBasis.getCardinality(), triNodes.dimension(0), triBasis.getBaseCellTopology().getDimension() );
00122 INTREPID_TEST_COMMAND( triBasis.getValues(vals, triNodes, OPERATOR_GRAD), throwCounter, nException );
00123
00124
00125 INTREPID_TEST_COMMAND( triBasis.getValues(vals, triNodes, OPERATOR_CURL), throwCounter, nException );
00126
00127
00128
00129
00130 INTREPID_TEST_COMMAND( triBasis.getDofOrdinal(3,0,0), throwCounter, nException );
00131
00132 INTREPID_TEST_COMMAND( triBasis.getDofOrdinal(1,1,1), throwCounter, nException );
00133
00134 INTREPID_TEST_COMMAND( triBasis.getDofOrdinal(0,2,1), throwCounter, nException );
00135
00136 INTREPID_TEST_COMMAND( triBasis.getDofTag(3), throwCounter, nException );
00137
00138 INTREPID_TEST_COMMAND( triBasis.getDofTag(-1), throwCounter, nException );
00139
00140 #ifdef HAVE_INTREPID_DEBUG
00141
00142
00143 FieldContainer<double> badPoints1(4, 5, 3);
00144 INTREPID_TEST_COMMAND( triBasis.getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
00145
00146
00147 FieldContainer<double> badPoints2(4, triBasis.getBaseCellTopology().getDimension() + 1);
00148 INTREPID_TEST_COMMAND( triBasis.getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
00149
00150
00151 FieldContainer<double> badVals1(4, 3);
00152 INTREPID_TEST_COMMAND( triBasis.getValues(badVals1, triNodes, OPERATOR_VALUE), throwCounter, nException );
00153
00154
00155 FieldContainer<double> badVals2(4, 3, 1);
00156 INTREPID_TEST_COMMAND( triBasis.getValues(badVals2, triNodes, OPERATOR_VALUE), throwCounter, nException );
00157
00158
00159 FieldContainer<double> badVals3(triBasis.getCardinality() + 1, triNodes.dimension(0), triBasis.getBaseCellTopology().getDimension());
00160 INTREPID_TEST_COMMAND( triBasis.getValues(badVals3, triNodes, OPERATOR_VALUE), throwCounter, nException );
00161
00162
00163 FieldContainer<double> badVals4(triBasis.getCardinality() + 1, triNodes.dimension(0));
00164 INTREPID_TEST_COMMAND( triBasis.getValues(badVals4, triNodes, OPERATOR_DIV), throwCounter, nException );
00165
00166
00167 FieldContainer<double> badVals5(triBasis.getCardinality(), triNodes.dimension(0) + 1, triBasis.getBaseCellTopology().getDimension());
00168 INTREPID_TEST_COMMAND( triBasis.getValues(badVals5, triNodes, OPERATOR_VALUE), throwCounter, nException );
00169
00170
00171 FieldContainer<double> badVals6(triBasis.getCardinality(), triNodes.dimension(0) + 1);
00172 INTREPID_TEST_COMMAND( triBasis.getValues(badVals6, triNodes, OPERATOR_DIV), throwCounter, nException );
00173
00174
00175 FieldContainer<double> badVals7(triBasis.getCardinality(), triNodes.dimension(0), triBasis.getBaseCellTopology().getDimension() + 1);
00176 INTREPID_TEST_COMMAND( triBasis.getValues(badVals7, triNodes, OPERATOR_VALUE), throwCounter, nException );
00177 #endif
00178
00179 }
00180 catch (std::logic_error err) {
00181 *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
00182 *outStream << err.what() << '\n';
00183 *outStream << "-------------------------------------------------------------------------------" << "\n\n";
00184 errorFlag = -1000;
00185 };
00186
00187
00188 if (throwCounter != nException) {
00189 errorFlag++;
00190 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00191 }
00192
00193 *outStream \
00194 << "\n"
00195 << "===============================================================================\n"\
00196 << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
00197 << "===============================================================================\n";
00198
00199 try{
00200 std::vector<std::vector<int> > allTags = triBasis.getAllDofTags();
00201
00202
00203 for (unsigned i = 0; i < allTags.size(); i++) {
00204 int bfOrd = triBasis.getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
00205
00206 std::vector<int> myTag = triBasis.getDofTag(bfOrd);
00207 if( !( (myTag[0] == allTags[i][0]) &&
00208 (myTag[1] == allTags[i][1]) &&
00209 (myTag[2] == allTags[i][2]) &&
00210 (myTag[3] == allTags[i][3]) ) ) {
00211 errorFlag++;
00212 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00213 *outStream << " getDofOrdinal( {"
00214 << allTags[i][0] << ", "
00215 << allTags[i][1] << ", "
00216 << allTags[i][2] << ", "
00217 << allTags[i][3] << "}) = " << bfOrd <<" but \n";
00218 *outStream << " getDofTag(" << bfOrd << ") = { "
00219 << myTag[0] << ", "
00220 << myTag[1] << ", "
00221 << myTag[2] << ", "
00222 << myTag[3] << "}\n";
00223 }
00224 }
00225
00226
00227 for( int bfOrd = 0; bfOrd < triBasis.getCardinality(); bfOrd++) {
00228 std::vector<int> myTag = triBasis.getDofTag(bfOrd);
00229 int myBfOrd = triBasis.getDofOrdinal(myTag[0], myTag[1], myTag[2]);
00230 if( bfOrd != myBfOrd) {
00231 errorFlag++;
00232 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00233 *outStream << " getDofTag(" << bfOrd << ") = { "
00234 << myTag[0] << ", "
00235 << myTag[1] << ", "
00236 << myTag[2] << ", "
00237 << myTag[3] << "} but getDofOrdinal({"
00238 << myTag[0] << ", "
00239 << myTag[1] << ", "
00240 << myTag[2] << ", "
00241 << myTag[3] << "} ) = " << myBfOrd << "\n";
00242 }
00243 }
00244 }
00245 catch (std::logic_error err){
00246 *outStream << err.what() << "\n\n";
00247 errorFlag = -1000;
00248 };
00249
00250 *outStream \
00251 << "\n"
00252 << "===============================================================================\n"\
00253 << "| TEST 3: correctness of basis function values |\n"\
00254 << "===============================================================================\n";
00255
00256 outStream -> precision(20);
00257
00258
00259
00260 double basisValues[] = {
00261
00262 0.0,-1.0, 1.0,-1.0, 0.0, 0.0,
00263 0.5,-1.0, 0.5,-0.5, 0.0,-0.5,
00264
00265 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
00266 0.5, 0.0, 0.5, 0.5, 0.0, 0.5,
00267
00268 -1.0, 0.0, 0.0, 0.0, -1.0, 1.0,
00269 -0.5, 0.0, -0.5, 0.5, -1.0, 0.5
00270 };
00271
00272
00273 double basisDivs[] = {
00274
00275 2.0, 2.0, 2.0,
00276 2.0, 2.0, 2.0,
00277 2.0, 2.0, 2.0,
00278
00279 2.0, 2.0, 2.0,
00280 2.0, 2.0, 2.0,
00281 2.0, 2.0, 2.0,
00282 };
00283
00284 try{
00285
00286
00287 int numFields = triBasis.getCardinality();
00288 int numPoints = triNodes.dimension(0);
00289 int spaceDim = triBasis.getBaseCellTopology().getDimension();
00290
00291
00292 FieldContainer<double> vals;
00293
00294
00295 vals.resize(numFields, numPoints, spaceDim);
00296 triBasis.getValues(vals, triNodes, OPERATOR_VALUE);
00297 for (int i = 0; i < numFields; i++) {
00298 for (int j = 0; j < numPoints; j++) {
00299 for (int k = 0; k < spaceDim; k++) {
00300
00301 int l = k + j * spaceDim + i * spaceDim * numPoints;
00302
00303 if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
00304 errorFlag++;
00305 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00306
00307
00308 *outStream << " address = "<< l <<"\n";
00309 *outStream << " At multi-index { ";
00310 *outStream << i << " ";*outStream << j << " ";*outStream << k << " ";
00311 *outStream << "} computed value: " << vals(i,j,k)
00312 << " but reference value: " << basisValues[l] << "\n";
00313 }
00314 }
00315 }
00316 }
00317
00318
00319
00320 vals.resize(numFields, numPoints);
00321 triBasis.getValues(vals, triNodes, OPERATOR_DIV);
00322 for (int i = 0; i < numFields; i++) {
00323 for (int j = 0; j < numPoints; j++) {
00324 int l = i + j * numFields;
00325 if (std::abs(vals(i,j) - basisDivs[l]) > INTREPID_TOL) {
00326 errorFlag++;
00327 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
00328
00329
00330 *outStream << " At (Field,Point,Dim) multi-index { ";
00331 *outStream << i << " ";*outStream << j << " ";
00332 *outStream << "} computed divergence component: " << vals(i,j)
00333 << " but reference divergence component: " << basisDivs[l] << "\n";
00334 }
00335 }
00336 }
00337
00338 }
00339
00340
00341 catch (std::logic_error err) {
00342 *outStream << err.what() << "\n\n";
00343 errorFlag = -1000;
00344 };
00345
00346 if (errorFlag != 0)
00347 std::cout << "End Result: TEST FAILED\n";
00348 else
00349 std::cout << "End Result: TEST PASSED\n";
00350
00351
00352 std::cout.copyfmt(oldFormatState);
00353
00354 return errorFlag;
00355 }