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"
54 #include "Intrepid_PointTools.hpp"
56 #include "Shards_CellTopology.hpp"
57 
58 #include <iostream>
59 using namespace Intrepid;
60 
66 int main(int argc, char *argv[]) {
67 
68  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
69 
70  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
71  int iprint = argc - 1;
72 
73  Teuchos::RCP<std::ostream> outStream;
74  Teuchos::oblackholestream bhs; // outputs nothing
75 
76  if (iprint > 0)
77  outStream = Teuchos::rcp(&std::cout, false);
78  else
79  outStream = Teuchos::rcp(&bhs, false);
80 
81  // Save the format state of the original std::cout.
82  Teuchos::oblackholestream oldFormatState;
83  oldFormatState.copyfmt(std::cout);
84 
85  *outStream \
86  << "===============================================================================\n" \
87  << "| |\n" \
88  << "| Unit Test HGRAD_TRI_Cn_FEM |\n" \
89  << "| |\n" \
90  << "| 1) Tests triangular Lagrange basis |\n" \
91  << "| |\n" \
92  << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
93  << "| Denis Ridzal (dridzal@sandia.gov) or |\n" \
94  << "| Robert Kirby (robert.c.kirby@ttu.edu) |\n" \
95  << "| |\n" \
96  << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
97  << "| Trilinos website: http://trilinos.sandia.gov |\n" \
98  << "| |\n" \
99  << "===============================================================================\n";
100 
101  int errorFlag = 0;
102 
103  // Let's instantiate a basis
104  try {
105  const int deg = 10;
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  const int nbf = myBasis.getCardinality();
111  FieldContainer<double> lattice( np_lattice , 2 );
112  PointTools::getLattice<double,FieldContainer<double> >( lattice ,
113  myBasis.getBaseCellTopology() ,
114  deg ,
115  0 ,
116  POINTTYPE_WARPBLEND );
117  FieldContainer<double> vals( nbf , np_lattice );
118 
119  myBasis.getValues( vals , lattice , OPERATOR_VALUE );
120 
121  // test for Kronecker property
122  for (int i=0;i<nbf;i++) {
123  for (int j=0;j<np_lattice;j++) {
124  if ( i==j && std::abs( vals(i,j) - 1.0 ) > INTREPID_TOL ) {
125  errorFlag++;
126  *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
127  *outStream << " Basis function " << i << " does not have unit value at its node\n";
128  }
129  if ( i!=j && std::abs( vals(i,j) ) > INTREPID_TOL ) {
130  errorFlag++;
131  *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
132  *outStream << " Basis function " << i << " does not vanish at node " << j << "\n";
133  }
134  }
135  }
136  }
137  catch (std::exception err) {
138  *outStream << err.what() << "\n\n";
139  errorFlag = -1000;
140  }
141 
142  try {
143  const int deg = 3;
144  Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND );
145  const std::vector<std::vector<std::vector<int> > >& dofdata = myBasis.getDofOrdinalData();
146  for (unsigned d=0;d<dofdata.size();d++) {
147  std::cout << "Dimension " << d << "\n";
148  for (unsigned f=0;f<dofdata[d].size();f++) {
149  std::cout << "\tFacet number " << f << "\n";
150  std::cout << "\t\tDOFS:\n";
151  for (unsigned n=0;n<dofdata[d][f].size();n++) {
152  std::cout << "\t\t\t" << dofdata[d][f][n] << "\n";
153  }
154  }
155  }
156  }
157  catch (std::exception err) {
158  *outStream << err.what() << "\n\n";
159  errorFlag = -1000;
160  }
161 
162  try {
163  const int deg = 1;
164  Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND );
165 
166  // Get a lattice
167  const int np_lattice = PointTools::getLatticeSize( myBasis.getBaseCellTopology() , deg , 0 );
168  const int nbf = myBasis.getCardinality();
169  FieldContainer<double> lattice( np_lattice , 2 );
170  PointTools::getLattice<double,FieldContainer<double> >( lattice ,
171  myBasis.getBaseCellTopology() ,
172  deg ,
173  0 ,
174  POINTTYPE_WARPBLEND );
175  FieldContainer<double> vals( nbf , np_lattice , 2 );
176 
177  myBasis.getValues( vals , lattice , OPERATOR_CURL );
178 
179  std::cout << vals << std::endl;
180  }
181  catch (std::exception err) {
182  *outStream << err.what() << "\n\n";
183  errorFlag = -1000;
184  }
185 
186 
187  if (errorFlag != 0)
188  std::cout << "End Result: TEST FAILED\n";
189  else
190  std::cout << "End Result: TEST PASSED\n";
191 
192  // reset format state of std::cout
193  std::cout.copyfmt(oldFormatState);
194 
195  return errorFlag;
196 }
Header file for the Intrepid::HGRAD_TRI_Cn_FEM class.
int main(int argc, char *argv[])
Performs a code-code comparison to FIAT for Nedelec bases on tets (values and curls) ...
Definition: test_01.cpp:65
virtual int getCardinality() const
Returns cardinality of the basis.
Header file for utility class to provide point tools, such as barycentric coordinates, equispaced lattices, and warp-blend point distrubtions.
Header file for utility class to provide multidimensional containers.
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Triangle cell.
Implementation of the default H(grad)-compatible Lagrange basis of arbitrary degree on Triangle cell...
virtual const shards::CellTopology getBaseCellTopology() const
Returns the base cell topology for which the basis is defined. See Shards documentation http://trilin...
virtual const std::vector< std::vector< std::vector< int > > > & getDofOrdinalData()
DoF tag to ordinal data structure.
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...