Dune Core Modules (2.9.1)

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
12#include <dune/common/parameterizedobject.hh>
14
19namespace Dune {
20
36 template< int dim, int dimworld = dim, class ctype = double >
37 struct BoundarySegment;
38
39 template <class BndSeg>
40 class BoundarySegmentBackupRestore
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 {
89 }
90 };
91
92 template< int dim, int dimworld, class ctype >
93 struct BoundarySegment : public BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > >
94 {
95 typedef BoundarySegment< dim, dimworld, ctype > ThisType;
96 typedef BoundarySegmentBackupRestore< BoundarySegment< dim, dimworld, ctype > > BaseType;
97
98 typedef typename BaseType :: ObjectStreamType ObjectStreamType;
99
100 using BaseType :: restore;
101 using BaseType :: registerFactory;
102
104 virtual ~BoundarySegment() {}
105
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
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Default exception for dummy implementations.
Definition: exceptions.hh:263
A factory class for parameterized objects.
Definition: parameterizedobject.hh:36
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition: singleton.hh:70
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:218
Dune namespace.
Definition: alignedallocator.hh:13
Useful wrapper for creating singletons.
virtual void backup(ObjectStreamType &buffer) const
write BoundarySegment's data to stream buffer
Definition: boundarysegment.hh:114
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)