5#ifndef DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
6#define DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
15#include <dune/geometry/multilineargeometry.hh>
24 template <
int dimworld>
25 struct DuneBoundaryProjection;
29 template <
int dimworld>
31 :
public BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > >
34 typedef BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > > BaseType;
35 typedef typename BaseType :: ObjectStreamType ObjectStreamType;
37 using BaseType :: restore;
38 using BaseType :: registerFactory;
51 virtual void backup( [[maybe_unused]] ObjectStreamType& buffer )
const
56 template <
class BufferImp>
57 void toBuffer( BufferImp& buffer )
const
63 template <
class BufferImp>
64 void toBuffer( MessageBufferIF< BufferImp > & buffer )
const
69 std::string data = str.str();
70 const size_t size = data.size();
72 for(
size_t i=0; i<
size; ++i )
73 buffer.write( data[ i ] );
76 template <
class BufferImp>
77 static std::unique_ptr< ThisType > restoreFromBuffer( BufferImp & buffer )
79 MessageBufferIF< BufferImp > buf( buffer );
80 return restoreFromBuffer( buf );
83 template <
class BufferImp>
84 static std::unique_ptr< ThisType > restoreFromBuffer( MessageBufferIF< BufferImp > & buffer )
90 for(
size_t i=0; i<
size; ++i )
91 buffer.read( data[ i ] );
94 str.write( data.c_str(),
size );
95 return BaseType::restore( str );
99 template <
int dimworld >
100 class BoundaryProjectionWrapper
101 :
public DuneBoundaryProjection< dimworld >
104 typedef DuneBoundaryProjection< dimworld > BaseType;
105 const BaseType& proj_;
111 BoundaryProjectionWrapper(
const BaseType& proje )
116 ~BoundaryProjectionWrapper () {}
119 CoordinateType operator() (
const CoordinateType& global)
const
121 return proj_( global );
129 template<
int dim,
int dimworld >
136 typedef typename Base :: ObjectStreamType ObjectStreamType;
153 const std::vector< CoordinateType > &vertices,
154 const std::shared_ptr< BoundarySegment > &boundarySegment )
156 boundarySegment_( boundarySegment )
160 : faceMapping_( readFaceMapping( buffer ) ),
167 return boundarySegment() ( faceMapping_.local( global ) );
172 return *boundarySegment_;
175 void backup( ObjectStreamType& buffer )
const
178 buffer.write( (
const char *) &key(),
sizeof(
int));
181 buffer.write( (
const char *) &type,
sizeof(
GeometryType) );
183 int corners = faceMapping_.
corners() ;
184 buffer.write( (
const char *) &corners,
sizeof(
int) );
187 for(
int i=0; i<corners; ++i )
189 corner = faceMapping_.
corner( i );
193 boundarySegment_->backup( buffer );
196 static void registerFactory()
200 key() = Base::template registerFactory< ThisType >();
211 FaceMapping readFaceMapping( ObjectStreamType& buffer )
214 buffer.read( (
char *) &type,
sizeof(GeometryType) );
216 buffer.read( (
char *) &corners,
sizeof(
int) );
217 std::vector< CoordinateType > vertices( corners, CoordinateType(0) );
218 for(
int i=0; i<corners; ++i )
222 return FaceMapping( type, vertices );
226 FaceMapping faceMapping_;
227 const std::shared_ptr< BoundarySegment > boundarySegment_;
237 template <
int dimworld>
238 struct CircleBoundaryProjection :
public DuneBoundaryProjection< dimworld >
241 typedef FieldVector< double, dimworld> CoordinateType;
244 CircleBoundaryProjection(
const double radius = std::sqrt( (
double)dimworld ))
245 : radius_( radius ) {}
248 virtual ~CircleBoundaryProjection() {}
251 virtual CoordinateType operator() (
const CoordinateType& global)
const
253 CoordinateType prj( global );
255 const double factor = radius_ / global.two_norm();
263 const double radius_;
Base class for grid boundary segments of arbitrary geometry.
Definition: boundaryprojection.hh:132
CoordinateType operator()(const CoordinateType &global) const
projection operator projection a global coordinate
Definition: boundaryprojection.hh:165
void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:175
BoundarySegmentWrapper(const GeometryType &type, const std::vector< CoordinateType > &vertices, const std::shared_ptr< BoundarySegment > &boundarySegment)
Definition: boundaryprojection.hh:152
typename Base::value_type value_type
The type of the elements stored in the vector.
Definition: fvector.hh:112
static constexpr int dimension
The size of this vector.
Definition: fvector.hh:106
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:33
generic geometry implementation based on corner coordinates
Definition: multilineargeometry.hh:181
Dune::GeometryType type() const
obtain the name of the reference element
Definition: multilineargeometry.hh:269
GlobalCoordinate corner(int i) const
obtain coordinates of the i-th corner
Definition: multilineargeometry.hh:275
int corners() const
obtain number of corners of the corresponding reference element
Definition: multilineargeometry.hh:272
Default exception for dummy implementations.
Definition: exceptions.hh:357
Describes the parallel communication interface class for MessageBuffers and DataHandles.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:94
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:32
virtual void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:51
virtual CoordinateType operator()(const CoordinateType &global) const =0
projection operator projection a global coordinate
virtual ~DuneBoundaryProjection()
destructor
Definition: boundaryprojection.hh:43
FieldVector< double, dimworld > CoordinateType
type of coordinate vector
Definition: boundaryprojection.hh:41