ug4
Loading...
Searching...
No Matches
operations_mat.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: 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#ifndef __H__UG__CPU_ALGEBRA__OPERATIONS_MAT__
34#define __H__UG__CPU_ALGEBRA__OPERATIONS_MAT__
35
36#include "common/common.h"
38
39// operations for matrices
40//-----------------------------------------------------------------------------
41// these functions execute matrix operations
42
44
46
48
50
51namespace ug
52{
53
54// functions transforming MatMult into the right operation, depending on matrix_algebra_type_traits.
56
58template<typename vector_t, typename matrix_t>
59inline bool MatMult(vector_t &dest,
60 const number &beta1, const matrix_t &A1, const vector_t &w1)
61{
63 ::MatMult(dest, beta1, A1, w1);
64}
65
67template<typename vector_t, typename matrix_t>
68inline bool MatMultAdd(vector_t &dest,
69 const number &alpha1, const vector_t &v1,
70 const number &beta1, const matrix_t &A1, const vector_t &w1 )
71{
73 ::MatMultAdd(dest, alpha1, v1, beta1, A1, w1);
74}
75
77template<typename vector_t, typename matrix_t>
78inline bool MatMultAdd(vector_t &dest,
79 const number &alpha1, const vector_t &v1,
80 const number &alpha2, const vector_t &v2,
81 const number &beta1, const matrix_t &A1, const vector_t &w1)
82{
84 ::MatMultAdd(dest, alpha1, v1, alpha2, v2, beta1, A1, w1);
85}
86
88template<typename vector_t, typename matrix_t>
89inline bool MatMultAdd(vector_t &dest,
90 const number &beta1, const matrix_t &A1, const vector_t &w1,
91 const number &beta2, const matrix_t &A2, const vector_t &w2)
92{
94 ::MatMultAdd(dest, beta1, A1, w1, A2, w2);
95}
96
98template<typename vector_t, typename matrix_t>
99inline bool MatMultAdd(vector_t &dest,
100 const number &alpha1, const vector_t &v1,
101 const number &beta1, const matrix_t &A1, const vector_t &w1,
102 const number &beta2, const matrix_t &A2, const vector_t &w2)
103{
105 ::MatMultAdd(dest, alpha1, v1, beta1, A1, w1, beta2, A2, w2);
106}
107
108
110template<typename vector_t, typename matrix_t>
111inline bool MatMultTransposed(vector_t &dest,
112 const number &beta1, const matrix_t &A1, const vector_t &w1 )
113{
115 ::MatMultTransposed(dest, beta1, A1, w1);
116}
117
118
120template<typename vector_t, typename matrix_t>
121inline bool MatMultTransposedAdd(vector_t &dest,
122 const number &alpha1, const vector_t &v1,
123 const number &beta1, const matrix_t &A1, const vector_t &w1 )
124{
126 ::MatMultTransposedAdd(dest, alpha1, v1, beta1, A1, w1);
127}
128/*
130template<typename vector_t, typename matrix_t>
131inline void MatMultAddNorm(vector_t &dest,
132 const number &beta1, const TE_MAT_RowApplicable<matrix_t> &A1, const vector_t &w1,
133 const number &alpha1, const vector_t &v1,
134 double &norm)
135{
136 if(OPERATIONS_VERBOSE) cout << "dest: " << dest << endl <<
137 "\t= " << beta1 << " * " << A1.cast() << "\t * " << w1 << endl <<
138 "\t+ " << alpha1 << " * " << v1 << endl;
139
140 norm=0;
141 for(size_t i=0; i<dest.size(); i++)
142 {
143 VecScaleAssign(dest[i], alpha1, v1[i]);
144 A1.cast().mat_mult_add_row(i, dest[i], beta1, w1);
145 VecNormSquaredAdd(dest[i], norm);
146 }
147}
148*/
149
150
151
152} // namespace ug
153#endif /* __H__UG__CPU_ALGEBRA__OPERATIONS_MAT__ */
double number
Definition types.h:124
the ug namespace
bool MatMultTransposedAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:121
bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:68
bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition operations_mat.h:59
bool MatMultTransposed(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:111
Definition matrix_algebra_types.h:75