dune-grid 2.8.0
Loading...
Searching...
No Matches
boundarysegment.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GRID_COMMON_BOUNDARY_SEGMENT_HH
4#define DUNE_GRID_COMMON_BOUNDARY_SEGMENT_HH
5
6#include <map>
7#include <sstream>
8
9#include <dune/common/singleton.hh>
10#include <dune/common/parameterizedobject.hh>
11#include <dune/common/fvector.hh>
12
17namespace Dune {
18
34 template< int dim, int dimworld = dim, class ctype = double >
35 struct BoundarySegment;
36
37 template <class BndSeg>
39 {
40 public:
41 // type of object stream used for storing boundary segment information
42 typedef std::stringstream ObjectStreamType ;
43
44 protected:
46 typedef BndSeg BoundarySegment;
47
49 typedef Dune::ParameterizedObjectFactory< std::unique_ptr< BoundarySegment > ( ObjectStreamType& ), int > FactoryType;
50
57 static std::unique_ptr< BoundarySegment > restore( ObjectStreamType& in )
58 {
59 int key = -1;
60 // read class key for restore
61 in.read( (char *) &key, sizeof( int ) );
62
63 // factory creates a unique_ptr which can be released later on
64 return factory().create( key, in );
65 }
66
67 template <class DerivedType>
68 static int registerFactory()
69 {
70 const int key = createKey();
71 // create factory method that produces unique_ptr
72 factory().template define< DerivedType >( key );
73 // return key for storage in derived class
74 return key;
75 }
76
77 private:
78 static int createKey()
79 {
80 static int key = 0;
81 return key++;
82 }
83
84 static FactoryType& factory()
85 {
86 return Dune::Singleton< FactoryType > :: instance();
87 }
88 };
89
90 template< int dim, int dimworld, class ctype >
91 struct BoundarySegment : public BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > >
92 {
95
96 typedef typename BaseType :: ObjectStreamType ObjectStreamType;
97
98 using BaseType :: restore;
100
102 virtual ~BoundarySegment() {}
103
106 virtual FieldVector< ctype, dimworld >
107 operator() ( const FieldVector< ctype, dim-1> &local ) const = 0;
108
112 virtual void backup( [[maybe_unused]] ObjectStreamType& buffer ) const
113 {
114 DUNE_THROW(NotImplemented,"BoundarySegment::backup needs to be overloaded!");
115 }
116 };
117
118
119} // end namespace Dune
120
121#endif
Include standard header files.
Definition: agrid.hh:58
BaseType::ObjectStreamType ObjectStreamType
Definition: boundarysegment.hh:96
BoundarySegment< dim, dimworld, ctype > ThisType
Definition: boundarysegment.hh:93
virtual void backup(ObjectStreamType &buffer) const
write BoundarySegment's data to stream buffer
Definition: boundarysegment.hh:112
BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > > BaseType
Definition: boundarysegment.hh:94
virtual FieldVector< ctype, dimworld > operator()(const FieldVector< ctype, dim-1 > &local) const =0
A function mapping local coordinates on a boundary segment to world coordinates.
virtual ~BoundarySegment()
Dummy virtual destructor.
Definition: boundarysegment.hh:102
Definition: boundarysegment.hh:39
static std::unique_ptr< BoundarySegment > restore(ObjectStreamType &in)
create an object of BoundarySegment type from a previously registered factory linked to key.
Definition: boundarysegment.hh:57
Dune::ParameterizedObjectFactory< std::unique_ptr< BoundarySegment >(ObjectStreamType &), int > FactoryType
type of factory creating a unique_ptr from an ObjectStreamType
Definition: boundarysegment.hh:49
BndSeg BoundarySegment
type of BoundarySegment interface class
Definition: boundarysegment.hh:46
std::stringstream ObjectStreamType
Definition: boundarysegment.hh:42
static int registerFactory()
Definition: boundarysegment.hh:68