94 #include "Epetra_Time.h" 
   95 #include "Epetra_Map.h" 
   96 #include "Epetra_FECrsMatrix.h" 
   97 #include "Epetra_FEVector.h" 
   98 #include "Epetra_SerialComm.h" 
  101 #include "Teuchos_oblackholestream.hpp" 
  102 #include "Teuchos_RCP.hpp" 
  103 #include "Teuchos_BLAS.hpp" 
  106 #include "Shards_CellTopology.hpp" 
  109 #include "EpetraExt_RowMatrixOut.h" 
  110 #include "EpetraExt_MultiVectorOut.h" 
  113 using namespace Intrepid;
 
  116 double evalu(
double & x, 
double & y, 
double & z);
 
  117 int evalGradu(
double & x, 
double & y, 
double & z, 
double & gradu1, 
double & gradu2, 
double & gradu3);
 
  118 double evalDivGradu(
double & x, 
double & y, 
double & z);
 
  120 int main(
int argc, 
char *argv[]) {
 
  124       std::cout <<
"\n>>> ERROR: Invalid number of arguments.\n\n";
 
  125       std::cout <<
"Usage:\n\n";
 
  126       std::cout <<
"  ./Intrepid_example_Drivers_Example_05.exe deg NX NY verbose\n\n";
 
  127       std::cout <<
" where \n";
 
  128       std::cout <<
"   int deg             - polynomial degree to be used (assumed > 1) \n";
 
  129       std::cout <<
"   int NX              - num intervals in x direction (assumed box domain, 0,1) \n";
 
  130       std::cout <<
"   int NY              - num intervals in y direction (assumed box domain, 0,1) \n";
 
  131       std::cout <<
"   verbose (optional)  - any character, indicates verbose output \n\n";
 
  137   int iprint     = argc - 1;
 
  138   Teuchos::RCP<std::ostream> outStream;
 
  139   Teuchos::oblackholestream bhs; 
 
  141     outStream = Teuchos::rcp(&std::cout, 
false);
 
  143     outStream = Teuchos::rcp(&bhs, 
false);
 
  146   Teuchos::oblackholestream oldFormatState;
 
  147   oldFormatState.copyfmt(std::cout);
 
  150     << 
"===============================================================================\n" \
 
  152     << 
"|  Example: Generate Stiffness Matrix and Right Hand Side Vector for          |\n" \
 
  153     << 
"|                   Poisson Equation on Quadrilateral Mesh                    |\n" \
 
  155     << 
"|  Questions? Contact  Pavel Bochev  (pbboche@sandia.gov),                    |\n" \
 
  156     << 
"|                      Denis Ridzal  (dridzal@sandia.gov),                    |\n" \
 
  157     << 
"|                      Kara Peterson (kjpeter@sandia.gov).                    |\n" \
 
  159     << 
"|  Intrepid's website: http://trilinos.sandia.gov/packages/intrepid           |\n" \
 
  160     << 
"|  Trilinos website:   http://trilinos.sandia.gov                             |\n" \
 
  162     << 
"===============================================================================\n";
 
  167   int deg          = atoi(argv[1]);  
 
  168   int NX            = atoi(argv[2]);  
 
  169   int NY            = atoi(argv[3]);  
 
  175   typedef shards::CellTopology    CellTopology;
 
  176   CellTopology quad_4(shards::getCellTopologyData<shards::Quadrilateral<4> >() );
 
  179   int numNodesPerElem = quad_4.getNodeCount();
 
  180   int spaceDim = quad_4.getDimension();
 
  184   *outStream << 
"Generating mesh ... \n\n";
 
  186   *outStream << 
"   NX" << 
"   NY\n";
 
  187   *outStream << std::setw(5) << NX <<
 
  188     std::setw(5) << NY << 
"\n\n";
 
  191   int numElems = NX*NY;
 
  192   int numNodes = (NX+1)*(NY+1);
 
  193   *outStream << 
" Number of Elements: " << numElems << 
" \n";
 
  194   *outStream << 
"    Number of Nodes: " << numNodes << 
" \n\n";
 
  197   double leftX = 0.0, rightX = 1.0;
 
  198   double leftY = 0.0, rightY = 1.0;
 
  201   double hx = (rightX-leftX)/((
double)NX);
 
  202   double hy = (rightY-leftY)/((
double)NY);
 
  208   for (
int j=0; j<NY+1; j++) {
 
  209     for (
int i=0; i<NX+1; i++) {
 
  210       nodeCoord(inode,0) = leftX + (double)i*hx;
 
  211       nodeCoord(inode,1) = leftY + (double)j*hy;
 
  212       if (j==0 || i==0 || j==NY || i==NX){
 
  213         nodeOnBoundary(inode)=1;
 
  216         nodeOnBoundary(inode)=0;
 
  224   ofstream fcoordout(
"coords.dat");
 
  225   for (
int i=0; i<numNodes; i++) {
 
  226     fcoordout << nodeCoord(i,0) <<
" ";
 
  227     fcoordout << nodeCoord(i,1) <<
"\n";
 
  237   for (
int j=0; j<NY; j++) {
 
  238     for (
int i=0; i<NX; i++) {
 
  239       elemToNode(ielem,0) = (NX + 1)*j + i;
 
  240       elemToNode(ielem,1) = (NX + 1)*j + i + 1;
 
  241       elemToNode(ielem,2) = (NX + 1)*(j + 1) + i + 1;
 
  242       elemToNode(ielem,3) = (NX + 1)*(j + 1) + i;
 
  248   ofstream fe2nout(
"elem2node.dat");
 
  249   for (
int j=0; j<NY; j++) {
 
  250     for (
int i=0; i<NX; i++) {
 
  251       int ielem = i + j * NX;
 
  252       for (
int m=0; m<numNodesPerElem; m++){
 
  253         fe2nout << elemToNode(ielem,m) <<
"  ";
 
  263   *outStream << 
"Getting cubature ... \n\n";
 
  267   int cubDegree = 2*deg;
 
  268   Teuchos::RCP<Cubature<double> > quadCub = cubFactory.
create(quad_4, cubDegree); 
 
  270   int cubDim       = quadCub->getDimension();
 
  271   int numCubPoints = quadCub->getNumPoints();
 
  276   quadCub->getCubature(cubPoints, cubWeights);
 
  281   *outStream << 
"Getting basis ... \n\n";
 
  285   int numFieldsG = quadHGradBasis.getCardinality();
 
  290   quadHGradBasis.getValues(quadGVals, cubPoints, OPERATOR_VALUE);
 
  291   quadHGradBasis.getValues(quadGrads, cubPoints, OPERATOR_GRAD);
 
  295   const int numDOF = (NX*deg+1)*(NY*deg+1);
 
  297   for (
int j=0;j<NY;j++) {
 
  298     for (
int i=0;i<NX;i++) {
 
  299       const int start = deg * j * ( NX * deg + 1 ) + i * deg;
 
  302       for (
int vertical=0;vertical<=deg;vertical++) {
 
  303         for (
int horizontal=0;horizontal<=deg;horizontal++) {
 
  304           ltgMapping(ielem,local_dof_cur) = start + vertical*(NX*deg+1)+horizontal;
 
  313   ofstream ltgout(
"ltg.dat");
 
  314   for (
int j=0; j<NY; j++) {
 
  315     for (
int i=0; i<NX; i++) {
 
  316       int ielem = i + j * NX;
 
  317       for (
int m=0; m<numFieldsG; m++){
 
  318         ltgout << ltgMapping(ielem,m) <<
"  ";
 
  327   *outStream << 
"Building stiffness matrix and right hand side ... \n\n";
 
  354   Epetra_SerialComm Comm;
 
  355   Epetra_Map globalMapG(numDOF, 0, Comm);
 
  356   Epetra_Time instantiateTimer(Comm);
 
  357   Epetra_FECrsMatrix StiffMatrix(Copy, globalMapG, 4*numFieldsG);
 
  358   const double instantiateTime = instantiateTimer.ElapsedTime();
 
  359   std::cout << 
"Time to instantiate sparse matrix " << instantiateTime << 
"\n";
 
  360   Epetra_FEVector u(globalMapG);
 
  361   Epetra_FEVector Ku(globalMapG);
 
  366   refQuadNodes(0,0,0) = 0.0;
 
  367   refQuadNodes(0,0,1) = 0.0;
 
  368   refQuadNodes(0,1,0) = hx;
 
  369   refQuadNodes(0,1,1) = 0.0;
 
  370   refQuadNodes(0,2,0) = hx;
 
  371   refQuadNodes(0,2,1) = hy;
 
  372   refQuadNodes(0,3,0) = 0.0;
 
  373   refQuadNodes(0,3,1) = hy;
 
  376   CellTools::setJacobian(refQuadJacobian, cubPoints, refQuadNodes, quad_4);
 
  377   CellTools::setJacobianInv(refQuadJacobInv, refQuadJacobian );
 
  378   CellTools::setJacobianDet(refQuadJacobDet, refQuadJacobian );
 
  381   fst::HGRADtransformGRAD<double>(quadGradsTransformed, refQuadJacobInv, quadGrads);
 
  384   fst::computeCellMeasure<double>(weightedMeasure, refQuadJacobDet, cubWeights);
 
  387   fst::multiplyMeasure<double>(quadGradsTransformedWeighted,
 
  388                                weightedMeasure, quadGradsTransformed);
 
  391   fst::integrate<double>(localStiffMatrix,
 
  392                          quadGradsTransformed, quadGradsTransformedWeighted, COMP_BLAS);
 
  395   Epetra_Time assemblyTimer(Comm);
 
  398    for (
int k=0; k<numElems; k++) 
 
  401        StiffMatrix.InsertGlobalValues(numFieldsG,<gMapping(k,0),numFieldsG,<gMapping(k,0),&localStiffMatrix(0,0,0));
 
  407    StiffMatrix.GlobalAssemble(); StiffMatrix.FillComplete();
 
  409    double assembleTime = assemblyTimer.ElapsedTime();
 
  410    std::cout << 
"Time to insert reference element matrix into global matrix: " << assembleTime << std::endl;
 
  411    std::cout << 
"There are " << StiffMatrix.NumGlobalNonzeros() << 
" nonzeros in the matrix.\n";
 
  412    std::cout << 
"There are " << numDOF << 
" global degrees of freedom.\n";
 
  414    Epetra_Time multTimer(Comm);
 
  415    StiffMatrix.Apply(u,Ku);
 
  416    double multTime = multTimer.ElapsedTime();
 
  417    std::cout << 
"Time to apply: " << multTime << std::endl;
 
  441    std::cout << 
"End Result: TEST PASSED\n";   
 
  444    std::cout.copyfmt(oldFormatState);
 
  451  double evalu(
double & x, 
double & y, 
double & z)
 
  459    double exactu = sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z);
 
  465  int evalGradu(
double & x, 
double & y, 
double & z, 
double & gradu1, 
double & gradu2, 
double & gradu3)
 
  475        gradu1 = (M_PI*cos(M_PI*x)+sin(M_PI*x))
 
  476                   *sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z);
 
  477        gradu2 = (M_PI*cos(M_PI*y)+sin(M_PI*y))
 
  478                   *sin(M_PI*x)*sin(M_PI*z)*exp(x+y+z);
 
  479        gradu3 = (M_PI*cos(M_PI*z)+sin(M_PI*z))
 
  480                   *sin(M_PI*x)*sin(M_PI*y)*exp(x+y+z);
 
  486  double evalDivGradu(
double & x, 
double & y, 
double & z)
 
  494    double divGradu = -3.0*M_PI*M_PI*sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z)
 
  495                     + 2.0*M_PI*cos(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z)
 
  496                     + 2.0*M_PI*cos(M_PI*y)*sin(M_PI*x)*sin(M_PI*z)*exp(x+y+z)
 
  497                     + 2.0*M_PI*cos(M_PI*z)*sin(M_PI*x)*sin(M_PI*y)*exp(x+y+z)
 
  498                     + 3.0*sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z);
 
Header file for utility class to provide multidimensional containers. 
Header file for the abstract base class Intrepid::DefaultCubatureFactory. 
Header file for the Intrepid::HGRAD_QUAD_Cn_FEM class. 
A factory class that generates specific instances of cubatures. 
Teuchos::RCP< Cubature< Scalar, ArrayPoint, ArrayWeight > > create(const shards::CellTopology &cellTopology, const std::vector< int > °ree)
Factory method.