Skip to content

Instantly share code, notes, and snippets.

@certik
Created November 24, 2010 06:35
Show Gist options
  • Save certik/713214 to your computer and use it in GitHub Desktop.
Save certik/713214 to your computer and use it in GitHub Desktop.
mesh = """
a = 1.0 # size of the mesh
b = sqrt(2)/2
vertices =
{
{ 0, -a }, # vertex 0
{ a, -a }, # vertex 1
{ -a, 0 }, # vertex 2
{ 0, 0 }, # vertex 3
{ a, 0 }, # vertex 4
{ -a, a }, # vertex 5
{ 0, a }, # vertex 6
{ a*b, a*b } # vertex 7
}
elements =
{
{ 0, 1, 4, 3, 0 }, # quad 0
{ 3, 4, 7, 0 }, # tri 1
{ 3, 7, 6, 0 }, # tri 2
{ 2, 3, 6, 5, 0 } # quad 3
}
boundaries =
{
{ 0, 1, 1 },
{ 1, 4, 2 },
{ 3, 0, 4 },
{ 4, 7, 2 },
{ 7, 6, 2 },
{ 2, 3, 4 },
{ 6, 5, 2 },
{ 5, 2, 3 }
}
curves =
{
{ 4, 7, 45 }, # +45 degree circular arcs
{ 7, 6, 45 }
}"""
from hermes2d.modules.electrostatics import Electrostatics
from hermes2d.hermes2d import Linearizer
from hermes2d.plot import sln2png, plot_sln_mayavi
from femhub.plot import return_mayavi_figure
def main():
e = Electrostatics()
e.set_mesh_str(mesh)
e.set_initial_mesh_refinement(2)
e.set_initial_poly_degree(4)
e.set_material_markers([8, 2])
e.set_permittivity_array([4, 3.1, 5])
e.set_charge_density_array([4, 3.1, 5])
e.set_boundary_markers_value([1, 3])
e.set_boundary_values([1, 0])
e.set_boundary_markers_derivative([2, 4])
e.set_boundary_derivatives([1, 5])
r, sln = e.calculate()
assert r is True
print "Saving solution to 'solution.png'"
fig = plot_sln_mayavi(sln, offscreen=True)
return_mayavi_figure(fig)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment