ug4
element_visitor_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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__element_visitor_util__
34 #define __H__UG__element_visitor_util__
35 
36 #include <vector>
37 #include "grid/grid.h"
39 
40 namespace ug
41 {
42 
44 template <class TIter>
45 void VisitAll(const TIter begin, const TIter end,
46  boost::function<void (typename TIter::value_type)> visitorCallback)
47 {
48  TIter iter = begin;
49  while(iter != end){
50  typename TIter::value_type val = *iter;
51  ++iter;
52  visitorCallback(val);
53  }
54 }
55 
57 
71 template <class TIter>
72 void VisitAreaBoundary(Grid& g, const TIter begin, const TIter end,
73  boost::function<bool (typename TIter::value_type)> cbBelongsToArea,
74  boost::function<void (typename Pointer2Value<typename TIter::value_type>::type::side)> cbVisitSide)
75 {
77  typedef typename TElem::side TSide;
78 
79  g.begin_marking();
80 
81  std::vector<TSide*> sides;
82  std::vector<TElem*> elems;
83  TIter iter = begin;
84  while(iter != facesEnd){
85  TElem* elem = *iter;
86  ++iter;
87  CollectAssociated(sides, g, elem);
88  for(size_t i = 0; i < sides.size(); ++i){
89  TSide* side = sides[i];
90  if(!g.is_marked(side)){
91  g.mark(side);
92  // collect associated elems and check whether all belong to the area
93  CollectAssociated(elems, g, side);
94  int numInArea = 0;
95  for(size_t i_elem = 0; i_elem < elems.size(); ++i_elem){
96  if(cbBelongsToArea(elems[i_elem]))
97  ++numInArea;
98  }
99 
100  if(numInArea == 1){
101  cbVisitSide(side);
102  }
103  }
104  }
105  }
106 
107  grid.end_marking();
108 }
109 
110 }// end of namespace
111 
112 #endif
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
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
UG_API void CollectAssociated(std::vector< Vertex * > &vVertexOut, Grid &grid, GridObject *obj, bool clearContainer=true)
Definition: grid_util_impl.hpp:169
the ug namespace
void VisitAll(const TIter begin, const TIter end, boost::function< void(typename TIter::value_type)> visitorCallback)
Visits all elements between begin and end and executes the visitorCallback on them.
Definition: element_visitor_util.h:45
void VisitAreaBoundary(Grid &g, const TIter begin, const TIter end, boost::function< bool(typename TIter::value_type)> cbBelongsToArea, boost::function< void(typename Pointer2Value< typename TIter::value_type >::type::side)> cbVisitSide)
Visits all boundary elements of the area specified through the iterators.
Definition: element_visitor_util.h:72
T value_type
Definition: sparsematrix_interface.h:2
Definition: metaprogramming_util.h:48