Intrepid
test_01.cpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Intrepid Package
5// Copyright (2007) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38// Denis Ridzal (dridzal@sandia.gov), or
39// Kara Peterson (kjpeter@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44
51#include "Teuchos_oblackholestream.hpp"
52#include "Teuchos_RCP.hpp"
53#include "Teuchos_GlobalMPISession.hpp"
56#include "Shards_CellTopology.hpp"
57
58#include <iostream>
59using namespace Intrepid;
60
66int main(int argc, char *argv[]) {
67 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
68
69 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
70 int iprint = argc - 1;
71
72 Teuchos::RCP<std::ostream> outStream;
73 Teuchos::oblackholestream bhs; // outputs nothing
74
75 if (iprint > 0)
76 outStream = Teuchos::rcp(&std::cout, false);
77 else
78 outStream = Teuchos::rcp(&bhs, false);
79
80 // Save the format state of the original std::cout.
81 Teuchos::oblackholestream oldFormatState;
82 oldFormatState.copyfmt(std::cout);
83
84 *outStream \
85 << "===============================================================================\n" \
86 << "| |\n" \
87 << "| Unit Test HGRAD_TRI_Cn_FEM |\n" \
88 << "| |\n" \
89 << "| 1) Tests triangular Lagrange basis |\n" \
90 << "| |\n" \
91 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
92 << "| Denis Ridzal (dridzal@sandia.gov) or |\n" \
93 << "| Robert Kirby (robert.c.kirby@ttu.edu) |\n" \
94 << "| |\n" \
95 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
96 << "| Trilinos website: http://trilinos.sandia.gov |\n" \
97 << "| |\n" \
98 << "===============================================================================\n";
99
100 int errorFlag = 0;
101
102 // Let's instantiate a basis
103 try {
104 const int deg = 10;
105
106 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND );
107
108 // Get a lattice
109 const int np_lattice = PointTools::getLatticeSize( myBasis.getBaseCellTopology() , deg , 0 );
110
111 const int nbf = myBasis.getCardinality();
112
113 FieldContainer<double> lattice( np_lattice , 2 );
114
115 PointTools::getLattice<double,FieldContainer<double> >( lattice ,
116 myBasis.getBaseCellTopology() ,
117 deg ,
118 0 ,
119 POINTTYPE_WARPBLEND );
120 FieldContainer<double> vals( nbf , np_lattice );
121
122 myBasis.getValues( vals , lattice , OPERATOR_VALUE );
123
124 // test for Kronecker property
125 for (int i=0;i<nbf;i++) {
126 for (int j=0;j<np_lattice;j++) {
127 if ( i==j && std::abs( vals(i,j) - 1.0 ) > INTREPID_TOL ) {
128 errorFlag++;
129 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
130 *outStream << " Basis function " << i << " does not have unit value at its node\n";
131 }
132 if ( i!=j && std::abs( vals(i,j) ) > INTREPID_TOL ) {
133 errorFlag++;
134 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
135 *outStream << " Basis function " << i << " does not vanish at node " << j << "\n";
136 }
137 }
138 }
139 }
140 catch (const std::exception & err) {
141 *outStream << err.what() << "\n\n";
142 errorFlag = -1000;
143 }
144
145 try {
146 const int deg = 3;
147
148 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND );
149 const std::vector<std::vector<std::vector<int> > >& dofdata = myBasis.getDofOrdinalData();
150 for (unsigned d=0;d<dofdata.size();d++) {
151 std::cout << "Dimension " << d << "\n";
152 for (unsigned f=0;f<dofdata[d].size();f++) {
153 std::cout << "\tFacet number " << f << "\n";
154 std::cout << "\t\tDOFS:\n";
155 for (unsigned n=0;n<dofdata[d][f].size();n++) {
156 std::cout << "\t\t\t" << dofdata[d][f][n] << "\n";
157 }
158 }
159 }
160 }
161 catch (const std::exception & err) {
162 *outStream << err.what() << "\n\n";
163 errorFlag = -1000;
164 }
165
166 try {
167
168 const int deg = 1;
169 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND );
170
171 // Get a lattice
172 const int np_lattice = PointTools::getLatticeSize( myBasis.getBaseCellTopology() , deg , 0 );
173
174 const int nbf = myBasis.getCardinality();
175
176 FieldContainer<double> lattice( np_lattice , 2 );
177
178 PointTools::getLattice<double,FieldContainer<double> >( lattice ,
179 myBasis.getBaseCellTopology() ,
180 deg ,
181 0 ,
182 POINTTYPE_WARPBLEND );
183
184 FieldContainer<double> vals( nbf , np_lattice , 2 );
185
186 myBasis.getValues( vals , lattice , OPERATOR_CURL );
187
188 std::cout << vals << std::endl;
189 }
190 catch (const std::exception & err) {
191 *outStream << err.what() << "\n\n";
192 errorFlag = -1000;
193 }
194
195
196 if (errorFlag != 0)
197 std::cout << "End Result: TEST FAILED\n";
198 else
199 std::cout << "End Result: TEST PASSED\n";
200
201 // reset format state of std::cout
202 std::cout.copyfmt(oldFormatState);
203
204 return errorFlag;
205}
int main(int argc, char *argv[])
Tests for Lagrange basis on triangles. Tests Kronecker property of basis and basic execution of diffe...
Definition: test_01.cpp:66
Header file for utility class to provide multidimensional containers.
Header file for the Intrepid::HGRAD_TRI_Cn_FEM class.
Header file for utility class to provide point tools, such as barycentric coordinates,...
Implementation of the default H(grad)-compatible Lagrange basis of arbitrary degree on Triangle cell.
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Triangle cell.
virtual const std::vector< std::vector< std::vector< int > > > & getDofOrdinalData()
DoF tag to ordinal data structure.
virtual const shards::CellTopology getBaseCellTopology() const
Returns the base cell topology for which the basis is defined. See Shards documentation http://trilin...
virtual int getCardinality() const
Returns cardinality of the basis.
Implementation of a templated lexicographical container for a multi-indexed scalar quantity....
static int getLatticeSize(const shards::CellTopology &cellType, const int order, const int offset=0)
Computes the number of points in a lattice of a given order on a simplex (currently disabled for othe...