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

« back to all changes in this revision

Viewing changes to demo/mesh/submesh/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) 2009 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// First added:  2009-02-11
 
5
// Last changed: 2009-03-02
 
6
//
 
7
// This demo program demonstrates how to extract matching sub meshes
 
8
// from a common mesh.
 
9
 
 
10
#include <dolfin.h>
 
11
 
 
12
using namespace dolfin;
 
13
 
 
14
int main()
 
15
{
 
16
  // Structure sub domain
 
17
  class Structure : public SubDomain
 
18
  {
 
19
    bool inside(const double* x, bool on_boundary) const
 
20
    {
 
21
      return x[0] > 1.4 - DOLFIN_EPS and x[0] < 1.6 + DOLFIN_EPS and x[1] < 0.6 + DOLFIN_EPS;
 
22
    }
 
23
  };
 
24
  
 
25
  // Create mesh
 
26
  Rectangle mesh(0.0, 0.0, 3.0, 1.0, 60, 20);
 
27
  
 
28
  // Create sub domain markers and mark everything as 0
 
29
  MeshFunction<unsigned int> sub_domains(mesh, mesh.topology().dim());
 
30
  sub_domains = 0;
 
31
  
 
32
  // Mark structure domain as 1
 
33
  Structure structure;
 
34
  structure.mark(sub_domains, 1);
 
35
  
 
36
  // Extract sub meshes
 
37
  SubMesh fluid_mesh(mesh, sub_domains, 0);
 
38
  SubMesh structure_mesh(mesh, sub_domains, 1);
 
39
 
 
40
  // Move structure mesh
 
41
  MeshGeometry& geometry = structure_mesh.geometry();
 
42
  for (VertexIterator v(structure_mesh); !v.end(); ++v)
 
43
  {
 
44
    const double* x = v->x();
 
45
    geometry.x(v->index())[0] += 0.1*x[0]*x[1];
 
46
  }
 
47
  
 
48
  // Move fluid mesh according to structure mesh
 
49
  fluid_mesh.move(structure_mesh);
 
50
  fluid_mesh.smooth();
 
51
  
 
52
  // Plot meshes
 
53
  plot(fluid_mesh);
 
54
  plot(structure_mesh);
 
55
}