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

« back to all changes in this revision

Viewing changes to demo/pde/lift-drag/cpp/main.cpp

  • 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
// Copyright (C) 2007-2008 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// Modified by Garthn N. Wells, 2009
 
5
//
 
6
// First added:  2007-05-14
 
7
// Last changed: 2009-03-14
 
8
//
 
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).
 
15
//
 
16
// The calculation only includes the pressure contribution (not shear
 
17
// forces).
 
18
 
 
19
#include <dolfin.h>
 
20
#include "Lift.h"
 
21
#include "Drag.h"
 
22
#include "Pressure.h"
 
23
 
 
24
using namespace dolfin;
 
25
 
 
26
// Define sub domain for the dolphin
 
27
class Fish : public SubDomain
 
28
{
 
29
  bool inside(const double* x, bool on_boundary) const
 
30
  {
 
31
    return (x[0] > DOLFIN_EPS && x[0] < (1.0 - DOLFIN_EPS) && 
 
32
            x[1] > DOLFIN_EPS && x[1] < (1.0 - DOLFIN_EPS) &&
 
33
            on_boundary);
 
34
  }
 
35
};  
 
36
 
 
37
int main()
 
38
{
 
39
  // Read mesh from file
 
40
  Mesh mesh("../mesh.xml.gz");
 
41
 
 
42
  PressureFunctionSpace Vp(mesh);
 
43
 
 
44
  // Read velocity field from file
 
45
  Function p(Vp, "../pressure.xml.gz");
 
46
 
 
47
  // Functionals for lift and drag
 
48
  FacetNormal n;
 
49
  LiftFunctional L(p, n);
 
50
  DragFunctional D(p, n);
 
51
 
 
52
  // Assemble functionals over sub domain
 
53
  Fish fish;
 
54
  double lift = assemble(L, fish);
 
55
  double drag = assemble(D, fish);
 
56
 
 
57
  message("Lift: %f", lift);
 
58
  message("Drag: %f", drag);
 
59
}