dune-grid 2.9.0
boundarysegment.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_GRID_COMMON_BOUNDARY_SEGMENT_HH
6#define DUNE_GRID_COMMON_BOUNDARY_SEGMENT_HH
7
8#include <map>
9#include <sstream>
10
11#include <dune/common/singleton.hh>
12#include <dune/common/parameterizedobject.hh>
13#include <dune/common/fvector.hh>
14
19namespace Dune {
20
36 template< int dim, int dimworld = dim, class ctype = double >
37 struct BoundarySegment;
38
39 template <class BndSeg>
41 {
42 public:
43 // type of object stream used for storing boundary segment information
44 typedef std::stringstream ObjectStreamType ;
45
46 protected:
48 typedef BndSeg BoundarySegment;
49
51 typedef Dune::ParameterizedObjectFactory< std::unique_ptr< BoundarySegment > ( ObjectStreamType& ), int > FactoryType;
52
59 static std::unique_ptr< BoundarySegment > restore( ObjectStreamType& in )
60 {
61 int key = -1;
62 // read class key for restore
63 in.read( (char *) &key, sizeof( int ) );
64
65 // factory creates a unique_ptr which can be released later on
66 return factory().create( key, in );
67 }
68
69 template <class DerivedType>
70 static int registerFactory()
71 {
72 const int key = createKey();
73 // create factory method that produces unique_ptr
74 factory().template define< DerivedType >( key );
75 // return key for storage in derived class
76 return key;
77 }
78
79 private:
80 static int createKey()
81 {
82 static int key = 0;
83 return key++;
84 }
85
86 static FactoryType& factory()
87 {
88 return Dune::Singleton< FactoryType > :: instance();
89 }
90 };
91
92 template< int dim, int dimworld, class ctype >
93 struct BoundarySegment : public BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > >
94 {
97
99
100 using BaseType :: restore;
102
104 virtual ~BoundarySegment() {}
105
108 virtual FieldVector< ctype, dimworld >
109 operator() ( const FieldVector< ctype, dim-1> &local ) const = 0;
110
114 virtual void backup( [[maybe_unused]] ObjectStreamType& buffer ) const
115 {
116 DUNE_THROW(NotImplemented,"BoundarySegment::backup needs to be overloaded!");
117 }
118 };
119
120
121} // end namespace Dune
122
123#endif
Include standard header files.
Definition: agrid.hh:60
BaseType::ObjectStreamType ObjectStreamType
Definition: boundarysegment.hh:98
BoundarySegment< dim, dimworld, ctype > ThisType
Definition: boundarysegment.hh:95
virtual void backup(ObjectStreamType &buffer) const
write BoundarySegment's data to stream buffer
Definition: boundarysegment.hh:114
BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > > BaseType
Definition: boundarysegment.hh:96
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:104
Definition: boundarysegment.hh:41
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:59
Dune::ParameterizedObjectFactory< std::unique_ptr< BoundarySegment >(ObjectStreamType &), int > FactoryType
type of factory creating a unique_ptr from an ObjectStreamType
Definition: boundarysegment.hh:51
BndSeg BoundarySegment
type of BoundarySegment interface class
Definition: boundarysegment.hh:48
std::stringstream ObjectStreamType
Definition: boundarysegment.hh:44
static int registerFactory()
Definition: boundarysegment.hh:70