Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
partition_weighting_callbacks.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Markus Breit
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__LIB_GRID__PARALLELIZATION__UTIL__PARTITION_WEIGHTING_CALLBACKS__
34#define __H__UG__LIB_GRID__PARALLELIZATION__UTIL__PARTITION_WEIGHTING_CALLBACKS__
35
36
37#include "lib_grid/multi_grid.h"
39#include "common/error.h"
40#include <vector>
41
42namespace ug
43{
44
50{
51 public:
53 virtual ~PartitionWeighting() {};
54
55 virtual int operator() (Edge* e1, Edge* e2) {return weigh(e1,e2);};
56 virtual int operator() (Face* f1, Face* f2) {return weigh(f1,f2);};
57 virtual int operator() (Volume* v1, Volume* v2) {return weigh(v1,v2);};
58
60 {
61 m_sh = sh;
62 }
63
64 void set_default_weights(int hWeight, int vWeight)
65 {
66 m_hWeight = hWeight;
67 m_vWeight = vWeight;
68 }
69
70 private:
71 template <class TElem>
72 int weigh(TElem* e1, TElem* e2)
73 {
74 if (!this->m_sh)
75 UG_THROW("Subset handler must be assigned to InterSubsetPartitionWeighting before it is used!");
76
77 if (this->m_sh->get_level(e1) == this->m_sh->get_level(e2))
78 return m_hWeight;
79
80 return m_vWeight;
81 }
82
83
84 protected:
86
87 int m_hWeight; // horizontal weight
88 int m_vWeight; // vertical weight
89};
90
91
97{
98 public:
101
102 public:
103 void set_inter_subset_weight(int si1, int si2, int weight)
104 {
105 m_vsi1.push_back(si1);
106 m_vsi2.push_back(si2);
107 m_vweights.push_back(weight);
108 }
109
110 virtual int operator() (Edge* e1, Edge* e2) {return weigh(e1,e2);};
111 virtual int operator() (Face* f1, Face* f2) {return weigh(f1,f2);};
112 virtual int operator() (Volume* v1, Volume* v2) {return weigh(v1,v2);};
113
114 private:
115 template <class TElem>
116 int weigh(TElem* e1, TElem* e2)
117 {
118 if (!this->m_sh)
119 UG_THROW("Subset handler must be assigned to InterSubsetPartitionWeighting before it is used!");
120
121 if (this->m_sh->get_level(e1) == this->m_sh->get_level(e2))
122 {
123 // check whether elems fulfill one of the indivisibility conditions
124 for (size_t i = 0; i < m_vsi1.size(); i++)
125 {
126 if (this->m_sh->get_subset_index(e1) == m_vsi1[i]
127 && this->m_sh->get_subset_index(e2) == m_vsi2[i])
128 {
129 return m_vweights[i];
130 }
131 }
132 return m_hWeight;
133 }
134 return m_vWeight;
135 }
136
137 private:
138 std::vector<int> m_vsi1;
139 std::vector<int> m_vsi2;
140 std::vector<int> m_vweights;
141};
142
143
154{
155 public:
157
158
159 public:
162
163 public:
164 void set_weight(int si, int weight)
165 {
166 m_vSi.push_back(si);
167 m_vWeights.push_back(weight);
168 }
169
170 virtual int operator() (Edge* e1, Edge* e2) {return weigh(e1,e2);};
171 virtual int operator() (Face* f1, Face* f2) {return weigh(f1,f2);};
172 virtual int operator() (Volume* v1, Volume* v2) {return weigh(v1,v2);};
173
174 private:
175 template <class TElem>
176 int weigh(TElem* e1, TElem* e2)
177 {
178 if (!this->m_sh)
179 UG_THROW("Subset handler must be assigned to InterSubsetPartitionWeighting before it is used!")
180
181 if (this->m_sh->get_level(e1) == this->m_sh->get_level(e2))
182 {
183 // check whether elems fulfill one of the indivisibility conditions
184 vertex_list vl1, vl2;
185 this->m_sh->grid()->associated_elements(vl1, e1);
186 this->m_sh->grid()->associated_elements(vl2, e2);
187
188 for (size_t i = 0; i < vl1.size(); i++)
189 {
190 for (size_t j = 0; j < m_vSi.size(); j++)
191 {
192 // check if vertex is in one of the restricted subsets
193 if (this->m_sh->get_subset_index(vl1[i]) != m_vSi[j])
194 continue;
195
196 // if so, check that it is a shared vertex of both elems
197 for (size_t k = 0; k < vl2.size(); k++)
198 {
199 if (vl1[i] == vl2[k])
200 return m_vWeights[j];
201 }
202 }
203 }
204 return m_hWeight;
205 }
206 return m_vWeight;
207 }
208
209 private:
210 std::vector<int> m_vSi;
211 std::vector<int> m_vWeights;
212};
213
214
215} // end of namespace
216
217
218#endif /* __H__UG__LIB_GRID__PARALLELIZATION__UTIL__PARTITION_WEIGHTING_CALLBACKS__ */
Base-class for edges.
Definition grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition grid_base_objects.h:510
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
Grid * grid() const
returns a pointer to the grid on which the subset-handler works.
Definition subset_handler_interface.cpp:304
int get_subset_index(GridObject *elem) const
Definition subset_handler_interface.cpp:560
Definition partition_weighting_callbacks.h:97
void set_inter_subset_weight(int si1, int si2, int weight)
Definition partition_weighting_callbacks.h:103
int weigh(TElem *e1, TElem *e2)
Definition partition_weighting_callbacks.h:116
std::vector< int > m_vsi1
Definition partition_weighting_callbacks.h:138
InterSubsetPartitionWeighting()
Definition partition_weighting_callbacks.h:99
std::vector< int > m_vweights
Definition partition_weighting_callbacks.h:140
std::vector< int > m_vsi2
Definition partition_weighting_callbacks.h:139
virtual ~InterSubsetPartitionWeighting()
Definition partition_weighting_callbacks.h:100
virtual int operator()(Edge *e1, Edge *e2)
Definition partition_weighting_callbacks.h:110
Handles subsets on a per level basis.
Definition subset_handler_multi_grid.h:60
uint get_level(TGeomObj *obj) const
returns the level in which an element is located
Definition subset_handler_multi_grid.h:84
Definition partition_weighting_callbacks.h:50
PartitionWeighting()
Definition partition_weighting_callbacks.h:52
void set_default_weights(int hWeight, int vWeight)
Definition partition_weighting_callbacks.h:64
int m_hWeight
Definition partition_weighting_callbacks.h:87
MGSubsetHandler * m_sh
Definition partition_weighting_callbacks.h:85
virtual ~PartitionWeighting()
Definition partition_weighting_callbacks.h:53
int weigh(TElem *e1, TElem *e2)
Definition partition_weighting_callbacks.h:72
virtual int operator()(Edge *e1, Edge *e2)
Definition partition_weighting_callbacks.h:55
int m_vWeight
Definition partition_weighting_callbacks.h:88
void set_subset_handler(MGSubsetHandler *sh)
Definition partition_weighting_callbacks.h:59
Definition partition_weighting_callbacks.h:154
std::vector< int > m_vSi
Definition partition_weighting_callbacks.h:210
void set_weight(int si, int weight)
Definition partition_weighting_callbacks.h:164
int weigh(TElem *e1, TElem *e2)
Definition partition_weighting_callbacks.h:176
virtual int operator()(Edge *e1, Edge *e2)
Definition partition_weighting_callbacks.h:170
std::vector< int > m_vWeights
Definition partition_weighting_callbacks.h:211
ProtectSubsetPartitionWeighting()
Definition partition_weighting_callbacks.h:160
MultiGrid::traits< Vertex >::secure_container vertex_list
Definition partition_weighting_callbacks.h:156
virtual ~ProtectSubsetPartitionWeighting()
Definition partition_weighting_callbacks.h:161
Volumes are 3-dimensional objects.
Definition grid_base_objects.h:754
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
The traits class holds some important types for each element-type.
Definition grid.h:136