> Ok, I made a progress, it seems it's working. Script and picture

Forgot to attach the script.

Ondrej
from hermes2d import Mesh, H1Shapeset, PrecalcShapeset, H1Space, \
       WeakForm, Solution, ScalarView, LinSystem, DummySolver, Linearizer
from hermes2d.forms import set_forms
from hermes2d.examples import get_example_mesh
from numpy import array
import pylab
import matplotlib.cm as cm
import matplotlib.collections as collections
import matplotlib.pyplot as P

mesh = Mesh()
mesh.load(get_example_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.linalg import cg
x, res = cg(A, b)
sln = Solution()
sln.set_fe_solution(space, pss, x)

l = Linearizer()
l.process_solution(sln)
v = l.get_vertices()
verts = []
vals = []
for t in l.get_triangles():
    triangle = tuple([tuple(v[n][:2]) for n in t])
    val = sum([v[n][2] for n in t])
    vals.append(val/3.)
    verts.append(triangle)

#vals = v[:, 2]
vals = array(vals)
print "Things converted to mpl format"

col = collections.PolyCollection(verts, linewidths=0, antialiaseds=0)
col.set_array(vals)
col.set_cmap(cm.jet)
fig = P.figure()
ax = fig.gca()
ax.add_collection(col)
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_aspect("equal")
pylab.show()
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to