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).
8
The calculation only includes the pressure contribution (not shear
12
# Copyright (C) 2007 Kristian B. Oelgaard
14
# This file is part of DOLFIN.
16
# DOLFIN is free software: you can redistribute it and/or modify
17
# it under the terms of the GNU Lesser General Public License as published by
18
# the Free Software Foundation, either version 3 of the License, or
19
# (at your option) any later version.
21
# DOLFIN is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU Lesser General Public License for more details.
26
# You should have received a copy of the GNU Lesser General Public License
27
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
29
# Modified by Anders Logg, 2008.
30
# Modified by Garth N. Wells, 2009.
32
# First added: 2007-11-14
33
# Last changed: 2008-12-27
37
# Read the mesh from file
38
mesh = Mesh("../mesh.xml.gz")
40
# Create FunctionSpace for pressure field
41
Vp = FunctionSpace(mesh, "CG", 1)
42
p = Function(Vp, "../pressure.xml.gz")
44
# Define sub domain for the dolphin
45
class Fish(SubDomain):
46
def inside(self, x, on_boundary):
47
return x[0] > DOLFIN_EPS and x[0] < (1.0 - DOLFIN_EPS) and \
48
x[1] > DOLFIN_EPS and x[1] < (1.0 - DOLFIN_EPS)
50
# Define functionals for drag and lift
55
# Assemble functionals over sub domain
57
drag = assemble(D, mesh=mesh, exterior_facet_domains=fish)
58
lift = assemble(L, mesh=mesh, exterior_facet_domains=fish)
60
print "Lift: %f" %lift
61
print "Drag: %f" %drag