33 #ifndef PERIODIC_IDENTIFIER_IMPL_HPP_
34 #define PERIODIC_IDENTIFIER_IMPL_HPP_
44 #include <boost/mpl/map.hpp>
45 #include <boost/mpl/at.hpp>
51 template <
class TAAPos>
52 template <
class TElem>
64 if (std::abs(len) < 10E-8)
70 if (std::abs(len) < 10E-8)
77 template <
class TElem>
94 }
else if (m1 && m2) {
110 if (TElem::HAS_SIDES) {
111 container sides1, sides2;
115 for (
size_t i = 0; i < sides1.size(); ++i) {
116 for (
size_t j = 0; j < sides2.size(); ++j) {
117 if(ident.
match(sides1[i], sides2[j])) {
118 identify(sides1[i], sides2[j], ident);
126 template <
class TElem>
129 return get_periodic_status_accessor<TElem>()[e] !=
P_NOT_PERIODIC;
131 UG_THROW(
"null pointer is never periodic.");
135 template <
class TElem>
138 return group(e)->m_master;
144 template <
class TElem>
148 return &
group(e)->get_slaves();
153 template <
class TElem>
161 if (!(
master(*elem) == *elem))
166 UG_LOG(
"group of " << (*elem)->reference_object_id() <<
"\tlevel: " <<
169 for (SlaveIter slave = g->
get_slaves().begin();
174 "wrong level in group")
186 template <
class TElem>
198 i != slaveCon->end(); ++i)
207 template <
class TElem,
class TParent>
219 "PeriodicBoundaryManager has to operate on a grid. No grid assigned.");
223 if(TElem::BASE_OBJECT_ID !=
VERTEX){
226 for(
size_t i = 0; i < vrts.
size(); ++i){
235 if (is_master<TParent>(pParent)) {
242 ParentSlaveContainer* parentSlaves =
slaves(pParent);
243 for (
typename ParentSlaveContainer::iterator i_slave =
244 parentSlaves->begin(); i_slave != parentSlaves->end();
246 TParent* parentSlave = *i_slave;
247 UG_ASSERT(parentSlave,
"parent slave not valid")
253 for (
size_t i_child = 0;
254 i_child < mg.
num_children<TElem>(parentSlave); ++i_child) {
255 TElem* c = mg.
get_child<TElem>(parentSlave, i_child);
258 "At most one 1 vertex-child is currently allowed");
264 if((e->base_object_id() ==
VERTEX)) {
269 bool allMarked =
true;
270 for(
size_t i = 0; i < vrts.
size(); ++i){
293 if (parentGroup == NULL) {
298 TParent* parentMaster = parentGroup->
m_master;
299 bool master_found =
false;
300 for (
size_t i_child = 0; i_child < mg.
num_children<TElem>(parentMaster);
302 TElem* c = mg.
get_child<TElem>(parentMaster, i_child);
305 "At most one 1 vertex-child is currently allowed");
311 if((e->base_object_id() ==
VERTEX)) {
318 bool allMarked =
true;
319 for(
size_t i = 0; i < vrts.
size(); ++i){
343 template <
class TElem>
374 template <
class TElem>
383 "replacing element is already in group")
395 template <
class TElem>
401 "level of slave and group mismatch")
405 UG_LOG(
"slave already engrouped. removing it from former group\n")
407 UG_THROW(
"slave could not be removed")
416 template <
class TElem>
420 set_group<TElem>(NULL, g->
m_master);
425 template <
class TElem>
430 if (pos !=
s.end()) {
436 UG_LOGN(
"delete last slave, remove_group")
449 template <
class TElem>
451 UG_ASSERT(g,
"should remove invalid group")
454 set_group<TElem>(NULL, g->
m_master);
457 for (iter =
s.begin(); iter !=
s.end(); ++iter) {
458 set_group<TElem>(NULL, *iter);
467 template <
class TElem>
478 for (SlaveIterator iter = slaves_g1.begin(); iter != slaves_g1.end();
497 template <
class TElem>
503 template <
class TElem>
505 return get_periodic_status_accessor<TElem>()[e] ==
P_MASTER;
508 template <
class TElem>
512 return get_group_accessor<TElem>()[e];
515 template <
class TElem>
517 UG_ASSERT(e,
"element not valid for attachment access.")
519 get_group_accessor<TElem>()[e] = g;
526 get_periodic_status_accessor<TElem>()[e] =
P_MASTER;
528 get_periodic_status_accessor<TElem>()[e] =
P_SLAVE;
532 template <
class TElem,
class TIterator>
543 for (SecContainerIter iter = begin; iter != end; ++iter) {
549 const char* sh_name =
"";
554 UG_THROW(
"Element in subset '" << sh_name
555 <<
"' is not periodic after identification: "
557 <<
"\nCheck your geometry for symmetry!\n")
561 Container* _slaves =
slaves(e);
563 UG_THROW(
"masters slave storage is not valid.")
568 for (SlaveIter i = _slaves->begin(); i != _slaves->end(); ++i) {
571 bool inserted = (
s.insert(
p)).second;
573 UG_THROW(
"master/slave pair already exists.");
579 template <
class TDomain>
582 typedef typename TDomain::subset_handler_type subset_handler_type;
584 subset_handler_type& sh = *dom.subset_handler();
586 int si1 = sh.get_subset_index(sName1);
587 int si2 = sh.get_subset_index(sName2);
595 UG_THROW(
"IdentifySubsets: given subset name " << sName1 <<
" does not exist");
597 UG_THROW(
"IdentifySubsets: given subset name " << sName2 <<
" does not exist");
603 template <
class TDomain>
611 if (sInd1 == -1 || sInd2 == -1) {
612 UG_THROW(
"IdentifySubsets: at least one invalid subset given!")
616 UG_THROW(
"IdentifySubsets: can not identify two identical subsets!")
620 if (!dom.grid()->has_periodic_boundaries()) {
621 dom.grid()->set_periodic_boundaries(
true);
626 typedef typename TDomain::position_type position_type;
627 typedef typename TDomain::position_accessor_type position_accessor_type;
630 typedef typename TDomain::subset_handler_type subset_handler_type;
632 subset_handler_type& sh = *dom.subset_handler();
635 position_accessor_type& aaPos = dom.position_accessor();
648 UG_THROW(
"IdentifySubsets: Given subsets have different number of vertices."
649 "\nnum# in " << sh.get_subset_name(sInd1) <<
": " << goc1.
num<
Vertex>() <<
650 "\nnum# in " << sh.get_subset_name(sInd2) <<
": " << goc2.
num<
Vertex>())
654 UG_THROW(
"IdentifySubsets: Given subsets have different number of edges."
655 "\nnum# in " << sh.get_subset_name(sInd1) <<
": " << goc1.
num<
Edge>() <<
656 "\nnum# in " << sh.get_subset_name(sInd2) <<
": " << goc2.
num<
Edge>())
660 UG_THROW(
"IdentifySubsets: Given subsets have different number of faces."
661 "\nnum# in " << sh.get_subset_name(sInd1) <<
": " << goc1.
num<
Face>() <<
662 "\nnum# in " << sh.get_subset_name(sInd2) <<
": " << goc2.
num<
Face>())
686 for (
size_t lvl = 0; lvl < goc1.
num_levels(); lvl++) {
690 for (gocIter iter1 = goc1.
begin<TElem>(lvl);
691 iter1 != goc1.
end<TElem>(lvl); ++iter1)
692 for (gocIter iter2 = goc2.
begin<TElem>(lvl);
693 iter2 != goc2.
end<TElem>(lvl); ++iter2) {
694 if(ident.
match(*iter1, *iter2)) {
695 pbm.
identify(*iter1, *iter2, ident);
A special iterator which allows to iterate over elements in a AttachedElementList.
Definition: attached_list.h:52
A special iterator which allows to iterate over elements in a AttachedElementList.
Definition: attached_list.h:107
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
void end_marking()
ends a marking sequence. Call this method when you're done with marking.
Definition: grid.cpp:1285
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition: grid_impl.hpp:843
void mark(GridObject *obj)
marks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition: grid_impl.hpp:773
void begin_marking()
begin marking.
Definition: grid.cpp:1262
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition: grid_impl.hpp:466
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
geometry_traits< TGeomObj >::iterator begin(size_t level=0)
Definition: grid_object_collection_impl.hpp:95
geometry_traits< TGeomObj >::iterator end(size_t level=0)
Definition: grid_object_collection_impl.hpp:106
size_t num() const
Definition: grid_object_collection_impl.hpp:130
size_t num_levels() const
returns the number of levels
Definition: grid_object_collection.h:128
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual int base_object_id() const =0
Interface to match periodic geometric elements.
Definition: periodic_boundary_manager.h:48
virtual bool match(Vertex *, Vertex *)=0
Definition: subset_handler_interface.h:223
const char * get_subset_name(int subsetIndex) const
returns the name of a subset
Definition: subset_handler_interface.cpp:438
int get_subset_index(GridObject *elem) const
Definition: subset_handler_interface.cpp:560
Definition: multi_grid.h:72
int get_level(TElem *elem) const
Definition: multi_grid.h:206
TChild * get_child(TElem *elem, size_t ind) const
returns the i-th child of the given child-type
Definition: multi_grid.h:268
geometry_traits< TElem >::iterator end(int level)
Definition: multi_grid.h:168
geometry_traits< TElem >::iterator begin(int level)
Definition: multi_grid.h:158
size_t num_children(TElem *elem) const
returns the number of children of the given child-type
Definition: multi_grid.h:225
This class matches geometric elements which are parallel translated.
Definition: periodic_boundary_manager.h:64
TPosAA::ValueType AttachmentType
Definition: periodic_boundary_manager.h:71
void set_shift(AttachmentType &shift)
Definition: periodic_boundary_manager.h:73
virtual bool match(Vertex *v1, Vertex *v2)
Definition: periodic_boundary_manager.h:66
bool match_impl(TElem *, TElem *) const
Definition: periodic_boundary_manager_impl.hpp:53
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
Container & get_slaves()
Definition: periodic_boundary_manager.h:122
Container SlaveContainer
Definition: periodic_boundary_manager.h:109
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 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
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
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
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
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
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
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
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
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
void print_identification() const
Definition: periodic_boundary_manager_impl.hpp:154
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
void replace_parent(TElem *e, TElem *pParent)
replaces all group occurrances of pParent by the specified elem
Definition: periodic_boundary_manager_impl.hpp:187
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
vector3 GetGridObjectCenter(Grid &g, TElem *elem)
Returns the center of the given element (SLOW - for debugging only!)
Definition: debug_util_impl.hpp:47
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
#define UG_LOGN(msg)
Definition: log.h:369
double number
Definition: types.h:124
void CalculateCenter(vector_t ¢erOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition: math_util_impl.hpp:98
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
vector_t::value_type VecLengthSq(const vector_t &v)
returns the squared length of v. Faster than VecLength.
Definition: math_vector_functions_common_impl.hpp:324
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
Definition: parallel_index_layout.h:77
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
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
Definition: grid_dim_traits.h:53