50 #include "Teuchos_oblackholestream.hpp"
51 #include "Teuchos_RCP.hpp"
52 #include "Teuchos_GlobalMPISession.hpp"
55 using namespace Intrepid;
57 #define INTREPID_TEST_COMMAND( S , throwCounter, nException ) \
63 catch (const std::logic_error & err) { \
65 *outStream << "Expected Error " << nException << " -------------------------------------------------------------\n"; \
66 *outStream << err.what() << '\n'; \
67 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
71 int main(
int argc,
char *argv[]) {
73 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
77 int iprint = argc - 1;
78 Teuchos::RCP<std::ostream> outStream;
79 Teuchos::oblackholestream bhs;
81 outStream = Teuchos::rcp(&std::cout,
false);
83 outStream = Teuchos::rcp(&bhs,
false);
86 Teuchos::oblackholestream oldFormatState;
87 oldFormatState.copyfmt(std::cout);
90 <<
"===============================================================================\n" \
92 <<
"| Unit Test (Basis_HCURL_QUAD_I1_FEM) |\n" \
94 <<
"| 1) Conversion of Dof tags into Dof ordinals and back |\n" \
95 <<
"| 2) Basis values for VALUE and CURL operators |\n" \
97 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
98 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
99 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
101 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
102 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
104 <<
"===============================================================================\n"\
105 <<
"| TEST 1: Basis creation, exception testing |\n"\
106 <<
"===============================================================================\n";
114 int throwCounter = 0;
118 quadNodes(0,0) = -1.0; quadNodes(0,1) = -1.0;
119 quadNodes(1,0) = 1.0; quadNodes(1,1) = -1.0;
120 quadNodes(2,0) = 1.0; quadNodes(2,1) = 1.0;
121 quadNodes(3,0) = -1.0; quadNodes(3,1) = 1.0;
123 quadNodes(4,0) = 0.0; quadNodes(4,1) = 0.0;
124 quadNodes(5,0) = 0.0; quadNodes(5,1) = -0.5;
125 quadNodes(6,0) = 0.0; quadNodes(6,1) = 0.5;
126 quadNodes(7,0) = -0.5; quadNodes(7,1) = 0.0;
127 quadNodes(8,0) = 0.5; quadNodes(8,1) = 0.0;
136 INTREPID_TEST_COMMAND( quadBasis.
getValues(vals, quadNodes, OPERATOR_GRAD), throwCounter, nException );
141 INTREPID_TEST_COMMAND( quadBasis.
getValues(vals, quadNodes, OPERATOR_DIV), throwCounter, nException );
146 INTREPID_TEST_COMMAND( quadBasis.
getDofOrdinal(3,0,0), throwCounter, nException );
148 INTREPID_TEST_COMMAND( quadBasis.
getDofOrdinal(1,1,1), throwCounter, nException );
150 INTREPID_TEST_COMMAND( quadBasis.
getDofOrdinal(0,4,1), throwCounter, nException );
152 INTREPID_TEST_COMMAND( quadBasis.
getDofTag(12), throwCounter, nException );
154 INTREPID_TEST_COMMAND( quadBasis.
getDofTag(-1), throwCounter, nException );
156 #ifdef HAVE_INTREPID_DEBUG
160 INTREPID_TEST_COMMAND( quadBasis.
getValues(vals, badPoints1, OPERATOR_VALUE), throwCounter, nException );
164 INTREPID_TEST_COMMAND( quadBasis.
getValues(vals, badPoints2, OPERATOR_VALUE), throwCounter, nException );
168 INTREPID_TEST_COMMAND( quadBasis.
getValues(badVals1, quadNodes, OPERATOR_VALUE), throwCounter, nException );
172 INTREPID_TEST_COMMAND( quadBasis.
getValues(badCurls1, quadNodes, OPERATOR_CURL), throwCounter, nException );
176 INTREPID_TEST_COMMAND( quadBasis.
getValues(badVals2, quadNodes, OPERATOR_VALUE), throwCounter, nException ) ;
180 INTREPID_TEST_COMMAND( quadBasis.
getValues(badVals3, quadNodes, OPERATOR_VALUE), throwCounter, nException ) ;
184 INTREPID_TEST_COMMAND( quadBasis.
getValues(badVals4, quadNodes, OPERATOR_VALUE), throwCounter, nException ) ;
189 quadNodes.dimension(0),
191 INTREPID_TEST_COMMAND( quadBasis.
getValues(vals, quadNodes, OPERATOR_D2), throwCounter, nException );
195 catch (
const std::logic_error & err) {
196 *outStream <<
"UNEXPECTED ERROR !!! ----------------------------------------------------------\n";
197 *outStream << err.what() <<
'\n';
198 *outStream <<
"-------------------------------------------------------------------------------" <<
"\n\n";
204 if (throwCounter != nException) {
206 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
212 <<
"===============================================================================\n"\
213 <<
"| TEST 2: correctness of tag to enum and enum to tag lookups |\n"\
214 <<
"===============================================================================\n";
217 std::vector<std::vector<int> > allTags = quadBasis.
getAllDofTags();
220 for (
unsigned i = 0; i < allTags.size(); i++) {
221 int bfOrd = quadBasis.
getDofOrdinal(allTags[i][0], allTags[i][1], allTags[i][2]);
223 std::vector<int> myTag = quadBasis.
getDofTag(bfOrd);
224 if( !( (myTag[0] == allTags[i][0]) &&
225 (myTag[1] == allTags[i][1]) &&
226 (myTag[2] == allTags[i][2]) &&
227 (myTag[3] == allTags[i][3]) ) ) {
229 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
230 *outStream <<
" getDofOrdinal( {"
231 << allTags[i][0] <<
", "
232 << allTags[i][1] <<
", "
233 << allTags[i][2] <<
", "
234 << allTags[i][3] <<
"}) = " << bfOrd <<
" but \n";
235 *outStream <<
" getDofTag(" << bfOrd <<
") = { "
239 << myTag[3] <<
"}\n";
244 for(
int bfOrd = 0; bfOrd < quadBasis.
getCardinality(); bfOrd++) {
245 std::vector<int> myTag = quadBasis.
getDofTag(bfOrd);
246 int myBfOrd = quadBasis.
getDofOrdinal(myTag[0], myTag[1], myTag[2]);
247 if( bfOrd != myBfOrd) {
249 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
250 *outStream <<
" getDofTag(" << bfOrd <<
") = { "
254 << myTag[3] <<
"} but getDofOrdinal({"
258 << myTag[3] <<
"} ) = " << myBfOrd <<
"\n";
262 catch (
const std::logic_error & err){
263 *outStream << err.what() <<
"\n\n";
269 <<
"===============================================================================\n"\
270 <<
"| TEST 3: correctness of basis function values |\n"\
271 <<
"===============================================================================\n";
273 outStream -> precision(20);
276 double basisValues[] = {
277 0.500000, 0, 0, 0, 0, 0, 0, -0.500000, 0.500000, 0, 0, 0.500000, 0, \
278 0, 0, 0, 0, 0, 0, 0.500000, -0.500000, 0, 0, 0, 0, 0, 0, 0, \
279 -0.500000, 0, 0, -0.500000, 0.250000, 0, 0, 0.250000, -0.250000, 0, \
280 0, -0.250000, 0.375000, 0, 0, 0.250000, -0.125000, 0, 0, -0.250000, \
281 0.125000, 0, 0, 0.250000, -0.375000, 0, 0, -0.250000, 0.250000, 0, 0, \
282 0.125000, -0.250000, 0, 0, -0.375000, 0.250000, 0, 0, 0.375000, \
283 -0.250000, 0, 0, -0.125000
287 double basisCurls[] = {
288 0.25, 0.25, 0.25, 0.25,
289 0.25, 0.25, 0.25, 0.25,
290 0.25, 0.25, 0.25, 0.25,
291 0.25, 0.25, 0.25, 0.25,
292 0.25, 0.25, 0.25, 0.25,
293 0.25, 0.25, 0.25, 0.25,
294 0.25, 0.25, 0.25, 0.25,
295 0.25, 0.25, 0.25, 0.25,
296 0.25, 0.25, 0.25, 0.25
304 int numPoints = quadNodes.dimension(0);
311 vals.
resize(numFields, numPoints, spaceDim);
312 quadBasis.
getValues(vals, quadNodes, OPERATOR_VALUE);
313 for (
int i = 0; i < numFields; i++) {
314 for (
int j = 0; j < numPoints; j++) {
315 for (
int k = 0; k < spaceDim; k++) {
318 int l = k + i * spaceDim + j * spaceDim * numFields;
319 if (std::abs(vals(i,j,k) - basisValues[l]) > INTREPID_TOL) {
321 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
324 *outStream <<
" At multi-index { ";
325 *outStream << i <<
" ";*outStream << j <<
" ";*outStream << k <<
" ";
326 *outStream <<
"} computed value: " << vals(i,j,k)
327 <<
" but reference value: " << basisValues[l] <<
"\n";
334 vals.
resize(numFields, numPoints);
335 quadBasis.
getValues(vals, quadNodes, OPERATOR_CURL);
336 for (
int i = 0; i < numFields; i++) {
337 for (
int j = 0; j < numPoints; j++) {
338 int l = i + j * numFields;
339 if (std::abs(vals(i,j) - basisCurls[l]) > INTREPID_TOL) {
341 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
344 *outStream <<
" At multi-index { ";
345 *outStream << i <<
" ";*outStream << j <<
" ";
346 *outStream <<
"} computed curl component: " << vals(i,j)
347 <<
" but reference curl component: " << basisCurls[l] <<
"\n";
354 catch (
const std::logic_error & err) {
355 *outStream << err.what() <<
"\n\n";
361 <<
"===============================================================================\n"\
362 <<
"| TEST 4: correctness of DoF locations |\n"\
363 <<
"===============================================================================\n";
366 Teuchos::RCP<Basis<double, FieldContainer<double> > > basis =
368 Teuchos::RCP<DofCoordsInterface<FieldContainer<double> > > coord_iface =
376 #ifdef HAVE_INTREPID_DEBUG
378 INTREPID_TEST_COMMAND( coord_iface->getDofCoords(cvals), throwCounter, nException );
380 INTREPID_TEST_COMMAND( coord_iface->getDofCoords(cvals), throwCounter, nException );
382 INTREPID_TEST_COMMAND( coord_iface->getDofCoords(cvals), throwCounter, nException );
385 INTREPID_TEST_COMMAND( coord_iface->getDofCoords(cvals), throwCounter, nException ); nException--;
387 if (throwCounter != nException) {
389 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
394 tangents(0,0) = 2.0; tangents(0,1) = 0.0;
395 tangents(1,0) = 0.0; tangents(1,1) = 2.0;
396 tangents(2,0) = -2.0; tangents(2,1) = 0.0;
397 tangents(3,0) = 0.0; tangents(3,1) = -2.0;
399 basis->getValues(bvals, cvals, OPERATOR_VALUE);
401 for (
int i=0; i<bvals.dimension(0); i++) {
402 for (
int j=0; j<bvals.dimension(1); j++) {
404 double tangent = 0.0;
405 for(
int d=0;d<spaceDim;d++)
406 tangent += bvals(i,j,d)*tangents(j,d);
408 if ((i != j) && (std::abs(tangent - 0.0) > INTREPID_TOL)) {
410 sprintf(buffer,
"\nValue of basis function %d at (%6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals(i,0), cvals(i,1), tangent, 0.0);
411 *outStream << buffer;
413 else if ((i == j) && (std::abs(tangent - 1.0) > INTREPID_TOL)) {
415 sprintf(buffer,
"\nValue of basis function %d at (%6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals(i,0), cvals(i,1), tangent, 1.0);
416 *outStream << buffer;
422 catch (
const std::logic_error & err){
423 *outStream << err.what() <<
"\n\n";
429 std::cout <<
"End Result: TEST FAILED\n";
431 std::cout <<
"End Result: TEST PASSED\n";
434 std::cout.copyfmt(oldFormatState);
virtual const std::vector< int > & getDofTag(const int dofOrd)
DoF ordinal to DoF tag lookup.
virtual int getCardinality() const
Returns cardinality of the basis.
This is an interface class for bases whose degrees of freedom can be associated with spatial location...
virtual const std::vector< std::vector< int > > & getAllDofTags()
Retrieves all DoF tags.
Header file for utility class to provide multidimensional containers.
Header file for the Intrepid::HCURL_QUAD_I1_FEM class.
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
Implementation of the default H(curl)-compatible FEM basis of degree 1 on Quadrilateral cell...
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...
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Quadrilateral cell.