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"
64using namespace Intrepid;
66void rhsFunc(FieldContainer<double> &,
const FieldContainer<double> &,
int,
int,
int);
67void neumann(FieldContainer<double> & ,
68 const FieldContainer<double> & ,
69 const FieldContainer<double> & ,
70 const shards::CellTopology & ,
72void u_exact(FieldContainer<double> &,
const FieldContainer<double> &,
int,
int,
int);
75void rhsFunc(FieldContainer<double> & result,
76 const FieldContainer<double> & points,
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);
125 const FieldContainer<double> & points,
126 const FieldContainer<double> & jacs,
127 const shards::CellTopology & parentCell,
128 int sideOrdinal,
int xd,
int yd,
int zd) {
130 int x = 0, y = 1, z = 2;
132 int numCells = result.dimension(0);
133 int numPoints = result.dimension(1);
135 FieldContainer<double> grad_u(numCells, numPoints, 3);
136 FieldContainer<double> side_normals(numCells, numPoints, 3);
137 FieldContainer<double> normal_lengths(numCells, numPoints);
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);
180void u_exact(FieldContainer<double> & result,
const FieldContainer<double> & points,
int xd,
int yd,
int zd) {
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);
192int 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_HEX_C2_FEM) |\n" \
215 <<
"| 1) Patch test involving mass and stiffness matrices, |\n" \
216 <<
"| for the Neumann problem on a physical parallelepiped |\n" \
217 <<
"| AND a reference hex Omega with boundary Gamma. |\n" \
219 <<
"| - div (grad u) + u = f in Omega, (grad u) . n = g on Gamma |\n" \
221 <<
"| For a generic parallelepiped, the basis recovers a complete |\n" \
222 <<
"| polynomial space of order 2. On a (scaled and/or translated) |\n" \
223 <<
"| reference hex, the basis recovers a complete tensor product |\n" \
224 <<
"| space of order 1 (i.e. incl. cross terms, e.g. x^2*y^2*z^2). |\n" \
226 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
227 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
228 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
230 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
231 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
233 <<
"===============================================================================\n"\
234 <<
"| TEST 1: Patch test |\n"\
235 <<
"===============================================================================\n";
240 outStream -> precision(16);
246 DefaultCubatureFactory<double> cubFactory;
247 shards::CellTopology cell(shards::getCellTopologyData< shards::Hexahedron<> >());
248 shards::CellTopology side(shards::getCellTopologyData< shards::Quadrilateral<> >());
249 int cellDim = cell.getDimension();
250 int sideDim = side.getDimension();
251 unsigned numSides = 6;
254 int numIntervals = 10;
255 int numInterpPoints = (numIntervals + 1)*(numIntervals + 1)*(numIntervals + 1);
256 FieldContainer<double> interp_points_ref(numInterpPoints, 3);
258 for (
int k=0; k<=numIntervals; k++) {
259 for (
int j=0; j<=numIntervals; j++) {
260 for (
int i=0; i<=numIntervals; i++) {
261 interp_points_ref(counter,0) = i*(1.0/numIntervals)-1.0;
262 interp_points_ref(counter,1) = j*(1.0/numIntervals)-1.0;
263 interp_points_ref(counter,2) = k*(1.0/numIntervals)-1.0;
270 FieldContainer<double> cell_nodes[2];
271 cell_nodes[0].resize(1, 8, cellDim);
272 cell_nodes[1].resize(1, 8, cellDim);
275 cell_nodes[0](0, 0, 0) = -5.0;
276 cell_nodes[0](0, 0, 1) = -1.0;
277 cell_nodes[0](0, 0, 2) = 0.0;
278 cell_nodes[0](0, 1, 0) = 4.0;
279 cell_nodes[0](0, 1, 1) = 1.0;
280 cell_nodes[0](0, 1, 2) = 1.0;
281 cell_nodes[0](0, 2, 0) = 8.0;
282 cell_nodes[0](0, 2, 1) = 3.0;
283 cell_nodes[0](0, 2, 2) = 1.0;
284 cell_nodes[0](0, 3, 0) = -1.0;
285 cell_nodes[0](0, 3, 1) = 1.0;
286 cell_nodes[0](0, 3, 2) = 0.0;
287 cell_nodes[0](0, 4, 0) = 5.0;
288 cell_nodes[0](0, 4, 1) = 9.0;
289 cell_nodes[0](0, 4, 2) = 1.0;
290 cell_nodes[0](0, 5, 0) = 14.0;
291 cell_nodes[0](0, 5, 1) = 11.0;
292 cell_nodes[0](0, 5, 2) = 2.0;
293 cell_nodes[0](0, 6, 0) = 18.0;
294 cell_nodes[0](0, 6, 1) = 13.0;
295 cell_nodes[0](0, 6, 2) = 2.0;
296 cell_nodes[0](0, 7, 0) = 9.0;
297 cell_nodes[0](0, 7, 1) = 11.0;
298 cell_nodes[0](0, 7, 2) = 1.0;
300 cell_nodes[1](0, 0, 0) = -1.0;
301 cell_nodes[1](0, 0, 1) = -1.0;
302 cell_nodes[1](0, 0, 2) = -1.0;
303 cell_nodes[1](0, 1, 0) = 1.0;
304 cell_nodes[1](0, 1, 1) = -1.0;
305 cell_nodes[1](0, 1, 2) = -1.0;
306 cell_nodes[1](0, 2, 0) = 1.0;
307 cell_nodes[1](0, 2, 1) = 1.0;
308 cell_nodes[1](0, 2, 2) = -1.0;
309 cell_nodes[1](0, 3, 0) = -1.0;
310 cell_nodes[1](0, 3, 1) = 1.0;
311 cell_nodes[1](0, 3, 2) = -1.0;
312 cell_nodes[1](0, 4, 0) = -1.0;
313 cell_nodes[1](0, 4, 1) = -1.0;
314 cell_nodes[1](0, 4, 2) = 1.0;
315 cell_nodes[1](0, 5, 0) = 1.0;
316 cell_nodes[1](0, 5, 1) = -1.0;
317 cell_nodes[1](0, 5, 2) = 1.0;
318 cell_nodes[1](0, 6, 0) = 1.0;
319 cell_nodes[1](0, 6, 1) = 1.0;
320 cell_nodes[1](0, 6, 2) = 1.0;
321 cell_nodes[1](0, 7, 0) = -1.0;
322 cell_nodes[1](0, 7, 1) = 1.0;
323 cell_nodes[1](0, 7, 2) = 1.0;
325 std::stringstream mystream[2];
326 mystream[0].str(
"\n>> Now testing basis on a generic parallelepiped ...\n");
327 mystream[1].str(
"\n>> Now testing basis on the reference hex ...\n");
330 for (
int pcell = 0; pcell < 2; pcell++) {
331 *outStream << mystream[pcell].str();
332 FieldContainer<double> interp_points(1, numInterpPoints, cellDim);
334 interp_points.resize(numInterpPoints, cellDim);
336 for (
int x_order=0; x_order <= max_order; x_order++) {
337 int max_y_order = max_order;
339 max_y_order -= x_order;
341 for (
int y_order=0; y_order <= max_y_order; y_order++) {
342 int max_z_order = max_order;
344 max_z_order -= x_order;
345 max_z_order -= y_order;
347 for (
int z_order=0; z_order <= max_z_order; z_order++) {
350 FieldContainer<double> exact_solution(1, numInterpPoints);
351 u_exact(exact_solution, interp_points, x_order, y_order, z_order);
356 double zero = basis_order*basis_order*basis_order*100*INTREPID_TOL;
359 Teuchos::RCP<Basis<double,FieldContainer<double> > > basis =
361 int numFields = basis->getCardinality();
364 Teuchos::RCP<Cubature<double> > cellCub = cubFactory.create(cell, 2*basis_order);
365 Teuchos::RCP<Cubature<double> > sideCub = cubFactory.create(side, 2*basis_order);
366 int numCubPointsCell = cellCub->getNumPoints();
367 int numCubPointsSide = sideCub->getNumPoints();
371 FieldContainer<double> cub_points_cell(numCubPointsCell, cellDim);
372 FieldContainer<double> cub_points_cell_physical(1, numCubPointsCell, cellDim);
373 FieldContainer<double> cub_weights_cell(numCubPointsCell);
374 FieldContainer<double> jacobian_cell(1, numCubPointsCell, cellDim, cellDim);
375 FieldContainer<double> jacobian_inv_cell(1, numCubPointsCell, cellDim, cellDim);
376 FieldContainer<double> jacobian_det_cell(1, numCubPointsCell);
377 FieldContainer<double> weighted_measure_cell(1, numCubPointsCell);
379 FieldContainer<double> value_of_basis_at_cub_points_cell(numFields, numCubPointsCell);
380 FieldContainer<double> transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
381 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
382 FieldContainer<double> grad_of_basis_at_cub_points_cell(numFields, numCubPointsCell, cellDim);
383 FieldContainer<double> transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
384 FieldContainer<double> weighted_transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
385 FieldContainer<double> fe_matrix(1, numFields, numFields);
387 FieldContainer<double> rhs_at_cub_points_cell_physical(1, numCubPointsCell);
388 FieldContainer<double> rhs_and_soln_vector(1, numFields);
391 FieldContainer<double> cub_points_side(numCubPointsSide, sideDim);
392 FieldContainer<double> cub_weights_side(numCubPointsSide);
393 FieldContainer<double> cub_points_side_refcell(numCubPointsSide, cellDim);
394 FieldContainer<double> cub_points_side_physical(1, numCubPointsSide, cellDim);
395 FieldContainer<double> jacobian_side_refcell(1, numCubPointsSide, cellDim, cellDim);
396 FieldContainer<double> jacobian_det_side_refcell(1, numCubPointsSide);
397 FieldContainer<double> weighted_measure_side_refcell(1, numCubPointsSide);
399 FieldContainer<double> value_of_basis_at_cub_points_side_refcell(numFields, numCubPointsSide);
400 FieldContainer<double> transformed_value_of_basis_at_cub_points_side_refcell(1, numFields, numCubPointsSide);
401 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_side_refcell(1, numFields, numCubPointsSide);
402 FieldContainer<double> neumann_data_at_cub_points_side_physical(1, numCubPointsSide);
403 FieldContainer<double> neumann_fields_per_side(1, numFields);
406 FieldContainer<double> value_of_basis_at_interp_points_ref(numFields, numInterpPoints);
407 FieldContainer<double> transformed_value_of_basis_at_interp_points_ref(1, numFields, numInterpPoints);
408 FieldContainer<double> interpolant(1, numInterpPoints);
410 FieldContainer<int> ipiv(numFields);
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 sideCub->getCubature(cub_points_side, cub_weights_side);
487 for (
unsigned i=0; i<numSides; i++) {
494 FunctionSpaceTools::computeFaceMeasure<double>(weighted_measure_side_refcell,
495 jacobian_side_refcell,
501 basis->getValues(value_of_basis_at_cub_points_side_refcell, cub_points_side_refcell, OPERATOR_VALUE);
503 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_side_refcell,
504 value_of_basis_at_cub_points_side_refcell);
507 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_side_refcell,
508 weighted_measure_side_refcell,
509 transformed_value_of_basis_at_cub_points_side_refcell);
515 neumann(neumann_data_at_cub_points_side_physical, cub_points_side_physical, jacobian_side_refcell,
516 cell, (
int)i, x_order, y_order, z_order);
518 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
519 neumann_data_at_cub_points_side_physical,
520 weighted_transformed_value_of_basis_at_cub_points_side_refcell,
531 Teuchos::LAPACK<int, double> solver;
532 solver.GESV(numFields, 1, &fe_matrix[0], numFields, &ipiv(0), &rhs_and_soln_vector[0], numFields, &info);
538 basis->getValues(value_of_basis_at_interp_points_ref, interp_points_ref, OPERATOR_VALUE);
540 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_interp_points_ref,
541 value_of_basis_at_interp_points_ref);
542 FunctionSpaceTools::evaluate<double>(interpolant, rhs_and_soln_vector, transformed_value_of_basis_at_interp_points_ref);
549 *outStream <<
"\nRelative norm-2 error between exact solution polynomial of order ("
550 << x_order <<
", " << y_order <<
", " << z_order
551 <<
") and finite element interpolant of order " << basis_order <<
": "
557 *outStream <<
"\n\nPatch test failed for solution polynomial order ("
558 << x_order <<
", " << y_order <<
", " << z_order <<
") and basis order " << basis_order <<
"\n\n";
568 catch (
const std::logic_error & err) {
569 *outStream << err.what() <<
"\n\n";
574 std::cout <<
"End Result: TEST FAILED\n";
576 std::cout <<
"End Result: TEST PASSED\n";
579 std::cout.copyfmt(oldFormatState);
void rhsFunc(FieldContainer< double > &, const FieldContainer< double > &, int, int, int)
right-hand side function
void u_exact(FieldContainer< double > &, const FieldContainer< double > &, int, int, int)
exact solution
void neumann(FieldContainer< double > &, const FieldContainer< double > &, const FieldContainer< double > &, const shards::CellTopology &, int, int, int, int)
neumann boundary conditions
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
Header file for utility class to provide multidimensional containers.
Header file for the Intrepid::HGRAD_HEX_C2_FEM class.
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Hexahedron cell.