5#ifndef DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
6#define DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
15#include <dune/geometry/multilineargeometry.hh>
19#include <dune/grid/io/file/gmshreader.hh>
25 template <
int dimworld>
26 struct DuneBoundaryProjection;
30 template <
int dimworld>
32 :
public BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > >
35 typedef BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > > BaseType;
36 typedef typename BaseType :: ObjectStreamType ObjectStreamType;
38 using BaseType :: restore;
39 using BaseType :: registerFactory;
52 virtual void backup( [[maybe_unused]] ObjectStreamType& buffer )
const
57 template <
class BufferImp>
58 void toBuffer( BufferImp& buffer )
const
64 template <
class BufferImp>
65 void toBuffer( MessageBufferIF< BufferImp > & buffer )
const
70 std::string data = str.str();
71 const size_t size = data.size();
73 for(
size_t i=0; i<size; ++i )
74 buffer.write( data[ i ] );
77 template <
class BufferImp>
78 static std::unique_ptr< ThisType > restoreFromBuffer( BufferImp & buffer )
80 MessageBufferIF< BufferImp > buf( buffer );
81 return restoreFromBuffer( buf );
84 template <
class BufferImp>
85 static std::unique_ptr< ThisType > restoreFromBuffer( MessageBufferIF< BufferImp > & buffer )
91 for(
size_t i=0; i<size; ++i )
92 buffer.read( data[ i ] );
95 str.write( data.c_str(), size );
96 return BaseType::restore( str );
100 template <
int dimworld >
101 class BoundaryProjectionWrapper
102 :
public DuneBoundaryProjection< dimworld >
105 typedef DuneBoundaryProjection< dimworld > BaseType;
106 const BaseType& proj_;
112 BoundaryProjectionWrapper(
const BaseType& proje )
117 ~BoundaryProjectionWrapper () {}
120 CoordinateType operator() (
const CoordinateType& global)
const
122 return proj_( global );
130 template<
int dim,
int dimworld >
137 typedef typename Base :: ObjectStreamType ObjectStreamType;
154 const std::vector< CoordinateType > &vertices,
155 const std::shared_ptr< BoundarySegment > &boundarySegment )
157 boundarySegment_( boundarySegment )
161 : faceMapping_( readFaceMapping( buffer ) ),
168 return boundarySegment() ( faceMapping_.local( global ) );
173 return *boundarySegment_;
176 void backup( ObjectStreamType& buffer )
const
179 buffer.write( (
const char *) &key(),
sizeof(
int));
182 buffer.write( (
const char *) &type,
sizeof(
GeometryType) );
184 int corners = faceMapping_.
corners() ;
185 buffer.write( (
const char *) &corners,
sizeof(
int) );
188 for(
int i=0; i<corners; ++i )
190 corner = faceMapping_.
corner( i );
194 boundarySegment_->backup( buffer );
197 static void registerFactory()
201 key() = Base::template registerFactory< ThisType >();
212 FaceMapping readFaceMapping( ObjectStreamType& buffer )
215 buffer.read( (
char *) &type,
sizeof(GeometryType) );
217 buffer.read( (
char *) &corners,
sizeof(
int) );
218 std::vector< CoordinateType > vertices( corners, CoordinateType(0) );
219 for(
int i=0; i<corners; ++i )
223 return FaceMapping( type, vertices );
227 FaceMapping faceMapping_;
228 const std::shared_ptr< BoundarySegment > boundarySegment_;
238 template <
int dimworld>
239 struct CircleBoundaryProjection :
public DuneBoundaryProjection< dimworld >
242 typedef FieldVector< double, dimworld> CoordinateType;
245 CircleBoundaryProjection(
const double radius = std::sqrt( (
double)dimworld ))
246 : radius_( radius ) {}
249 virtual ~CircleBoundaryProjection() {}
252 virtual CoordinateType operator() (
const CoordinateType& global)
const
254 CoordinateType prj( global );
256 const double factor = radius_ / global.two_norm();
264 const double radius_;
Base class for grid boundary segments of arbitrary geometry.
Definition: boundaryprojection.hh:133
CoordinateType operator()(const CoordinateType &global) const
projection operator projection a global coordinate
Definition: boundaryprojection.hh:166
void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:176
BoundarySegmentWrapper(const GeometryType &type, const std::vector< CoordinateType > &vertices, const std::shared_ptr< BoundarySegment > &boundarySegment)
Definition: boundaryprojection.hh:153
static constexpr int dimension
The size of this vector.
Definition: fvector.hh:100
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
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:263
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, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:94
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:33
virtual void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:52
virtual CoordinateType operator()(const CoordinateType &global) const =0
projection operator projection a global coordinate
virtual ~DuneBoundaryProjection()
destructor
Definition: boundaryprojection.hh:44
FieldVector< double, dimworld > CoordinateType
type of coordinate vector
Definition: boundaryprojection.hh:42