1
// Copyright (C) 2007-2008 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Garthn N. Wells, 2009
6
// First added: 2007-05-14
7
// Last changed: 2009-03-14
9
// This demo demonstrates how to compute functionals (or forms in
10
// general) over subsets of the mesh. The two functionals lift and
11
// drag are computed for the pressure field around a dolphin. Here, we
12
// use the pressure field obtained from solving the Stokes equations
13
// (see demo program in the sub directory
14
// src/demo/pde/stokes/taylor-hood).
16
// The calculation only includes the pressure contribution (not shear
24
using namespace dolfin;
26
// Define sub domain for the dolphin
27
class Fish : public SubDomain
29
bool inside(const double* x, bool on_boundary) const
31
return (x[0] > DOLFIN_EPS && x[0] < (1.0 - DOLFIN_EPS) &&
32
x[1] > DOLFIN_EPS && x[1] < (1.0 - DOLFIN_EPS) &&
39
// Read mesh from file
40
Mesh mesh("../mesh.xml.gz");
42
PressureFunctionSpace Vp(mesh);
44
// Read velocity field from file
45
Function p(Vp, "../pressure.xml.gz");
47
// Functionals for lift and drag
49
LiftFunctional L(p, n);
50
DragFunctional D(p, n);
52
// Assemble functionals over sub domain
54
double lift = assemble(L, fish);
55
double drag = assemble(D, fish);
57
message("Lift: %f", lift);
58
message("Drag: %f", drag);