|
Intrepid
|
00001 // @HEADER 00002 // ************************************************************************ 00003 // 00004 // Intrepid Package 00005 // Copyright (2007) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Pavel Bochev (pbboche@sandia.gov) or 00025 // Denis Ridzal (dridzal@sandia.gov) or 00026 // Robert Kirby (robert.c.kirby@ttu.edu) 00027 // 00028 // ************************************************************************ 00029 // @HEADER 00030 00031 00037 #include "Intrepid_FieldContainer.hpp" 00038 #include "Teuchos_oblackholestream.hpp" 00039 #include "Teuchos_RCP.hpp" 00040 #include "Teuchos_GlobalMPISession.hpp" 00041 #include "Intrepid_PointTools.hpp" 00042 #include "Intrepid_HGRAD_TRI_Cn_FEM.hpp" 00043 #include "Shards_CellTopology.hpp" 00044 00045 #include <iostream> 00046 using namespace Intrepid; 00047 00053 int main(int argc, char *argv[]) { 00054 00055 Teuchos::GlobalMPISession mpiSession(&argc, &argv); 00056 00057 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. 00058 int iprint = argc - 1; 00059 00060 Teuchos::RCP<std::ostream> outStream; 00061 Teuchos::oblackholestream bhs; // outputs nothing 00062 00063 if (iprint > 0) 00064 outStream = Teuchos::rcp(&std::cout, false); 00065 else 00066 outStream = Teuchos::rcp(&bhs, false); 00067 00068 // Save the format state of the original std::cout. 00069 Teuchos::oblackholestream oldFormatState; 00070 oldFormatState.copyfmt(std::cout); 00071 00072 *outStream \ 00073 << "===============================================================================\n" \ 00074 << "| |\n" \ 00075 << "| Unit Test HGRAD_TRI_Cn_FEM |\n" \ 00076 << "| |\n" \ 00077 << "| 1) Tests triangular Lagrange basis |\n" \ 00078 << "| |\n" \ 00079 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \ 00080 << "| Denis Ridzal (dridzal@sandia.gov) or |\n" \ 00081 << "| Robert Kirby (robert.c.kirby@ttu.edu) |\n" \ 00082 << "| |\n" \ 00083 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ 00084 << "| Trilinos website: http://trilinos.sandia.gov |\n" \ 00085 << "| |\n" \ 00086 << "===============================================================================\n"; 00087 00088 int errorFlag = 0; 00089 00090 // Let's instantiate a basis 00091 try { 00092 const int deg = 10; 00093 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND ); 00094 00095 // Get a lattice 00096 const int np_lattice = PointTools::getLatticeSize( myBasis.getBaseCellTopology() , deg , 0 ); 00097 const int nbf = myBasis.getCardinality(); 00098 FieldContainer<double> lattice( np_lattice , 2 ); 00099 PointTools::getLattice<double,FieldContainer<double> >( lattice , 00100 myBasis.getBaseCellTopology() , 00101 deg , 00102 0 , 00103 POINTTYPE_WARPBLEND ); 00104 FieldContainer<double> vals( nbf , np_lattice ); 00105 00106 myBasis.getValues( vals , lattice , OPERATOR_VALUE ); 00107 00108 // test for Kronecker property 00109 for (int i=0;i<nbf;i++) { 00110 for (int j=0;j<np_lattice;j++) { 00111 if ( i==j && std::abs( vals(i,j) - 1.0 ) > INTREPID_TOL ) { 00112 errorFlag++; 00113 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00114 *outStream << " Basis function " << i << " does not have unit value at its node\n"; 00115 } 00116 if ( i!=j && std::abs( vals(i,j) ) > INTREPID_TOL ) { 00117 errorFlag++; 00118 *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; 00119 *outStream << " Basis function " << i << " does not vanish at node " << j << "\n"; 00120 } 00121 } 00122 } 00123 } 00124 catch (std::exception err) { 00125 *outStream << err.what() << "\n\n"; 00126 errorFlag = -1000; 00127 } 00128 00129 try { 00130 const int deg = 3; 00131 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND ); 00132 const std::vector<std::vector<std::vector<int> > >& dofdata = myBasis.getDofOrdinalData(); 00133 for (unsigned d=0;d<dofdata.size();d++) { 00134 std::cout << "Dimension " << d << "\n"; 00135 for (unsigned f=0;f<dofdata[d].size();f++) { 00136 std::cout << "\tFacet number " << f << "\n"; 00137 std::cout << "\t\tDOFS:\n"; 00138 for (unsigned n=0;n<dofdata[d][f].size();n++) { 00139 std::cout << "\t\t\t" << dofdata[d][f][n] << "\n"; 00140 } 00141 } 00142 } 00143 } 00144 catch (std::exception err) { 00145 *outStream << err.what() << "\n\n"; 00146 errorFlag = -1000; 00147 } 00148 00149 try { 00150 const int deg = 1; 00151 Basis_HGRAD_TRI_Cn_FEM<double,FieldContainer<double> > myBasis( deg , POINTTYPE_WARPBLEND ); 00152 00153 // Get a lattice 00154 const int np_lattice = PointTools::getLatticeSize( myBasis.getBaseCellTopology() , deg , 0 ); 00155 const int nbf = myBasis.getCardinality(); 00156 FieldContainer<double> lattice( np_lattice , 2 ); 00157 PointTools::getLattice<double,FieldContainer<double> >( lattice , 00158 myBasis.getBaseCellTopology() , 00159 deg , 00160 0 , 00161 POINTTYPE_WARPBLEND ); 00162 FieldContainer<double> vals( nbf , np_lattice , 2 ); 00163 00164 myBasis.getValues( vals , lattice , OPERATOR_CURL ); 00165 00166 std::cout << vals << std::endl; 00167 } 00168 catch (std::exception err) { 00169 *outStream << err.what() << "\n\n"; 00170 errorFlag = -1000; 00171 } 00172 00173 00174 if (errorFlag != 0) 00175 std::cout << "End Result: TEST FAILED\n"; 00176 else 00177 std::cout << "End Result: TEST PASSED\n"; 00178 00179 // reset format state of std::cout 00180 std::cout.copyfmt(oldFormatState); 00181 00182 return errorFlag; 00183 }
1.7.4