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_BLAS.hpp"
102 #include "Teuchos_BLAS_types.hpp"
105 #include "Shards_CellTopology.hpp"
108 #include "EpetraExt_MultiVectorOut.h"
111 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_06.exe deg NX NY 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 <<
" verbose (optional) - any character, indicates verbose output \n\n";
130 int iprint = argc - 1;
131 Teuchos::RCP<std::ostream> outStream;
132 Teuchos::oblackholestream bhs;
134 outStream = Teuchos::rcp(&std::cout,
false);
136 outStream = Teuchos::rcp(&bhs,
false);
139 Teuchos::oblackholestream oldFormatState;
140 oldFormatState.copyfmt(std::cout);
143 <<
"===============================================================================\n" \
145 <<
"| Example: Apply Stiffness Matrix for |\n" \
146 <<
"| Poisson Equation on Quadrilateral Mesh |\n" \
148 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
149 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
150 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
152 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
153 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
155 <<
"===============================================================================\n";
160 int deg = atoi(argv[1]);
161 int NX = atoi(argv[2]);
162 int NY = atoi(argv[3]);
168 typedef shards::CellTopology CellTopology;
169 CellTopology quad_4(shards::getCellTopologyData<shards::Quadrilateral<4> >() );
172 int numNodesPerElem = quad_4.getNodeCount();
173 int spaceDim = quad_4.getDimension();
177 *outStream <<
"Generating mesh ... \n\n";
179 *outStream <<
" NX" <<
" NY\n";
180 *outStream << std::setw(5) << NX <<
181 std::setw(5) << NY <<
"\n\n";
184 int numElems = NX*NY;
185 int numNodes = (NX+1)*(NY+1);
186 *outStream <<
" Number of Elements: " << numElems <<
" \n";
187 *outStream <<
" Number of Nodes: " << numNodes <<
" \n\n";
190 double leftX = 0.0, rightX = 1.0;
191 double leftY = 0.0, rightY = 1.0;
194 double hx = (rightX-leftX)/((
double)NX);
195 double hy = (rightY-leftY)/((
double)NY);
201 for (
int j=0; j<NY+1; j++) {
202 for (
int i=0; i<NX+1; i++) {
203 nodeCoord(inode,0) = leftX + (double)i*hx;
204 nodeCoord(inode,1) = leftY + (double)j*hy;
205 if (j==0 || i==0 || j==NY || i==NX){
206 nodeOnBoundary(inode)=1;
209 nodeOnBoundary(inode)=0;
217 ofstream fcoordout(
"coords.dat");
218 for (
int i=0; i<numNodes; i++) {
219 fcoordout << nodeCoord(i,0) <<
" ";
220 fcoordout << nodeCoord(i,1) <<
"\n";
230 for (
int j=0; j<NY; j++) {
231 for (
int i=0; i<NX; i++) {
232 elemToNode(ielem,0) = (NX + 1)*j + i;
233 elemToNode(ielem,1) = (NX + 1)*j + i + 1;
234 elemToNode(ielem,2) = (NX + 1)*(j + 1) + i + 1;
235 elemToNode(ielem,3) = (NX + 1)*(j + 1) + i;
241 ofstream fe2nout(
"elem2node.dat");
242 for (
int j=0; j<NY; j++) {
243 for (
int i=0; i<NX; i++) {
244 int ielem = i + j * NX;
245 for (
int m=0; m<numNodesPerElem; m++){
246 fe2nout << elemToNode(ielem,m) <<
" ";
255 *outStream <<
"Getting cubature ... \n\n";
259 int cubDegree = 2*deg;
260 Teuchos::RCP<Cubature<double> > quadCub = cubFactory.
create(quad_4, cubDegree);
262 int cubDim = quadCub->getDimension();
263 int numCubPoints = quadCub->getNumPoints();
268 quadCub->getCubature(cubPoints, cubWeights);
273 *outStream <<
"Getting basis ... \n\n";
277 int numFieldsG = quadHGradBasis.getCardinality();
282 quadHGradBasis.getValues(quadGVals, cubPoints, OPERATOR_VALUE);
283 quadHGradBasis.getValues(quadGrads, cubPoints, OPERATOR_GRAD);
287 const int numDOF = (NX*deg+1)*(NY*deg+1);
289 for (
int j=0;j<NY;j++) {
290 for (
int i=0;i<NX;i++) {
291 const int start = deg * j * ( NX * deg + 1 ) + i * deg;
294 for (
int vertical=0;vertical<=deg;vertical++) {
295 for (
int horizontal=0;horizontal<=deg;horizontal++) {
296 ltgMapping(ielem,local_dof_cur) = start + vertical*(NX*deg+1)+horizontal;
319 *outStream <<
"Applying stiffness matrix and right hand side ... \n\n";
346 Epetra_SerialComm Comm;
347 Epetra_Map globalMapG(numDOF, 0, Comm);
348 Epetra_FEVector u(globalMapG);
349 Epetra_FEVector Ku(globalMapG);
352 std::cout <<
"About to start ref element matrix\n";
355 refQuadNodes(0,0,0) = 0.0;
356 refQuadNodes(0,0,1) = 0.0;
357 refQuadNodes(0,1,0) = hx;
358 refQuadNodes(0,1,1) = 0.0;
359 refQuadNodes(0,2,0) = hx;
360 refQuadNodes(0,2,1) = hy;
361 refQuadNodes(0,3,0) = 0.0;
362 refQuadNodes(0,3,1) = hy;
365 CellTools::setJacobian(refQuadJacobian, cubPoints, refQuadNodes, quad_4);
366 CellTools::setJacobianInv(refQuadJacobInv, refQuadJacobian );
367 CellTools::setJacobianDet(refQuadJacobDet, refQuadJacobian );
370 fst::HGRADtransformGRAD<double>(quadGradsTransformed, refQuadJacobInv, quadGrads);
373 fst::computeCellMeasure<double>(weightedMeasure, refQuadJacobDet, cubWeights);
376 fst::multiplyMeasure<double>(quadGradsTransformedWeighted,
377 weightedMeasure, quadGradsTransformed);
380 fst::integrate<double>(localStiffMatrix,
381 quadGradsTransformed, quadGradsTransformedWeighted, COMP_BLAS);
383 std::cout <<
"Finished with reference element matrix\n";
395 Epetra_Time multTimer(Comm);
400 double *uVals = u[0];
401 double *KuVals = Ku[0];
403 Teuchos::BLAS<int,double> blas;
404 Epetra_Time scatterTime(Comm);
405 std::cout <<
"Scattering\n";
407 for (
int k=0; k<numElems; k++)
409 for (
int i=0;i<numFieldsG;i++)
411 uScattered(k,i) = uVals[ltgMapping(k,i)];
414 const double scatTime = scatterTime.ElapsedTime();
415 std::cout <<
"Scattered in time " << scatTime <<
"\n";
417 Epetra_Time blasTimer(Comm);
418 blas.GEMM(Teuchos::NO_TRANS , Teuchos::NO_TRANS ,
419 numFieldsG , numElems, numFieldsG ,
421 &localStiffMatrix(0,0,0) ,
428 const double blasTime = blasTimer.ElapsedTime();
429 std::cout <<
"Element matrices applied in " << blasTime <<
"\n";
431 Epetra_Time gatherTimer(Comm);
433 for (
int k=0;k<numElems;k++)
435 for (
int i=0;i<numFieldsG;i++)
437 KuVals[ltgMapping(k,i)] += KuScattered(k,i);
441 const double gatherTime = gatherTimer.ElapsedTime();
442 std::cout <<
"Gathered in " << gatherTime <<
"\n";
445 const double applyTime = gatherTime + blasTime + scatTime;
446 std::cout <<
"Time to do matrix-free product: " << applyTime << std::endl;
449 std::cout <<
"End Result: TEST PASSED\n";
452 std::cout.copyfmt(oldFormatState);
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.