Unit SquareΒΆ

Here we show some example of plotting the objects defined on a Unit Square

[1]:
import dolfin as df
from fenics_plotly import plot
[2]:
mesh = df.UnitSquareMesh(3, 3)
[3]:
plot(mesh)
[4]:
plot(mesh, wireframe=False)
[5]:
V = df.FunctionSpace(mesh, "CG",  3)
p = df.Function(V)
p.interpolate(df.Expression("sin(x[0])", degree=1))
plot(p, scatter=True, wireframe=False)
[6]:
plot(V)
[7]:
plot(p, wireframe=False, show_grid=True)
plot(p, wireframe=True, show_grid=True)
[8]:
V = df.VectorFunctionSpace(mesh, "CG",  2)
u = df.Function(V)
u.interpolate(df.Expression(("1 + x[0]", "x[1]") , degree=1))
plot(u, size=1)
plot(u, normalize=True, size=0.1)
plot(u, norm=True, size=0.6)
[9]:
for component in ["magnitude", "x", "y"]:
    plot(u, component=component)
[10]:
# Create a facet fuction in order to mark the subdomains
ffun = df.MeshFunction("size_t", mesh, 2)
ffun.set_all(0)

fixed = df.CompiledSubDomain("x[0] < 0.5")
free = df.CompiledSubDomain("x[0] >= 0.5")
# Mark the first subdomain with value 1

fixed_marker = 1
fixed.mark(ffun, fixed_marker)

# Mark the second subdomain with value 2
free = df.CompiledSubDomain("near(x[0], 1) && on_boundary")
free_marker = 2
free.mark(ffun, free_marker)

plot(ffun)
[11]:
V = df.VectorFunctionSpace(mesh, "CG",  2)
left = df.CompiledSubDomain("near(x[0], 0) && on_boundary")
bc = df.DirichletBC(V, df.Constant((0.0, 0.0)), left)
plot(bc, wireframe=True)