| 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 |
# Copyright (C) 2007 Kristian B. Oelgaard |
| 13 |
# |
| 14 |
# This file is part of DOLFIN. |
| 15 |
# |
| 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. |
| 20 |
# |
| 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. |
| 25 |
# |
| 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/>. |
| 28 |
# |
| 29 |
# Modified by Anders Logg, 2008. |
| 30 |
# Modified by Garth N. Wells, 2009. |
| 31 |
# |
| 32 |
# First added: 2007-11-14 |
| 33 |
# Last changed: 2008-12-27 |
| 34 |
|
| 35 |
|
| 36 |
from dolfin import * |
| 37 |
|
| 38 |
# Read the mesh from file |
| 39 |
mesh = Mesh("../dolfin_fine.xml.gz") |
| 40 |
|
| 41 |
# Create FunctionSpace for pressure field |
| 42 |
Vp = FunctionSpace(mesh, "CG", 1) |
| 43 |
p = Function(Vp, "../dolfin_fine_pressure.xml.gz") |
| 44 |
|
| 45 |
# Define sub domain for the dolphin |
| 46 |
class Fish(SubDomain): |
| 47 |
def inside(self, x, on_boundary): |
| 48 |
return x[0] > DOLFIN_EPS and x[0] < (1.0 - DOLFIN_EPS) and \ |
| 49 |
x[1] > DOLFIN_EPS and x[1] < (1.0 - DOLFIN_EPS) |
| 50 |
|
| 51 |
markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 1) |
| 52 |
Fish().mark(markers, 1); |
| 53 |
|
| 54 |
# Define functionals for drag and lift |
| 55 |
ds = ds(subdomain_data=markers) |
| 56 |
n = FacetNormal(mesh) |
| 57 |
D = -p*n[0]*ds(1) |
| 58 |
L = p*n[1]*ds(1) |
| 59 |
|
| 60 |
# Assemble functionals over sub domain |
| 61 |
drag = assemble(D) |
| 62 |
lift = assemble(L) |
| 63 |
|
| 64 |
print("Lift: %f" % lift) |
| 65 |
print("Drag: %f" % drag) |