dune-fem 2.8.0
Loading...
Searching...
No Matches
registry.hh
Go to the documentation of this file.
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
14
15namespace Dune
16{
17
18 namespace Fem
19 {
20
21 // QuadratureStorageRegistry
22 // -------------------------
23
25 {
27
28 public:
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
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
50 {
52 }
53
55 {
57 }
58
59 private:
60 static inline void assertSingleThreadMode ( const bool );
61
62 public:
64 static void initialize ()
65 {
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
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
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
Definition: bindguard.hh:11
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: mpimanager.hh:436
Definition: registry.hh:25
static StorageListType & storageList()
Definition: registry.hh:49
static void initialize()
initialize static variables
Definition: registry.hh:64
static void unregisterStorage(StorageInterface &storage)
Definition: registry.hh:85
std::list< QuadratureInfo > QuadratureInfoListType
Definition: registry.hh:47
static void registerQuadrature(const Quadrature &quadrature, const GeometryType &type, std::size_t codim)
Definition: registry.hh:102
static void registerStorage(StorageInterface &storage)
Definition: registry.hh:70
static void registerQuadrature(const Quadrature &quadrature)
Definition: registry.hh:96
std::list< StorageInterface * > StorageListType
Definition: registry.hh:37
static QuadratureInfoListType & quadratureInfoList()
Definition: registry.hh:54
virtual ~StorageInterface()
Definition: registry.hh:31
virtual void cacheQuadrature(std::size_t id, std::size_t codim, std::size_t quadSize)=0
std::size_t codim
Definition: registry.hh:42
GeometryType type
Definition: registry.hh:44
std::size_t id
Definition: registry.hh:41
std::size_t size
Definition: registry.hh:43
int nop() const
obtain the number of integration points
Definition: quadrature.hh:295
GeometryType geometryType() const
obtain GeometryType for this integration point list
Definition: quadrature.hh:362
size_t id() const
obtain the identifier of the integration point list
Definition: quadrature.hh:327
actual interface class for quadratures
Definition: quadrature.hh:405
@ codimension
Definition: quadrature.hh:435
return singleton instance of given Object type.
Definition: singleton.hh:88