~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to demo/undocumented/meshintersection/3D/cpp/main.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
int main()
28
28
{
29
 
  UnitSphere sphere(20);
30
 
  UnitCube cube(20, 20, 20);
 
29
  Sphere sphere(Point(0, 0, 0), 1.0);
 
30
  Mesh sphere_mesh(sphere, 16);
 
31
  UnitCubeMesh cube_mesh(20, 20, 20);
31
32
 
32
33
  // Access mesh geometry
33
 
  MeshGeometry& geometry = sphere.geometry();
 
34
  MeshGeometry& geometry = sphere_mesh.geometry();
34
35
 
35
36
  // Start center and propagtion speed for the sphere.
36
37
  const double dt = 0.1;
37
38
  double t = -0.61;
38
39
 
39
40
  // Scale and move the circle.
40
 
  for (VertexIterator vertex(sphere); !vertex.end(); ++vertex)
 
41
  for (VertexIterator vertex(sphere_mesh); !vertex.end(); ++vertex)
41
42
  {
42
43
    double* x = geometry.x(vertex->index());
43
44
    x[0] = x[0]*0.7 + t;
45
46
    x[2] = x[2]*0.7 + t;
46
47
  }
47
48
 
48
 
  boost::shared_ptr<dolfin::MeshFunction<unsigned int> >intersection(new dolfin::MeshFunction<unsigned int>(cube, cube.topology().dim()));
 
49
  boost::shared_ptr<dolfin::MeshFunction<std::size_t> >
 
50
    intersection(new dolfin::MeshFunction<std::size_t>(cube_mesh, cube_mesh.topology().dim()));
49
51
 
50
52
  VTKPlotter p(intersection);
51
53
  p.parameters["scalarbar"] = false;
52
54
 
53
55
  bool first = true;
54
 
  while (t < 1.4) 
 
56
  while (t < 1.4)
55
57
  {
56
58
    // Compute intersection with boundary of square
57
 
    BoundaryMesh boundary(sphere);
58
 
    std::set<dolfin::uint> cells;
59
 
    cube.intersected_cells(boundary, cells);
 
59
    BoundaryMesh boundary(sphere_mesh);
 
60
    std::set<std::size_t> cells;
 
61
    cube_mesh.intersected_cells(boundary, cells);
60
62
 
61
63
    // Copy values to mesh function for plotting
62
64
    *intersection = 0;
63
 
    for (std::set<dolfin::uint>::const_iterator i = cells.begin(); i != cells.end(); i++)
 
65
    for (std::set<std::size_t>::const_iterator i = cells.begin(); i != cells.end(); i++)
64
66
      (*intersection)[*i] = 1;
65
67
 
66
68
    // Plot intersection
73
75
    }
74
76
 
75
77
    // Propagate sphere along the line t(1,1,1).
76
 
    for (VertexIterator vertex(sphere); !vertex.end(); ++vertex)
 
78
    for (VertexIterator vertex(sphere_mesh); !vertex.end(); ++vertex)
77
79
    {
78
80
      double* x = geometry.x(vertex->index());
79
81
      x[0] += dt;
90
92
  return 0;
91
93
}
92
94
 
93
 
 
94
95
#else
95
96
 
96
97
int main()
99
100
  return 0;
100
101
}
101
102
 
102
 
 
103
103
#endif