DUNE-FEM (unstable)

registry.hh
1#ifndef DUNE_FEM_QUADRATURE_CACHING_REGISTRY_HH
2#define DUNE_FEM_QUADRATURE_CACHING_REGISTRY_HH
3
4// system includes
5#include <cstddef>
6#include <algorithm>
7#include <list>
8
9// dune-geometry includes
10#include <dune/geometry/type.hh>
11
12// dune-fem includes
13#include <dune/fem/storage/singleton.hh>
14
15namespace Dune
16{
17
18 namespace Fem
19 {
20
21 // QuadratureStorageRegistry
22 // -------------------------
23
24 class QuadratureStorageRegistry
25 {
26 typedef QuadratureStorageRegistry ThisType;
27
28 public:
29 struct StorageInterface
30 {
31 virtual ~StorageInterface () {}
32 virtual void cacheQuadrature ( std::size_t id, std::size_t codim, std::size_t quadSize ) = 0;
33 virtual GeometryType type () const = 0;
34 };
35
36 // private:
37 typedef std::list< StorageInterface * > StorageListType;
38
39 struct QuadratureInfo
40 {
41 std::size_t id;
42 std::size_t codim;
43 std::size_t size;
44 GeometryType type;
45 };
46
47 typedef std::list< QuadratureInfo > QuadratureInfoListType;
48
49 static StorageListType &storageList ()
50 {
52 }
53
54 static QuadratureInfoListType &quadratureInfoList ()
55 {
57 }
58
59 private:
60 static inline void assertSingleThreadMode ( const bool );
61
62 public:
64 static void initialize ()
65 {
66 storageList();
67 quadratureInfoList();
68 }
69
70 static void registerStorage ( StorageInterface &storage )
71 {
72 assertSingleThreadMode( false );
73
74 storageList().push_back( &storage );
75
76 const GeometryType type = storage.type();
77 for( QuadratureInfoListType::iterator it = quadratureInfoList().begin(); it != quadratureInfoList().end(); ++it )
78 {
79 // only cache shape functions for quadratures with same geometry type
80 if( type == it->type )
81 storage.cacheQuadrature( it->id, it->codim, it->size );
82 }
83 }
84
85 static void unregisterStorage ( StorageInterface &storage )
86 {
87 assertSingleThreadMode( false );
88
89 const StorageListType::iterator pos
90 = std::find( storageList().begin(), storageList().end(), &storage );
91 if( pos != storageList().end() )
92 storageList().erase( pos );
93 }
94
95 template< class Quadrature >
96 static void registerQuadrature ( const Quadrature &quadrature )
97 {
98 registerQuadrature( quadrature, quadrature.geometryType(), Quadrature::codimension );
99 }
100
101 template< class Quadrature >
102 static void registerQuadrature ( const Quadrature &quadrature,
103 const GeometryType &type, std::size_t codim )
104 {
105 assertSingleThreadMode( true );
106
107 QuadratureInfo quadInfo = { quadrature.id(), codim, std::size_t( quadrature.nop() ), type };
108 quadratureInfoList().push_back( quadInfo );
109
110 for( typename StorageListType::iterator it = storageList().begin(); it != storageList().end(); ++it )
111 {
112 // only cache shape functions for quadratures with same geometry type
113 if( (*it)->type() == type )
114 (*it)->cacheQuadrature( quadInfo.id, quadInfo.codim, quadInfo.size );
115 }
116 }
117 };
118
119 } // namespace Fem
120
121} // namespace Dune
122
123#include <dune/fem/misc/mpimanager.hh>
124
125namespace Dune
126{
127 namespace Fem
128 {
129 inline void QuadratureStorageRegistry::assertSingleThreadMode(const bool quad)
130 {
131 // make sure we work in single thread mode
132 // when quadratures are registered
133 if( ! MPIManager::singleThreadMode() )
134 {
135 const char* text = quad ? "registerQuadrature" : "registerStorage";
136 DUNE_THROW(SingleThreadModeError,"QuadratureStorageRegistry" << text << ": only call in single thread mode!");
137 }
138 }
139 }
140}
141#endif // #ifndef DUNE_FEM_QUADRATURE_CACHING_REGISTRY_HH
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:123
actual interface class for quadratures
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)