本文整理汇总了Python中hermes2d.Mesh类的典型用法代码示例。如果您正苦于以下问题:Python Mesh类的具体用法?Python Mesh怎么用?Python Mesh使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_example_03
def test_example_03():
from hermes2d.examples.c03 import set_bc
set_verbose(False)
P_INIT = 5 # Uniform polynomial degree of mesh elements.
# Problem parameters.
CONST_F = 2.0
# Load the mesh file
mesh = Mesh()
mesh.load(get_example_mesh())
# Sample "manual" mesh refinement
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(1)
set_forms(wf)
# Initialize the linear system
ls = LinSystem(wf)
ls.set_spaces(space)
# Assemble and solve the matrix problem.
sln = Solution()
ls.assemble()
ls.solve_system(sln)
示例2: test_example_04
def test_example_04():
from hermes2d.examples.c04 import set_bc
set_verbose(False)
# Below you can play with the parameters CONST_F, P_INIT, and UNIFORM_REF_LEVEL.
INIT_REF_NUM = 2 # number of initial uniform mesh refinements
P_INIT = 2 # initial polynomial degree in all elements
# Load the mesh file
mesh = Mesh()
mesh.load(get_example_mesh())
# Perform initial mesh refinements
for i in range(INIT_REF_NUM):
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 the linear system
ls = LinSystem(wf)
ls.set_spaces(space)
# Assemble and solve the matrix problem
sln = Solution()
ls.assemble()
ls.solve_system(sln)
示例3: test_example_08
def test_example_08():
from hermes2d.examples.c08 import set_bc, set_forms
set_verbose(False)
# The following parameter can be changed:
P_INIT = 4
# Load the mesh file
mesh = Mesh()
mesh.load(get_sample_mesh())
# Perform uniform mesh refinement
mesh.refine_all_elements()
# Create the x- and y- displacement space using the default H1 shapeset
xdisp = H1Space(mesh, P_INIT)
ydisp = H1Space(mesh, P_INIT)
set_bc(xdisp, ydisp)
# Initialize the weak formulation
wf = WeakForm(2)
set_forms(wf)
# Initialize the linear system.
ls = LinSystem(wf)
ls.set_spaces(xdisp, ydisp)
# Assemble and solve the matrix problem
xsln = Solution()
ysln = Solution()
ls.assemble()
ls.solve_system(xsln, ysln, lib="scipy")
示例4: test_plot_mesh3e
def test_plot_mesh3e():
mesh = Mesh()
mesh.load(domain_mesh)
mesh.refine_all_elements()
mesh.refine_all_elements()
plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
示例5: test_example_07
def test_example_07():
from hermes2d.examples.c07 import set_bc, set_forms
set_verbose(False)
# The following parameters can be changed:
P_INIT = 2 # Initial polynomial degree of all mesh elements.
INIT_REF_NUM = 4 # Number of initial uniform refinements
# Load the mesh
mesh = Mesh()
mesh.load(get_07_mesh())
# Perform initial mesh refinements.
for i in range(INIT_REF_NUM):
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 the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)
# Assemble and solve the matrix problem
sln = Solution()
ls.assemble()
ls.solve_system(sln)
示例6: test_ScalarView_mpl_unknown
def test_ScalarView_mpl_unknown():
mesh = Mesh()
mesh.load(domain_mesh)
mesh.refine_element(0)
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)
# create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(5)
space.assign_dofs()
# initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)
solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(space)
sys.set_pss(pss)
# assemble the stiffness matrix and solve the system
sys.assemble()
A = sys.get_matrix()
b = sys.get_rhs()
from scipy.sparse.linalg import cg
x, res = cg(A, b)
sln = Solution()
sln.set_fe_solution(space, pss, x)
view = ScalarView("Solution")
示例7: export_mesh
def export_mesh(self, lib="hermes2d"):
"""
Exports the mesh in various FE solver formats.
lib == "hermes2d" ... returns the hermes2d Mesh
Currently only hermes2d is implemented.
Example:
>>> m = Mesh([[0.0,1.0],[1.0,1.0],[1.0,0.0],[0.0,0.0],],[[1,0,2],[2,0,3],],[[3,2,1],[2,1,2],[1,0,3],[0,3,4],],[])
>>> h = m.export_mesh()
>>> h
<hermes2d._hermes2d.Mesh object at 0x7f07284721c8>
"""
if lib == "hermes2d":
from hermes2d import Mesh
m = Mesh()
nodes = self._nodes
elements = [list(e)+[0] for e in self._elements]
boundaries = self._boundaries
curves = self._curves
m.create(nodes, elements, boundaries, curves)
return m
else:
raise NotImplementedError("unknown library")
示例8: test_example_05
def test_example_05():
from hermes2d.examples.c05 import set_bc
from hermes2d.examples.c05 import set_forms as set_forms_surf
set_verbose(False)
P_INIT = 4 # initial polynomial degree in all elements
CORNER_REF_LEVEL = 12 # number of mesh refinements towards the re-entrant corner
# Load the mesh file
mesh = Mesh()
mesh.load(get_example_mesh())
# Perform initial mesh refinements.
mesh.refine_towards_vertex(3, CORNER_REF_LEVEL)
# 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 the linear system.
ls = LinSystem(wf)
ls.set_spaces(space)
# Assemble and solve the matrix problem
sln = Solution()
ls.assemble()
ls.solve_system(sln)
示例9: test_matrix
def test_matrix():
set_verbose(False)
mesh = Mesh()
mesh.load(domain_mesh)
mesh.refine_element(0)
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)
# create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(5)
space.assign_dofs()
# initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)
solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(space)
sys.set_pss(pss)
# assemble the stiffness matrix and solve the system
sln = Solution()
sys.assemble()
A = sys.get_matrix()
示例10: test_plot_mesh3c
def test_plot_mesh3c():
mesh = Mesh()
mesh.load(domain_mesh)
mesh.refine_all_elements()
mesh.refine_all_elements()
plot_mesh_mpl_simple(mesh.nodes_dict, mesh.elements, plot_nodes=False)
示例11: test_example_03
def test_example_03():
set_verbose(False)
mesh = Mesh()
mesh.load(domain_mesh)
mesh.refine_element(0)
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)
# create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(5)
from hermes2d.examples.c03 import set_bc
set_bc(space)
space.assign_dofs()
# initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)
solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(space)
sys.set_pss(pss)
# assemble the stiffness matrix and solve the system
sln = Solution()
sys.assemble()
sys.solve_system(sln)
assert abs(sln.l2_norm() - 0.25493) < 1e-4
assert abs(sln.h1_norm() - 0.89534) < 1e-4
示例12: test_plot_mesh3d
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)
示例13: test_plot_mesh1b
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)
示例14: test_plot_mesh1a
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)
示例15: test_plot_mesh2
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)