Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
geom_provider.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__LIB_DISC__SPATIAL_DISC__DISC_UTIL__GEOM_PROVIDER__
34#define __H__UG__LIB_DISC__SPATIAL_DISC__DISC_UTIL__GEOM_PROVIDER__
35
36#include <map>
38
39namespace ug{
40
41
43
50template <typename TGeom>
52{
53 public:
55
61 static const bool staticLocalData = TGeom::staticLocalData;
62
63 protected:
66
69
73 return inst;
74 }
75
78 LFEIDandQuadOrder(const LFEID lfeID, const int order)
79 : m_lfeID(lfeID), m_order(order) {}
80
82 bool operator<(const LFEIDandQuadOrder& v) const
83 {
84 if(m_lfeID != v.m_lfeID) return m_lfeID < v.m_lfeID;
85 else return m_order < v.m_order;
86 }
87
89 const int m_order;
90 };
91
93 typedef std::map<LFEIDandQuadOrder, TGeom*> MapType;
95
97 static TGeom& get_class(const LFEID lfeID, const int quadOrder) {
98
99 LFEIDandQuadOrder key(lfeID, quadOrder);
100
101 typedef std::pair<typename MapType::iterator,bool> ret_type;
102 ret_type ret = m_mLFEIDandOrder.insert(std::pair<LFEIDandQuadOrder,TGeom*>(key,NULL));
103
104 // newly inserted, need construction of data
105 if(ret.second == true){
106 if(ret.first->second != NULL){
107 UG_THROW("Newly inserted element must have Pointer = NULL");
108 }
109 else{
110 ret.first->second = new TGeom();
111 }
112 }
113
114 return *ret.first->second;
115 }
116
118 static void clear_geoms(){
119 typedef typename std::map<LFEIDandQuadOrder, TGeom*>::iterator MapIter;
120 for(MapIter iter = m_mLFEIDandOrder.begin(); iter != m_mLFEIDandOrder.end(); ++iter)
121 if(iter->second)
122 delete iter->second;
123
124 m_mLFEIDandOrder.clear();
125 }
126
127 public:
129 typedef TGeom Type;
130
132 static inline TGeom& get(const LFEID lfeID, const int quadOrder){
133 // in case of static data, use only one object
134 if(staticLocalData) return get();
135
136 // return the object based on identifier
137 return inst().get_class(lfeID, quadOrder);
138 }
139
141 static inline TGeom& get(){
142 static TGeom inst;
143 if(!staticLocalData)
144 UG_THROW("GeomProvider: accessing geometry without keys, but"
145 " geometry may change local data. Use access by keys instead.");
146 return inst;
147 }
148
150 static inline void clear(){
151 inst().clear_geoms();
152 }
153};
154
155template <typename TGeom>
156std::map<typename GeomProvider<TGeom>::LFEIDandQuadOrder, TGeom*> GeomProvider<TGeom>::m_mLFEIDandOrder
157 = std::map<typename GeomProvider<TGeom>::LFEIDandQuadOrder, TGeom*>();
158
159
160} // end namespace ug
161
162#endif /* __H__UG__LIB_DISC__SPATIAL_DISC__DISC_UTIL__GEOM_PROVIDER__ */
Geom Provider, holding a single instance of a geometry.
Definition geom_provider.h:52
static TGeom & get(const LFEID lfeID, const int quadOrder)
returns a singleton based on the identifier
Definition geom_provider.h:132
GeomProvider()
private constructor
Definition geom_provider.h:65
static GeomProvider< TGeom > & inst()
singleton provider
Definition geom_provider.h:71
static TGeom & get_class(const LFEID lfeID, const int quadOrder)
returns class based on identifier
Definition geom_provider.h:97
static void clear_geoms()
clears all instances
Definition geom_provider.h:118
TGeom Type
type of provided object
Definition geom_provider.h:129
static TGeom & get()
returns a singleton based on the identifier
Definition geom_provider.h:141
static const bool staticLocalData
flag indicating if local data may change
Definition geom_provider.h:61
~GeomProvider()
destructor
Definition geom_provider.h:68
static void clear()
clears all singletons
Definition geom_provider.h:150
static MapType m_mLFEIDandOrder
Definition geom_provider.h:94
std::map< LFEIDandQuadOrder, TGeom * > MapType
vector holding instances
Definition geom_provider.h:93
Identifier for Local Finite Elements.
Definition local_finite_element_id.h:98
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
struct to sort keys
Definition geom_provider.h:77
const LFEID m_lfeID
Definition geom_provider.h:88
const int m_order
Definition geom_provider.h:89
bool operator<(const LFEIDandQuadOrder &v) const
operator <
Definition geom_provider.h:82
LFEIDandQuadOrder(const LFEID lfeID, const int order)
Definition geom_provider.h:78