ug4
matrix_use_global_functions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013: 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 // MATRIX_USE_GLOBAL_FUNCTIONS
35 
36 #include "../operations_vec.h"
37 
38 namespace ug{
39 
42 template<typename vector_t, typename matrix_t>
43 inline bool MatMultAddDirect(vector_t &dest,
44  const number &beta1, const matrix_t &A1, const vector_t &w1,
45  const number &alpha1, const vector_t &v1)
46 {
47  VecScaleAssign(dest, alpha1, v1);
48  return MatMultAddDirect(dest, beta1, A1.cast(), w1);
49 }
50 
52 template<typename vector_t, typename matrix_t>
53 inline bool MatMultAddDirect(vector_t &dest,
54  const number &beta1, const matrix_t &A1, const vector_t &w1,
55  const number &alpha1, const vector_t &v1,
56  const number &alpha2, const vector_t &v2)
57 {
58  bool b = MatMultDirect(dest, beta1, A1, w1);
59  VecScaleAdd(dest, 1.0, dest, alpha1, v1, alpha2, v2);
60  return b;
61 }
62 
63 
65 template<typename vector_t, typename matrix_t>
66 inline bool MatMultAddDirect(vector_t &dest,
67  const number &beta1, const matrix_t &A1, const vector_t &w1,
68  const number &beta2, const matrix_t &A2, const vector_t &w2)
69 {
70  MatMultDirect(dest, beta1, A1.cast(), w1);
71  return MatMultAddDirect(dest, beta2, A2, w2, 1.0, dest);
72 }
73 
74 
76 template<typename vector_t, typename matrix_t>
77 inline bool MatMultAddDirect(vector_t &dest,
78  const number &beta1, const matrix_t &A1, const vector_t &w1,
79  const number &beta2, const matrix_t &A2, const vector_t &w2,
80  const number &alpha1, const vector_t &v1)
81 {
82  bool b = MatMultAddDirect(dest, beta1, A1, w1, beta2, A2, w2);
83  VecScaleAdd(dest, 1.0, dest, alpha1, v1);
84  return b;
85 }
86 
87 
88 template<typename vector_t, typename matrix_t>
90 {
92  static inline bool MatMult(vector_t &dest,
93  const number &beta1, const matrix_t &A1, const vector_t &w1)
94  {
95  return MatMultDirect(dest, beta1, A1, w1);
96  }
97 
99  static inline 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  {
103  return MatMultAddDirect(dest, alpha1, v1, beta1, A1, w1);
104  }
105 
107  static inline bool MatMultAdd(vector_t &dest,
108  const number &alpha1, const vector_t &v1,
109  const number &alpha2, const vector_t &v2,
110  const number &beta1, const matrix_t &A1, const vector_t &w1)
111  {
112  return MatMultAddDirect(dest, alpha1, v1, alpha2, v2, beta1, A1, w1);
113  }
114 
116  static inline bool MatMultAdd(vector_t &dest,
117  const number &beta1, const matrix_t &A1, const vector_t &w1,
118  const number &beta2, const matrix_t &A2, const vector_t &w2)
119  {
120  return MatMultAddDirect(dest, beta1, A1, w1, A2, w2);
121  }
122 
124  static inline bool MatMultAdd(vector_t &dest,
125  const number &alpha1, const vector_t &v1,
126  const number &beta1, const matrix_t &A1, const vector_t &w1,
127  const number &beta2, const matrix_t &A2, const vector_t &w2)
128  {
129  return MatMultAddDirect(dest, alpha1, v1, beta1, A1, w1, beta2, A2, w2);
130  }
131 
133  static inline bool MatMultTransposed(vector_t &dest,
134  const number &beta1, const matrix_t &A1, const vector_t &w1)
135  {
136  return MatMultTransposed(dest, beta1, A1, w1);
137  }
138 
140  static inline bool MatMultTransposedAdd(vector_t &dest,
141  const number &alpha1, const vector_t &v1,
142  const number &beta1, const matrix_t &A1, const vector_t &w1)
143  {
144  return MatMultTransposedAddDirect(dest, alpha1, w1, beta1, A1, w1);
145  }
146 };
147 }
double number
Definition: types.h:124
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
the ug namespace
@ MATRIX_USE_GLOBAL_FUNCTIONS
Definition: matrix_algebra_types.h:69
bool MatMultDirect(ParallelVector< vector_type > &dest, const number &beta1, const ParallelMatrix< matrix_type > &A1, const ParallelVector< vector_type > &w1)
Definition: parallel_matrix_impl.h:224
bool MatMultAddDirect(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1, const number &alpha1, const vector_t &v1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition: matrix_use_global_functions.h:43
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition: operations_vec.h:49
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
static bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition: matrix_use_global_functions.h:92
static 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: matrix_use_global_functions.h:99
static bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &alpha2, const vector_t &v2, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1 + alpha2*v2;
Definition: matrix_use_global_functions.h:107
static 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^T *w1;
Definition: matrix_use_global_functions.h:140
static bool MatMultTransposed(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1^T *w1;
Definition: matrix_use_global_functions.h:133
static bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1, const number &beta2, const matrix_t &A2, const vector_t &w2)
calculates dest = beta1 * A1 *w1 + beta2 * A2*w2 + alpha1*v1;
Definition: matrix_use_global_functions.h:124
static bool MatMultAdd(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1, const number &beta2, const matrix_t &A2, const vector_t &w2)
calculates dest = beta1 * A1 *w1 + beta2 * A2*w2;
Definition: matrix_use_global_functions.h:116
Definition: matrix_algebra_types.h:75