# Automatically generated:
d = Domain.geometry({0:[55,305],1:[216,303],2:[266,255],3:[270,107],4:[165,102],5:[161,191],6:[63,211]}, {0:[1,6],1:[0,2],2:[1,3],3:[2,4],4:[3,5],5:[4,6],6:[5,0]})
m = d.triangulate()
m.plot()
#m.edit()
# Hermes2D: Example 03 (poisson)
# This example shows how to solve a first simple PDE.
# - create the mesh
# - perform initial refinements
# - create a H1 space over the mesh
# - define weak formulation
# - initialize matrix solver
# - assemble and solve the matrix system
# - visualize the solution
#
# PDE: Poisson equation -Laplace u = CONST_F with homogeneous (zero)
# Dirichlet boundary conditions.
# The following parameters can be changed
P_INIT = 5 # Uniform polynomial degree of mesh elements.
# Import modules
from hermes2d import MeshView, H1Shapeset, PrecalcShapeset, H1Space, \
WeakForm, Solution, ScalarView, LinSystem, DummySolver
from hermes2d.forms import set_forms
from hermes2d.examples.c03 import set_bc
# Initialize the mesh
try:
mesh = m.get_mesh()
except:
# old api:
mesh = m.export_mesh()
# Sample "manual" mesh refinements
mesh.refine_element(0)
mesh.refine_element(3)
# Initialize the shapeset and the cache
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)
# Create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(P_INIT)
# Set boundary conditions
set_bc(space)
# Enumerate degrees of freedom
space.assign_dofs()
# Initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)
# Initialize the linear system and solver
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)
# Display the Solution
sln.plot(filename="a.png")
# Display the Mesh
mesh.plot(space=space, filename="b.png")
# Positioning the images
print """<html><table border=1><tr><td><img src="cell://a.png"></span></td><td><img src="cell://b.png" width="540" height="405"></td></tr></table></html>"""