93 #include "Epetra_Time.h" 
   94 #include "Epetra_Map.h" 
   95 #include "Epetra_FEVector.h" 
   96 #include "Epetra_SerialComm.h" 
   99 #include "Teuchos_oblackholestream.hpp" 
  100 #include "Teuchos_RCP.hpp" 
  101 #include "Teuchos_Time.hpp" 
  104 #include "Shards_CellTopology.hpp" 
  107 #include "EpetraExt_MultiVectorOut.h" 
  110 using namespace Intrepid;
 
  113 int main(
int argc, 
char *argv[]) {
 
  117     std::cout <<
"\n>>> ERROR: Invalid number of arguments.\n\n";
 
  118     std::cout <<
"Usage:\n\n";
 
  119     std::cout <<
"  ./Intrepid_example_Drivers_Example_14.exe deg NX NY NZ verbose\n\n";
 
  120     std::cout <<
" where \n";
 
  121     std::cout <<
"   int deg             - polynomial degree to be used (assumed >= 1) \n";
 
  122     std::cout <<
"   int NX              - num intervals in x direction (assumed box domain, 0,1) \n";
 
  123     std::cout <<
"   int NY              - num intervals in y direction (assumed box domain, 0,1) \n";
 
  124     std::cout <<
"   int NZ              - num intervals in y direction (assumed box domain, 0,1) \n";
 
  125     std::cout <<
"   verbose (optional)  - any character, indicates verbose output \n\n";
 
  131   int iprint     = argc - 1;
 
  132   Teuchos::RCP<std::ostream> outStream;
 
  133   Teuchos::oblackholestream bhs; 
 
  135     outStream = Teuchos::rcp(&std::cout, 
false);
 
  137     outStream = Teuchos::rcp(&bhs, 
false);
 
  140   Teuchos::oblackholestream oldFormatState;
 
  141   oldFormatState.copyfmt(std::cout);
 
  144     << 
"===============================================================================\n" \
 
  146     << 
"|  Example: Apply Stiffness Matrix for                                        |\n" \
 
  147     << 
"|                   Poisson Equation on Hexahedral Mesh                       |\n" \
 
  149     << 
"|  Questions? Contact  Pavel Bochev  (pbboche@sandia.gov),                    |\n" \
 
  150     << 
"|                      Denis Ridzal  (dridzal@sandia.gov),                    |\n" \
 
  151     << 
"|                      Kara Peterson (kjpeter@sandia.gov).                    |\n" \
 
  153     << 
"|  Intrepid's website: http://trilinos.sandia.gov/packages/intrepid           |\n" \
 
  154     << 
"|  Trilinos website:   http://trilinos.sandia.gov                             |\n" \
 
  156     << 
"===============================================================================\n";
 
  161   int deg          = atoi(argv[1]);  
 
  162   int NX           = atoi(argv[2]);  
 
  163   int NY           = atoi(argv[3]);  
 
  164   int NZ           = atoi(argv[4]);  
 
  170   typedef shards::CellTopology    CellTopology;
 
  171   CellTopology hex_8(shards::getCellTopologyData<shards::Hexahedron<8> >() );
 
  174   int numNodesPerElem = hex_8.getNodeCount();
 
  175   int spaceDim = hex_8.getDimension();
 
  179   *outStream << 
"Generating mesh ... \n\n";
 
  181   *outStream << 
"   NX" << 
"   NY" << 
"   NZ\n";
 
  182   *outStream << std::setw(5) << NX <<
 
  183     std::setw(5) << NY << std::setw(5) << NZ << 
"\n\n";
 
  186   int numElems = NX*NY*NZ;
 
  187   int numNodes = (NX+1)*(NY+1)*(NZ+1);
 
  188   *outStream << 
" Number of Elements: " << numElems << 
" \n";
 
  189   *outStream << 
"    Number of Nodes: " << numNodes << 
" \n\n";
 
  192   double leftX = 0.0, rightX = 1.0;
 
  193   double leftY = 0.0, rightY = 1.0;
 
  194   double leftZ = 0.0, rightZ = 1.0;
 
  197   double hx = (rightX-leftX)/((
double)NX);
 
  198   double hy = (rightY-leftY)/((
double)NY);
 
  199   double hz = (rightZ-leftZ)/((
double)NZ);
 
  205   for (
int k=0; k<NZ+1; k++) 
 
  207       for (
int j=0; j<NY+1; j++) 
 
  209           for (
int i=0; i<NX+1; i++) 
 
  211               nodeCoord(inode,0) = leftX + (double)i*hx;
 
  212               nodeCoord(inode,1) = leftY + (double)j*hy;
 
  213               nodeCoord(inode,2) = leftZ + (double)k*hz;
 
  214               if (k==0 || k==NZ || j==0 || i==0 || j==NY || i==NX)
 
  216                   nodeOnBoundary(inode)=1;
 
  220                   nodeOnBoundary(inode)=0;
 
  229   ofstream fcoordout(
"coords.dat");
 
  230   for (
int i=0; i<numNodes; i++) {
 
  231     fcoordout << nodeCoord(i,0) <<
" ";
 
  232     fcoordout << nodeCoord(i,1) <<
" ";
 
  233     fcoordout << nodeCoord(i,2) <<
"\n";
 
  241   *outStream << 
"Getting cubature and basis ... \n\n";
 
  248   const int numCubPoints1D = glcub->getNumPoints();
 
  253   glcub->getCubature(cubPoints1D,cubWeights1D);
 
  257   cub_to_tensor.push_back( glcub );
 
  258   cub_to_tensor.push_back( glcub );
 
  259   cub_to_tensor.push_back( glcub );
 
  261   Array<RCP<FieldContainer<double> > > wts_by_dim(3);
 
  262   wts_by_dim[0] = rcp( &cubWeights1D , 
false ); wts_by_dim[1] = wts_by_dim[0]; wts_by_dim[2] = wts_by_dim[1];
 
  268   Array< Array< RCP< Basis< double , FieldContainer<double> > > > > &bases = hexBasis.getBases();
 
  272   Array< RCP< FieldContainer<double> > > basisVals( 3 );
 
  274   bases[0][0]->getValues( bvals1D , cubPoints1D , OPERATOR_VALUE );
 
  275   basisVals[0] = rcp( &bvals1D , 
false ); basisVals[1] = basisVals[0]; basisVals[2] = basisVals[0];
 
  277   Array< RCP< FieldContainer<double> > > basisDVals( 3 );
 
  279   bases[0][0]->getValues( bdvals1D , cubPoints1D , OPERATOR_D1 );
 
  280   basisDVals[0] = rcp( &bdvals1D , 
false ); basisDVals[1] = basisDVals[0]; basisDVals[2] = basisDVals[0];
 
  283   const int numCubPoints = cubhex.getNumPoints();
 
  286   cubhex.getCubature( cubPoints3D , cubWeights3D );
 
  291   for (
int k=0; k<NZ; k++) 
 
  293       for (
int j=0; j<NY; j++) 
 
  295           for (
int i=0; i<NX; i++) 
 
  297               elemToNode(ielem,0) = k * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i;
 
  298               elemToNode(ielem,1) = k * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i + 1;
 
  299               elemToNode(ielem,2) = k * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i + 1;
 
  300               elemToNode(ielem,3) = k * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i;
 
  301               elemToNode(ielem,4) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i;
 
  302               elemToNode(ielem,5) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i + 1;
 
  303               elemToNode(ielem,6) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i + 1;
 
  304               elemToNode(ielem,7) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i;
 
  311   ofstream fe2nout(
"elem2node.dat");
 
  312   for (
int k=0;k<NZ;k++)
 
  314       for (
int j=0; j<NY; j++) 
 
  316           for (
int i=0; i<NX; i++) 
 
  318               int ielem = i + j * NX + k * NY * NY;
 
  319               for (
int m=0; m<numNodesPerElem; m++)
 
  321                   fe2nout << elemToNode(ielem,m) <<
"  ";
 
  333   const int numDOF = (NX*deg+1)*(NY*deg+1)*(NZ*deg+1);
 
  335   for (
int k=0;k<NZ;k++) 
 
  337       for (
int j=0;j<NY;j++) 
 
  339           for (
int i=0;i<NX;i++) 
 
  341               const int start = k * ( NY * deg + 1 ) * ( NX * deg + 1 ) + j * ( NX * deg + 1 ) + i * deg;
 
  344               for (
int kloc=0;kloc<=deg;kloc++) 
 
  346                   for (
int jloc=0;jloc<=deg;jloc++) 
 
  348                       for (
int iloc=0;iloc<=deg;iloc++)
 
  350                           ltgMapping(ielem,local_dof_cur) = start 
 
  351                             + kloc * ( NX * deg + 1 ) * ( NY * deg + 1 )
 
  352                             + jloc * ( NX * deg + 1 )
 
  365   ofstream ltgout(
"ltg.dat");
 
  366   for (
int k=0;k<NZ;k++)  
 
  368       for (
int j=0; j<NY; j++) 
 
  370           for (
int i=0; i<NX; i++) 
 
  372               int ielem = i + j * NX + k * NX * NY;
 
  373               for (
int m=0; m<hexBasis.getCardinality(); m++)
 
  375                   ltgout << ltgMapping(ielem,m) <<
"  ";
 
  385   Epetra_SerialComm Comm;
 
  386   Epetra_Map globalMapG(numDOF, 0, Comm);
 
  387   Epetra_FEVector u(globalMapG);  u.Random();
 
  388   Epetra_FEVector Ku(globalMapG);
 
  398   for (
int i=0;i<numElems;i++)
 
  400       for (
int j=0;j<numNodesPerElem;j++)
 
  402           const int nodeCur = elemToNode(i,j);
 
  403           for (
int k=0;k<spaceDim;k++) 
 
  405               cellVertices(i,j,k) = nodeCoord(nodeCur,k);
 
  428   double *uVals = u[0];
 
  429   double *KuVals = Ku[0];
 
  431   Teuchos::Time full_timer( 
"Time to apply operator matrix-free:" );
 
  432   Teuchos::Time scatter_timer( 
"Time to scatter dof:" );
 
  433   Teuchos::Time elementwise_timer( 
"Time to do elementwise computation:" ); 
 
  434   Teuchos::Time grad_timer( 
"Time to compute gradients:" );
 
  435   Teuchos::Time pointwise_timer( 
"Time to do pointwise transformations:" );
 
  436   Teuchos::Time moment_timer( 
"Time to compute moments:" );
 
  437   Teuchos::Time gather_timer( 
"Time to gather dof:" );
 
  441   scatter_timer.start();
 
  442   for (
int k=0; k<numElems; k++) 
 
  444       for (
int i=0;i<hexBasis.getCardinality();i++) 
 
  446           uScattered(k,0,i) = uVals[ltgMapping(k,i)];
 
  449   scatter_timer.stop();
 
  451   elementwise_timer.start();
 
  454   Intrepid::TensorProductSpaceTools::evaluateGradient<double>( gradU , uScattered ,basisVals , basisDVals );
 
  456   pointwise_timer.start();
 
  457   Intrepid::FunctionSpaceToolsInPlace::HGRADtransformGRAD<double>( gradU , cellJacobian );
 
  458   Intrepid::FunctionSpaceToolsInPlace::HGRADtransformGRADDual<double>( gradU , cellJacobian );
 
  459   Intrepid::FunctionSpaceToolsInPlace::multiplyMeasure<double>( gradU , cellJacobDet );
 
  460   pointwise_timer.stop();
 
  461   moment_timer.start();
 
  462   Intrepid::TensorProductSpaceTools::momentsGrad<double>( KuScattered , gradU , basisVals , basisDVals , wts_by_dim );
 
  464   elementwise_timer.stop();
 
  465   gather_timer.start();
 
  466   for (
int k=0;k<numElems;k++)
 
  468       for (
int i=0;i<hexBasis.getCardinality();i++)
 
  470           KuVals[ltgMapping(k,i)] += KuScattered(k,0,i);
 
  476   *outStream << full_timer.name() << 
" " << full_timer.totalElapsedTime() << 
" sec\n";
 
  477   *outStream << 
"\t" << scatter_timer.name() << 
" " << scatter_timer.totalElapsedTime() << 
" sec\n";
 
  478   *outStream << 
"\t" << elementwise_timer.name() << 
" " << elementwise_timer.totalElapsedTime() << 
" sec\n";
 
  479   *outStream << 
"\t\t" << grad_timer.name() << 
" " << grad_timer.totalElapsedTime() << 
" sec\n";
 
  480   *outStream << 
"\t\t" << pointwise_timer.name() << 
" " << pointwise_timer.totalElapsedTime() << 
" sec\n";
 
  481   *outStream << 
"\t\t" << moment_timer.name() << 
" " << moment_timer.totalElapsedTime() << 
" sec\n";
 
  482   *outStream << 
"\t" << gather_timer.name() << 
" " << gather_timer.totalElapsedTime() << 
" sec\n";
 
  485   *outStream << 
"End Result: TEST PASSED\n";
 
  488   std::cout.copyfmt(oldFormatState);
 
Header file for utility class to provide multidimensional containers. 
Header file for the Intrepid::CubatureTensor class. 
Header file for the Intrepid::HGRAD_HEX_Cn_FEM class. 
Utilizes cubature (integration) rules contained in the library Polylib (Spencer Sherwin, Aeronautics, Imperial College London) within Intrepid. 
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Hexahedron cell...
Header file for the Intrepid::CubaturePolylib class. 
Defines tensor-product cubature (integration) rules in Intrepid.