3#ifndef DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
4#define DUNE_GRID_COMMON_BOUNDARYPROJECTION_HH
13#include <dune/geometry/multilineargeometry.hh>
17#include <dune/grid/io/file/gmshreader.hh>
23 template <
int dimworld>
24 struct DuneBoundaryProjection;
28 template <
int dimworld>
30 :
public BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > >
33 typedef BoundarySegmentBackupRestore< DuneBoundaryProjection< dimworld > > BaseType;
34 typedef typename BaseType :: ObjectStreamType ObjectStreamType;
36 using BaseType :: restore;
37 using BaseType :: registerFactory;
50 virtual void backup( [[maybe_unused]] ObjectStreamType& buffer )
const
55 template <
class BufferImp>
56 void toBuffer( BufferImp& buffer )
const
62 template <
class BufferImp>
63 void toBuffer( MessageBufferIF< BufferImp > & buffer )
const
68 std::string data = str.str();
69 const size_t size = data.size();
71 for(
size_t i=0; i<size; ++i )
72 buffer.write( data[ i ] );
75 template <
class BufferImp>
76 static std::unique_ptr< ThisType > restoreFromBuffer( BufferImp & buffer )
78 MessageBufferIF< BufferImp > buf( buffer );
79 return restoreFromBuffer( buf );
82 template <
class BufferImp>
83 static std::unique_ptr< ThisType > restoreFromBuffer( MessageBufferIF< BufferImp > & buffer )
89 for(
size_t i=0; i<size; ++i )
90 buffer.read( data[ i ] );
93 str.write( data.c_str(), size );
94 return BaseType::restore( str );
98 template <
int dimworld >
99 class BoundaryProjectionWrapper
100 :
public DuneBoundaryProjection< dimworld >
103 typedef DuneBoundaryProjection< dimworld > BaseType;
104 const BaseType& proj_;
110 BoundaryProjectionWrapper(
const BaseType& proje )
115 ~BoundaryProjectionWrapper () {}
118 CoordinateType operator() (
const CoordinateType& global)
const
120 return proj_( global );
128 template<
int dim,
int dimworld >
135 typedef typename Base :: ObjectStreamType ObjectStreamType;
152 const std::vector< CoordinateType > &vertices,
153 const std::shared_ptr< BoundarySegment > &boundarySegment )
155 boundarySegment_( boundarySegment )
159 : faceMapping_( readFaceMapping( buffer ) ),
166 return boundarySegment() ( faceMapping_.local( global ) );
171 return *boundarySegment_;
174 void backup( ObjectStreamType& buffer )
const
177 buffer.write( (
const char *) &key(),
sizeof(
int));
180 buffer.write( (
const char *) &type,
sizeof(
GeometryType) );
182 int corners = faceMapping_.
corners() ;
183 buffer.write( (
const char *) &corners,
sizeof(
int) );
186 for(
int i=0; i<corners; ++i )
188 corner = faceMapping_.
corner( i );
192 boundarySegment_->backup( buffer );
195 static void registerFactory()
199 key() = Base::template registerFactory< ThisType >();
210 FaceMapping readFaceMapping( ObjectStreamType& buffer )
213 buffer.read( (
char *) &type,
sizeof(GeometryType) );
215 buffer.read( (
char *) &corners,
sizeof(
int) );
216 std::vector< CoordinateType > vertices( corners, CoordinateType(0) );
217 for(
int i=0; i<corners; ++i )
221 return FaceMapping( type, vertices );
225 FaceMapping faceMapping_;
226 const std::shared_ptr< BoundarySegment > boundarySegment_;
236 template <
int dimworld>
237 struct CircleBoundaryProjection :
public DuneBoundaryProjection< dimworld >
240 typedef FieldVector< double, dimworld> CoordinateType;
243 CircleBoundaryProjection(
const double radius = std::sqrt( (
double)dimworld ))
244 : radius_( radius ) {}
247 virtual ~CircleBoundaryProjection() {}
250 virtual CoordinateType operator() (
const CoordinateType& global)
const
252 CoordinateType prj( global );
254 const double factor = radius_ / global.two_norm();
262 const double radius_;
Base class for grid boundary segments of arbitrary geometry.
Definition: boundaryprojection.hh:131
CoordinateType operator()(const CoordinateType &global) const
projection operator projection a global coordinate
Definition: boundaryprojection.hh:164
void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:174
BoundarySegmentWrapper(const GeometryType &type, const std::vector< CoordinateType > &vertices, const std::shared_ptr< BoundarySegment > &boundarySegment)
Definition: boundaryprojection.hh:151
@ dimension
The size of this vector.
Definition: fvector.hh:102
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:31
generic geometry implementation based on corner coordinates
Definition: multilineargeometry.hh:179
Dune::GeometryType type() const
obtain the name of the reference element
Definition: multilineargeometry.hh:261
GlobalCoordinate corner(int i) const
obtain coordinates of the i-th corner
Definition: multilineargeometry.hh:267
int corners() const
obtain number of corners of the corresponding reference element
Definition: multilineargeometry.hh:264
Default exception for dummy implementations.
Definition: exceptions.hh:261
Describes the parallel communication interface class for MessageBuffers and DataHandles.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
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:216
Dune namespace.
Definition: alignedallocator.hh:11
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:92
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:31
virtual void backup(ObjectStreamType &buffer) const
write DuneBoundaryProjection's data to stream buffer
Definition: boundaryprojection.hh:50
virtual CoordinateType operator()(const CoordinateType &global) const =0
projection operator projection a global coordinate
virtual ~DuneBoundaryProjection()
destructor
Definition: boundaryprojection.hh:42
FieldVector< double, dimworld > CoordinateType
type of coordinate vector
Definition: boundaryprojection.hh:40