ug4
matrix_use_row_functions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012: 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 #include "../operations_vec.h"
34 namespace ug
35 {
36 // MATRIX_USE_ROW_FUNCTIONS
38 
39 template<typename vector_t, typename matrix_t>
41 {
43  static inline bool MatMult(vector_t &dest,
44  const number &beta1, const matrix_t &A1, const vector_t &w1)
45  {
46  for(size_t i=0; i<dest.size(); i++)
47  {
48  dest[i] = 0.0;
49  A1.mat_mult_add_row(i, dest[i], beta1, w1);
50  }
51  return true;
52  }
53 
55  static inline bool MatMultAdd(vector_t &dest,
56  const number &alpha1, const vector_t &v1,
57  const number &beta1, const matrix_t &A1, const vector_t &w1)
58  {
59  for(size_t i=0; i<dest.size(); i++)
60  {
61  VecScaleAssign(dest[i], alpha1, v1[i]);
62  A1.mat_mult_add_row(i, dest[i], beta1, w1);
63  }
64  return true;
65  }
66 
68  static inline bool MatMultAdd(vector_t &dest,
69  const number &alpha1, const vector_t &v1,
70  const number &alpha2, const vector_t &v2,
71  const number &beta1, const matrix_t &A1, const vector_t &w1)
72  {
73  for(size_t i=0; i<dest.size(); i++)
74  {
75  VecScaleAdd(dest[i], alpha1, v1[i], alpha2, v2[i]);
76  A1.cast().mat_mult_add_row(i, dest[i], beta1, w1);
77  }
78  return true;
79  }
80 
81 
83  static inline bool MatMultAdd(vector_t &dest,
84  const number &beta1, const matrix_t &A1, const vector_t &w1,
85  const number &beta2, const matrix_t &A2, const vector_t &w2)
86  {
87  for(size_t i=0; i<dest.size(); i++)
88  {
89  dest[i] = 0.0;
90  A1.cast().mat_mult_add_row(i, dest[i], beta1, w1);
91  A2.cast().mat_mult_add_row(i, dest[i], beta2, w2);
92  }
93  return true;
94  }
95 
96 
98  static inline bool MatMultAdd(vector_t &dest,
99  const number &alpha1, const vector_t &v1,
100  const number &beta1, const matrix_t &A1, const vector_t &w1,
101  const number &beta2, const matrix_t &A2, const vector_t &w2)
102  {
103  for(size_t i=0; i<dest.size(); i++)
104  {
105  VecScaleAssign(dest[i], alpha1, v1[i]);
106  A1.cast().mat_mult_add_row(i, dest[i], beta1, w1);
107  A2.cast().mat_mult_add_row(i, dest[i], beta2, w2);
108  }
109  return true;
110  }
111 
113  static inline bool MatMultTransposed(vector_t &dest,
114  const number &beta1, const matrix_t &A1, const vector_t &w1)
115  {
116  return MatMultTransposed(dest, beta1, A1, w1);
117  }
118 
120  static inline bool MatMultTransposedAdd(vector_t &dest,
121  const number &alpha1, const vector_t &v1,
122  const number &beta1, const matrix_t &A1, const vector_t &w1)
123  {
124  return MatMultTransposedAddDirect(dest, beta1, A1, w1, alpha1, w1);
125  }
126 };
127 }
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_ROW_FUNCTIONS
Definition: matrix_algebra_types.h:68
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 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 + alpha2*v2 + beta1 * A1 *w1;
Definition: matrix_use_row_functions.h:68
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_row_functions.h:113
static bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition: matrix_use_row_functions.h:43
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_row_functions.h:83
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_row_functions.h:120
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_row_functions.h:55
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_row_functions.h:98
Definition: matrix_algebra_types.h:75