Line data Source code
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
37 : ///////////////////////////////////////////////////////////////////////////////////////////////////
38 :
39 : template<typename vector_t, typename matrix_t>
40 : struct mat_operations_class<vector_t, matrix_t, MATRIX_USE_ROW_FUNCTIONS>
41 : {
42 : //! calculates dest = beta1 * A1;
43 0 : static inline bool MatMult(vector_t &dest,
44 : const number &beta1, const matrix_t &A1, const vector_t &w1)
45 : {
46 0 : for(size_t i=0; i<dest.size(); i++)
47 : {
48 0 : dest[i] = 0.0;
49 0 : A1.mat_mult_add_row(i, dest[i], beta1, w1);
50 : }
51 0 : return true;
52 : }
53 :
54 : //! calculates dest = alpha1*v1 + beta1 * A1 *w1;
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 :
67 : //! calculates dest = alpha1*v1 + alpha2*v2 + beta1 * A1 *w1;
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 :
82 : //! calculates dest = beta1 * A1 *w1 + beta2 * A2*w2;
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 :
97 : //! calculates dest = beta1 * A1 *w1 + beta2 * A2*w2 + alpha1*v1;
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 :
112 : //! calculates dest = beta1 * A1^T *w1;
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 :
119 : //! calculates dest = alpha1*v1 + beta1 * A1^T *w1;
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 : }
|