Beispiel #1
0
    def runTest(self):
        m = self.init_mesh()
        basis = InteriorBasis(m, self.element_type())

        A = laplace.assemble(basis)
        b = unit_load.assemble(basis)
        x = solve(*condense(A, b, D=basis.get_dofs()))

        self.assertAlmostEqual(np.max(x), self.maxval, places=3)
Beispiel #2
0
    def runTest(self):
        path = Path(__file__).parents[1] / 'docs' / 'examples' / 'meshes'
        m = self.mesh_type.load(path / self.filename)
        basis = InteriorBasis(m, self.element_type())

        A = laplace.assemble(basis)
        b = unit_load.assemble(basis)
        x = solve(*condense(A, b, D=basis.get_dofs()))

        self.assertAlmostEqual(np.max(x), 0.06261690318912218, places=3)
Beispiel #3
0
def test_periodic_mesh_assembly(m, mdgtype, etype, check1, check2):
    def _sort(ix):
        # sort index arrays so that ix[0] matches
        return ix[np.argsort(np.sum(m.p, axis=0)[ix])]

    mp = mdgtype.periodic(m, _sort(m.nodes_satisfying(check1)),
                          _sort(m.nodes_satisfying(check2)))
    basis = Basis(mp, etype())
    A = laplace.assemble(basis)

    f = unit_load.assemble(basis)
    D = basis.get_dofs()
    x = solve(*condense(A, f, D=D))

    if m.dim() == 2:
        assert_almost_equal(x.max(), 0.125)
    else:
        assert_almost_equal(x.max(), 0.07389930610869411, decimal=3)
    assert not np.isnan(x).any()
Beispiel #4
0
def laplace(m, **params):
    """Solve the Laplace equation using the FEM.

    Parameters
    ----------
    m
        A Mesh object.

    """
    e = ElementTriP1()
    basis = CellBasis(m, e)
    A = laplacian.assemble(basis)
    b = unit_load.assemble(basis)
    u = solve(*condense(A, b, I=m.interior_nodes()))

    # evaluate the error estimators
    fbasis = [InteriorFacetBasis(m, e, side=i) for i in [0, 1]]
    w = {"u" + str(i + 1): fbasis[i].interpolate(u) for i in [0, 1]}

    @Functional
    def interior_residual(w):
        h = w.h
        return h**2

    eta_K = interior_residual.elemental(basis)

    @Functional
    def edge_jump(w):
        h = w.h
        n = w.n
        dw1 = grad(w["u1"])
        dw2 = grad(w["u2"])
        return h * ((dw1[0] - dw2[0]) * n[0] + (dw1[1] - dw2[1]) * n[1])**2

    eta_E = edge_jump.elemental(fbasis[0], **w)

    tmp = np.zeros(m.facets.shape[1])
    np.add.at(tmp, fbasis[0].find, eta_E)
    eta_E = np.sum(0.5 * tmp[m.t2f], axis=0)

    return eta_E + eta_K
Beispiel #5
0
def assembler(m):
    basis = Basis(m, ElementTetP1())
    return (
        laplace.assemble(basis),
        unit_load.assemble(basis),
    )