Intrepid
test_02.cpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Intrepid Package
5// Copyright (2007) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38// Denis Ridzal (dridzal@sandia.gov), or
39// Kara Peterson (kjpeter@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
50#include "Intrepid_HGRAD_PYR_C1_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"
62
63using namespace std;
64using namespace Intrepid;
65
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 & ,
71 int, int, int, int);
72void u_exact(FieldContainer<double> &, const FieldContainer<double> &, int, int, int);
73
75void rhsFunc(FieldContainer<double> & result,
76 const FieldContainer<double> & points,
77 int xd,
78 int yd,
79 int zd) {
80
81 int x = 0, y = 1, z = 2;
82
83 // second x-derivatives of u
84 if (xd > 1) {
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);
89 }
90 }
91 }
92
93 // second y-derivatives of u
94 if (yd > 1) {
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);
99 }
100 }
101 }
102
103 // second z-derivatives of u
104 if (zd > 1) {
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);
109 }
110 }
111 }
112
113 // add u
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);
117 }
118 }
119
120}
121
122
124void neumann(FieldContainer<double> & result,
125 const FieldContainer<double> & points,
126 const FieldContainer<double> & jacs,
127 const shards::CellTopology & parentCell,
128 int sideOrdinal, int xd, int yd, int zd) {
129
130 int x = 0, y = 1, z = 2;
131
132 int numCells = result.dimension(0);
133 int numPoints = result.dimension(1);
134
135 FieldContainer<double> grad_u(numCells, numPoints, 3);
136 FieldContainer<double> side_normals(numCells, numPoints, 3);
137 FieldContainer<double> normal_lengths(numCells, numPoints);
138
139 // first x-derivatives of u
140 if (xd > 0) {
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);
145 }
146 }
147 }
148
149 // first y-derivatives of u
150 if (yd > 0) {
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);
155 }
156 }
157 }
158
159 // first z-derivatives of u
160 if (zd > 0) {
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);
165 }
166 }
167 }
168
169 CellTools<double>::getPhysicalSideNormals(side_normals, jacs, sideOrdinal, parentCell);
170
171 // scale normals
172 RealSpaceTools<double>::vectorNorm(normal_lengths, side_normals, NORM_TWO);
173 FunctionSpaceTools::scalarMultiplyDataData<double>(side_normals, normal_lengths, side_normals, true);
174
175 FunctionSpaceTools::dotMultiplyDataData<double>(result, grad_u, side_normals);
176
177}
178
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);
185 }
186 }
187}
188
189
190
191
192int main(int argc, char *argv[]) {
193
194 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
195
196 // This little trick lets us print to std::cout only if
197 // a (dummy) command-line argument is provided.
198 int iprint = argc - 1;
199 Teuchos::RCP<std::ostream> outStream;
200 Teuchos::oblackholestream bhs; // outputs nothing
201 if (iprint > 0)
202 outStream = Teuchos::rcp(&std::cout, false);
203 else
204 outStream = Teuchos::rcp(&bhs, false);
205
206 // Save the format state of the original std::cout.
207 Teuchos::oblackholestream oldFormatState;
208 oldFormatState.copyfmt(std::cout);
209
210 *outStream \
211 << "===============================================================================\n" \
212 << "| |\n" \
213 << "| Unit Test (Basis_HGRAD_PYR_C1_FEM) |\n" \
214 << "| |\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" \
218 << "| |\n" \
219 << "| - div (grad u) + u = f in Omega, (grad u) . n = g on Gamma |\n" \
220 << "| |\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" \
225 << "| |\n" \
226 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
227 << "| Trilinos website: http://trilinos.sandia.gov |\n" \
228 << "| |\n" \
229 << "===============================================================================\n"\
230 << "| TEST 1: Patch test |\n"\
231 << "===============================================================================\n";
232
233
234 int errorFlag = 0;
235
236 outStream -> precision(16);
237
238
239 try {
240
241 int max_order = 1; // max total order of polynomial solution
242 DefaultCubatureFactory<double> cubFactory; // create factory
243 shards::CellTopology cell(shards::getCellTopologyData< shards::Pyramid<> >()); // create parent cell topology
244 shards::CellTopology sideQ(shards::getCellTopologyData< shards::Quadrilateral<> >()); // create relevant subcell (side) topology
245 shards::CellTopology sideT(shards::getCellTopologyData< shards::Triangle<> >());
246 int cellDim = cell.getDimension();
247 int sideQDim = sideQ.getDimension();
248 int sideTDim = sideT.getDimension();
249
250 // Define array containing points at which the solution is evaluated, on the reference Pyramid.
251 int numIntervals = 10;
252 int numInterpPoints = ((numIntervals + 1)*(numIntervals + 2)*(numIntervals + 3))/6;
253 FieldContainer<double> interp_points_ref(numInterpPoints, 3);
254 int counter = 0;
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);
262 counter++;
263 }
264 }
265 }
266 }
267
268 /* Definition of parent cell. */
269 FieldContainer<double> cell_nodes(1, 5, cellDim);
270 // funky Pyramid (affine mapping)
271 cell_nodes(0, 0, 0) = -1.0;
272 cell_nodes(0, 0, 1) = 3.0;
273 cell_nodes(0, 0, 2) = 2.0;
274 cell_nodes(0, 1, 0) = 3.0;
275 cell_nodes(0, 1, 1) = -2.0;
276 cell_nodes(0, 1, 2) = -1.0;
277 cell_nodes(0, 2, 0) = 6.0;
278 cell_nodes(0, 2, 1) = 3.0;
279 cell_nodes(0, 2, 2) = -1.0;
280 cell_nodes(0, 3, 0) = 4.0;
281 cell_nodes(0, 3, 1) = 2.0;
282 cell_nodes(0, 3, 2) = -2.0;
283 cell_nodes(0, 4, 0) = 5.0;
284 cell_nodes(0, 4, 1) = -1.0;
285 cell_nodes(0, 4, 2) = 1.0;
286
287 // perturbed reference Pyramid
288 /*cell_nodes(0, 0, 0) = -1.1;
289 cell_nodes(0, 0, 1) = -1.1;
290 cell_nodes(0, 0, 2) = 0.2;
291 cell_nodes(0, 1, 0) = 1.2;
292 cell_nodes(0, 1, 1) = -1.1;
293 cell_nodes(0, 1, 2) = 0.05;
294 cell_nodes(0, 2, 0) = 1.0;
295 cell_nodes(0, 2, 1) = 0.9;
296 cell_nodes(0, 2, 2) = 0.1;
297 cell_nodes(0, 3, 0) = -1.1;
298 cell_nodes(0, 3, 1) = 0.9;
299 cell_nodes(0, 3, 2) = -0.1;
300 cell_nodes(0, 4, 0) = 0.1;
301 cell_nodes(0, 4, 1) = -0.1;
302 cell_nodes(0, 4, 2) = 1.1; */
303
304 // reference Pyramid
305 /*cell_nodes(0, 0, 0) = -1.0;
306 cell_nodes(0, 0, 1) = -1.0;
307 cell_nodes(0, 0, 2) = 0.0;
308 cell_nodes(0, 1, 0) = 1.0;
309 cell_nodes(0, 1, 1) = -1.0;
310 cell_nodes(0, 1, 2) = 0.0;
311 cell_nodes(0, 2, 0) = 1.0;
312 cell_nodes(0, 2, 1) = 1.0;
313 cell_nodes(0, 2, 2) = 0.0;
314 cell_nodes(0, 3, 0) = -1.0;
315 cell_nodes(0, 3, 1) = 1.0;
316 cell_nodes(0, 3, 2) = 1.0;
317 cell_nodes(0, 4, 0) = 0.0;
318 cell_nodes(0, 4, 1) = 0.0;
319 cell_nodes(0, 4, 2) = 1.0; */
320
321
322 FieldContainer<double> interp_points(1, numInterpPoints, cellDim);
323 CellTools<double>::mapToPhysicalFrame(interp_points, interp_points_ref, cell_nodes, cell);
324 interp_points.resize(numInterpPoints, cellDim);
325
326 for (int x_order=0; x_order <= max_order; x_order++) {
327 for (int y_order=0; y_order <= max_order-x_order; y_order++) {
328 for (int z_order=0; z_order <= max_order-x_order-y_order; z_order++) {
329
330 // evaluate exact solution
331 FieldContainer<double> exact_solution(1, numInterpPoints);
332 u_exact(exact_solution, interp_points, x_order, y_order, z_order);
333
334 int basis_order = 1;
335
336 // set test tolerance;
337 double zero = basis_order*basis_order*basis_order*100*INTREPID_TOL;
338
339 //create basis
340 Teuchos::RCP<Basis<double,FieldContainer<double> > > basis =
341 Teuchos::rcp(new Basis_HGRAD_PYR_C1_FEM<double,FieldContainer<double> >() );
342 int numFields = basis->getCardinality();
343
344 // create cubatures
345 Teuchos::RCP<Cubature<double> > cellCub = cubFactory.create(cell, 2*basis_order);
346 Teuchos::RCP<Cubature<double> > sideQCub = cubFactory.create(sideQ, 2*basis_order);
347 Teuchos::RCP<Cubature<double> > sideTCub = cubFactory.create(sideT, 2*basis_order);
348 int numCubPointsCell = cellCub->getNumPoints();
349 int numCubPointsSideQ = sideQCub->getNumPoints();
350 int numCubPointsSideT = sideTCub->getNumPoints();
351
352 /* Computational arrays. */
353 /* Section 1: Related to parent cell integration. */
354 FieldContainer<double> cub_points_cell(numCubPointsCell, cellDim);
355 FieldContainer<double> cub_points_cell_physical(1, numCubPointsCell, cellDim);
356 FieldContainer<double> cub_weights_cell(numCubPointsCell);
357 FieldContainer<double> jacobian_cell(1, numCubPointsCell, cellDim, cellDim);
358 FieldContainer<double> jacobian_inv_cell(1, numCubPointsCell, cellDim, cellDim);
359 FieldContainer<double> jacobian_det_cell(1, numCubPointsCell);
360 FieldContainer<double> weighted_measure_cell(1, numCubPointsCell);
361
362 FieldContainer<double> value_of_basis_at_cub_points_cell(numFields, numCubPointsCell);
363 FieldContainer<double> transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
364 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell);
365 FieldContainer<double> grad_of_basis_at_cub_points_cell(numFields, numCubPointsCell, cellDim);
366 FieldContainer<double> transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
367 FieldContainer<double> weighted_transformed_grad_of_basis_at_cub_points_cell(1, numFields, numCubPointsCell, cellDim);
368 FieldContainer<double> fe_matrix(1, numFields, numFields);
369
370 FieldContainer<double> rhs_at_cub_points_cell_physical(1, numCubPointsCell);
371 FieldContainer<double> rhs_and_soln_vector(1, numFields);
372
373 /* Section 2: Related to subcell (side) integration. */
374 unsigned numSides = 5;
375 unsigned numSidesT = 4;
376 FieldContainer<double> cub_points_sideQ(numCubPointsSideQ, sideQDim);
377 FieldContainer<double> cub_points_sideT(numCubPointsSideT, sideTDim);
378 FieldContainer<double> cub_weights_sideQ(numCubPointsSideQ);
379 FieldContainer<double> cub_weights_sideT(numCubPointsSideT);
380 FieldContainer<double> cub_points_sideQ_refcell(numCubPointsSideQ, cellDim);
381 FieldContainer<double> cub_points_sideT_refcell(numCubPointsSideT, cellDim);
382 FieldContainer<double> cub_points_sideQ_physical(1, numCubPointsSideQ, cellDim);
383 FieldContainer<double> cub_points_sideT_physical(1, numCubPointsSideT, cellDim);
384 FieldContainer<double> jacobian_sideQ_refcell(1, numCubPointsSideQ, cellDim, cellDim);
385 FieldContainer<double> jacobian_sideT_refcell(1, numCubPointsSideT, cellDim, cellDim);
386 FieldContainer<double> jacobian_det_sideQ_refcell(1, numCubPointsSideQ);
387 FieldContainer<double> jacobian_det_sideT_refcell(1, numCubPointsSideT);
388 FieldContainer<double> weighted_measure_sideQ_refcell(1, numCubPointsSideQ);
389 FieldContainer<double> weighted_measure_sideT_refcell(1, numCubPointsSideT);
390
391 FieldContainer<double> value_of_basis_at_cub_points_sideQ_refcell(numFields, numCubPointsSideQ);
392 FieldContainer<double> value_of_basis_at_cub_points_sideT_refcell(numFields, numCubPointsSideT);
393 FieldContainer<double> transformed_value_of_basis_at_cub_points_sideQ_refcell(1, numFields, numCubPointsSideQ);
394 FieldContainer<double> transformed_value_of_basis_at_cub_points_sideT_refcell(1, numFields, numCubPointsSideT);
395 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell(1, numFields, numCubPointsSideQ);
396 FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points_sideT_refcell(1, numFields, numCubPointsSideT);
397 FieldContainer<double> neumann_data_at_cub_points_sideQ_physical(1, numCubPointsSideQ);
398 FieldContainer<double> neumann_data_at_cub_points_sideT_physical(1, numCubPointsSideT);
399 FieldContainer<double> neumann_fields_per_side(1, numFields);
400
401 /* Section 3: Related to global interpolant. */
402 FieldContainer<double> value_of_basis_at_interp_points_ref(numFields, numInterpPoints);
403 FieldContainer<double> transformed_value_of_basis_at_interp_points_ref(1, numFields, numInterpPoints);
404 FieldContainer<double> interpolant(1, numInterpPoints);
405
406 FieldContainer<int> ipiv(numFields);
407
408
409
410 /******************* START COMPUTATION ***********************/
411
412 // get cubature points and weights
413 cellCub->getCubature(cub_points_cell, cub_weights_cell);
414
415 // compute geometric cell information
416 CellTools<double>::setJacobian(jacobian_cell, cub_points_cell, cell_nodes, cell);
417 CellTools<double>::setJacobianInv(jacobian_inv_cell, jacobian_cell);
418 CellTools<double>::setJacobianDet(jacobian_det_cell, jacobian_cell);
419
420 // compute weighted measure
421 FunctionSpaceTools::computeCellMeasure<double>(weighted_measure_cell, jacobian_det_cell, cub_weights_cell);
422
424 // Computing mass matrices:
425 // tabulate values of basis functions at (reference) cubature points
426 basis->getValues(value_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_VALUE);
427
428 // transform values of basis functions
429 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_cell,
430 value_of_basis_at_cub_points_cell);
431
432 // multiply with weighted measure
433 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_cell,
434 weighted_measure_cell,
435 transformed_value_of_basis_at_cub_points_cell);
436
437 // compute mass matrices
438 FunctionSpaceTools::integrate<double>(fe_matrix,
439 transformed_value_of_basis_at_cub_points_cell,
440 weighted_transformed_value_of_basis_at_cub_points_cell,
441 COMP_BLAS);
443
445 // Computing stiffness matrices:
446 // tabulate gradients of basis functions at (reference) cubature points
447 basis->getValues(grad_of_basis_at_cub_points_cell, cub_points_cell, OPERATOR_GRAD);
448
449 // transform gradients of basis functions
450 FunctionSpaceTools::HGRADtransformGRAD<double>(transformed_grad_of_basis_at_cub_points_cell,
451 jacobian_inv_cell,
452 grad_of_basis_at_cub_points_cell);
453
454 // multiply with weighted measure
455 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_grad_of_basis_at_cub_points_cell,
456 weighted_measure_cell,
457 transformed_grad_of_basis_at_cub_points_cell);
458
459 // compute stiffness matrices and sum into fe_matrix
460 FunctionSpaceTools::integrate<double>(fe_matrix,
461 transformed_grad_of_basis_at_cub_points_cell,
462 weighted_transformed_grad_of_basis_at_cub_points_cell,
463 COMP_BLAS,
464 true);
466
468 // Computing RHS contributions:
469 // map cell (reference) cubature points to physical space
470 CellTools<double>::mapToPhysicalFrame(cub_points_cell_physical, cub_points_cell, cell_nodes, cell);
471
472 // evaluate rhs function
473 rhsFunc(rhs_at_cub_points_cell_physical, cub_points_cell_physical, x_order, y_order, z_order);
474
475 // compute rhs
476 FunctionSpaceTools::integrate<double>(rhs_and_soln_vector,
477 rhs_at_cub_points_cell_physical,
478 weighted_transformed_value_of_basis_at_cub_points_cell,
479 COMP_BLAS);
480
481 // compute neumann b.c. contributions and adjust rhs
482 sideQCub->getCubature(cub_points_sideQ, cub_weights_sideQ);
483 sideTCub->getCubature(cub_points_sideT, cub_weights_sideT);
484
485 for (unsigned i=0; i<numSidesT; i++) {
486 // compute geometric cell information
487 CellTools<double>::mapToReferenceSubcell(cub_points_sideT_refcell, cub_points_sideT, sideTDim, (int)i, cell);
488 CellTools<double>::setJacobian(jacobian_sideT_refcell, cub_points_sideT_refcell, cell_nodes, cell);
489 CellTools<double>::setJacobianDet(jacobian_det_sideT_refcell, jacobian_sideT_refcell);
490
491 // compute weighted face measure
492 FunctionSpaceTools::computeFaceMeasure<double>(weighted_measure_sideT_refcell,
493 jacobian_sideT_refcell,
494 cub_weights_sideT,
495 i,
496 cell);
497
498 // tabulate values of basis functions at side cubature points, in the reference parent cell domain
499 basis->getValues(value_of_basis_at_cub_points_sideT_refcell, cub_points_sideT_refcell, OPERATOR_VALUE);
500 // transform
501 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_sideT_refcell,
502 value_of_basis_at_cub_points_sideT_refcell);
503
504 // multiply with weighted measure
505 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_sideT_refcell,
506 weighted_measure_sideT_refcell,
507 transformed_value_of_basis_at_cub_points_sideT_refcell);
508
509 // compute Neumann data
510 // map side cubature points in reference parent cell domain to physical space
511 CellTools<double>::mapToPhysicalFrame(cub_points_sideT_physical, cub_points_sideT_refcell, cell_nodes, cell);
512 // now compute data
513 neumann(neumann_data_at_cub_points_sideT_physical, cub_points_sideT_physical, jacobian_sideT_refcell,
514 cell, (int)i, x_order, y_order, z_order);
515
516 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
517 neumann_data_at_cub_points_sideT_physical,
518 weighted_transformed_value_of_basis_at_cub_points_sideT_refcell,
519 COMP_BLAS);
520
521 // adjust RHS
522 RealSpaceTools<double>::add(rhs_and_soln_vector, neumann_fields_per_side);;
523 }
524
525 for (unsigned i=numSidesT; i<numSides; i++) {
526 // compute geometric cell information
527 CellTools<double>::mapToReferenceSubcell(cub_points_sideQ_refcell, cub_points_sideQ, sideQDim, (int)i, cell);
528 CellTools<double>::setJacobian(jacobian_sideQ_refcell, cub_points_sideQ_refcell, cell_nodes, cell);
529 CellTools<double>::setJacobianDet(jacobian_det_sideQ_refcell, jacobian_sideQ_refcell);
530
531 // compute weighted face measure
532 FunctionSpaceTools::computeFaceMeasure<double>(weighted_measure_sideQ_refcell,
533 jacobian_sideQ_refcell,
534 cub_weights_sideQ,
535 i,
536 cell);
537
538 // tabulate values of basis functions at side cubature points, in the reference parent cell domain
539 basis->getValues(value_of_basis_at_cub_points_sideQ_refcell, cub_points_sideQ_refcell, OPERATOR_VALUE);
540 // transform
541 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_cub_points_sideQ_refcell,
542 value_of_basis_at_cub_points_sideQ_refcell);
543
544 // multiply with weighted measure
545 FunctionSpaceTools::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell,
546 weighted_measure_sideQ_refcell,
547 transformed_value_of_basis_at_cub_points_sideQ_refcell);
548
549 // compute Neumann data
550 // map side cubature points in reference parent cell domain to physical space
551 CellTools<double>::mapToPhysicalFrame(cub_points_sideQ_physical, cub_points_sideQ_refcell, cell_nodes, cell);
552 // now compute data
553 neumann(neumann_data_at_cub_points_sideQ_physical, cub_points_sideQ_physical, jacobian_sideQ_refcell,
554 cell, (int)i, x_order, y_order, z_order);
555
556 FunctionSpaceTools::integrate<double>(neumann_fields_per_side,
557 neumann_data_at_cub_points_sideQ_physical,
558 weighted_transformed_value_of_basis_at_cub_points_sideQ_refcell,
559 COMP_BLAS);
560
561 // adjust RHS
562 RealSpaceTools<double>::add(rhs_and_soln_vector, neumann_fields_per_side);;
563 }
565
567 // Solution of linear system:
568 int info = 0;
569 Teuchos::LAPACK<int, double> solver;
570 solver.GESV(numFields, 1, &fe_matrix[0], numFields, &ipiv(0), &rhs_and_soln_vector[0], numFields, &info);
572
574 // Building interpolant:
575 // evaluate basis at interpolation points
576 basis->getValues(value_of_basis_at_interp_points_ref, interp_points_ref, OPERATOR_VALUE);
577 // transform values of basis functions
578 FunctionSpaceTools::HGRADtransformVALUE<double>(transformed_value_of_basis_at_interp_points_ref,
579 value_of_basis_at_interp_points_ref);
580 FunctionSpaceTools::evaluate<double>(interpolant, rhs_and_soln_vector, transformed_value_of_basis_at_interp_points_ref);
582
583 /******************* END COMPUTATION ***********************/
584
585 RealSpaceTools<double>::subtract(interpolant, exact_solution);
586
587 *outStream << "\nRelative norm-2 error between exact solution polynomial of order ("
588 << x_order << ", " << y_order << ", " << z_order
589 << ") and finite element interpolant of order " << basis_order << ": "
590 << RealSpaceTools<double>::vectorNorm(&interpolant[0], interpolant.dimension(1), NORM_TWO) /
591 RealSpaceTools<double>::vectorNorm(&exact_solution[0], exact_solution.dimension(1), NORM_TWO) << "\n";
592
593 if (RealSpaceTools<double>::vectorNorm(&interpolant[0], interpolant.dimension(1), NORM_TWO) /
594 RealSpaceTools<double>::vectorNorm(&exact_solution[0], exact_solution.dimension(1), NORM_TWO) > zero) {
595 *outStream << "\n\nPatch test failed for solution polynomial order ("
596 << x_order << ", " << y_order << ", " << z_order << ") and basis order " << basis_order << "\n\n";
597 errorFlag++;
598 }
599 } // end for z_order
600 } // end for y_order
601 } // end for x_order
602
603 }
604 // Catch unexpected errors
605 catch (const std::logic_error & err) {
606 *outStream << err.what() << "\n\n";
607 errorFlag = -1000;
608 };
609
610 if (errorFlag != 0)
611 std::cout << "End Result: TEST FAILED\n";
612 else
613 std::cout << "End Result: TEST PASSED\n";
614
615 // reset format state of std::cout
616 std::cout.copyfmt(oldFormatState);
617
618 return errorFlag;
619}
void rhsFunc(FieldContainer< double > &, const FieldContainer< double > &, int, int, int)
right-hand side function
Definition test_02.cpp:75
void u_exact(FieldContainer< double > &, const FieldContainer< double > &, int, int, int)
exact solution
Definition test_02.cpp:180
void neumann(FieldContainer< double > &, const FieldContainer< double > &, const FieldContainer< double > &, const shards::CellTopology &, int, int, int, int)
neumann boundary conditions
Definition test_02.cpp:124
Header file for utility class to provide array tools, such as tensor contractions,...
Header file for the Intrepid::CellTools class.
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
Header file for utility class to provide multidimensional containers.
Header file for the Intrepid::FunctionSpaceTools class.
Header file for classes providing basic linear algebra functionality in 1D, 2D and 3D.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Pyramid cell.
A stateless class for operations on cell data. Provides methods for:
static void mapToReferenceSubcell(ArraySubcellPoint &refSubcellPoints, const ArrayParamPoint &paramPoints, const int subcellDim, const int subcellOrd, const shards::CellTopology &parentCell)
Computes parameterization maps of 1- and 2-subcells of reference cells.
static void mapToPhysicalFrame(ArrayPhysPoint &physPoints, const ArrayRefPoint &refPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell=-1)
Computes F, the reference-to-physical frame map.
static void getPhysicalSideNormals(ArraySideNormal &sideNormals, const ArrayJac &worksetJacobians, const int &worksetSideOrd, const shards::CellTopology &parentCell)
Computes non-normalized normal vectors to physical sides in a side workset .
static void setJacobianDet(ArrayJacDet &jacobianDet, const ArrayJac &jacobian)
Computes the determinant of the Jacobian matrix DF of the reference-to-physical frame map F.
static void setJacobianInv(ArrayJacInv &jacobianInv, const ArrayJac &jacobian)
Computes the inverse of the Jacobian matrix DF of the reference-to-physical frame map F.
Implementation of basic linear algebra functionality in Euclidean space.
static void subtract(Scalar *diffArray, const Scalar *inArray1, const Scalar *inArray2, const int size)
Subtracts contiguous data inArray2 from inArray1 of size size: diffArray = inArray1 - inArray2.
static Scalar vectorNorm(const Scalar *inVec, const size_t dim, const ENorm normType)
Computes norm (1, 2, infinity) of the vector inVec of size dim.
static void add(Scalar *sumArray, const Scalar *inArray1, const Scalar *inArray2, const int size)
Adds contiguous data inArray1 and inArray2 of size size: sumArray = inArray1 + inArray2.