Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ass_tuner_impl.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_IMPL__
34#define __H__UG__LIB_DISC__SPATIAL_DISC__ASS_TUNER_IMPL__
35
36#include "ass_tuner.h"
37
38namespace ug{
39
40template <typename TAlgebra>
42 vector_type& vec) const
43{
44 if (single_index_assembling_enabled()){ vec.resize(1);}
45 else{
46 const size_t numIndex = dd->num_indices();
47 vec.resize(numIndex);
48 }
49
50 if (m_bClearOnResize)
51 vec.set(0.0);
52}
53
54template <typename TAlgebra>
56 matrix_type& mat) const
57{
58 if (single_index_assembling_enabled())
59 {
60 if (m_bClearOnResize) mat.resize_and_clear(1, 1);
61 else mat.resize_and_keep_values(1,1);
62 }
63 else
64 {
65 const size_t numIndex = dd->num_indices();
66 if (m_bClearOnResize)
67 {
68 if (m_bMatrixStructureIsConst)
69 {
70 UG_COND_THROW(mat.num_rows() != dd->num_indices() || mat.num_cols() != dd->num_indices(),
71 "The assembling tuner is set to use a constant matrix structure, "
72 "but the number of indices in the new matrix is different from that in the old one.");
73 mat.clear_retain_structure();
74 }
75 else
76 mat.resize_and_clear(numIndex, numIndex);
77 }
78 else
79 mat.resize_and_keep_values(numIndex, numIndex);
80 }
81}
82
83template <typename TAlgebra>
84template <typename TElem>
86{
87 if(m_pBoolMarker)
88 if(!m_pBoolMarker->is_marked(elem)) return false;
89
90 return true;
91}
92
93
94template <typename TAlgebra>
95template <typename TElem>
97 ConstSmartPtr<DoFDistribution> dd, int si) const
98{
99 if (!m_pSelector)
100 UG_THROW("Selector-iterator not set!")
101
102 Selector* sel = m_pSelector;
103 const ISubsetHandler& sh = *dd->subset_handler();
104
105 for(typename Selector::traits<TElem>::iterator iter = sel->begin<TElem>();
106 iter != sel->end<TElem>(); ++iter)
107 {
108 if(sh.get_subset_index(*iter) == si)
109 vElem.push_back(*iter);
110 }
111}
112
113template <typename TAlgebra>
115{
116 // check if assembling has been carried out with respect to one index only.
117 // For that case assembling-matrices have been resized to a block-matrix at one DoF only.
118 if(single_index_assembling_enabled())
119 {
120 if (mat.num_rows() != 1 || mat.num_cols() != 1)
121 UG_THROW("#rows and #cols need to be 1 for setting dirichlet rows"
122 " in an index-wise manner.")
123
124 const size_t index = ind[0];
125 if (index == m_SingleAssIndex)
126 SetDirichletRow(mat, 0, ind[1]);
127 }
128 else{
129 SetDirichletRow(mat, ind);
130 }
131}
132
133template <typename TAlgebra>
134void AssemblingTuner<TAlgebra>::set_dirichlet_val(vector_type& vec, const DoFIndex& ind, const double val) const
135{
136 // check if assembling has been carried out with respect to one index only.
137 // For that case assembling-vectors have been resized to a block-vector at one DoF only.
138 if(single_index_assembling_enabled())
139 {
140 if(vec.size() != 1)
141 UG_THROW("vector-size needs to be 1 for setting dirichlet values"
142 " in an index-wise manner.");
143
144 const size_t index = ind[0];
145 if(index == m_SingleAssIndex)
146 BlockRef(vec[0], ind[1]) = val;
147 }
148 else{
149 DoFRef(vec, ind) = val;
150 }
151}
152
153
154} // end namespace ug
155
156#endif /* __H__UG__LIB_DISC__SPATIAL_DISC__ASS_TUNER_IMPL__ */
Definition smart_pointer.h:296
void set_dirichlet_val(vector_type &vec, const DoFIndex &ind, const double val) const
Definition ass_tuner_impl.h:134
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
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
void set_dirichlet_row(matrix_type &mat, const DoFIndex &ind) const
Definition ass_tuner_impl.h:114
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
Definition subset_handler_interface.h:223
int get_subset_index(GridObject *elem) const
Definition subset_handler_interface.cpp:560
Definition multi_index.h:50
specialization of ISelector for a grid of class Grid.
Definition selector_grid.h:96
geometry_traits< TElem >::iterator end()
Definition selector_grid_impl.hpp:134
geometry_traits< TElem >::iterator begin()
Definition selector_grid_impl.hpp:106
void SetDirichletRow(TSparseMatrix &A, size_t i, size_t alpha)
Definition sparsematrix_util.h:796
#define UG_THROW(msg)
Definition error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
the ug namespace
double & BlockRef(T &vec, size_t i)
Definition blocks.h:66
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition multi_index.h:276
geometry_traits< TElem >::iterator iterator
Definition selector_grid.h:104