from dolfin import *
import numpy as np
# Create mesh
#N = 30
N = 10
mesh = UnitSquare(N,N)
# Define function space
V = FunctionSpace(mesh, "CG", 1)
# Start time
t0 = 0
# Time-dependent expression used for the
g = ??
# Source term is 0
f = ??
# Create boundary domain
def boundary_domain(x,on_boundary):
return on_boundary
bc = DirichletBC(V,g,boundary_domain)
#Interpolate g for t=t0
u0 =
u = TrialFunction(V)
v = TestFunction(V)
# time step
dt = 0.001
# Define variational forms
a = ??
L = ??
# Only once since dt is constant
A = assemble(a)
#Reuse b after all, don't allocate memory for b each time
#b = None
# Compute solution
u1 = ?
T = 0.1
t = dt
# Define file storing solution in vtk format
u_file = File("u_sol.pvd")
while t <=T :
print "time =",t
# Update g and f
...
#Assemble b
...
# Apply boundary condition
...
# Solve linear algebra system
...
# Writ out to solution for this time step
u_file << u1
# next time step. Increase t and make u0 the previous solution
# for the next time step
t += dt
u0.assign(u1)