93 #include "Epetra_Time.h"
94 #include "Epetra_Map.h"
95 #include "Epetra_FEVector.h"
96 #include "Epetra_FECrsMatrix.h"
97 #include "Epetra_SerialComm.h"
100 #include "Teuchos_oblackholestream.hpp"
101 #include "Teuchos_RCP.hpp"
106 #include "Shards_CellTopology.hpp"
109 #include "EpetraExt_MultiVectorOut.h"
115 using namespace Intrepid;
117 int main(
int argc,
char *argv[]) {
121 std::cout <<
"\n>>> ERROR: Invalid number of arguments.\n\n";
122 std::cout <<
"Usage:\n\n";
123 std::cout <<
" ./Intrepid_example_Drivers_Example_15.exe deg NX NY NZ verbose\n\n";
124 std::cout <<
" where \n";
125 std::cout <<
" int deg - polynomial degree to be used (assumed >= 1) \n";
126 std::cout <<
" int NX - num intervals in x direction (assumed box domain, 0,1) \n";
127 std::cout <<
" int NY - num intervals in y direction (assumed box domain, 0,1) \n";
128 std::cout <<
" int NZ - num intervals in y direction (assumed box domain, 0,1) \n";
129 std::cout <<
" verbose (optional) - any character, indicates verbose output \n\n";
135 int iprint = argc - 1;
136 Teuchos::RCP<std::ostream> outStream;
137 Teuchos::oblackholestream bhs;
139 outStream = Teuchos::rcp(&std::cout,
false);
141 outStream = Teuchos::rcp(&bhs,
false);
144 Teuchos::oblackholestream oldFormatState;
145 oldFormatState.copyfmt(std::cout);
148 <<
"===============================================================================\n" \
150 <<
"| Example: Build Stiffness Matrix for |\n" \
151 <<
"| Poisson Equation on Hexahedral Mesh |\n" \
153 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
154 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
155 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
157 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
158 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
160 <<
"===============================================================================\n";
165 int deg = atoi(argv[1]);
166 int NX = atoi(argv[2]);
167 int NY = atoi(argv[3]);
168 int NZ = atoi(argv[4]);
174 typedef shards::CellTopology CellTopology;
175 CellTopology hex_8(shards::getCellTopologyData<shards::Hexahedron<8> >() );
178 int numNodesPerElem = hex_8.getNodeCount();
179 int spaceDim = hex_8.getDimension();
183 *outStream <<
"Generating mesh ... \n\n";
185 *outStream <<
" NX" <<
" NY" <<
" NZ\n";
186 *outStream << std::setw(5) << NX <<
187 std::setw(5) << NY << std::setw(5) << NZ <<
"\n\n";
190 int numElems = NX*NY*NZ;
191 int numNodes = (NX+1)*(NY+1)*(NZ+1);
192 *outStream <<
" Number of Elements: " << numElems <<
" \n";
193 *outStream <<
" Number of Nodes: " << numNodes <<
" \n\n";
196 double leftX = 0.0, rightX = 1.0;
197 double leftY = 0.0, rightY = 1.0;
198 double leftZ = 0.0, rightZ = 1.0;
201 double hx = (rightX-leftX)/((
double)NX);
202 double hy = (rightY-leftY)/((
double)NY);
203 double hz = (rightZ-leftZ)/((
double)NZ);
209 for (
int k=0; k<NZ+1; k++)
211 for (
int j=0; j<NY+1; j++)
213 for (
int i=0; i<NX+1; i++)
215 nodeCoord(inode,0) = leftX + (double)i*hx;
216 nodeCoord(inode,1) = leftY + (double)j*hy;
217 nodeCoord(inode,2) = leftZ + (double)k*hz;
218 if (k==0 || k==NZ || j==0 || i==0 || j==NY || i==NX)
220 nodeOnBoundary(inode)=1;
224 nodeOnBoundary(inode)=0;
233 ofstream fcoordout(
"coords.dat");
234 for (
int i=0; i<numNodes; i++) {
235 fcoordout << nodeCoord(i,0) <<
" ";
236 fcoordout << nodeCoord(i,1) <<
" ";
237 fcoordout << nodeCoord(i,2) <<
"\n";
247 for (
int k=0; k<NZ; k++)
249 for (
int j=0; j<NY; j++)
251 for (
int i=0; i<NX; i++)
253 elemToNode(ielem,0) = k * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i;
254 elemToNode(ielem,1) = k * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i + 1;
255 elemToNode(ielem,2) = k * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i + 1;
256 elemToNode(ielem,3) = k * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i;
257 elemToNode(ielem,4) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i;
258 elemToNode(ielem,5) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + j * ( NX + 1 ) + i + 1;
259 elemToNode(ielem,6) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i + 1;
260 elemToNode(ielem,7) = ( k + 1 ) * ( NX + 1 ) * ( NY + 1 ) + ( j + 1 ) * ( NX + 1 ) + i;
267 ofstream fe2nout(
"elem2node.dat");
268 for (
int k=0;k<NZ;k++)
270 for (
int j=0; j<NY; j++)
272 for (
int i=0; i<NX; i++)
274 int ielem = i + j * NX + k * NY * NY;
275 for (
int m=0; m<numNodesPerElem; m++)
277 fe2nout << elemToNode(ielem,m) <<
" ";
287 *outStream <<
"Getting cubature ... \n\n";
291 int cubDegree = 2*deg;
292 Teuchos::RCP<Cubature<double> > quadCub = cubFactory.
create(hex_8, cubDegree);
294 int cubDim = quadCub->getDimension();
295 int numCubPoints = quadCub->getNumPoints();
300 quadCub->getCubature(cubPoints, cubWeights);
305 *outStream <<
"Getting basis ... \n\n";
309 int numFieldsG = quadHGradBasis.getCardinality();
314 quadHGradBasis.getValues(quadGVals, cubPoints, OPERATOR_VALUE);
315 quadHGradBasis.getValues(quadGrads, cubPoints, OPERATOR_GRAD);
319 const int numDOF = (NX*deg+1)*(NY*deg+1)*(NZ*deg+1);
321 for (
int k=0;k<NZ;k++)
323 for (
int j=0;j<NY;j++)
325 for (
int i=0;i<NX;i++)
327 const int start = k * ( NY * deg + 1 ) * ( NX * deg + 1 ) + j * ( NX * deg + 1 ) + i * deg;
330 for (
int kloc=0;kloc<=deg;kloc++)
332 for (
int jloc=0;jloc<=deg;jloc++)
334 for (
int iloc=0;iloc<=deg;iloc++)
336 ltgMapping(ielem,local_dof_cur) = start
337 + kloc * ( NX * deg + 1 ) * ( NY * deg + 1 )
338 + jloc * ( NX * deg + 1 )
351 ofstream ltgout(
"ltg.dat");
352 for (
int k=0;k<NZ;k++)
354 for (
int j=0; j<NY; j++)
356 for (
int i=0; i<NX; i++)
358 int ielem = i + j * NX + k * NX * NY;
359 for (
int m=0; m<numFieldsG; m++)
361 ltgout << ltgMapping(ielem,m) <<
" ";
371 Epetra_SerialComm Comm;
372 Epetra_Map globalMapG(numDOF, 0, Comm);
373 Epetra_FEVector u(globalMapG); u.Random();
374 Epetra_FEVector Ku(globalMapG);
383 *outStream <<
"Building local stiffness matrices...\n\n";
386 int numCells = numElems;
404 for (
int i=0;i<numElems;i++)
406 for (
int j=0;j<numNodesPerElem;j++)
408 const int nodeCur = elemToNode(i,j);
409 for (
int k=0;k<spaceDim;k++)
411 cellVertices(i,j,k) = nodeCoord(nodeCur,k);
416 Epetra_Time localConstructTimer( Comm );
419 CellTools::setJacobian(cellJacobian,cubPoints,cellVertices,hex_8);
420 CellTools::setJacobianInv(cellJacobInv, cellJacobian );
421 CellTools::setJacobianDet(cellJacobDet, cellJacobian );
424 fst::HGRADtransformGRAD<double>(transformedBasisGradients, cellJacobInv, quadGrads);
427 fst::computeCellMeasure<double>(weightedMeasure, cellJacobDet, cubWeights);
430 fst::multiplyMeasure<double>(weightedTransformedBasisGradients,
431 weightedMeasure, transformedBasisGradients);
434 fst::integrate<double>(localStiffMatrices,
435 transformedBasisGradients, weightedTransformedBasisGradients , COMP_BLAS);
437 const double localConstructTime = localConstructTimer.ElapsedTime();
440 Epetra_Time insertionTimer(Comm);
442 vector<map<int,double> > mat(numDOF);
447 for (
int el=0; el<numElems; el++)
449 for (
int i=0;i<numFieldsG;i++)
451 const int glob_row = ltgMapping(el,i);
452 map<int,double> & cur_row = mat[glob_row];
454 for (
int j=0;j<numFieldsG;j++)
456 const int glob_col = ltgMapping(el,j);
457 const double cur_val = localStiffMatrices(el,i,j);
458 map<int,double>::iterator it = cur_row.find( glob_col );
459 if (it != cur_row.end())
461 it->second += cur_val;
465 cur_row[glob_col] = cur_val;
471 const double insertionTime = insertionTimer.ElapsedTime( );
474 *outStream <<
"Time to build local matrices (including Jacobian computation): "<< localConstructTime <<
"\n";
475 *outStream <<
"Time to assemble global matrix from local matrices: " << insertionTime <<
"\n";
476 *outStream <<
"Total construction time: " << localConstructTime + insertionTime <<
"\n";
483 *outStream <<
"End Result: TEST PASSED\n";
486 std::cout.copyfmt(oldFormatState);
Header file for utility class to provide multidimensional containers.
Header file for the Intrepid::HGRAD_HEX_Cn_FEM class.
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Hexahedron cell...
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.