19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

"""<br />

<strong>FEniCS</strong> program for the deflection w(x,y) of a membrane:<br />

-Laplace(w) = p = Gaussian function, in a unit circle,<br />

with w = 0 on the boundary.<br />

"""<br />

from dolfin import *<br />

import numpy<br />

# Set pressure function:<br />

T = 10.0 # tension<br />

A = 1.0 # pressure amplitude<br />

R = 0.3 # radius of domain<br />

theta = 0.2<br />

x0 = 0.6*R*cos(theta)<br />

y0 = 0.6*R*sin(theta)<br />

sigma = 0.025<br />

sigma = 50 # large value for verification<br />

n = 40 # approx no of elements in radial direction<br />

mesh = UnitCircle(n)<br />

V = FunctionSpace(mesh, ’Lagrange’, 1)<br />

# Define boundary condition w=0<br />

def boundary(x, on_boundary):<br />

return on_boundary<br />

bc = DirichletBC(V, Constant(0.0), boundary)<br />

# Define variational problem<br />

w = TrialFunction(V)<br />

v = TestFunction(V)<br />

a = inner(nabla_grad(w), nabla_grad(v))*dx<br />

f = Expression(’4*exp(-0.5*(pow((R*x[0] - x0)/sigma, 2)) ’<br />

’ -0.5*(pow((R*x[1] - y0)/sigma, 2)))’,<br />

R=R, x0=x0, y0=y0, sigma=sigma)<br />

L = f*v*dx<br />

# Compute solution<br />

w = Function(V)<br />

problem = LinearVariationalProblem(a, L, w, bc)<br />

solver = LinearVariationalSolver(problem)<br />

solver.parameters[’linear_solver’] = ’cg’<br />

solver.parameters[’preconditioner’] = ’ilu’<br />

solver.solve()<br />

# Plot scaled solution, mesh and pressure<br />

plot(mesh, title=’Mesh over scaled domain’)<br />

plot(w, title=’Scaled deflection’)<br />

f = interpolate(f, V)<br />

plot(f, title=’Scaled pressure’)<br />

# Find maximum real deflection<br />

max_w = w.vector().array().max()<br />

max_D = A*max_w/(8*pi*sigma*T)<br />

print ’Maximum real deflection is’, max_D<br />

# Verification for "flat" pressure (large sigma)<br />

if sigma >= 50:<br />

w_e = Expression("1 - x[0]*x[0] - x[1]*x[1]")<br />

w_e = interpolate(w_e, V)<br />

23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!