~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to demo/pde/poisson/python/demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2009-10-12 14:13:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012141318-hkbxl0sq555vqv7d
Tags: 0.9.4-1
* New upstream release. This version cleans up the design of the
  function class by adding a new abstraction for user-defined
  functions called Expression. A number of minor bugfixes and
  improvements have also been made.
* debian/watch: Update for new flat directory structure.
* Update debian/copyright.
* debian/rules: Use explicit paths to PETSc 3.0.0 and SLEPc 3.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
on the unit square with source f given by
6
6
 
7
 
    f(x, y) = 500*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)
 
7
    f(x, y) = 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02)
8
8
 
9
9
and boundary conditions given by
10
10
 
11
 
    u(x, y) = 0 for x = 0 or x = 1
 
11
    u(x, y) = 0        for x = 0 or x = 1
 
12
du/dn(x, y) = sin(5*x) for y = 0 or y = 1
12
13
"""
13
14
 
14
15
__author__ = "Anders Logg (logg@simula.no)"
15
 
__date__ = "2007-08-16 -- 2008-12-13"
16
 
__copyright__ = "Copyright (C) 2007-2008 Anders Logg"
 
16
__date__ = "2007-08-16 -- 2009-10-06"
 
17
__copyright__ = "Copyright (C) 2007-2009 Anders Logg"
17
18
__license__  = "GNU LGPL Version 2.1"
18
19
 
19
20
from dolfin import *
20
21
 
21
 
#dolfin_set("linear algebra backend","Epetra")
22
 
 
23
22
# Create mesh and define function space
24
23
mesh = UnitSquare(32, 32)
25
24
V = FunctionSpace(mesh, "CG", 1)
36
35
# Define variational problem
37
36
v = TestFunction(V)
38
37
u = TrialFunction(V)
39
 
f = Function(V, "500.0 * exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
40
 
a = dot(grad(v), grad(u))*dx
41
 
L = v*f*dx
 
38
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", V = V)
 
39
g = Expression("sin(5*x[0])", V = V)
 
40
a = inner(grad(v), grad(u))*dx
 
41
L = v*f*dx - v*g*ds
42
42
 
43
43
# Compute solution
44
44
problem = VariationalProblem(a, L, bc)