Comment 4 for bug 914880

Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 914880] Re: 1D plot issue persists in OSX10.6 build

This modified script works fine for me. Using DOLFIN 1.0.

Johan

####################################################33

from dolfin import *

# Create mesh and define function space
mesh = UnitInterval(32)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define Dirichlet boundary (x = 0 or x = 1)
def boundary(x):
    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

# Define boundary condition
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-pow(x[0] - 0.5, 2) / 0.02)")
a = inner(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)

# Save solution in VTK format
file = File("poisson.pvd")
file << u

# Plot solution
plot(u, interactive=True)

On Wednesday January 11 2012 19:13:38 Ernesto Ismail wrote:
> Thanks for the prompt reply Johan.
>
> If I run the following, the solution process completes and I can open
> the .pvd in ParaView. The plot command throws an error.
>
> from dolfin import *
>
> # Create mesh and define function space
> mesh = UnitInterval(32)
> V = FunctionSpace(mesh, "Lagrange", 1)
>
> # Define Dirichlet boundary (x = 0 or x = 1)
> def boundary(x):
> return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
>
> # Define boundary condition
> u0 = Constant(0.0)
> bc = DirichletBC(V, u0, boundary)
>
> # Define variational problem
> u = TrialFunction(V)
> v = TestFunction(V)
> f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
> g = Expression("sin(5*x[0])")
> a = inner(grad(u), grad(v))*dx
> L = f*v*dx + g*v*ds
>
> # Compute solution
> u = Function(V)
> solve(a == L, u, bc)
>
> # Save solution in VTK format
> file = File("poisson.pvd")
> file << u
>
> # Plot solution
> plot(u, interactive=True)