Line data Source code
1 : /*
2 : * Copyright (c) 2010-2011: 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 :
34 : #ifndef __H__UG__SMALL_ALGEBRA__BLOCKS__
35 : #define __H__UG__SMALL_ALGEBRA__BLOCKS__
36 :
37 : #include <ostream>
38 :
39 : namespace ug{
40 :
41 0 : inline double dabs(double a) { return a > 0 ? a : -a; }
42 :
43 :
44 : template <typename t> struct block_traits;
45 : template<typename value_type, typename vec_type> struct block_multiply_traits;
46 :
47 :
48 : //////////////////////////////////////////////////////
49 :
50 : template<typename TYPE>
51 : inline double BlockNorm2(const TYPE &v)
52 : {
53 : return v.norm2();
54 : }
55 :
56 : template<typename TYPE>
57 0 : inline double BlockNorm(const TYPE &v)
58 : {
59 0 : return sqrt(BlockNorm2(v));
60 : }
61 :
62 :
63 : //////////////////////////////////////////////////////
64 :
65 : // get/set vector
66 : template<typename T> inline double &BlockRef(T &vec, size_t i)
67 : {
68 : return vec[i];
69 : }
70 :
71 : template<typename T> inline const double &BlockRef(const T &vec, size_t i)
72 : {
73 : return vec[i];
74 : }
75 :
76 : // get/set matrix
77 : template<typename T> inline double &BlockRef(T &mat, size_t i, size_t j)
78 : {
79 : return mat(i, j);
80 : }
81 :
82 : template<typename T> inline const double &BlockRef(const T &mat, size_t i, size_t j)
83 : {
84 : return mat(i, j);
85 : }
86 :
87 :
88 : //////////////////////////////////////////////////////
89 :
90 : /*template<typename T, size_t n> inline bool BlockSerialize(const DenseVector<FixedArray<T, n> > &t, std::ostream &buff)
91 : {
92 : for(int i=0; i<n; i++)
93 : BlockSerialize(v[i], buff);
94 : return true;
95 : }
96 :
97 :
98 : template<typename T, size_t n> inline bool BlockDeserialize(const DenseVector<FixedArray<T, n> > &t, std::ostream &buff)
99 : {
100 : for(int i=0; i<n; i++)
101 : BlockDeserialize(v[i], buff);
102 : return true;
103 : }
104 : */
105 : //////////////////////////////////////////////////////
106 :
107 :
108 : //////////////////////////////////////////////////////
109 :
110 :
111 : //////////////////////////////////////////////////////
112 : // algebra stuff to avoid temporary variables
113 :
114 :
115 : // MATRICES
116 :
117 : // todo: replace add_mult etc. with template expressions
118 : // dest = b*vec
119 : template<typename A, typename B, typename C> inline void AssignMult(A &dest, const B &b, const C &vec);
120 : // dest += b*vec
121 : template<typename A, typename B, typename C> inline void AddMult(A &dest, const B &b, const C &vec);
122 : // dest -= b*vec
123 : template<typename A, typename B, typename C> inline void SubMult(A &dest, const B &b, const C &vec);
124 :
125 : // VECTORs
126 :
127 :
128 :
129 : //////////////////////////////////////////////////////
130 : //setSize(t, a, b) for matrices
131 : template<typename T>
132 : inline void SetSize(T &t, size_t a, size_t b);
133 :
134 : //setSize(t, a) for vectors
135 : template<typename T>
136 : inline void SetSize(T &t, size_t a);
137 :
138 : // getSize
139 : template<typename T>
140 : inline size_t GetSize(const T &t);
141 :
142 : //getRows
143 : template<typename T>
144 : inline size_t GetRows(const T &t);
145 :
146 : // getRows
147 : template<typename T>
148 : inline size_t GetCols(const T &t);
149 :
150 :
151 :
152 : } // namespace ug
153 :
154 : #include "double.h"
155 : #include "small_matrix/densevector.h"
156 : #include "small_matrix/densematrix.h"
157 : #include "small_matrix/block_dense.h"
158 : #include "storage/storage.h"
159 :
160 : #endif /* __H__UG__SMALL_ALGEBRA__BLOCKS__ */
|