~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/demo/mesh/subdomains/cpp/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

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
 
// First added:  2007-04-24
5
 
// Last changed: 2008-02-13
6
 
//
7
 
// This demo program demonstrates how to mark sub domains
8
 
// of a mesh and store the sub domain markers as a mesh
9
 
// function to a DOLFIN XML file.
10
 
//
11
 
// The sub domain markers produced by this demo program
12
 
// are the ones used for the Stokes demo programs.
13
 
 
14
 
#include <dolfin.h>
15
 
 
16
 
using namespace dolfin;
17
 
 
18
 
int main()
19
 
{
20
 
  // Sub domain for no-slip (everything except inflow and outflow)
21
 
  class Noslip : public SubDomain
22
 
  {
23
 
    bool inside(const real* x, bool on_boundary) const
24
 
    {
25
 
      return on_boundary;
26
 
    }
27
 
  };
28
 
 
29
 
  // Sub domain for inflow (right)
30
 
  class Inflow : public SubDomain
31
 
  {
32
 
    bool inside(const real* x, bool on_boundary) const
33
 
    {
34
 
      return x[0] > 1.0 - DOLFIN_EPS && on_boundary;
35
 
    }
36
 
  };
37
 
 
38
 
  // Sub domain for outflow (left)
39
 
  class Outflow : public SubDomain
40
 
  {
41
 
    bool inside(const real* x, bool on_boundary) const
42
 
    {
43
 
      return x[0] < DOLFIN_EPS && on_boundary;
44
 
    }
45
 
  };
46
 
 
47
 
  // Read mesh
48
 
  Mesh mesh("../../../../../data/meshes/dolfin-2.xml.gz");
49
 
 
50
 
  // Create mesh function over the cell facets
51
 
  MeshFunction<unsigned int> sub_domains(mesh, mesh.topology().dim() - 1);
52
 
 
53
 
  // Mark all facets as sub domain 3
54
 
  sub_domains = 3;
55
 
 
56
 
  // Mark no-slip facets as sub domain 0
57
 
  Noslip noslip;
58
 
  noslip.mark(sub_domains, 0);
59
 
 
60
 
  // Mark inflow as sub domain 1
61
 
  Inflow inflow;
62
 
  inflow.mark(sub_domains, 1);
63
 
 
64
 
  // Mark outflow as sub domain 2
65
 
  Outflow outflow;
66
 
  outflow.mark(sub_domains, 2);
67
 
 
68
 
  // Save sub domains to file
69
 
  File file("subdomains.xml");
70
 
  file << sub_domains;
71
 
}