ug4
ass_tuner.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Authors: Raphael Prohl, Andreas Vogel
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_DISC__SPATIAL_DISC__ASS_TUNER__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__ASS_TUNER__
35 
40 
41 namespace ug{
42 
43 template <typename TDomain, typename TAlgebra>
44 class IDomainConstraint;
45 
47 
53 {
54  CT_NONE = 0,
56  CT_MAY_DEPEND_ON_HANGING = 1 << 1, // constraints which may depend on hanging DoFs; but NOT vice-versa
57  CT_HANGING = 1 << 2, // constraint defined for hanging DoFs
58  CT_CONSTRAINTS = 1 << 3, // any other constraint which MUST NOT depend on a hanging DoF
59  CT_DIRICHLET = 1 << 4, // Dirichlet constraints
61 };
62 
63 template <typename TAlgebra>
65 {
66  public:
68  typedef TAlgebra algebra_type;
69 
71  typedef typename algebra_type::matrix_type matrix_type;
72 
74  typedef typename algebra_type::vector_type vector_type;
75 
76  public:
77 
79  void add_local_vec_to_global(vector_type& vec, const LocalVector& lvec) const
80  { AddLocalVector(vec, lvec);}
81 
83  void add_local_mat_to_global(matrix_type& mat, const LocalMatrix& lmat) const
84  { AddLocalMatrixToGlobal(mat, lmat);}
85 };
86 
88 template <typename TAlgebra>
90 {
91  public:
93  typedef TAlgebra algebra_type;
94 
96  typedef typename algebra_type::matrix_type matrix_type;
97 
99  typedef typename algebra_type::vector_type vector_type;
100 
103 
104  public:
111 
113  virtual ~AssemblingTuner() {}
114 
117  {
118  m_pMapper = pMapper;
119  }
120 
124  {
125  if (m_pMapper)
126  m_pMapper->add_local_vec_to_global(vec, lvec, dd);
127  else
128  m_defaultMapper.add_local_vec_to_global(vec, lvec);
129  }
130 
133  {
134  if (m_pMapper)
135  m_pMapper->add_local_mat_to_global(mat, lmat, dd);
136  else
137  m_defaultMapper.add_local_mat_to_global(mat, lmat);
138  }
139 
140  void modify_LocalSol(LocalVector& vecMod, const LocalVector& lvec,
142  {
143  if (m_pMapper)
144  m_pMapper->modify_LocalSol(vecMod, lvec, dd);
145  }
147 
154  void set_marker(BoolMarker* mark = NULL){ m_pBoolMarker = mark; }
155 
157 
166  void set_selector(Selector* sel = NULL){ m_pSelector = sel; }
167 
169 
177  void set_single_index_assembling(const size_t index)
178  {
179  m_SingleAssIndex = index; m_bSingleAssIndex = true;
180  }
181 
184 
185 
187  void enable_modify_solution(bool bEnable) {m_bModifySolutionImplemented = bEnable;}
188 
191 
192 
194  virtual void set_force_regular_grid(bool bForce) {m_bForceRegGrid = bForce;}
195 
197  bool regular_grid_forced() const {return m_bForceRegGrid;}
198 
199 
201  void enable_constraints(int bEnableTypes) {m_ConstraintTypesEnabled = bEnableTypes;}
202 
205 
207  bool constraint_type_enabled(int type) const {return (type & m_ConstraintTypesEnabled);}
208 
209 
211  void enable_elem_discs(int bEnableTypes) {m_ElemTypesEnabled = bEnableTypes;}
212 
215 
217  bool elem_disc_type_enabled(int type) const {return (type & m_ElemTypesEnabled);}
218 
219 
223 
225  template <typename TElem>
226  void collect_selected_elements(std::vector<TElem*>& vElem, ConstSmartPtr<DoFDistribution> dd, int si) const;
227 
229  bool selected_elements_used() const {return (m_pSelector != NULL);}
230 
232  template <typename TElem>
233  bool element_used(TElem* elem) const;
234 
237  void set_dirichlet_row(matrix_type& mat, const DoFIndex& ind) const;
238  void set_dirichlet_val(vector_type& vec, const DoFIndex& ind, const double val) const;
239 
244 
251  void set_matrix_is_const(bool bCh) {m_bMatrixIsConst = bCh;}
252 
254 
260  bool matrix_is_const() const {return m_bMatrixIsConst;}
261 
262  protected:
265 
268 
271 
274 
278 
281 
285 
288 
291 
294 
297 
300 };
301 
302 } // end namespace ug
303 
304 #include "ass_tuner_impl.h"
305 
306 #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__ASS_TUNER__ */
Definition: smart_pointer.h:296
The AssemblingTuner class combines tools to adapt the assembling routine.
Definition: ass_tuner.h:90
bool m_bForceRegGrid
forces the assembling to regard the grid as regular
Definition: ass_tuner.h:280
int m_ConstraintTypesEnabled
enables the constraints
Definition: ass_tuner.h:287
void disable_single_index_assembling()
sets an index for which the assembling should be carried out
Definition: ass_tuner.h:176
void set_single_index_assembling(const size_t index)
Definition: ass_tuner.h:177
void add_local_mat_to_global(matrix_type &mat, const LocalMatrix &lmat, ConstSmartPtr< DoFDistribution > dd) const
Definition: ass_tuner.h:131
void disable_clear_on_resize()
Definition: ass_tuner.h:243
void set_dirichlet_val(vector_type &vec, const DoFIndex &ind, const double val) const
Definition: ass_tuner_impl.h:134
bool m_bModifySolutionImplemented
Definition: ass_tuner.h:284
bool regular_grid_forced() const
returns if assembling is to considered as regular grid
Definition: ass_tuner.h:197
LocalToGlobalMapper< TAlgebra > m_defaultMapper
default LocalToGlobalMapper
Definition: ass_tuner.h:264
virtual ~AssemblingTuner()
destructor
Definition: ass_tuner.h:113
void set_marker(BoolMarker *mark=NULL)
sets a marker to exclude elements from assembling
Definition: ass_tuner.h:154
AssemblingTuner()
constructor
Definition: ass_tuner.h:106
virtual void set_force_regular_grid(bool bForce)
forces the assembling to consider the grid as regular
Definition: ass_tuner.h:194
void resize(ConstSmartPtr< DoFDistribution > dd, vector_type &vec) const
resize functions used in assemble funcs
Definition: ass_tuner_impl.h:41
algebra_type::vector_type vector_type
Type of algebra vector.
Definition: ass_tuner.h:99
ILocalToGlobalMapper< TAlgebra > * m_pMapper
LocalToGlobalMapper.
Definition: ass_tuner.h:267
bool m_bSingleAssIndex
object for DoFindex-wise assemble routine
Definition: ass_tuner.h:276
TAlgebra algebra_type
Algebra type.
Definition: ass_tuner.h:93
vector_type::value_type value_type
Type of algebra value.
Definition: ass_tuner.h:102
void enable_elem_discs(int bEnableTypes)
enables elem discs
Definition: ass_tuner.h:211
algebra_type::matrix_type matrix_type
Type of algebra matrix.
Definition: ass_tuner.h:96
bool element_used(TElem *elem) const
returns if element is to be used in assembling
Definition: ass_tuner_impl.h:85
Selector * m_pSelector
selector used to set a list of elements for the assembling
Definition: ass_tuner.h:273
void set_mapping(ILocalToGlobalMapper< TAlgebra > *pMapper=NULL)
set local to global mapping
Definition: ass_tuner.h:116
bool m_bMatrixIsConst
disables matrix assembling if set to false
Definition: ass_tuner.h:293
int enabled_elem_discs() const
returns flags of enabled elem discs
Definition: ass_tuner.h:214
int enabled_constraints() const
returns flags of enabled constraints
Definition: ass_tuner.h:204
void set_matrix_structure_is_const(bool b)
Definition: ass_tuner.h:253
void set_matrix_is_const(bool bCh)
Definition: ass_tuner.h:251
bool matrix_is_const() const
Definition: ass_tuner.h:260
BoolMarker * m_pBoolMarker
marker used to skip elements
Definition: ass_tuner.h:270
bool constraint_type_enabled(int type) const
returns if constraint type enabled
Definition: ass_tuner.h:207
void modify_LocalSol(LocalVector &vecMod, const LocalVector &lvec, ConstSmartPtr< DoFDistribution > dd) const
Definition: ass_tuner.h:140
bool m_bClearOnResize
disables clearing of vector/matrix on resize
Definition: ass_tuner.h:299
void enable_modify_solution(bool bEnable)
enables the usage of modify solution
Definition: ass_tuner.h:187
void add_local_vec_to_global(vector_type &vec, const LocalVector &lvec, ConstSmartPtr< DoFDistribution > dd) const
LocalToGlobalMapper-function calls.
Definition: ass_tuner.h:122
void enable_constraints(int bEnableTypes)
enables constraints
Definition: ass_tuner.h:201
bool m_bMatrixStructureIsConst
keeps matrix structure from last call if set to true
Definition: ass_tuner.h:296
void set_dirichlet_row(matrix_type &mat, const DoFIndex &ind) const
Definition: ass_tuner_impl.h:114
size_t m_SingleAssIndex
Definition: ass_tuner.h:277
void set_selector(Selector *sel=NULL)
sets a selector of elements for assembling
Definition: ass_tuner.h:166
bool modify_solution_enabled() const
checks whether the assemble index is set or not
Definition: ass_tuner.h:190
bool selected_elements_used() const
returns if only selected elements used for assembling
Definition: ass_tuner.h:229
bool single_index_assembling_enabled() const
checks whether the assemble DoFindex is set or not
Definition: ass_tuner.h:183
void collect_selected_elements(std::vector< TElem * > &vElem, ConstSmartPtr< DoFDistribution > dd, int si) const
gets the element iterator from the Selector
Definition: ass_tuner_impl.h:96
bool elem_disc_type_enabled(int type) const
returns if elem disc type enabled
Definition: ass_tuner.h:217
int m_ElemTypesEnabled
enables the constraints
Definition: ass_tuner.h:290
Allows to mark elements.
Definition: bool_marker.h:64
interface for definition of special LocalToGlobal mappings
Definition: local_to_global_mapper.h:50
Definition: local_algebra.h:422
Definition: ass_tuner.h:65
algebra_type::vector_type vector_type
Type of algebra vector.
Definition: ass_tuner.h:74
TAlgebra algebra_type
Algebra type.
Definition: ass_tuner.h:68
algebra_type::matrix_type matrix_type
Type of algebra matrix.
Definition: ass_tuner.h:71
void add_local_mat_to_global(matrix_type &mat, const LocalMatrix &lmat) const
adds a local matrix to the global one
Definition: ass_tuner.h:83
void add_local_vec_to_global(vector_type &vec, const LocalVector &lvec) const
adds a local vector to the global one
Definition: ass_tuner.h:79
Definition: local_algebra.h:198
Definition: multi_index.h:50
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
specialization of ISelector for a grid of class Grid.
Definition: selector_grid.h:96
CPUAlgebra::vector_type vector_type
the ug namespace
ConstraintType
Types of constraint.
Definition: ass_tuner.h:53
@ CT_DIRICHLET
Definition: ass_tuner.h:59
@ CT_HANGING
Definition: ass_tuner.h:57
@ CT_ALL
Definition: ass_tuner.h:60
@ CT_MAY_DEPEND_ON_HANGING
Definition: ass_tuner.h:56
@ CT_ASSEMBLED
Definition: ass_tuner.h:55
@ CT_CONSTRAINTS
Definition: ass_tuner.h:58
@ EDT_ALL
Definition: elem_disc_interface.h:64
@ CT_NONE
Definition: ass_tuner.h:54
void AddLocalVector(TVector &vec, const LocalVector &lvec)
Definition: local_algebra.h:753
void AddLocalMatrixToGlobal(TMatrix &mat, const LocalMatrix &lmat)
Definition: local_algebra.h:767
T value_type
Definition: sparsematrix_interface.h:2