ug4
matrix_operator_functions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2014: G-CSC, Goethe University Frankfurt
3  * Author: Konstantinos Xylouris
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 
40 #ifndef __H__LIB_ALGEBRA__MATRIX_OPERATOR_FUNCTIONS__
41 #define __H__LIB_ALGEBRA__MATRIX_OPERATOR_FUNCTIONS__
42 
44 
45 namespace ug
46 {
47 /*
48 template <typename X, typename Y, typename M>
49 void MatAdd( IMatrixOperator<M, X, Y>& opOut,
50  IMatrixOperator<M, X, Y>& op1,
51  IMatrixOperator<M, X, Y>& op2)
52 {
53  typedef IMatrixOperator<M, X, Y> MatrixOperator;
54 
55  typedef typename MatrixOperator::matrix_type Matrix;
56 
57  Matrix& matOut = opOut.get_matrix();
58  Matrix& mat1 = op1.get_matrix();
59  Matrix& mat2 = op2.get_matrix();
60 
61 // matOut = mat1 + mat2;
62  MatAdd<X, M>(matOut, mat1, mat2);
63 }
64 */
65 
66 template <typename X, typename Y, typename M>
68 {
69  PROFILE_FUNC_GROUP("algebra");
71 
72  typedef typename MatrixOperator::matrix_type Matrix;
73 
74  Matrix& matOut = opOut.get_matrix();
75  size_t numRows = matOut.num_rows();
76  size_t numCols = matOut.num_cols();
77 
78  matOut.resize_and_clear(numRows, numCols);
79 
80  for(size_t i = 0; i < numRows; ++i)
81  matOut(i, i) = 1.0;
82 }
83 
84 
85 template <typename X, typename Y, typename M>
87 {
88  PROFILE_FUNC_GROUP("algebra");
90 
91  typedef typename MatrixOperator::matrix_type Matrix;
92 
93  Matrix& matRes = res.get_matrix();
94  Matrix& matA1 = A1.get_matrix();
95  Matrix& matA2 = A2.get_matrix();
96  MatAdd(matRes, alpha1, matA1, alpha2, matA2);
97 }
98 
99 template <typename X, typename Y, typename M>
101 {
102  PROFILE_FUNC_GROUP("algebra");
104  typedef typename MatrixOperator::matrix_type Matrix;
105  Matrix& matA = A.get_matrix();
106 
107  matA.scale(alpha);
108 }
109 
110 template <typename X, typename Y, typename M>
112 {
113  PROFILE_FUNC_GROUP("algebra");
115  typedef typename MatrixOperator::matrix_type Matrix;
116 
117  Matrix& matA = A.get_matrix();
118  Matrix& matAT = AT.get_matrix();
119 
120  matAT.set_as_transpose_of(matA);
121 }
122 
123 }// end of namespace
124 
125 #endif
Definition: matrix_operator.h:49
M matrix_type
Definition: matrix_operator.h:58
virtual M & get_matrix()
Definition: matrix_operator.h:74
void MatIdentity(matrix_t &mOut)
Fills the matrix with the identity matrix.
Definition: math_matrix_functions_common_impl.hpp:865
void MatAdd(matrix_t &mOut, const matrix_t &m1, const matrix_t &m2)
adds two matrices and stores the result in a third one
Definition: math_matrix_functions_common_impl.hpp:52
void MatScale(matrix_t &mOut, typename matrix_t::value_type s, const matrix_t &m)
scales a matrix_t
Definition: math_matrix_functions_common_impl.hpp:317
number alpha
double number
Definition: types.h:124
the ug namespace
void MatTranspose(MatrixOperator< M, X, Y > &AT, MatrixOperator< M, X, Y > &A)
Definition: matrix_operator_functions.h:111
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258