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

« back to all changes in this revision

Viewing changes to demo/pde/lift-drag/python/demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2008-09-16 08:41:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080916084120-i8k3u6lhx3mw3py3
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""This demo demonstrates how to compute functionals (or forms in
 
2
general) over subsets of the mesh. The two functionals lift and
 
3
drag are computed for the pressure field around a dolphin. Here, we
 
4
use the pressure field obtained from solving the Stokes equations
 
5
(see demo program in the sub directory
 
6
src/demo/pde/stokes/taylor-hood).
 
7
 
 
8
The calculation only includes the pressure contribution (not shear
 
9
forces).
 
10
"""
 
11
 
 
12
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"
 
13
__date__ = "2007-11-14 -- 2008-12-27"
 
14
__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"
 
15
__license__  = "GNU LGPL Version 2.1"
 
16
 
 
17
# Modified by Anders Logg, 2008.
 
18
# Modified by Garth N. Wells, 2009.
 
19
 
 
20
from dolfin import *
 
21
 
 
22
# Read the mesh from file
 
23
mesh =  Mesh("../mesh.xml.gz")
 
24
 
 
25
# Create FunctionSpace for pressure field 
 
26
Vp = FunctionSpace(mesh, "CG", 1)
 
27
 
 
28
p = Function(Vp, "../pressure.xml.gz")
 
29
 
 
30
# Define sub domain for the dolphin
 
31
class Fish(SubDomain):
 
32
    def inside(self, x, on_boundary):
 
33
        return x[0] > DOLFIN_EPS and x[0] < (1.0 - DOLFIN_EPS) and \
 
34
               x[1] > DOLFIN_EPS and x[1] < (1.0 - DOLFIN_EPS)
 
35
 
 
36
# Define functionals for drag and lift
 
37
n = FacetNormal(mesh)
 
38
D = -p*n[0]*ds
 
39
L = p*n[1]*ds
 
40
 
 
41
# Assemble functionals over sub domain
 
42
fish =  Fish()
 
43
drag = assemble(D, exterior_facet_domains = fish)
 
44
lift = assemble(L, exterior_facet_domains = fish)
 
45
 
 
46
print "Lift: %f" %lift
 
47
print "Drag: %f" %drag