50 #include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" 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" 70 const shards::CellTopology & ,
84 for (
int cell=0; cell<result.
dimension(0); cell++) {
85 for (
int pt=0; pt<result.
dimension(1); pt++) {
86 result(cell,pt) = - xd*(xd-1)*std::pow(points(cell,pt,x), xd-2) * std::pow(points(cell,pt,y), yd);
93 for (
int cell=0; cell<result.
dimension(0); cell++) {
94 for (
int pt=0; pt<result.
dimension(1); pt++) {
95 result(cell,pt) -= yd*(yd-1)*std::pow(points(cell,pt,y), yd-2) * std::pow(points(cell,pt,x), xd);
101 for (
int cell=0; cell<result.
dimension(0); cell++) {
102 for (
int pt=0; pt<result.
dimension(1); pt++) {
103 result(cell,pt) += std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd);
114 const shards::CellTopology & parentCell,
115 int sideOrdinal,
int xd,
int yd) {
128 for (
int cell=0; cell<numCells; cell++) {
129 for (
int pt=0; pt<numPoints; pt++) {
130 grad_u(cell,pt,x) = xd*std::pow(points(cell,pt,x), xd-1) * std::pow(points(cell,pt,y), yd);
137 for (
int cell=0; cell<numCells; cell++) {
138 for (
int pt=0; pt<numPoints; pt++) {
139 grad_u(cell,pt,y) = yd*std::pow(points(cell,pt,y), yd-1) * std::pow(points(cell,pt,x), xd);
148 FunctionSpaceTools::scalarMultiplyDataData<double>(side_normals, normal_lengths, side_normals,
true);
150 FunctionSpaceTools::dotMultiplyDataData<double>(result, grad_u, side_normals);
157 for (
int cell=0; cell<result.
dimension(0); cell++) {
158 for (
int pt=0; pt<result.
dimension(1); pt++) {
159 result(cell,pt) = std::pow(points(pt,x), xd)*std::pow(points(pt,y), yd);
167 int main(
int argc,
char *argv[]) {
169 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
173 int iprint = argc - 1;
174 Teuchos::RCP<std::ostream> outStream;
175 Teuchos::oblackholestream bhs;
177 outStream = Teuchos::rcp(&std::cout,
false);
179 outStream = Teuchos::rcp(&bhs,
false);
182 Teuchos::oblackholestream oldFormatState;
183 oldFormatState.copyfmt(std::cout);
186 <<
"===============================================================================\n" \
188 <<
"| Unit Test (Basis_HGRAD_QUAD_C2_FEM) |\n" \
190 <<
"| 1) Patch test involving mass and stiffness matrices, |\n" \
191 <<
"| for the Neumann problem on a physical parallelogram |\n" \
192 <<
"| AND a reference quad Omega with boundary Gamma. |\n" \
194 <<
"| - div (grad u) + u = f in Omega, (grad u) . n = g on Gamma |\n" \
196 <<
"| For a generic parallelogram, the basis recovers a complete |\n" \
197 <<
"| polynomial space of order 2. On a (scaled and/or translated) |\n" \
198 <<
"| reference quad, the basis recovers a complete tensor product |\n" \
199 <<
"| space of order 2 (i.e. incl. the x^2*y, x*y^2, x^2*y^2 terms). |\n" \
201 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
202 <<
"| Denis Ridzal (dridzal@sandia.gov), |\n" \
203 <<
"| Kara Peterson (kjpeter@sandia.gov). |\n" \
205 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
206 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
208 <<
"===============================================================================\n"\
209 <<
"| TEST 1: Patch test |\n"\
210 <<
"===============================================================================\n";
215 outStream -> precision(16);
222 shards::CellTopology cell(shards::getCellTopologyData< shards::Quadrilateral<> >());
223 shards::CellTopology side(shards::getCellTopologyData< shards::Line<> >());
224 int cellDim = cell.getDimension();
225 int sideDim = side.getDimension();
228 int numIntervals = 10;
229 int numInterpPoints = (numIntervals + 1)*(numIntervals + 1);
232 for (
int j=0; j<=numIntervals; j++) {
233 for (
int i=0; i<=numIntervals; i++) {
234 interp_points_ref(counter,0) = i*(2.0/numIntervals)-1.0;
235 interp_points_ref(counter,1) = j*(2.0/numIntervals)-1.0;
242 cell_nodes[0].
resize(1, 4, cellDim);
243 cell_nodes[1].
resize(1, 4, cellDim);
246 cell_nodes[0](0, 0, 0) = -5.0;
247 cell_nodes[0](0, 0, 1) = -1.0;
248 cell_nodes[0](0, 1, 0) = 4.0;
249 cell_nodes[0](0, 1, 1) = 1.0;
250 cell_nodes[0](0, 2, 0) = 8.0;
251 cell_nodes[0](0, 2, 1) = 3.0;
252 cell_nodes[0](0, 3, 0) = -1.0;
253 cell_nodes[0](0, 3, 1) = 1.0;
255 cell_nodes[1](0, 0, 0) = -1.0;
256 cell_nodes[1](0, 0, 1) = -1.0;
257 cell_nodes[1](0, 1, 0) = 1.0;
258 cell_nodes[1](0, 1, 1) = -1.0;
259 cell_nodes[1](0, 2, 0) = 1.0;
260 cell_nodes[1](0, 2, 1) = 1.0;
261 cell_nodes[1](0, 3, 0) = -1.0;
262 cell_nodes[1](0, 3, 1) = 1.0;
264 std::stringstream mystream[2];
265 mystream[0].str(
"\n>> Now testing basis on a generic parallelogram ...\n");
266 mystream[1].str(
"\n>> Now testing basis on the reference quad ...\n");
268 for (
int pcell = 0; pcell < 2; pcell++) {
269 *outStream << mystream[pcell].str();
272 interp_points.resize(numInterpPoints, cellDim);
274 for (
int x_order=0; x_order <= max_order; x_order++) {
275 int max_y_order = max_order;
277 max_y_order -= x_order;
279 for (
int y_order=0; y_order <= max_y_order; y_order++) {
283 u_exact(exact_solution, interp_points, x_order, y_order);
288 double zero = basis_order*basis_order*100*INTREPID_TOL;
291 Teuchos::RCP<Basis<double,FieldContainer<double> > > basis =
293 int numFields = basis->getCardinality();
296 Teuchos::RCP<Cubature<double> > cellCub = cubFactory.
create(cell, 2*basis_order);
297 Teuchos::RCP<Cubature<double> > sideCub = cubFactory.
create(side, 2*basis_order);
298 int numCubPointsCell = cellCub->getNumPoints();
299 int numCubPointsSide = sideCub->getNumPoints();
313 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
315 FieldContainer<double> transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
316 FieldContainer<double> weighted_transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
323 unsigned numSides = 4;
333 FieldContainer<double> transformed_value_of_basis_at_cub_points_side_refcell(1, numFields, numCubPointsSide);
334 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_side_refcell(1, numFields, numCubPointsSide);
350 cellCub->getCubature(cub_points_cell, cub_weights_cell);
358 FunctionSpaceTools::computeCellMeasure<double>(weighted_measure_cell, jacobian_det_cell, cub_weights_cell);
363 basis->getValues(value_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_VALUE);
366 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_cell,
367 value_of_basis_at_cub_points_cell);
370 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_cell,
371 weighted_measure_cell,
372 transformed_value_of_basis_at_cub_points_cell);
375 FunctionSpaceTools::integrate<double>(fe_matrix,
376 transformed_value_of_basis_at_cub_points_cell,
377 weighted_transformed_value_of_basis_at_cub_points_cell,
384 basis->getValues(grad_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_GRAD);
387 FunctionSpaceTools::HGRADtransformGRAD<double>(transformed_grad_of_basis_at_cub_points_cell,
389 grad_of_basis_at_cub_points_cell);
392 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_grad_of_basis_at_cub_points_cell,
393 weighted_measure_cell,
394 transformed_grad_of_basis_at_cub_points_cell);
397 FunctionSpaceTools::integrate<double>(fe_matrix,
398 transformed_grad_of_basis_at_cub_points_cell,
399 weighted_transformed_grad_of_basis_at_cub_points_cell,
410 rhsFunc(rhs_at_cub_points_cell_physical, cub_points_cell_physical, x_order, y_order);
413 FunctionSpaceTools::integrate<double>(rhs_and_soln_vector,
414 rhs_at_cub_points_cell_physical,
415 weighted_transformed_value_of_basis_at_cub_points_cell,
419 sideCub->getCubature(cub_points_side, cub_weights_side);
420 for (
unsigned i=0; i<numSides; i++) {
427 FunctionSpaceTools::computeEdgeMeasure<double>(weighted_measure_side_refcell,
428 jacobian_side_refcell,
434 basis->getValues(value_of_basis_at_cub_points_side_refcell, cub_points_side_refcell, OPERATOR_VALUE);
436 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_side_refcell,
437 value_of_basis_at_cub_points_side_refcell);
440 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_side_refcell,
441 weighted_measure_side_refcell,
442 transformed_value_of_basis_at_cub_points_side_refcell);
448 neumann(neumann_data_at_cub_points_side_physical, cub_points_side_physical, jacobian_side_refcell,
449 cell, (
int)i, x_order, y_order);
451 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
452 neumann_data_at_cub_points_side_physical,
453 weighted_transformed_value_of_basis_at_cub_points_side_refcell,
464 Teuchos::LAPACK<int, double> solver;
465 solver.GESV(numFields, 1, &fe_matrix[0], numFields, &ipiv(0), &rhs_and_soln_vector[0], numFields, &info);
471 basis->getValues(value_of_basis_at_interp_points, interp_points_ref, OPERATOR_VALUE);
473 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_interp_points,
474 value_of_basis_at_interp_points);
475 FunctionSpaceTools::evaluate<double>(interpolant, rhs_and_soln_vector, transformed_value_of_basis_at_interp_points);
482 *outStream <<
"\nRelative norm-2 error between exact solution polynomial of order (" 483 << x_order <<
", " << y_order <<
") and finite element interpolant of order " << basis_order <<
": " 489 *outStream <<
"\n\nPatch test failed for solution polynomial order (" 490 << x_order <<
", " << y_order <<
") and basis order " << basis_order <<
"\n\n";
499 catch (std::logic_error err) {
500 *outStream << err.what() <<
"\n\n";
505 std::cout <<
"End Result: TEST FAILED\n";
507 std::cout <<
"End Result: TEST PASSED\n";
510 std::cout.copyfmt(oldFormatState);
int main(int argc, char *argv[])
outdated tests for orthogonal bases
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 the default H(grad)-compatible FEM basis of degree 2 on Quadrilateral cell...
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
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.