Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
remove_duplicates_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
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_remove_duplicates_util
34#define __H__UG_remove_duplicates_util
35
36#include "lib_grid/grid/grid.h"
38
39namespace ug{
40
43template <class TElemIter>
44void RemoveDuplicates(Grid& grid, TElemIter elemsBegin, TElemIter elemsEnd)
45{
46 typedef typename TElemIter::value_type TElemPtr;
47 typedef typename PtrToValueType<TElemPtr>::base_type TElem;
48
49 grid.begin_marking();
50
51// the first is the double, the second the original
52 std::vector<std::pair<TElem*, TElem*> > doubles;
54
55 for(TElemIter iter = elemsBegin; iter != elemsEnd; ++iter){
56 TElem* e = *iter;
57 if(!grid.is_marked(e)){
58 typename TElem::ConstVertexArray vrts = e->vertices();
59 const size_t numVrts = e->num_vertices();
60
61 bool allMarked = true;
62 for(size_t i = 0; i < numVrts; ++i){
63 if(!grid.is_marked(vrts[i])){
64 allMarked = false;
65 break;
66 }
67 }
68
69 bool isDouble = false;
70
71 if(allMarked){
72 // a necessary condition is met. However not yet sufficient.
73 // find marked elems wich connect the same vertices.
74 grid.associated_elements(elems, vrts[0]);
75 for(size_t i = 0; i < elems.size(); ++i){
76 TElem* te = elems[i];
77 if(grid.is_marked(te) && CompareVertices(e, te)){
78 // e is a double
79 isDouble = true;
80 doubles.push_back(std::make_pair(e, te));
81 break;
82 }
83 }
84 }
85
86 // finally mark e and its vertices (every processed non-double element is marked).
87 if(!isDouble){
88 grid.mark(e);
89 for(size_t i = 0; i < numVrts; ++i)
90 grid.mark(vrts[i]);
91 }
92 }
93 }
94
95 grid.end_marking();
96
97// now erase all doubles
98 for(size_t i = 0; i < doubles.size(); ++i){
99 // this allows listeners to take actions
100 grid.objects_will_be_merged(doubles[i].second, doubles[i].second,
101 doubles[i].first);
102 grid.erase(doubles[i].first);
103 }
104}
105
106}// end of namespace
107
108#endif //__H__UG_remove_duplicates_util
Manages the elements of a grid and their interconnection.
Definition grid.h:132
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 erase(GridObject *geomObj)
Definition grid.cpp:459
void begin_marking()
begin marking.
Definition grid.cpp:1262
void objects_will_be_merged(Vertex *target, Vertex *elem1, Vertex *elem2)
notifies the grid that two objects will be merged.
Definition grid_impl.hpp:244
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
bool CompareVertices(const FaceVertices *fv1, const FaceVertices *fv2)
Checks whether fv1 and fv2 contain the same vertices.
Definition grid_util.cpp:44
the ug namespace
void RemoveDuplicates(Grid &grid, TElemIter elemsBegin, TElemIter elemsEnd)
Removes elements which share the same set of vertices with other elements in the given range.
Definition remove_duplicates_util.h:44
PointerConstArray< TElem * > secure_container
Definition grid.h:146
void base_type
Definition grid_base_objects.h:1011