ug4
Loading...
Searching...
No Matches
smallalgebra_interface.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011: G-CSC, Goethe University Frankfurt
3 * Author: Martin Rupp
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
34#ifndef __H__UG__MARTIN_ALGEBRA__BLOCKS__
35#define __H__UG__MARTIN_ALGEBRA__BLOCKS__
36
37#include <ostream>
38
39namespace ug{
40
41template <typename t> struct block_traits;
42template<typename value_type, typename vec_type> struct block_multiply_traits;
43
44
46
47template<typename TYPE>
48inline double BlockNorm2(const TYPE &v);
49
50
51template<typename TYPE>
52inline double BlockNorm(const TYPE &v);
53
54
56
57// BlockRef: get/set vector
58// since double does not support operator [], we need this function
59// mostly it will be "assert(i==0); return vec;" or "return vec[i];"
60template<typename T> inline double &BlockRef(T &vec, size_t i);
61// const version
62template<typename T> inline const double &BlockRef(const T &vec, size_t i);
63
64// BlockRef: get/set matrix
65// same thing for matrices
66template<typename T> inline double &BlockRef(T &mat, size_t i, size_t j);
67// const version
68template<typename T> inline const double &BlockRef(const T &mat, size_t i, size_t j);
70
71
73// SetSize(t, a, b) for matrices
74template<typename T> inline void SetSize(T &t, size_t a, size_t b);
75
76// SetSize(t, a) for vectors
77template<typename T> inline void SetSize(T &t, size_t a);
78
79// GetSize
80template<typename T> inline size_t GetSize(const T &t);
81
82template<typename T> inline size_t GetRows(const T &t);
83
84template<typename T> inline size_t GetCols(const T &t);
85
86
87
89// traits: information for numbers
90// Here, the template parameter(s) correspond(s) to type 'number'
91// (i.e. 'double' or 'float'). Definitions for matrices are placed
92// in other headers.
93
94
95template<typename T>
96struct block_traits<T>
97{
98 typedef T vec_type;
99
100 // inverse_type: specify this type so we know what type to use
101 // INSTEAD of inverting the matrix (e.g. can be LU decomposition or Jacobi)
102 typedef T inverse_type;
103
104 // is_static is used in several functions. if so,
105 // the type has static number of rows/cols and can be copied via memcpy
106 // (that means no pointers used).
107 enum { is_static = true};
108
109 enum { static_num_rows = 1};
110 enum { static_num_cols = 1};
111 enum { static_size = 1 };
112};
113
114/*
115 * used to determine the result of the muliplication of two values
116 */
117template<typename T>
119{
120 typedef T1 ReturnType;
121};
122
123/*
124 * initializes the inverse inv of m. This function gets the inverse type of m
125 * by using block_traits<T>::inverse_type. Please note that the inverse_type and
126 * T need not be the same. Examples:
127 * T = dense matrix, inverse_type = LU decompositions
128 * T = small sparse matrix, inverse_type = couple of Jacobi steps.
129 * T = double, inverse_type = double
130 * T = complex, inverse_type = complex
131 *
132 * The inverse_type needs only to support the MatMult and MatMultAdd functions,
133 * and you can also do all work there (like when you have a sparse matrix block and
134 * want to use gauss-seidel on this block, then GetInverse just sets a pointer to
135 * the sparse matrix).
136 *
137 */
138template<typename T>
139inline bool GetInverse(block_traits<T>::inverse_type &inv, const T &m);
140
141
142/*
143 * This functions really inverts m.
144 * Use this function with care, because it is possible that some structures do not support it
145 * (like sparse matrices).
146 */
147template<typename T>
148inline bool Invert(T &m);
149
151// dest = beta * mat^{-1} vec
152template<typename TMat, typename TVec>
153inline bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec);
154
155
156} // namespace ug
157
158
double number
Definition types.h:124
the ug namespace
size_t GetCols(const T &t)
bool GetInverse(block_traits< T >::inverse_type &inv, const T &m)
bool Invert(T &m)
double & BlockRef(T &vec, size_t i)
Definition blocks.h:66
void SetSize(T &t, size_t a, size_t b)
size_t GetRows(const T &t)
double BlockNorm2(const TYPE &v)
Definition blocks.h:51
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
size_t GetSize(const T &t)
double BlockNorm(const TYPE &v)
Definition blocks.h:57
T1 ReturnType
Definition smallalgebra_interface.h:120
Definition smallalgebra_interface.h:42
T inverse_type
Definition smallalgebra_interface.h:102
T vec_type
Definition smallalgebra_interface.h:98
Definition communication_policies.h:58
@ is_static
Definition communication_policies.h:60