5#ifndef DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
6#define DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
13#include <dune/common/fvector.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
54 DUNE_THROW(NotImplemented,
"DuneBoundaryProjection::backup not overloaded!");
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;
139 typedef MultiLinearGeometry<
typename Base::CoordinateType::value_type,dim-1,dimworld> FaceMapping;
154 const std::vector< CoordinateType > &vertices,
155 const std::shared_ptr< BoundarySegment > &boundarySegment )
156 : faceMapping_( FaceMapping( type, vertices ) ),
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));
181 GeometryType type = faceMapping_.type();
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 );
191 buffer.write( (
const char *) &corner[ 0 ],
sizeof(
double)*CoordinateType::dimension );
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 )
221 buffer.read( (
char *) &vertices[ i ][ 0 ],
sizeof(
double)*CoordinateType::dimension );
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
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:33
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Include standard header files.
Definition: agrid.hh:60
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