dune-grid  2.2.0
psurfaceboundary.hh
Go to the documentation of this file.
00001 #ifndef PSURFACE_BOUNDARY_HH
00002 #define PSURFACE_BOUNDARY_HH
00003 
00007 #include "../../../common/gridfactory.hh"
00008 
00009 #if HAVE_PSURFACE
00010 #include <psurface/PSurface.h>
00011 
00012 namespace Dune {
00013 
00024     template <int dim>
00025     class PSurfaceBoundary
00026     {
00027         dune_static_assert((dim==1 or dim==2), "PSurfaceBoundaries can only have dimensions 1 or 2!");
00028     
00029     public:
00030         
00032         class PSurfaceBoundarySegment : public Dune::BoundarySegment<dim+1>
00033         {
00034         public:
00035             
00041             PSurfaceBoundarySegment(const shared_ptr<PSurfaceBoundary<dim> >& psurfaceBoundary, int segment)
00042                 : psurfaceBoundary_(psurfaceBoundary),
00043                 segment_(segment)
00044             {}
00045 
00047             virtual Dune::FieldVector<double, dim+1> operator()(const Dune::FieldVector<double,dim>& local) const {
00048 
00049                 Dune::FieldVector<double, dim+1> result;
00050         
00051                 // Transform local to barycentric coordinates
00052                 PSURFACE_NAMESPACE StaticVector<float,dim> barCoords;
00053 
00054                 if (dim==2) {
00055                     barCoords[0] = 1 - local[0] - local[1];
00056                     barCoords[1] = local[0];
00057                 } else {  // dim==1
00058                     barCoords[0] = 1 - local[0];
00059                 }
00060 
00061                 PSURFACE_NAMESPACE StaticVector<float,dim+1> r; 
00062 
00063                 if (!psurfaceBoundary_->getPSurfaceObject()->positionMap(segment_, barCoords, r))
00064                     DUNE_THROW(Dune::GridError, "psurface::positionMap returned error code");
00065 
00066                 for (int i=0; i<dim+1; i++)
00067                     result[i] = r[i];
00068 
00069                 return result;
00070             }
00071 
00072             shared_ptr<PSurfaceBoundary<dim> > psurfaceBoundary_;
00073             int segment_;
00074         };
00075 
00076         
00077         
00079         PSurfaceBoundary(PSURFACE_NAMESPACE PSurface<dim,float>* psurface)
00080         : psurface_(psurface)
00081         {}
00082     
00090         PSURFACE_NAMESPACE PSurface<dim,float>* getPSurfaceObject()
00091         {
00092             return psurface_.get();
00093         }
00094         
00095     private:
00096     
00097         std::auto_ptr<PSURFACE_NAMESPACE PSurface<dim,float> > psurface_;
00098     
00099     };
00100 
00101 }
00102 
00103 #endif // #if HAVE_PSURFACE
00104 #endif // #ifndef PSURFACE_BOUNDARY_HH