51 #include "Teuchos_oblackholestream.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_GlobalMPISession.hpp"
56 using namespace Intrepid;
58 #define INTREPID_TEST_COMMAND( S , throwCounter, nException ) \
64 catch (std::logic_error err) { \
66 *outStream << "Expected Error " << nException << " -------------------------------------------------------------\n"; \
67 *outStream << err.what() << '\n'; \
68 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
72 int main(
int argc,
char *argv[]) {
74 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
78 int iprint = argc - 1;
79 Teuchos::RCP<std::ostream> outStream;
80 Teuchos::oblackholestream bhs;
82 outStream = Teuchos::rcp(&std::cout,
false);
84 outStream = Teuchos::rcp(&bhs,
false);
87 Teuchos::oblackholestream oldFormatState;
88 oldFormatState.copyfmt(std::cout);
91 <<
"===============================================================================\n" \
93 <<
"| Unit Test (Basis_HGRAD_LINE_C1_FEM) |\n" \
95 <<
"| 1) Conversion of Dof tags into Dof ordinals and back |\n" \
96 <<
"| 2) Basis values for VALUE, GRAD, CURL, DIV, and Dk operators |\n" \
98 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
99 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
100 <<
"| Kara Peterson (dridzal@sandia.gov). |\n" \
102 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
103 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
105 <<
"===============================================================================\n"\
106 <<
"| TEST 1: Basis creation, exception testing |\n"\
107 <<
"===============================================================================\n";
116 int throwCounter = 0;
120 lineNodes(0,0) = -1.0;
121 lineNodes(1,0) = 1.0;
122 lineNodes(2,0) = 0.0;
123 lineNodes(3,0) = 0.5;
135 INTREPID_TEST_COMMAND( lineBasis.
getDofOrdinal(2,0,0), throwCounter, nException );
137 INTREPID_TEST_COMMAND( lineBasis.
getDofOrdinal(1,1,1), throwCounter, nException );
139 INTREPID_TEST_COMMAND( lineBasis.
getDofOrdinal(0,4,0), throwCounter, nException );
141 INTREPID_TEST_COMMAND( lineBasis.
getDofTag(5), throwCounter, nException );
143 INTREPID_TEST_COMMAND( lineBasis.
getDofTag(-1), throwCounter, nException );
145 #ifdef HAVE_INTREPID_DEBUG
149 INTREPID_TEST_COMMAND( lineBasis.
getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
153 INTREPID_TEST_COMMAND( lineBasis.
getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
157 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals1, lineNodes, OPERATOR_VALUE), throwCounter, nException );
161 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals2, lineNodes, OPERATOR_GRAD), throwCounter, nException );
164 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals2, lineNodes, OPERATOR_DIV), throwCounter, nException );
167 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals2, lineNodes, OPERATOR_CURL), throwCounter, nException );
170 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals2, lineNodes, OPERATOR_D2), throwCounter, nException );
174 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals3, lineNodes, OPERATOR_VALUE), throwCounter, nException );
178 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals4, lineNodes, OPERATOR_VALUE), throwCounter, nException );
182 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals5, lineNodes, OPERATOR_GRAD), throwCounter, nException );
186 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals6, lineNodes, OPERATOR_D2), throwCounter, nException );
189 INTREPID_TEST_COMMAND( lineBasis.
getValues(badVals6, lineNodes, OPERATOR_D3), throwCounter, nException );
193 catch (std::logic_error err) {
194 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
195 *outStream << err.what() <<
'\n';
196 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
201 if (throwCounter != nException) {
203 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
208 <<
"===============================================================================\n"\
209 <<
"| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
210 <<
"===============================================================================\n";
213 std::vector<std::vector<int> > allTags = lineBasis.
getAllDofTags();
216 for (
unsigned i = 0; i < allTags.size(); i++) {
217 int bfOrd = lineBasis.
getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
219 std::vector<int> myTag = lineBasis.
getDofTag(bfOrd);
220 if( !( (myTag[0] == allTags[i][0]) &&
221 (myTag[1] == allTags[i][1]) &&
222 (myTag[2] == allTags[i][2]) &&
223 (myTag[3] == allTags[i][3]) ) ) {
225 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
226 *outStream <<
" getDofOrdinal( {"
227 << allTags[i][0] <<
", "
228 << allTags[i][1] <<
", "
229 << allTags[i][2] <<
", "
230 << allTags[i][3] <<
"}) = " << bfOrd <<
" but \n";
231 *outStream <<
" getDofTag(" << bfOrd <<
") = { "
235 << myTag[3] <<
"}\n";
240 for(
int bfOrd = 0; bfOrd < lineBasis.
getCardinality(); bfOrd++) {
241 std::vector<int> myTag = lineBasis.
getDofTag(bfOrd);
242 int myBfOrd = lineBasis.
getDofOrdinal(myTag[0], myTag[1], myTag[2]);
243 if( bfOrd != myBfOrd) {
245 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
246 *outStream <<
" getDofTag(" << bfOrd <<
") = { "
250 << myTag[3] <<
"} but getDofOrdinal({"
254 << myTag[3] <<
"} ) = " << myBfOrd <<
"\n";
258 catch (std::logic_error err){
259 *outStream << err.what() <<
"\n\n";
265 <<
"===============================================================================\n"\
266 <<
"| TEST 3: correctness of basis function values |\n"\
267 <<
"===============================================================================\n";
269 outStream -> precision(20);
272 double basisValues[] = {
280 double basisDerivs[] = {
291 int numPoints = lineNodes.dimension(0);
298 vals.
resize(numFields, numPoints);
299 lineBasis.
getValues(vals, lineNodes, OPERATOR_VALUE);
300 for (
int i = 0; i < numFields; i++) {
301 for (
int j = 0; j < numPoints; j++) {
302 int l = i + j * numFields;
303 if (std::abs(vals(i,j) - basisValues[l]) > INTREPID_TOL) {
305 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
308 *outStream <<
" At multi-index { ";
309 *outStream << i <<
" ";*outStream << j <<
" ";
310 *outStream <<
"} computed value: " << vals(i,j)
311 <<
" but reference value: " << basisValues[l] <<
"\n";
317 vals.
resize(numFields, numPoints, spaceDim);
318 lineBasis.
getValues(vals, lineNodes, OPERATOR_GRAD);
319 for (
int i = 0; i < numFields; i++) {
320 for (
int j = 0; j < numPoints; j++) {
321 for (
int k = 0; k < spaceDim; k++) {
322 int l = k + i * spaceDim + j * spaceDim * numFields;
323 if (std::abs(vals(i,j,k) - basisDerivs[l]) > INTREPID_TOL) {
325 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
328 *outStream <<
" At multi-index { ";
329 *outStream << i <<
" ";*outStream << j <<
" ";*outStream << k <<
" ";
330 *outStream <<
"} computed grad component: " << vals(i,j,k)
331 <<
" but reference grad component: " << basisDerivs[l] <<
"\n";
338 lineBasis.
getValues(vals, lineNodes, OPERATOR_D1);
339 for (
int i = 0; i < numFields; i++) {
340 for (
int j = 0; j < numPoints; j++) {
341 for (
int k = 0; k < spaceDim; k++) {
342 int l = k + i * spaceDim + j * spaceDim * numFields;
343 if (std::abs(vals(i,j,k) - basisDerivs[l]) > INTREPID_TOL) {
345 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
348 *outStream <<
" At multi-index { ";
349 *outStream << i <<
" ";*outStream << j <<
" ";*outStream << k <<
" ";
350 *outStream <<
"} computed D1 component: " << vals(i,j,k)
351 <<
" but reference D1 component: " << basisDerivs[l] <<
"\n";
359 vals.
resize(numFields, numPoints, spaceDim);
360 lineBasis.
getValues(vals, lineNodes, OPERATOR_CURL);
361 for (
int i = 0; i < numFields; i++) {
362 for (
int j = 0; j < numPoints; j++) {
363 for (
int k = 0; k < spaceDim; k++) {
364 int l = k + i * spaceDim + j * spaceDim * numFields;
365 if (std::abs(vals(i,j,k) - basisDerivs[l]) > INTREPID_TOL) {
367 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
370 *outStream <<
" At multi-index { ";
371 *outStream << i <<
" ";*outStream << j <<
" ";*outStream << k <<
" ";
372 *outStream <<
"} computed curl component: " << vals(i,j,k)
373 <<
" but reference curl component: " << basisDerivs[l] <<
"\n";
381 lineBasis.
getValues(vals, lineNodes, OPERATOR_DIV);
382 for (
int i = 0; i < numFields; i++) {
383 for (
int j = 0; j < numPoints; j++) {
384 for (
int k = 0; k < spaceDim; k++) {
385 int l = k + i * spaceDim + j * spaceDim * numFields;
386 if (std::abs(vals(i,j,k) - basisDerivs[l]) > INTREPID_TOL) {
388 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
391 *outStream <<
" At multi-index { ";
392 *outStream << i <<
" ";*outStream << j <<
" ";*outStream << k <<
" ";
393 *outStream <<
"} computed D1 component: " << vals(i,j,k)
394 <<
" but reference D1 component: " << basisDerivs[l] <<
"\n";
402 for(EOperator op = OPERATOR_D2; op < OPERATOR_MAX; op++) {
405 int DkCardin = Intrepid::getDkCardinality(op, spaceDim);
406 vals.
resize(numFields, numPoints, DkCardin);
408 lineBasis.
getValues(vals, lineNodes, op);
409 for (
int i = 0; i < vals.
size(); i++) {
410 if (std::abs(vals[i]) > INTREPID_TOL) {
412 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
415 std::vector<int> myIndex;
417 int ord = Intrepid::getOperatorOrder(op);
418 *outStream <<
" At multi-index { ";
419 for(
int j = 0; j < vals.
rank(); j++) {
420 *outStream << myIndex[j] <<
" ";
422 *outStream <<
"} computed D"<< ord <<
" component: " << vals[i]
423 <<
" but reference D" << ord <<
" component: 0 \n";
430 catch (std::logic_error err) {
431 *outStream << err.what() <<
"\n\n";
436 std::cout <<
"End Result: TEST FAILED\n";
438 std::cout <<
"End Result: TEST PASSED\n";
441 std::cout.copyfmt(oldFormatState);
int size() const
Returns size of the FieldContainer defined as the product of its dimensions.
virtual const std::vector< int > & getDofTag(const int dofOrd)
DoF ordinal to DoF tag lookup.
virtual int getCardinality() const
Returns cardinality of the basis.
virtual const std::vector< std::vector< int > > & getAllDofTags()
Retrieves all DoF tags.
Header file for utility class to provide multidimensional containers.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Line cell.
void getMultiIndex(int &i0, const int valueEnum) const
Returns the multi-index of a value, based on its enumeration, as a list, for rank-1 containers...
int rank() const
Return rank of the FieldContainer = number of indices used to tag the multi-indexed value...
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Line cell.
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
virtual int getDofOrdinal(const int subcDim, const int subcOrd, const int subcDofOrd)
DoF tag to ordinal lookup.
virtual const shards::CellTopology getBaseCellTopology() const
Returns the base cell topology for which the basis is defined. See Shards documentation http://trilin...
Header file for the Intrepid::HGRAD_LINE_C1_FEM class.