1 #ifndef DUNE_ALU_BNDPROJECTION_HH
2 #define DUNE_ALU_BNDPROJECTION_HH
3 
4 #include <memory>
5 
6 #include <dune/common/exceptions.hh>
7 
8 namespace Dune {
9 
10   //! \brief ALUGrid boundary projection implementation
11   //!  DuneBndProjection has to fulfil the DuneBoundaryProjection interface
12   template < class GridImp, class ctype = double >
13   class ALUGridBoundaryProjection : public GridImp :: ALUGridVertexProjectionType
14   {
15     typedef typename GridImp :: ALUGridVertexProjectionType   BaseType;
16     typedef ALUGridBoundaryProjection< GridImp, ctype >      ThisType;
17 
18     typedef GridImp GridType;
19     // type of double coordinate vector
20     typedef ctype coord_t[ 3 ];
21 
22     typedef typename BaseType::BufferType  BufferType;
23 
24   public:
25     //! type of boundary projection
26     typedef typename GridType :: DuneBoundaryProjectionType DuneBoundaryProjectionType;
27 
28     typedef std::unique_ptr< const DuneBoundaryProjectionType >  DuneBoundaryProjectionPointerType;
29 
30 
31     // type of projection (i.e. integer identifier)
32     typedef typename BaseType :: ProjectionType  ProjectionType;
33 
34     using BaseType :: none;
35     using BaseType :: global;
36     using BaseType :: surface;
37     using BaseType :: segment;
38 
39   protected:
40     DuneBoundaryProjectionPointerType projection_;
41     ProjectionType projectionType_;
42 
43   public:
44 
45     //! type of coordinate vector
46     typedef typename DuneBoundaryProjectionType :: CoordinateType CoordinateType;
47 
48     //! constructor storing reference to boundary projection implementation
ALUGridBoundaryProjection(const DuneBoundaryProjectionType * ptr,const ProjectionType pt=BaseType::none)49     ALUGridBoundaryProjection( const DuneBoundaryProjectionType* ptr, const ProjectionType pt = BaseType::none )
50       : projection_( ptr ), projectionType_( (projection_) ? pt : BaseType::none )
51     {
52     }
53 
projectionType() const54     ProjectionType projectionType() const { return projectionType_; }
55 
56     //! (old) method projection vertices defaults to segment 0
operator ()(const coord_t & orig,coord_t & prj) const57     int operator () (const coord_t &orig,
58                      coord_t &prj) const
59     {
60       return this->operator()( orig, 0, prj);
61     }
62 
63     //! projection operator
operator ()(const coord_t & orig,const int segmentId,coord_t & prj) const64     int operator () (const coord_t &orig,
65                      const int segmentId,
66                      coord_t &prj) const
67     {
68       // if pointer is zero we do nothing, i.e. identity mapping
69       if( projection_ )
70       {
71         // call projection operator
72         reinterpret_cast<CoordinateType &> (* (&prj[0])) =
73           (*projection_)( reinterpret_cast<const CoordinateType &> (* (&orig[0])) );
74       }
75 
76       // return 1 for success
77       return 1;
78     }
79 
backup(BufferType & os) const80     void backup( BufferType& os ) const
81     {
82       assert( !projection_ ? (projectionType() == BaseType::none) : true );
83 
84       // store whether projection is global (i.e. exists one on all cores)
85       if( !projection_ )
86         DUNE_THROW(InvalidStateException,"ALUGridBoundaryProjection::backup: pointer to projection is invalid");
87 
88       projection_->toBuffer( os );
89     }
90 
registerFactory()91     static void registerFactory()
92     {
93       BaseType :: setFactoryMethod( &factory );
94     }
95 
factory(BufferType & os)96     static BaseType* factory( BufferType& os )
97     {
98       return new ThisType( DuneBoundaryProjectionType::restoreFromBuffer( os ).release(), segment );
99     }
100   };
101 
102 } // end namespace Dune
103 #endif
104