How to use meshzoo - 10 common examples

To help you get started, we’ve selected a few meshzoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / pyfvm / examples / test_convection.py View on Github external
def test():
    class DC(object):
        def apply(self, u):
            a = numpy.array([2, 1, 0])
            return (
                integrate(lambda x: -n_dot_grad(u(x)) + n_dot(a) * u(x), dS)
                - integrate(lambda x: 1.0, dV)
                )

        def dirichlet(self, u):
            return [(u, Boundary())]

    vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51)
    mesh = voropy.mesh_tri.MeshTri(vertices, cells)

    matrix, rhs = pyfvm.discretize_linear(DC(), mesh)

    u = linalg.spsolve(matrix, rhs)

    mesh.write('out.vtu', point_data={'u': u})
    return
github nschloe / pyfvm / examples / test_bratu.py View on Github external
def test():
    class Bratu(object):
        def apply(self, u):
            return integrate(lambda x: -n_dot_grad(u(x)), dS) \
                 - integrate(lambda x: 2.0 * exp(u(x)), dV)

        def dirichlet(self, u):
            return [(u, Boundary())]

    vertices, cells = meshzoo.rectangle(0.0, 2.0, 0.0, 1.0, 101, 51)
    mesh = voropy.mesh_tri.MeshTri(vertices, cells)

    f, jacobian = pyfvm.discretize(Bratu(), mesh)

    def jacobian_solver(u0, rhs):
        from scipy.sparse import linalg
        jac = jacobian.get_linear_operator(u0)
        return linalg.spsolve(jac, rhs)

    u0 = numpy.zeros(len(vertices))
    u = pyfvm.newton(f.eval, jacobian_solver, u0)
    # import scipy.optimize
    # u = scipy.optimize.newton_krylov(f.eval, u0)

    mesh.write('out.vtu', point_data={'u': u})
    return
github nschloe / pyfvm / examples / test_singular_perturbation.py View on Github external
def test():
    class Singular(object):
        def apply(self, u):
            return integrate(lambda x: - 1.0e-2 * n_dot_grad(u(x)), dS) \
                   + integrate(u, dV) \
                   - integrate(lambda x: 1.0, dV)

        def dirichlet(self, u):
            return [(u, Boundary())]

    vertices, cells = meshzoo.rectangle(0.0, 1.0, 0.0, 1.0, 51, 51)
    mesh = voropy.mesh_tri.MeshTri(vertices, cells)

    matrix, rhs = pyfvm.discretize_linear(Singular(), mesh)

    u = linalg.spsolve(matrix, rhs)

    mesh.write('out.vtu', point_data={'u': u})
    return
github nschloe / pyfvm / tests / test_convection / test_convection_square.py View on Github external
def get_mesh(k):
    n = 2**(k+1)
    vertices, cells = meshzoo.rectangle(
            0.0, 1.0,
            0.0, 1.0,
            n+1, n+1,
            zigzag=True
            )
    return voropy.mesh_tri.MeshTri(vertices, cells)
github nschloe / pyfvm / test / test_convection.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.rectangle(
            0.0, 1.0, 0.0, 1.0, n + 1, n + 1, zigzag=True
        )
        return meshplex.MeshTri(vertices, cells)
github nschloe / pyfvm / tests / test_reaction / test_reaction_square.py View on Github external
def get_mesh(k):
    n = 2**(k+1)
    vertices, cells = meshzoo.rectangle(
            0.0, 1.0,
            0.0, 1.0,
            n+1, n+1,
            zigzag=True
            )
    return voropy.mesh_tri.MeshTri(vertices, cells)
github nschloe / meshzoo / test / test_rectangle.py View on Github external
def test_center():
    points, cells = meshzoo.rectangle(nx=11, ny=9, variant="center")
    meshzoo.show2d(points, cells)
    assert len(points) == 99
    assert len(cells) == 160
github nschloe / pyfvm / test / test_reaction.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.cube(
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
        )
        return meshplex.MeshTetra(vertices, cells)
github nschloe / pyfvm / tests / test_convection / test_convection_cube.py View on Github external
def get_mesh(k):
    n = 2**(k+1)
    vertices, cells = meshzoo.cube(
            0.0, 1.0,
            0.0, 1.0,
            0.0, 1.0,
            n+1, n+1, n+1
            )
    return voropy.mesh_tetra.MeshTetra(vertices, cells, mode='algebraic')
github nschloe / pyfvm / test / test_convection.py View on Github external
def get_mesh(self, k):
        n = 2 ** (k + 1)
        vertices, cells = meshzoo.cube(
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, n + 1, n + 1, n + 1
        )
        return meshplex.MeshTetra(vertices, cells)