dune-grid  2.2.1
psurfaceboundary.hh
Go to the documentation of this file.
1 #ifndef PSURFACE_BOUNDARY_HH
2 #define PSURFACE_BOUNDARY_HH
3 
7 #include "../../../common/gridfactory.hh"
8 
9 #if HAVE_PSURFACE
10 #include <psurface/PSurface.h>
11 
12 namespace Dune {
13 
24  template <int dim>
25  class PSurfaceBoundary
26  {
27  dune_static_assert((dim==1 or dim==2), "PSurfaceBoundaries can only have dimensions 1 or 2!");
28 
29  public:
30 
32  class PSurfaceBoundarySegment : public Dune::BoundarySegment<dim+1>
33  {
34  public:
35 
41  PSurfaceBoundarySegment(const shared_ptr<PSurfaceBoundary<dim> >& psurfaceBoundary, int segment)
42  : psurfaceBoundary_(psurfaceBoundary),
43  segment_(segment)
44  {}
45 
47  virtual Dune::FieldVector<double, dim+1> operator()(const Dune::FieldVector<double,dim>& local) const {
48 
49  Dune::FieldVector<double, dim+1> result;
50 
51  // Transform local to barycentric coordinates
52  PSURFACE_NAMESPACE StaticVector<float,dim> barCoords;
53 
54  if (dim==2) {
55  barCoords[0] = 1 - local[0] - local[1];
56  barCoords[1] = local[0];
57  } else { // dim==1
58  barCoords[0] = 1 - local[0];
59  }
60 
61  PSURFACE_NAMESPACE StaticVector<float,dim+1> r;
62 
63  if (!psurfaceBoundary_->getPSurfaceObject()->positionMap(segment_, barCoords, r))
64  DUNE_THROW(Dune::GridError, "psurface::positionMap returned error code");
65 
66  for (int i=0; i<dim+1; i++)
67  result[i] = r[i];
68 
69  return result;
70  }
71 
72  shared_ptr<PSurfaceBoundary<dim> > psurfaceBoundary_;
73  int segment_;
74  };
75 
76 
77 
79  PSurfaceBoundary(PSURFACE_NAMESPACE PSurface<dim,float>* psurface)
80  : psurface_(psurface)
81  {}
82 
90  PSURFACE_NAMESPACE PSurface<dim,float>* getPSurfaceObject()
91  {
92  return psurface_.get();
93  }
94 
95  private:
96 
97  std::auto_ptr<PSURFACE_NAMESPACE PSurface<dim,float> > psurface_;
98 
99  };
100 
101 }
102 
103 #endif // #if HAVE_PSURFACE
104 #endif // #ifndef PSURFACE_BOUNDARY_HH