Nektar++
Loading...
Searching...
No Matches
TestTetExactMass.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestTetExactMass.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: The P3 tetrahedron mass matrix on P+1 points per direction
32// with the Gauss-Jacobi(1,0) rule (eGaussGaussAlpha1Beta0) in the collapsed
33// directions is exact, where Gauss-Legendre in every direction is not.
34//
35///////////////////////////////////////////////////////////////////////////////
36
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
40#include <cmath>
41
43{
44
45using namespace LibUtilities;
46
47/// The P3 orthogonal tet on @p np points per direction of the given types.
48static StdRegions::StdTetExpSharedPtr MakeTet(const unsigned int np,
49 const PointsType p0,
50 const PointsType p1,
51 const PointsType p2)
52{
53 const unsigned int nm = 4;
54 const BasisKey b0(eOrtho_A, nm, PointsKey(np, p0));
55 const BasisKey b1(eOrtho_B, nm, PointsKey(np, p1));
56 const BasisKey b2(eOrtho_C, nm, PointsKey(np, p2));
58}
59
60/// The largest entry of the difference between the mass matrices of @p a
61/// and @p b.
64{
65 const DNekMatSharedPtr ma = a->GetStdMatrix(
67 const DNekMatSharedPtr mb = b->GetStdMatrix(
69 BOOST_REQUIRE_EQUAL(ma->GetRows(), mb->GetRows());
70 BOOST_REQUIRE_EQUAL(ma->GetColumns(), mb->GetColumns());
71
72 NekDouble diff = 0.0;
73 for (unsigned int i = 0; i < ma->GetRows(); ++i)
74 {
75 for (unsigned int j = 0; j < ma->GetColumns(); ++j)
76 {
77 diff = std::max(diff,
78 std::abs(ma->GetValue(i, j) - mb->GetValue(i, j)));
79 }
80 }
81 return diff;
82}
83
84BOOST_AUTO_TEST_CASE(TestTetExactMassRules)
85{
86 // Reference: the default collapsed rules on twice the points, exact
87 // well beyond the degree 2P = 6 the P3 mass matrix needs.
88 const auto ref = MakeTet(8, eGaussLobattoLegendre, eGaussRadauMAlpha1Beta0,
89 eGaussRadauMAlpha2Beta0);
90
91 // Rule D: Gauss-Legendre in the first two directions, Gauss-Jacobi(1,0)
92 // in the third.
93 const auto ruleD = MakeTet(4, eGaussGaussLegendre, eGaussGaussLegendre,
95 BOOST_CHECK_SMALL(MassDifference(ruleD, ref), 1.0e-13);
96
97 // Rule C: Gauss-Jacobi(1,0) in the second and third directions.
100 BOOST_CHECK_SMALL(MassDifference(ruleC, ref), 1.0e-13);
101
102 // Gauss-Legendre in every direction is exact to degree 5 only, so the
103 // top modes' mass is wrong: the reason for the rules above.
106 BOOST_CHECK(MassDifference(gl, ref) > 1.0e-3);
107}
108
109} // namespace Nektar::StdRegionsUnitTests
Describes the specification for a Basis.
Definition Basis.h:45
Defines a specification for a set of points.
Definition Points.h:50
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
@ eGaussGaussAlpha1Beta0
1D Gauss-Jacobi quadrature points,
Definition PointsType.h:100
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:51
@ eGaussGaussLegendre
1D Gauss-Gauss-Legendre quadrature points
Definition PointsType.h:46
@ eOrtho_A
Principle Orthogonal Functions .
Definition BasisType.h:42
@ eOrtho_C
Principle Orthogonal Functions .
Definition BasisType.h:46
@ eOrtho_B
Principle Orthogonal Functions .
Definition BasisType.h:44
std::shared_ptr< StdTetExp > StdTetExpSharedPtr
Definition StdTetExp.h:187
static StdRegions::StdTetExpSharedPtr MakeTet(const unsigned int np, const PointsType p0, const PointsType p1, const PointsType p2)
The P3 orthogonal tet on np points per direction of the given types.
static NekDouble MassDifference(const StdRegions::StdTetExpSharedPtr &a, const StdRegions::StdTetExpSharedPtr &b)
The largest entry of the difference between the mass matrices of a and b.
BOOST_AUTO_TEST_CASE(TestQuadInvBwdTransPseudoInverse)
std::shared_ptr< DNekMat > DNekMatSharedPtr