56 #include "Teuchos_oblackholestream.hpp"
57 #include "Teuchos_RCP.hpp"
58 #include "Teuchos_GlobalMPISession.hpp"
59 #include "Teuchos_SerialDenseMatrix.hpp"
60 #include "Teuchos_SerialDenseVector.hpp"
61 #include "Teuchos_LAPACK.hpp"
64 using namespace Intrepid;
70 const shards::CellTopology & ,
81 int x = 0, y = 1, z = 2;
85 for (
int cell=0; cell<result.
dimension(0); cell++) {
86 for (
int pt=0; pt<result.
dimension(1); pt++) {
87 result(cell,pt) = - xd*(xd-1)*std::pow(points(cell,pt,x), xd-2) *
88 std::pow(points(cell,pt,y), yd) * std::pow(points(cell,pt,z), zd);
95 for (
int cell=0; cell<result.
dimension(0); cell++) {
96 for (
int pt=0; pt<result.
dimension(1); pt++) {
97 result(cell,pt) -= yd*(yd-1)*std::pow(points(cell,pt,y), yd-2) *
98 std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,z), zd);
105 for (
int cell=0; cell<result.
dimension(0); cell++) {
106 for (
int pt=0; pt<result.
dimension(1); pt++) {
107 result(cell,pt) -= zd*(zd-1)*std::pow(points(cell,pt,z), zd-2) *
108 std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd);
114 for (
int cell=0; cell<result.
dimension(0); cell++) {
115 for (
int pt=0; pt<result.
dimension(1); pt++) {
116 result(cell,pt) += std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd) * std::pow(points(cell,pt,z), zd);
127 const shards::CellTopology & parentCell,
128 int sideOrdinal,
int xd,
int yd,
int zd) {
130 int x = 0, y = 1, z = 2;
141 for (
int cell=0; cell<numCells; cell++) {
142 for (
int pt=0; pt<numPoints; pt++) {
143 grad_u(cell,pt,x) = xd*std::pow(points(cell,pt,x), xd-1) *
144 std::pow(points(cell,pt,y), yd) * std::pow(points(cell,pt,z), zd);
151 for (
int cell=0; cell<numCells; cell++) {
152 for (
int pt=0; pt<numPoints; pt++) {
153 grad_u(cell,pt,y) = yd*std::pow(points(cell,pt,y), yd-1) *
154 std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,z), zd);
161 for (
int cell=0; cell<numCells; cell++) {
162 for (
int pt=0; pt<numPoints; pt++) {
163 grad_u(cell,pt,z) = zd*std::pow(points(cell,pt,z), zd-1) *
164 std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd);
173 FunctionSpaceTools::scalarMultiplyDataData<double>(side_normals, normal_lengths, side_normals,
true);
175 FunctionSpaceTools::dotMultiplyDataData<double>(result, grad_u, side_normals);
181 int x = 0, y = 1, z = 2;
182 for (
int cell=0; cell<result.
dimension(0); cell++) {
183 for (
int pt=0; pt<result.
dimension(1); pt++) {
184 result(cell,pt) = std::pow(points(pt,x), xd)*std::pow(points(pt,y), yd)*std::pow(points(pt,z), zd);
192 int main(
int argc,
char *argv[]) {
194 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
198 int iprint = argc - 1;
199 Teuchos::RCP<std::ostream> outStream;
200 Teuchos::oblackholestream bhs;
202 outStream = Teuchos::rcp(&std::cout,
false);
204 outStream = Teuchos::rcp(&bhs,
false);
207 Teuchos::oblackholestream oldFormatState;
208 oldFormatState.copyfmt(std::cout);
211 <<
"===============================================================================\n" \
213 <<
"| Unit Test (Basis_HGRAD_PYR_I2_FEM) |\n" \
215 <<
"| 1) Patch test involving mass and stiffness matrices, |\n" \
216 <<
"| for the Neumann problem on a pyramid patch |\n" \
217 <<
"| Omega with boundary Gamma. |\n" \
219 <<
"| - div (grad u) + u = f in Omega, (grad u) . n = g on Gamma |\n" \
221 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
222 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
223 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
224 <<
"| Mauro Perego (mperego@sandia.gov). |\n" \
226 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
227 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
229 <<
"===============================================================================\n"\
230 <<
"| TEST 1: Patch test |\n"\
231 <<
"===============================================================================\n";
236 outStream -> precision(16);
243 shards::CellTopology cell(shards::getCellTopologyData< shards::Pyramid<> >());
244 shards::CellTopology sideQ(shards::getCellTopologyData< shards::Quadrilateral<> >());
245 shards::CellTopology sideT(shards::getCellTopologyData< shards::Triangle<> >());
246 int cellDim = cell.getDimension();
247 int sideQDim = sideQ.getDimension();
248 int sideTDim = sideT.getDimension();
251 int numIntervals = 10;
252 int numInterpPoints = ((numIntervals + 1)*(numIntervals + 2)*(numIntervals + 3))/6;
255 for (
int k=0; k<=numIntervals; k++) {
256 for (
int j=0; j<=numIntervals; j++) {
257 for (
int i=0; i<=numIntervals; i++) {
258 if (i+j+k <= numIntervals) {
259 interp_points_ref(counter,0) = i*(1.0/numIntervals);
260 interp_points_ref(counter,1) = j*(1.0/numIntervals);
261 interp_points_ref(counter,2) = k*(1.0/numIntervals);
273 cell_nodes(0, 0, 0) = -4.0;
274 cell_nodes(0, 0, 1) = -9.0;
275 cell_nodes(0, 0, 2) = -5.0;
276 cell_nodes(0, 1, 0) = -6.0;
277 cell_nodes(0, 1, 1) = -3.0;
278 cell_nodes(0, 1, 2) = 3.0;
279 cell_nodes(0, 2, 0) = 10.0;
280 cell_nodes(0, 2, 1) = 5.0;
281 cell_nodes(0, 2, 2) = 7.0;
282 cell_nodes(0, 3, 0) = 12.0;
283 cell_nodes(0, 3, 1) = -1.0;
284 cell_nodes(0, 3, 2) = -1.0;
285 cell_nodes(0, 4, 0) = 5.0;
286 cell_nodes(0, 4, 1) = 5.0;
287 cell_nodes(0, 4, 2) = -3.0;
328 interp_points.resize(numInterpPoints, cellDim);
330 for (
int x_order=0; x_order <= max_order; x_order++) {
331 for (
int y_order=0; y_order <= max_order-x_order; y_order++) {
332 for (
int z_order=0; z_order <= max_order-x_order-y_order; z_order++) {
336 u_exact(exact_solution, interp_points, x_order, y_order, z_order);
341 double zero = basis_order*basis_order*basis_order*100*INTREPID_TOL;
344 Teuchos::RCP<Basis<double,FieldContainer<double> > > basis =
346 int numFields = basis->getCardinality();
349 Teuchos::RCP<Cubature<double> > cellCub = cubFactory.
create(cell, 2*basis_order);
350 Teuchos::RCP<Cubature<double> > sideQCub = cubFactory.
create(sideQ, 2*basis_order);
351 Teuchos::RCP<Cubature<double> > sideTCub = cubFactory.
create(sideT, 2*basis_order);
352 int numCubPointsCell = cellCub->getNumPoints();
353 int numCubPointsSideQ = sideQCub->getNumPoints();
354 int numCubPointsSideT = sideTCub->getNumPoints();
368 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
370 FieldContainer<double> transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
371 FieldContainer<double> weighted_transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
378 unsigned numSides = 5;
379 unsigned numSidesT = 4;
397 FieldContainer<double> transformed_value_of_basis_at_cub_points_sideQ_refcell(1, numFields, numCubPointsSideQ);
398 FieldContainer<double> transformed_value_of_basis_at_cub_points_sideT_refcell(1, numFields, numCubPointsSideT);
399 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell(1, numFields, numCubPointsSideQ);
400 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_sideT_refcell(1, numFields, numCubPointsSideT);
417 cellCub->getCubature(cub_points_cell, cub_weights_cell);
425 FunctionSpaceTools::computeCellMeasure<double>(weighted_measure_cell, jacobian_det_cell, cub_weights_cell);
430 basis->getValues(value_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_VALUE);
433 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_cell,
434 value_of_basis_at_cub_points_cell);
437 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_cell,
438 weighted_measure_cell,
439 transformed_value_of_basis_at_cub_points_cell);
442 FunctionSpaceTools::integrate<double>(fe_matrix,
443 transformed_value_of_basis_at_cub_points_cell,
444 weighted_transformed_value_of_basis_at_cub_points_cell,
451 basis->getValues(grad_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_GRAD);
454 FunctionSpaceTools::HGRADtransformGRAD<double>(transformed_grad_of_basis_at_cub_points_cell,
456 grad_of_basis_at_cub_points_cell);
459 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_grad_of_basis_at_cub_points_cell,
460 weighted_measure_cell,
461 transformed_grad_of_basis_at_cub_points_cell);
464 FunctionSpaceTools::integrate<double>(fe_matrix,
465 transformed_grad_of_basis_at_cub_points_cell,
466 weighted_transformed_grad_of_basis_at_cub_points_cell,
477 rhsFunc(rhs_at_cub_points_cell_physical, cub_points_cell_physical, x_order, y_order, z_order);
480 FunctionSpaceTools::integrate<double>(rhs_and_soln_vector,
481 rhs_at_cub_points_cell_physical,
482 weighted_transformed_value_of_basis_at_cub_points_cell,
486 sideQCub->getCubature(cub_points_sideQ, cub_weights_sideQ);
487 sideTCub->getCubature(cub_points_sideT, cub_weights_sideT);
489 for (
unsigned i=0; i<numSidesT; i++) {
496 FunctionSpaceTools::computeFaceMeasure<double>(weighted_measure_sideT_refcell,
497 jacobian_sideT_refcell,
503 basis->getValues(value_of_basis_at_cub_points_sideT_refcell, cub_points_sideT_refcell, OPERATOR_VALUE);
505 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_sideT_refcell,
506 value_of_basis_at_cub_points_sideT_refcell);
509 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_sideT_refcell,
510 weighted_measure_sideT_refcell,
511 transformed_value_of_basis_at_cub_points_sideT_refcell);
517 neumann(neumann_data_at_cub_points_sideT_physical, cub_points_sideT_physical, jacobian_sideT_refcell,
518 cell, (
int)i, x_order, y_order, z_order);
520 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
521 neumann_data_at_cub_points_sideT_physical,
522 weighted_transformed_value_of_basis_at_cub_points_sideT_refcell,
529 for (
unsigned i=numSidesT; i<numSides; i++) {
536 FunctionSpaceTools::computeFaceMeasure<double>(weighted_measure_sideQ_refcell,
537 jacobian_sideQ_refcell,
543 basis->getValues(value_of_basis_at_cub_points_sideQ_refcell, cub_points_sideQ_refcell, OPERATOR_VALUE);
545 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_sideQ_refcell,
546 value_of_basis_at_cub_points_sideQ_refcell);
549 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell,
550 weighted_measure_sideQ_refcell,
551 transformed_value_of_basis_at_cub_points_sideQ_refcell);
557 neumann(neumann_data_at_cub_points_sideQ_physical, cub_points_sideQ_physical, jacobian_sideQ_refcell,
558 cell, (
int)i, x_order, y_order, z_order);
560 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
561 neumann_data_at_cub_points_sideQ_physical,
562 weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell,
573 Teuchos::LAPACK<int, double> solver;
574 solver.GESV(numFields, 1, &fe_matrix[0], numFields, &ipiv(0), &rhs_and_soln_vector[0], numFields, &info);
582 basis->getValues(value_of_basis_at_interp_points_ref, interp_points_ref, OPERATOR_VALUE);
584 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_interp_points_ref,
585 value_of_basis_at_interp_points_ref);
586 FunctionSpaceTools::evaluate<double>(interpolant, rhs_and_soln_vector, transformed_value_of_basis_at_interp_points_ref);
593 *outStream <<
"\nRelative norm-2 error between exact solution polynomial of order ("
594 << x_order <<
", " << y_order <<
", " << z_order
595 <<
") and finite element interpolant of order " << basis_order <<
": "
601 *outStream <<
"\n\nPatch test failed for solution polynomial order ("
602 << x_order <<
", " << y_order <<
", " << z_order <<
") and basis order " << basis_order <<
"\n\n";
611 catch (
const std::logic_error & err) {
612 *outStream << err.what() <<
"\n\n";
617 std::cout <<
"End Result: TEST FAILED\n";
619 std::cout <<
"End Result: TEST PASSED\n";
622 std::cout.copyfmt(oldFormatState);
int dimension(const int whichDim) const
Returns the specified dimension.
Header file for utility class to provide multidimensional containers.
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
Implementation of an H(grad)-compatible FEM basis of degree 2 on a Pyramid 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.
Header file for the Intrepid::HGRAD_PYR_I2_FEM class.