Example #1
0
class TestNodality(TestCase):
    """Test for Element.doflocs."""

    elems = [
        ElementLineP0(),
        ElementLineP1(),
        ElementLineP2(),
        ElementLinePp(1),
        ElementLinePp(3),
        ElementLineMini(),
        ElementTriP0(),
        ElementTriP1(),
        ElementTriP2(),
        ElementTriP3(),
        ElementTriP4(),
        ElementTriMini(),
        ElementQuad0(),
        ElementQuad1(),
        ElementQuad2(),
        ElementQuadS2(),
        ElementQuadP(1),
        ElementQuadP(3),
        ElementTetP0(),
        ElementTetP1(),
        ElementTetP2(),
        ElementTetMini(),
        ElementHex1(),
        ElementHexS2(),
        ElementHex2(),
        ElementTetCR(),
        ElementTetCCR(),
        ElementTriCR(),
        ElementTriCCR(),
        ElementWedge1(),
    ]

    def runTest(self):
        for e in self.elems:
            N = e.doflocs.shape[0]
            Ih = np.zeros((N, N))
            for itr in range(N):
                Ih[itr] = e.lbasis(e.doflocs.T, itr)[0]

            # Remove nan-rows: test nodality only on non-nan doflocs.
            #
            # Some elements, such as ElementTriMini might have a combination
            # of nodal dofs and non-nodal dofs.
            #
            # Nodal dof is defined so that there exists a point where the
            # corresponding basis function is one, and other basis functions
            # are zero. Non-nodal dof does not satisfy this property.
            ix = np.isnan(np.sum(Ih, axis=1))
            Nnan = np.sum(ix)
            ixs = np.nonzero(~ix)[0]
            Ih = Ih[ixs].T[ixs].T

            assert_allclose(Ih,
                            np.eye(N - Nnan),
                            atol=1e-13,
                            err_msg="{}".format(type(e)))
Example #2
0
 def create_basis(self, m):
     b = CellBasis(m, ElementQuadRT0())
     return (b, b.with_element(ElementQuad0()))
Example #3
0

@pytest.mark.parametrize(
    "mtype,e1,e2,flat",
    [
        (MeshTri, ElementTriP1(), ElementTriP0(), False),
        (MeshTri, ElementTriP1(), ElementTriP1(), False),
        (MeshTri, ElementTriP2(), ElementTriP1(), False),
        (MeshTri, ElementTriP2(), ElementTriP2(), False),
        (MeshTri, ElementTriP1(), ElementTriP0(), True),
        (MeshTri, ElementTriP1(), ElementTriP1(), True),
        (MeshTri, ElementTriP2(), ElementTriP1(), True),
        (MeshTri, ElementTriP2(), ElementTriP2(), True),
        (MeshTri, ElementTriP2(), None, False),
        (MeshTri, ElementTriP2(), None, True),
        (MeshQuad, ElementQuad1(), ElementQuad0(), False),
        (MeshQuad, ElementQuad1(), ElementQuad1(), False),
        (MeshQuad, ElementQuad2(), ElementQuad2(), False),
        (MeshQuad, ElementQuad1(), ElementQuad0(), True),
        (MeshQuad, ElementQuad1(), ElementQuad1(), True),
        (MeshQuad, ElementQuad2(), ElementQuad2(), True),
        (MeshTet, ElementTetP1(), ElementTetP0(), False),
        (MeshTet, ElementTetP2(), ElementTetP2(), False),
        (MeshHex, ElementHex1(), ElementHex0(), False),
        (MeshHex, ElementHex1(), ElementHex1(), False),
        (MeshHex, ElementHex2(), ElementHex2(), False),
    ],
)
def test_trace(mtype, e1, e2, flat):

    m = mtype().refined(3)
Example #4
0
class TestDerivatives(TestCase):
    """Test values of derivatives."""

    elems = [
        ElementLineP0(),
        ElementLineP1(),
        ElementLineP2(),
        ElementLineMini(),
        ElementTriP0(),
        ElementTriP1(),
        ElementTriP2(),
        ElementTriP3(),
        ElementTriP4(),
        ElementTriMini(),
        ElementQuad0(),
        ElementQuad1(),
        ElementQuad2(),
        ElementQuadS2(),
        ElementTetP0(),
        ElementTetP1(),
        ElementTetP2(),
        ElementTetMini(),
        ElementHex1(),
        ElementHexS2(),
        ElementHex2(),
        ElementTriCR(),
        ElementTriCCR(),
        ElementTetCR(),
        ElementTetCCR(),
        ElementWedge1(),
    ]

    def runTest(self):
        for elem in self.elems:
            eps = 1e-6
            for base in [0., .3, .6, .9]:
                if elem.dim == 1:
                    y = np.array([[base, base + eps]])
                elif elem.dim == 2:
                    y = np.array([[base, base + eps, base, base],
                                  [base, base, base, base + eps]])
                elif elem.dim == 3:
                    y = np.array([[base, base + eps, base, base, base, base],
                                  [base, base, base, base + eps, base, base],
                                  [base, base, base, base, base, base + eps]])
                i = 0
                while True:
                    try:
                        out = elem.lbasis(y, i)
                    except ValueError:
                        break
                    diff = (out[0][1] - out[0][0]) / eps
                    errmsg = 'x-derivative for {}th bfun failed for {}'
                    self.assertAlmostEqual(diff,
                                           out[1][0][0],
                                           delta=1e-3,
                                           msg=errmsg.format(i, elem))
                    if elem.dim > 1:
                        diff = (out[0][3] - out[0][2]) / eps
                        errmsg = 'y-derivative for {}th bfun failed for {}'
                        self.assertAlmostEqual(diff,
                                               out[1][1][3],
                                               delta=1e-3,
                                               msg=errmsg.format(i, elem))
                    if elem.dim == 3:
                        diff = (out[0][5] - out[0][4]) / eps
                        errmsg = 'z-derivative for {}th bfun failed for {}'
                        self.assertAlmostEqual(diff,
                                               out[1][2][4],
                                               delta=1e-3,
                                               msg=errmsg.format(i, elem))
                    i += 1
Example #5
0
class TestIncompatibleMeshElement(TestCase):
    def runTest(self):

        with self.assertRaises(ValueError):
            m = MeshTri()
            e = ElementTetP2()
            basis = InteriorBasis(m, e)


@pytest.mark.parametrize("mtype,e1,e2", [
    (MeshTri, ElementTriP1(), ElementTriP0()),
    (MeshTri, ElementTriP1(), ElementTriP1()),
    (MeshTri, ElementTriP2(), ElementTriP1()),
    (MeshTri, ElementTriP2(), ElementTriP2()),
    (MeshTri, ElementTriP2(), None),
    (MeshQuad, ElementQuad1(), ElementQuad0()),
    (MeshQuad, ElementQuad1(), ElementQuad1()),
    (MeshQuad, ElementQuad2(), ElementQuad2()),
    (MeshTet, ElementTetP1(), ElementTetP0()),
    (MeshTet, ElementTetP2(), ElementTetP2()),
    (MeshHex, ElementHex1(), ElementHex0()),
    (MeshHex, ElementHex1(), ElementHex1()),
    (MeshHex, ElementHex2(), ElementHex2()),
])
def test_trace(mtype, e1, e2):

    m = mtype().refined(3)

    # use the boundary where last coordinate is zero
    basis = FacetBasis(
        m, e1, facets=m.facets_satisfying(lambda x: x[x.shape[0] - 1] == 0.0))
Example #6
0
            e = ElementTetP2()
            basis = InteriorBasis(m, e)


@pytest.mark.parametrize("mtype,e1,e2", [
    (MeshTri, ElementTriP1(), ElementLineP0()),
    (MeshTri, ElementTriP1(), ElementLineP1()),
    (MeshTri, ElementTriP2(), ElementLineP1()),
    (MeshTri, ElementTriP2(), ElementLineP2()),
    (MeshTri, ElementTriP2(), None),
    (MeshQuad, ElementQuad1(), ElementLineP0()),
    (MeshQuad, ElementQuad1(), ElementLineP1()),
    (MeshQuad, ElementQuad2(), ElementLineP2()),
    (MeshTet, ElementTetP1(), ElementTriP0()),
    (MeshTet, ElementTetP2(), ElementTriP2()),
    (MeshHex, ElementHex1(), ElementQuad0()),
    (MeshHex, ElementHex1(), ElementQuad1()),
    (MeshHex, ElementHex2(), ElementQuad2()),
])
def test_trace(mtype, e1, e2):

    m = mtype().refined(3)

    # use the boundary where last coordinate is zero
    basis = FacetBasis(
        m, e1, facets=m.facets_satisfying(lambda x: x[x.shape[0] - 1] == 0.0))
    xfun = project(lambda x: x[0], basis_to=InteriorBasis(m, e1))
    nbasis, y = basis.trace(xfun,
                            lambda p: p[0:(p.shape[0] - 1)],
                            target_elem=e2)