Exemplo n.º 1
0
def test_plot_mesh3d():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_all_elements()
    mesh.refine_all_elements()

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
Exemplo n.º 2
0
def test_plot_mesh1b():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 3
0
def test_plot_mesh3d():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_all_elements()
    mesh.refine_all_elements()

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
Exemplo n.º 4
0
def test_plot_mesh1b():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 5
0
def test_plot_mesh1a():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="simple", show=False)
    plot_mesh_mpl_simple(mesh.nodes, mesh.elements)
    plot_mesh_mpl_simple(mesh.nodes_dict, mesh.elements)
    plot_mesh_mpl_simple(mesh.nodes, mesh.elements, plot_nodes=False)
    plot_mesh_mpl_simple(mesh.nodes_dict, mesh.elements, plot_nodes=False)
Exemplo n.º 6
0
def test_plot_mesh2():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="simple", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements, plot_nodes=False)
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 7
0
def test_plot_mesh1c():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    assert raises(
        ValueError,
        'view.show(mesh, lib="mpl", method="something_unknown_123")')
Exemplo n.º 8
0
def test_plot_mesh2():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="simple", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements, plot_nodes=False)
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 9
0
    def calc(threshold=0.3,
             strategy=0,
             h_only=False,
             error_tol=1,
             interactive_plotting=False,
             show_mesh=False,
             show_graph=True):
        mesh = Mesh()
        mesh.create([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],
        ], [
            [2, 3, 0, 1, 0],
        ], [
            [0, 1, 1],
            [1, 2, 1],
            [2, 3, 1],
            [3, 0, 1],
        ], [])

        mesh.refine_all_elements()

        shapeset = H1Shapeset()
        pss = PrecalcShapeset(shapeset)

        space = H1Space(mesh, shapeset)
        set_bc(space)
        space.set_uniform_order(1)

        wf = WeakForm(1)
        set_forms(wf)

        sln = Solution()
        rsln = Solution()
        solver = DummySolver()

        selector = H1ProjBasedSelector(CandList.HP_ANISO, 1.0, -1, shapeset)

        view = ScalarView("Solution")
        iter = 0
        graph = []
        while 1:
            space.assign_dofs()

            sys = LinSystem(wf, solver)
            sys.set_spaces(space)
            sys.set_pss(pss)
            sys.assemble()
            sys.solve_system(sln)
            dofs = sys.get_matrix().shape[0]
            if interactive_plotting:
                view.show(sln,
                          lib=lib,
                          notebook=True,
                          filename="a%02d.png" % iter)

            rsys = RefSystem(sys)
            rsys.assemble()

            rsys.solve_system(rsln)

            hp = H1Adapt([space])
            hp.set_solutions([sln], [rsln])
            err_est = hp.calc_error() * 100

            err_est = hp.calc_error(sln, rsln) * 100
            print "iter=%02d, err_est=%5.2f%%, DOFS=%d" % (iter, err_est, dofs)
            graph.append([dofs, err_est])
            if err_est < error_tol:
                break
            hp.adapt(selector, threshold, strategy)
            iter += 1

        if not interactive_plotting:
            view.show(sln, lib=lib, notebook=True)

        if show_mesh:
            mview = MeshView("Mesh")
            mview.show(mesh, lib="mpl", notebook=True, filename="b.png")

        if show_graph:
            from numpy import array
            graph = array(graph)
            import pylab
            pylab.clf()
            pylab.plot(graph[:, 0], graph[:, 1], "ko", label="error estimate")
            pylab.plot(graph[:, 0], graph[:, 1], "k-")
            pylab.title("Error Convergence for the Inner Layer Problem")
            pylab.legend()
            pylab.xlabel("Degrees of Freedom")
            pylab.ylabel("Error [%]")
            pylab.yscale("log")
            pylab.grid()
            pylab.savefig("graph.png")
Exemplo n.º 10
0
    ], [])

# Perform initial mesh refinements
mesh.refine_all_elements()

# Create an H1 space with default shapeset
space = H1Space(mesh, P_INIT)
set_bc(space)

# Initialize the weak formulation
wf = WeakForm()
set_forms(wf)

# Initialize views
sview = ScalarView("Solution")
mview = MeshView("Mesh")
graph = []

# Initialize refinement selector
selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

# Initialize the coarse mesh problem
ls = LinSystem(wf)
ls.set_spaces(space)

# Adaptivity loop
iter = 0
done =  False
print "Calculating..."
sln_coarse = Solution()
sln_fine = Solution()
Exemplo n.º 11
0
#! /usr/bin/env python

"""
Displays a mesh file.

Usage:

./show_mesh.py file.mesh
"""

from hermes2d import Mesh, MeshView
import sys

filename = sys.argv[1]

mesh = Mesh()
mesh.load(filename)

mview = MeshView(filename, 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders")
Exemplo n.º 12
0
# Create finite element space
space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(P_INIT)

# Enumerate basis functions
space.assign_dofs()

# Initialize the weak formulation
wf = WeakForm(1)
set_forms(wf)

# Visualize solution and mesh
sview = ScalarView("Coarse solution", 0, 0, 600, 1000)
oview = OrderView("Polynomial orders", 1220, 0, 600, 1000)
mview = MeshView("Example 12", 100, 100, 500, 500)

# Matrix solver
solver = DummySolver()

# Adaptivity loop
it = 0
ndofs = 0
done = False
sln_coarse = Solution()
sln_fine = Solution()

while (not done):
    print("\n---- Adaptivity step %d ---------------------------------------------\n" % (it+1))
    it += 1
Exemplo n.º 13
0
#! /usr/bin/env python

"""
Displays a mesh file.

Usage:

./show_mesh.py file.mesh
"""

from hermes2d import Mesh, MeshView
import sys

filename = sys.argv[1]

mesh = Mesh()
mesh.load(filename)

mview = MeshView(filename, 100, 100, 500, 500)
mview.show(mesh)
Exemplo n.º 14
0
def test_plot_mesh4():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", show=False, method="orders")
Exemplo n.º 15
0
    def calc(
        threshold=0.3,
        strategy=0,
        h_only=False,
        error_tol=1,
        interactive_plotting=False,
        show_mesh=False,
        show_graph=True,
    ):
        mesh = Mesh()
        mesh.create(
            [[0, 0], [1, 0], [1, 1], [0, 1]], [[2, 3, 0, 1, 0]], [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]], []
        )

        mesh.refine_all_elements()

        shapeset = H1Shapeset()
        pss = PrecalcShapeset(shapeset)

        space = H1Space(mesh, shapeset)
        set_bc(space)
        space.set_uniform_order(1)

        wf = WeakForm(1)
        set_forms(wf)

        sln = Solution()
        rsln = Solution()
        solver = DummySolver()

        selector = H1ProjBasedSelector(CandList.HP_ANISO, 1.0, -1, shapeset)

        view = ScalarView("Solution")
        iter = 0
        graph = []
        while 1:
            space.assign_dofs()

            sys = LinSystem(wf, solver)
            sys.set_spaces(space)
            sys.set_pss(pss)
            sys.assemble()
            sys.solve_system(sln)
            dofs = sys.get_matrix().shape[0]
            if interactive_plotting:
                view.show(sln, lib=lib, notebook=True, filename="a%02d.png" % iter)

            rsys = RefSystem(sys)
            rsys.assemble()

            rsys.solve_system(rsln)

            hp = H1Adapt([space])
            hp.set_solutions([sln], [rsln])
            err_est = hp.calc_error() * 100

            err_est = hp.calc_error(sln, rsln) * 100
            print "iter=%02d, err_est=%5.2f%%, DOFS=%d" % (iter, err_est, dofs)
            graph.append([dofs, err_est])
            if err_est < error_tol:
                break
            hp.adapt(selector, threshold, strategy)
            iter += 1

        if not interactive_plotting:
            view.show(sln, lib=lib, notebook=True)

        if show_mesh:
            mview = MeshView("Mesh")
            mview.show(mesh, lib="mpl", notebook=True, filename="b.png")

        if show_graph:
            from numpy import array

            graph = array(graph)
            import pylab

            pylab.clf()
            pylab.plot(graph[:, 0], graph[:, 1], "ko", label="error estimate")
            pylab.plot(graph[:, 0], graph[:, 1], "k-")
            pylab.title("Error Convergence for the Inner Layer Problem")
            pylab.legend()
            pylab.xlabel("Degrees of Freedom")
            pylab.ylabel("Error [%]")
            pylab.yscale("log")
            pylab.grid()
            pylab.savefig("graph.png")
Exemplo n.º 16
0
# Matrix solver
solver = DummySolver()

# adaptivity loop
it = 1
done = False
cpu = 0.0

x_sln_coarse = Solution()
y_sln_coarse = Solution()

x_sln_fine = Solution()
y_sln_fine = Solution()

xomview = MeshView()
yomview = MeshView()
while(not done):

    print ("\n---- Adaptivity step %d ---------------------------------------------\n" % it)
    it += 1

    # Calculating the number of degrees of freedom
    ndofs = xdisp.assign_dofs()
    ndofs += ydisp.assign_dofs(ndofs)

    print("xdof=%d, ydof=%d\n" % (xdisp.get_num_dofs(), ydisp.get_num_dofs()) )

    # Solve the coarse mesh problem
    ls = LinSystem(wf, solver)
    ls.set_spaces(xdisp, ydisp)
Exemplo n.º 17
0
Arquivo: 22.py Projeto: solin/hermes2d
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

space = H1Space(mesh, shapeset)
set_bc(space)
space.set_uniform_order(1)

wf = WeakForm(1)
set_forms(wf)

sln = Solution()
rsln = Solution()
solver = DummySolver()

view = ScalarView("Solution")
mview = MeshView("Mesh")
graph = []
iter = 0
print "Calculating..."

while 1:
    space.assign_dofs()

    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)
    sys.assemble()
    sys.solve_system(sln)
    dofs = sys.get_matrix().shape[0]
    if interactive_plotting:
        view.show(sln, lib="mayavi", filename="a%02d.png" % iter)
Exemplo n.º 18
0
def test_plot_mesh4():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", show=False, method="orders")
Exemplo n.º 19
0
#! /usr/bin/env python

from hermes2d import Mesh, MeshView
from hermes2d.examples import get_example_mesh
domain_mesh = get_example_mesh()

mesh = Mesh()
mesh.load(domain_mesh)
#mesh.refine_element(2)
#mesh.refine_all_elements()
#mesh.refine_all_elements()
#mesh.refine_all_elements()

mview = MeshView("Hello world!", 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders", notebook=False)
mview.wait()
Exemplo n.º 20
0
#! /usr/bin/env python
"""
Displays a mesh file.

Usage:

./show_mesh.py file.mesh
"""

from hermes2d import Mesh, MeshView
import sys

filename = sys.argv[1]

mesh = Mesh()
mesh.load(filename)

mview = MeshView(filename, 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders")