Dune Core Modules (2.7.1)

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 
10 #include <dune/common/parameterizedobject.hh>
11 #include <dune/common/fvector.hh>
12 
17 namespace Dune {
18 
34  template< int dim, int dimworld = dim, class ctype = double >
35  struct BoundarySegment;
36 
37  template <class BndSeg>
38  class BoundarySegmentBackupRestore
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  {
87  }
88  };
89 
90  template< int dim, int dimworld, class ctype >
91  struct BoundarySegment : public BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > >
92  {
93  typedef BoundarySegment< dim, dimworld, ctype > ThisType;
94  typedef BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > > BaseType;
95 
96  typedef typename BaseType :: ObjectStreamType ObjectStreamType;
97 
98  using BaseType :: restore;
99  using BaseType :: registerFactory;
100 
102  virtual ~BoundarySegment() {}
103 
107  operator() ( const FieldVector< ctype, dim-1> &local ) const = 0;
108 
112  virtual void backup( 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
Default exception for dummy implementations.
Definition: exceptions.hh:261
A factory class for parameterized objects.
Definition: parameterizedobject.hh:34
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition: singleton.hh:68
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:14
Useful wrapper for creating singletons.
virtual void backup(ObjectStreamType &buffer) const
write BoundarySegment's data to stream buffer
Definition: boundarysegment.hh:112
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)