Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
periodic_boundary_manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 * Author: Martin Scherer
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 PERIODIC_IDENTIFIER_H_
34#define PERIODIC_IDENTIFIER_H_
35
36#include "lib_grid/grid/grid.h"
37#include "lib_grid/multi_grid.h"
39
40#include <set>
41
42namespace ug {
43
45
49public:
50 virtual ~IIdentifier() {}
51 virtual bool match(Vertex*, Vertex*) = 0;
52 virtual bool match(Edge*, Edge*) = 0;
53 virtual bool match(Face*, Face*) = 0;
54 virtual bool match(Volume*, Volume*) {UG_THROW("not impled, because volume identification is not supported.")}
55};
56
58
64template<class TPosAA> class ParallelShiftIdentifier: public IIdentifier {
65public:
66 virtual bool match(Vertex* v1, Vertex* v2) {return match_impl(v1, v2);}
67 virtual bool match(Edge* e1, Edge* e2) {return match_impl(e1, e2);}
68 virtual bool match(Face* f1, Face* f2) {return match_impl(f1, f2);}
69
71 typedef typename TPosAA::ValueType AttachmentType;
72 ParallelShiftIdentifier(TPosAA& aa) : m_aaPos(aa) {}
74protected:
77 TPosAA& m_aaPos;
78 template<class TElem> bool match_impl(TElem*, TElem*) const;
79};
80
81
82//template<class TPosAA, int dim> class TransformationBasedIdentifier : public IIdentifier {
83//public:
84// TransformationBasedIdentifier(TPosAA& aa) : m_aaPos(aa) {}
85// void setTransformation(MathMatrix<dim,dim>& T) {this->T = T;}
86//
87// virtual bool match(Vertex*, Vertex*);
88// virtual bool match(Edge*, Edge*);
89// virtual bool match(Face*, Face*);
90//protected:
91// MathMatrix<dim,dim> T;
92// TPosAA& m_aaPos;
93//};
94
96
100public:
101
105 template <class TElem, class Container = std::vector<TElem*> >
106 class Group
107 {
108 public:
109 typedef Container SlaveContainer;
110 typedef typename Container::iterator SlaveIterator;
111 // the set typedefs are used to check for periodicity after identification
112 typedef typename std::pair<TElem*, TElem*> master_slave_pair;
113 typedef typename std::set<master_slave_pair> unique_pairs;
114
115 Group(TElem* m = NULL) : m_master(m) {}
116
117 void add_slave(TElem* e) {
118 UG_ASSERT(e, "add_slave: slave not valid");
119 UG_ASSERT(e != m_master, "element already master!");
120 m_slaves.push_back(e); }
121
122 Container& get_slaves() { return m_slaves; }
123 TElem* m_master;
124
125 protected:
126 Container m_slaves;
127 };
128
132
135
136 // sets grid and inits group info attachment accessors
137 void set_grid(Grid* g);
138 Grid* get_grid() const;
139
140 // sets the subset handler to use for element lookup
141// void set_subset_handler(ISubsetHandler* sh);
142
144
152 template <class TElem> void identify(TElem* e1, TElem* e2, IIdentifier& i);
153
154 template <class TElem> bool is_periodic(TElem* e) const;
155 template <class TElem> bool is_slave(TElem*) const;
156 template <class TElem> bool is_master(TElem*) const;
157 template <class TElem> TElem* master(TElem* e) const;
158 template <class TElem> typename Group<TElem>::SlaveContainer* slaves(
159 TElem* e) const;
160 template <class TElem> void print_identification() const;
161
162
164 virtual void grid_to_be_destroyed(Grid* grid);
165 virtual void vertex_created(Grid* grid, Vertex* vrt,
166 GridObject* pParent = NULL,
167 bool replacesParent = false);
168
169 virtual void edge_created(Grid* grid, Edge* e,
170 GridObject* pParent = NULL,
171 bool replacesParent = false);
172
173 virtual void face_created(Grid* grid, Face* f,
174 GridObject* pParent = NULL,
175 bool replacesParent = false);
176
177 virtual void vertex_to_be_erased(Grid* grid, Vertex* vrt,
178 Vertex* replacedBy = NULL);
179
180 virtual void edge_to_be_erased(Grid* grid, Edge* e,
181 Edge* replacedBy = NULL);
182
183 virtual void face_to_be_erased(Grid* grid, Face* f,
184 Face* replacedBy = NULL);
185
188 const GridObjectCollection& goc2,
189 ISubsetHandler* sh = NULL);
190
194 void validity_check();
195
201// void set_identifier(SmartPtr<IIdentifier> i, size_t si);
202
203protected:
204 // no copy construction allowed
206
209
211// ISubsetHandler* m_pSH;
212
214
218// std::vector<SmartPtr<IIdentifier> > m_vIdentifier;
219
224
229
231 template <class TElem> void make_slave(Group<TElem>* g, TElem* e);
232 template <class TElem> bool remove_slave(TElem* slave);
233
234 // make e a master of g
235 template <class TElem> void make_master(Group<TElem>* g, TElem* e);
236
237 template <class TElem> void merge_groups(Group<TElem>* g0, Group<TElem>* g1);
238
239 // get typed attachment accessor for group attachment
240 template <class TElem>
243
244 template <class TElem>
247
248 // get typed attachment accessor for periodic status attachment
249 template <class TElem>
252
253 template <class TElem>
256
257 // gets group of given element e
258 template <class TElem> Group<TElem>* group(TElem* e) const;
259 // set group attachment to element e
260 template <class TElem> void set_group(Group<TElem>* g, TElem* e);
261 template <class TElem> void remove_group(Group<TElem>* g);
262
264 template <class TElem>
265 void replace_parent(TElem* e, TElem* pParent);
266
268 template <class TElem, class TParent>
269 void handle_creation(TElem* e, TParent* pParent);
270
272 template <class TElem>
273 void handle_deletion(TElem* e, TElem* replacedBy);
274
276 template <class TElem>
277 void handle_creation_cast_wrapper(TElem* e, GridObject* parent, bool replacesParent);
278
279 template <class TElem, class TIterator>
281 TIterator begin,
282 TIterator end,
283 typename Group<TElem>::unique_pairs& s,
284 ISubsetHandler* sh);
285
286 template <class TElem>
287 void validity_check();
288
289};
290
292
296template <class TElem,class TAttachment>
298{
299 public:
300 typedef typename TAttachment::ValueType ValueType;
303
305
306 PeriodicAttachmentAccessor(Grid& g, TAttachment& a) : m_pbm(NULL)
307 {
308 access(g, a);
309 }
310
312
313 bool access(Grid& g, TAttachment& a)
314 {
316 return m_aa.access(g, a);
317 }
318
319 RefType operator[](TElem* e) {
320 if(m_pbm && m_pbm->is_slave(e))
321 return m_aa[m_pbm->master(e)];
322 return m_aa[e];
323 }
324
325 ConstRefType operator[](TElem* e) const {
326 if(m_pbm && m_pbm->is_slave(e))
327 return m_aa[m_pbm->master(e)];
328 return m_aa[e];
329 }
330
331 private:
334};
335
336
346template <class TDomain>
347void IdentifySubsets(TDomain& dom, int sInd1, int sInd2);
348
358template <class TDomain>
359void IdentifySubsets(TDomain& dom, const char* sName1, const char* sName2);
360
361} // end of namespace ug
362
363// include implementation
365
366#endif /* PERIODIC_IDENTIFIER_H_ */
Base-class for edges.
Definition grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition grid_base_objects.h:510
the generic attachment-accessor for access to grids attachment pipes.
Definition grid.h:182
Manages the elements of a grid and their interconnection.
Definition grid.h:132
PeriodicBoundaryManager * periodic_boundary_manager()
returns a pointer to the associated periodic boundary manager.
Definition grid.cpp:209
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition grid_object_collection.h:96
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition grid_base_objects.h:157
Definition grid_observer.h:80
Interface to match periodic geometric elements.
Definition periodic_boundary_manager.h:48
virtual bool match(Volume *, Volume *)
Definition periodic_boundary_manager.h:54
virtual bool match(Vertex *, Vertex *)=0
virtual ~IIdentifier()
Definition periodic_boundary_manager.h:50
virtual bool match(Face *, Face *)=0
virtual bool match(Edge *, Edge *)=0
Definition subset_handler_interface.h:223
Definition multi_grid.h:72
This class matches geometric elements which are parallel translated.
Definition periodic_boundary_manager.h:64
virtual ~ParallelShiftIdentifier()
Definition periodic_boundary_manager.h:70
TPosAA & m_aaPos
Definition periodic_boundary_manager.h:77
ParallelShiftIdentifier(TPosAA &aa)
Definition periodic_boundary_manager.h:72
TPosAA::ValueType AttachmentType
Definition periodic_boundary_manager.h:71
AttachmentType m_shift_opposite
Definition periodic_boundary_manager.h:76
AttachmentType m_shift
Definition periodic_boundary_manager.h:75
virtual bool match(Face *f1, Face *f2)
Definition periodic_boundary_manager.h:68
void set_shift(AttachmentType &shift)
Definition periodic_boundary_manager.h:73
virtual bool match(Vertex *v1, Vertex *v2)
Definition periodic_boundary_manager.h:66
virtual bool match(Edge *e1, Edge *e2)
Definition periodic_boundary_manager.h:67
bool match_impl(TElem *, TElem *) const
Definition periodic_boundary_manager_impl.hpp:53
Accesses attachements with consideration to periodic boundaries.
Definition periodic_boundary_manager.h:298
PeriodicAttachmentAccessor(PeriodicBoundaryManager &pbm)
Definition periodic_boundary_manager.h:311
bool access(Grid &g, TAttachment &a)
Definition periodic_boundary_manager.h:313
RefType operator[](TElem *e)
Definition periodic_boundary_manager.h:319
attachment_value_traits< ValueType >::reference RefType
Definition periodic_boundary_manager.h:301
ConstRefType operator[](TElem *e) const
Definition periodic_boundary_manager.h:325
PeriodicAttachmentAccessor()
Definition periodic_boundary_manager.h:304
attachment_value_traits< ValueType >::const_reference ConstRefType
Definition periodic_boundary_manager.h:302
PeriodicAttachmentAccessor(Grid &g, TAttachment &a)
Definition periodic_boundary_manager.h:306
PeriodicBoundaryManager * m_pbm
Definition periodic_boundary_manager.h:333
TAttachment::ValueType ValueType
Definition periodic_boundary_manager.h:300
Grid::AttachmentAccessor< TElem, TAttachment > m_aa
Definition periodic_boundary_manager.h:332
Definition periodic_boundary_manager.h:107
TElem * m_master
Definition periodic_boundary_manager.h:123
std::set< master_slave_pair > unique_pairs
Definition periodic_boundary_manager.h:113
Group(TElem *m=NULL)
Definition periodic_boundary_manager.h:115
Container m_slaves
Definition periodic_boundary_manager.h:126
Container SlaveContainer
Definition periodic_boundary_manager.h:109
Container & get_slaves()
Definition periodic_boundary_manager.h:122
Container::iterator SlaveIterator
Definition periodic_boundary_manager.h:110
std::pair< TElem *, TElem * > master_slave_pair
Definition periodic_boundary_manager.h:112
void add_slave(TElem *e)
Definition periodic_boundary_manager.h:117
Definition periodic_boundary_manager.h:99
void set_grid(Grid *g)
Definition periodic_boundary_manager.cpp:46
const Grid::AttachmentAccessor< TElem, Attachment< Group< TElem > * > > & get_group_accessor() const
virtual void face_to_be_erased(Grid *grid, Face *f, Face *replacedBy=NULL)
Notified whenever an element of the given type is erased from the given grid.
Definition periodic_boundary_manager.cpp:245
void handle_creation_cast_wrapper(TElem *e, GridObject *parent, bool replacesParent)
casts parent pointer to exact type before calling handle_creation
Definition periodic_boundary_manager_impl.hpp:344
void identify(TElem *e1, TElem *e2, IIdentifier &i)
Definition periodic_boundary_manager_impl.hpp:78
Grid::AttachmentAccessor< Edge, Attachment< PeriodicStatus > > m_aaPeriodicStatusEDG
Definition periodic_boundary_manager.h:227
bool is_master(TElem *) const
Definition periodic_boundary_manager_impl.hpp:504
void check_elements_periodicity(TIterator begin, TIterator end, typename Group< TElem >::unique_pairs &s, ISubsetHandler *sh)
Definition periodic_boundary_manager_impl.hpp:533
void remove_group(Group< TElem > *g)
Definition periodic_boundary_manager_impl.hpp:450
virtual void face_created(Grid *grid, Face *f, GridObject *pParent=NULL, bool replacesParent=false)
Notified whenever a new element of the given type is created in the given grid.
Definition periodic_boundary_manager.cpp:230
virtual void grid_to_be_destroyed(Grid *grid)
grid observation methods
Definition periodic_boundary_manager.cpp:199
PeriodicBoundaryManager(const PeriodicBoundaryManager &)
Definition periodic_boundary_manager.h:205
bool is_periodic(TElem *e) const
Definition periodic_boundary_manager_impl.hpp:127
void make_master(Group< TElem > *g, TElem *e)
Definition periodic_boundary_manager_impl.hpp:417
Grid::AttachmentAccessor< TElem, Attachment< PeriodicStatus > > & get_periodic_status_accessor()
Grid::AttachmentAccessor< Vertex, Attachment< Group< Vertex > * > > m_aaGroupVRT
store subset handler of domain to lookup element subset ids
Definition periodic_boundary_manager.h:221
void validity_check()
Definition periodic_boundary_manager.cpp:391
Group< TElem >::SlaveContainer * slaves(TElem *e) const
Definition periodic_boundary_manager_impl.hpp:146
void handle_creation(TElem *e, TParent *pParent)
handles creation of element type
Definition periodic_boundary_manager_impl.hpp:208
Grid::AttachmentAccessor< Face, Attachment< PeriodicStatus > > m_aaPeriodicStatusFCE
Definition periodic_boundary_manager.h:228
Grid::AttachmentAccessor< TElem, Attachment< Group< TElem > * > > & get_group_accessor()
const Grid::AttachmentAccessor< TElem, Attachment< PeriodicStatus > > & get_periodic_status_accessor() const
void merge_groups(Group< TElem > *g0, Group< TElem > *g1)
Definition periodic_boundary_manager_impl.hpp:468
void set_group(Group< TElem > *g, TElem *e)
Definition periodic_boundary_manager_impl.hpp:516
virtual void edge_created(Grid *grid, Edge *e, GridObject *pParent=NULL, bool replacesParent=false)
Notified whenever a new element of the given type is created in the given grid.
Definition periodic_boundary_manager.cpp:225
Group< TElem > * group(TElem *e) const
Definition periodic_boundary_manager_impl.hpp:509
Grid * get_grid() const
Definition periodic_boundary_manager.cpp:96
TElem * master(TElem *e) const
Definition periodic_boundary_manager_impl.hpp:136
Grid::AttachmentAccessor< Vertex, Attachment< PeriodicStatus > > m_aaPeriodicStatusVRT
attachment accessors for PeriodicStatus
Definition periodic_boundary_manager.h:226
bool check_periodicity(const GridObjectCollection &goc1, const GridObjectCollection &goc2, ISubsetHandler *sh=NULL)
checks that all elements of given gocs are periodic (called after identification)
Definition periodic_boundary_manager.cpp:257
virtual void edge_to_be_erased(Grid *grid, Edge *e, Edge *replacedBy=NULL)
Notified whenever an element of the given type is erased from the given grid.
Definition periodic_boundary_manager.cpp:240
MultiGrid * m_pGrid
grid instance we operate on
Definition periodic_boundary_manager.h:208
bool is_slave(TElem *) const
Definition periodic_boundary_manager_impl.hpp:498
virtual void vertex_to_be_erased(Grid *grid, Vertex *vrt, Vertex *replacedBy=NULL)
Notified whenever an element of the given type is erased from the given grid.
Definition periodic_boundary_manager.cpp:235
PeriodicStatus
Definition periodic_boundary_manager.h:129
@ P_SLAVE
Definition periodic_boundary_manager.h:130
@ P_NOT_PERIODIC
Definition periodic_boundary_manager.h:130
@ P_MASTER
Definition periodic_boundary_manager.h:130
@ P_SLAVE_MASTER_UNKNOWN
Definition periodic_boundary_manager.h:130
bool remove_slave(TElem *slave)
Definition periodic_boundary_manager_impl.hpp:426
virtual void vertex_created(Grid *grid, Vertex *vrt, GridObject *pParent=NULL, bool replacesParent=false)
Notified whenever a new element of the given type is created in the given grid.
Definition periodic_boundary_manager.cpp:220
Grid::AttachmentAccessor< Face, Attachment< Group< Face > * > > m_aaGroupFCE
Definition periodic_boundary_manager.h:223
void print_identification() const
Definition periodic_boundary_manager_impl.hpp:154
PeriodicBoundaryManager()
Definition periodic_boundary_manager.cpp:37
void make_slave(Group< TElem > *g, TElem *e)
make element e slave of group g
Definition periodic_boundary_manager_impl.hpp:396
void handle_deletion(TElem *e, TElem *replacedBy)
handles deletion of element type
Definition periodic_boundary_manager_impl.hpp:375
Grid::AttachmentAccessor< Edge, Attachment< Group< Edge > * > > m_aaGroupEDG
Definition periodic_boundary_manager.h:222
~PeriodicBoundaryManager()
Definition periodic_boundary_manager.cpp:40
void replace_parent(TElem *e, TElem *pParent)
replaces all group occurrances of pParent by the specified elem
Definition periodic_boundary_manager_impl.hpp:187
Base-class for all vertex-types.
Definition grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition grid_base_objects.h:754
#define UG_ASSERT(expr, msg)
Definition assert.h:70
#define UG_THROW(msg)
Definition error.h:57
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition math_vector_functions_common_impl.hpp:252
the ug namespace
void IdentifySubsets(TDomain &dom, int sInd1, int sInd2)
identifies subset 1 with subset 2. If the grid of given domain has no periodic boundary manager attac...
Definition periodic_boundary_manager_impl.hpp:604
TValue & reference
Definition attachment_pipe.h:112
const TValue & const_reference
Definition attachment_pipe.h:113