Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
double.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: 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 * blockMatrix.h
35 *
36 * Header File for general block matrix / double accessing
37 * i.e. setAt(mat, i, j, d) -> mat(i,j) = d
38 * and setAt(f, 0, 0, d) -> f = d.
39 * This means doubles and block matrices can be accessed
40 * by the same methods.
41 */
42
43// todo: also with float / complex<float> / complex<double>
44
45#ifndef __H__UG__SMALL_ALGEBRA__DOUBLE__
46#define __H__UG__SMALL_ALGEBRA__DOUBLE__
47
48#include "blocks.h"
49#include "common/common.h"
50
51namespace ug{
52
53
55template<typename T> number BlockNorm(const T &t);
56template <>
57inline number BlockNorm(const number &a)
58{
59 return a>0 ? a : -a;
60}
61
62template<typename T> number BlockNorm2(const T &t);
63template <>
64inline number BlockNorm2(const number &a)
65{
66 return a*a;
67}
68
69template<typename T> number BlockMaxNorm(const T &t);
70template <>
71inline number BlockMaxNorm(const number &a)
72{
73 return a>0 ? a : -a;
74}
75
77// get/set specialization for numbers
78
79template<> inline number &BlockRef(number &m, size_t i)
80{
81 UG_ASSERT(i == 0, "block is number, doesnt have component (" << i << ").");
82 return m;
83}
84template<> inline const number &BlockRef(const number &m, size_t i)
85{
86 UG_ASSERT(i == 0, "block is number, doesnt have component (" << i << ").");
87 return m;
88}
89
90template<> inline number &BlockRef(number &m, size_t i, size_t j)
91{
92 UG_ASSERT(i == 0 && j == 0, "block is number, doesnt have component (" << i << ", " << j << ").");
93 return m;
94}
95template<> inline const number &BlockRef(const number &m, size_t i, size_t j)
96{
97 UG_ASSERT(i == 0 && j == 0, "block is number, doesnt have component (" << i << ", " << j << ").");
98 return m;
99}
100
102// algebra stuff to avoid temporary variables
103
104inline void AssignMult(number &dest, const number &b, const number &vec)
105{
106 dest = b*vec;
107}
108// dest += vec*b
109inline void AddMult(number &dest, const number &b, const number &vec)
110{
111 dest += b*vec;
112}
113
114
115// dest -= vec*b
116inline void SubMult(number &dest, const number &b, const number &vec)
117{
118 dest -= b*vec;
119}
120
121
123//setSize(t, a, b) for numbers
124template<>
125inline void SetSize(number &d, size_t a)
126{
127 UG_ASSERT(a == 1, "block is number, cannot change size to " << a << ".");
128 return;
129}
130
131template<>
132inline void SetSize(number &d, size_t a, size_t b)
133{
134 UG_ASSERT(a == 1 && b == 1, "block is number, cannot change size to (" << a << ", " << b << ").");
135 return;
136}
137
138template<>
139inline size_t GetSize(const number &t)
140{
141 return 1;
142}
143
144template<>
145inline size_t GetRows(const number &t)
146{
147 return 1;
148}
149
150template<>
151inline size_t GetCols(const number &t)
152{
153 return 1;
154}
156
157inline bool InverseMatMult(number &dest, const double &beta, const number &mat, const number &vec)
158{
159 dest = beta*vec/mat;
160 return true;
161}
162
164// traits: information for numbers
165
166
167template<>
169{
172
173 enum { is_static = true};
174 enum { static_num_rows = 1};
175 enum { static_num_cols = 1};
176 enum { static_size = 1 };
177 enum { depth = 0 };
178};
179
181{
183};
184
185template<typename T>
187{
188 typedef T ReturnType;
189};
190
191template<typename T>
193{
194 typedef T ReturnType;
195};
196
197inline bool GetInverse(number &inv, const number &m)
198{
199 inv = 1.0/m;
200 return (m != 0.0);
201}
202
203inline bool Invert(number &m)
204{
205 bool b = (m != 0.0);
206 m = 1/m;
207 return b;
208}
209
210} // namespace ug
211
212#endif
213
214
215
#define UG_ASSERT(expr, msg)
Definition assert.h:70
double number
Definition types.h:124
the ug namespace
size_t GetCols(const T &t)
bool GetInverse(block_traits< T >::inverse_type &inv, const T &m)
void AssignMult(A &dest, const B &b, const C &vec)
void SubMult(A &dest, const B &b, const C &vec)
bool Invert(T &m)
double & BlockRef(T &vec, size_t i)
Definition blocks.h:66
void SetSize(T &t, size_t a, size_t b)
size_t GetRows(const T &t)
number BlockMaxNorm(const T &t)
double BlockNorm2(const TYPE &v)
Definition blocks.h:51
void AddMult(A &dest, const B &b, const C &vec)
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
size_t GetSize(const T &t)
double BlockNorm(const TYPE &v)
Definition blocks.h:57
T ReturnType
Definition double.h:194
T ReturnType
Definition double.h:188
number ReturnType
Definition double.h:182
Definition smallalgebra_interface.h:42
number inverse_type
Definition double.h:171
number vec_type
Definition double.h:170
Definition communication_policies.h:58
@ is_static
Definition communication_policies.h:60