1
# This demo solves the time-dependent convection-diffusion equation by
2
# a least-squares stabilized cG(1)cG(1) method. The velocity field used
3
# in the simulation is the output from the Stokes (Taylor-Hood) demo.
4
# The sub domains for the different boundary conditions are computed
5
# by the demo program in src/demo/subdomains.
7
# Modified by Anders Logg, 2008
9
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"
10
__date__ = "2007-11-14 -- 2008-01-04"
11
__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"
12
__license__ = "GNU LGPL Version 2.1"
16
# Load mesh and create finite elements
17
mesh = Mesh("../../../../../data/meshes/dolfin-2.xml.gz")
18
scalar = FiniteElement("Lagrange", "triangle", 1)
19
vector = VectorElement("Lagrange", "triangle", 2)
21
# Load subdomains and velocity
22
sub_domains = MeshFunction("uint", mesh, "../subdomains.xml.gz");
23
velocity = Function(vector, "../velocity.xml.gz");
25
# Initialise source function and previous solution function
26
f = Function(scalar, mesh, 0.0)
27
u0 = Function(scalar, mesh, 0.0)
35
# Test and trial functions
36
v = TestFunction(scalar)
37
u = TrialFunction(scalar)
40
u0 = Function(scalar, mesh, Vector())
41
u1 = Function(scalar, mesh, Vector())
44
a = v*u*dx + 0.5*k*(v*dot(velocity, grad(u))*dx + c*dot(grad(v), grad(u))*dx)
45
L = v*u0*dx - 0.5*k*(v*dot(velocity, grad(u0))*dx + c*dot(grad(v), grad(u0))*dx) + k*v*f*dx
47
# Set up boundary condition
48
g = Function(mesh, 1.0)
49
bc = DirichletBC(g, sub_domains, 1)
55
out_file = File("temperature.pvd")
60
# Assemble vector and apply boundary conditions
64
# Solve the linear system
65
solve(A, u1.vector(), b)
67
# Save the solution to file
70
# Move to next interval