Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
smooth_partition_bounds.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_smooth_partition_bounds
34#define __H__UG_smooth_partition_bounds
35
36#include "../partitioner.h"
38
39namespace ug{
40
42template <class elem_t>/*, int dim>*/
44{
45 public:
47 m_mg(NULL),
48 m_partitions(NULL)
49 // m_consideringVerticalSidesOnly(false)
50 {}
51
57
59 {
60 m_mg = mg;
61 m_partitions = partitions;
63 }
64
65 // void set_position_attachment(position_attachment_t aPos);
66
67 // void consider_vertical_sides_only(bool enable)
68 // {
69 // m_consideringVerticalSidesOnly = enable;
70 // if(enable){
71 // UG_COND_THROW(!mg->has_vertex_attachment(m_aPos),
72 // "consider_vertical_sides_only may only be enabled if "
73 // "a valid position attachment for the underlying grid "
74 // "has been set previously.");
75 // m_aaPos.access(*mg, m_aPos);
76 // }
77 // }
78
79 // bool considering_vertical_sides_only() const {return m_consideringVerticalSidesOnly;}
80
81 void post_process(int partitionLvl)
82 {
83 using namespace std;
84 // we'll regularize the partition to reduce h-interface sizes
85 // (also important to improve gmg-smoother efficiency).
86 //todo: PARALLEL IMPLEMENTATION, EQUALLY DISTRIBUTE SWAP-ELEMENTS
87 MultiGrid& mg = *m_mg;
89
91
93
94 vector<int> nbrSubs;
95 bool assignToSmallerSubsetsOnly = true;
96
97 for(int main_iteration = 0; main_iteration < 2; ++main_iteration){
98 SetAttachmentValues(aaSubsetNbrs, mg.begin<side_t>(partitionLvl),
99 mg.end<side_t>(partitionLvl), pair<int, int>(-1, -1));
100
101 // regularization step 1: assign element-subset-indices to sides
102 lg_for_each_in_lvl_template(elem_t, e, mg, partitionLvl){
103 int si = sh.get_subset_index(e);
104 if(si >= 0){
105 mg.associated_elements(sides, e);
106 for_each_in_vec(side_t* s, sides){
107 if(aaSubsetNbrs[s].first == -1)
108 aaSubsetNbrs[s].first = si;
109 else
110 aaSubsetNbrs[s].second = si;
111 }end_for;
112 }
113 }end_for;
114
115 //todo: regularization step 1.5: communicate subsetNbrs
116 // ...
117
118 // regularization step 2: check for elements whose neighbors belong to other partitions
119 lg_for_each_in_lvl_template(elem_t, e, mg, partitionLvl){
120 int si = sh.get_subset_index(e);
121 if(si >= 0){
122 nbrSubs.clear();
123 mg.associated_elements(sides, e);
124 int numOwnSubsetNbrs = 0;
125 for_each_in_vec(side_t* s, sides){
126 if(s->reference_object_id() == ROID_QUADRILATERAL){
127 const subset_pair_t& nbrs = aaSubsetNbrs[s];
128 if(nbrs.first == si && nbrs.second == si)
129 ++numOwnSubsetNbrs;
130 else if(nbrs.first != -1 && nbrs.first != si)
131 nbrSubs.push_back(nbrs.first);
132 else if(nbrs.second != -1 && nbrs.second != si)
133 nbrSubs.push_back(nbrs.second);
134 }
135 }end_for;
136
137 // we'll now search for the subset which shares the most sides.
138 int newSubsetNbrs = numOwnSubsetNbrs;
139 int newSub = si;
140
141 for(size_t i_nbrSub = 0; i_nbrSub < nbrSubs.size(); ++i_nbrSub){
142 int nbrSub = nbrSubs[i_nbrSub];
143 if(nbrSub != -1){// otherwise the subset has already been processed
144 int count = 1;
145 for(size_t i = i_nbrSub + 1; i < nbrSubs.size(); ++i){
146 if(nbrSubs[i] == nbrSub){
147 nbrSubs[i] = -1;
148 ++count;
149 }
150 }
151
152 if(count > newSubsetNbrs){
153 newSubsetNbrs = count;
154 newSub = nbrSub;
155 }
156 }
157 }
158
159 // assign the new subset.
160 //todo: use a more elaborate decider to which subset an element shall be assigned.
161 if(newSub != -1
162 && ((assignToSmallerSubsetsOnly && newSub < si)
163 || (!assignToSmallerSubsetsOnly && newSub != si)))
164 {
165 sh.assign_subset(e, newSub);
166 }
167 }
168 }end_for;
169
170 // in the second iteration we'll assign to all neighbors
171 assignToSmallerSubsetsOnly = false;
172 }
173 }
174
179
180 private:
181 typedef typename elem_t::side side_t;
182 typedef std::pair<int, int> subset_pair_t;
184
188 // bool m_consideringVerticalSidesOnly;
189};
190
191}// end of namespace
192
193#endif //__H__UG_smooth_partition_bounds
parameterString s
A generic specialization of IAttachment.
Definition attachment_pipe.h:263
the generic attachment-accessor for access to grids attachment pipes.
Definition grid.h:182
void detach_from(IAttachment &attachment)
Definition grid_impl.hpp:369
void attach_to(IAttachment &attachment, bool passOnValues)
attach with custom pass-on-behaviour and unspecified default value.
Definition grid_impl.hpp:296
bool has_attachment(IAttachment &attachment)
Definition grid.h:796
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
Partitions elements of a grid into several subsets.
Definition subset_handler_grid.h:53
void assign_subset(Vertex *elem, int subsetIndex)
assigns a vertex to a subset.
Definition subset_handler_grid.cpp:204
allows to post-process partitions
Definition partitioner.h:146
int get_subset_index(GridObject *elem) const
Definition subset_handler_interface.cpp:560
Definition multi_grid.h:72
geometry_traits< TElem >::iterator begin(int level)
Definition multi_grid.h:158
geometry_traits< TElem >::iterator end(int level)
Definition multi_grid.h:168
early draft. Currently only useful for prism-geometries in the d3f-wipp setting
Definition smooth_partition_bounds.h:44
SmoothPartitionBounds()
Definition smooth_partition_bounds.h:46
std::pair< int, int > subset_pair_t
Definition smooth_partition_bounds.h:182
a_subset_pair_t m_aSubsetNbrs
Definition smooth_partition_bounds.h:187
MultiGrid * m_mg
Definition smooth_partition_bounds.h:185
void partitioning_done()
Definition smooth_partition_bounds.h:175
SubsetHandler * m_partitions
Definition smooth_partition_bounds.h:186
void post_process(int partitionLvl)
Definition smooth_partition_bounds.h:81
Attachment< subset_pair_t > a_subset_pair_t
Definition smooth_partition_bounds.h:183
elem_t::side side_t
Definition smooth_partition_bounds.h:181
void init_post_processing(MultiGrid *mg, SubsetHandler *partitions)
Definition smooth_partition_bounds.h:58
virtual ~SmoothPartitionBounds()
Definition smooth_partition_bounds.h:52
void SetAttachmentValues(TAttachmentAccessor &aaVal, TIter elemsBegin, TIter elemsEnd, const TVal &val)
sets attachment-values for elements between elemsBegin and elemsEnd.
Definition attachment_util_impl.hpp:44
#define lg_for_each_in_lvl_template(_feType, _feVar, _feCon, _feLvl)
Definition lg_for_each.h:59
Definition smart_pointer.h:814
the ug namespace
@ ROID_QUADRILATERAL
Definition grid_base_objects.h:79
The traits class holds some important types for each element-type.
Definition grid.h:136
#define for_each_in_vec(_vfeDecl, _vfeVec)
Allows iteration over all members of an std::vector compatible type.
Definition vec_for_each.h:52
#define end_for
Allows iteration over all members of an std::vector compatible type.
Definition vec_for_each.h:56