ug4
te.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-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 #ifndef __H__UG__LIB_ALGEBRA__TEMPLATE_EXPRESSIONS2__
35 #define __H__UG__LIB_ALGEBRA__TEMPLATE_EXPRESSIONS2__
36 
37 //#include "blockMatrix.h"
38 
39 
40 namespace ug{
41 
47 template<typename T>
49 {
50 public:
51  const T& cast() const {return static_cast<const T&>(*this); }
52  double scaling() const { return cast().scaling(); }
53 };
54 
55 template<typename T>
56 class TE_VecScale : public TE_AlphaVec<TE_VecScale<T> >
57 {
58 public:
59  typedef T vector_type;
60  double a;
61  const T& v;
62 
63  double scaling() const { return a;}
64  const T &vec() const { return v; }
65 
66  inline TE_VecScale(double a_, const T & v_) : a(a_), v(v_)
67  { }
68 
69 };
70 
71 template<class T>
72 class TE_Vector : public TE_AlphaVec<TE_Vector<T> >
73 {
74 public:
75  typedef T vector_type;
76  double scaling() const { return 1.0;}
77  const T& vec() const {return static_cast<const T&>(*this); }
78 };
79 
80 
81 
83 // alpha*v
84 
85 template<typename T>
87 {
89 }
90 
91 template<typename T>
93 {
95 }
96 
98 
102 
103 
104 template<typename T>
106 {
107 public:
108  double a1;
109  const T& v1;
110  double a2;
111  const T& v2;
112  inline TE_VecAdd2(double a1_, const T& v1_, double a2_, const T& v2_)
113  : a1(a1_), v1(v1_), a2(a2_), v2(v2_) {}
114 };
115 
116 
117 template<typename T>
119 {
120 public:
121  double a1;
122  const T& v1;
123  double a2;
124  const T& v2;
125  double a3;
126  const T& v3;
127  inline TE_VecAdd3(double a1_, const T& v1_, double a2_, const T& v2_, double a3_, const T& v3_)
128  : a1(a1_), v1(v1_), a2(a2_), v2(v2_), a3(a3_), v3(v3_) {}
129 };
130 
131 
132 
133 
134 // ////////////////////////
135 // v1 + v2
136 
138 template<typename L, typename R>
140 {
141  return TE_VecAdd2<typename L::vector_type> (l.scaling(), l.cast().vec(), r.scaling(), r.cast().vec());
142 }
143 template<typename L, typename R>
145 {
146  return TE_VecAdd2<typename L::vector_type> (l.scaling(), l.cast().vec(), -r.scaling(), r.cast().vec());
147 }
148 
150 // (v1+v2)+v3
152 template<typename L, typename R>
154 {
155  return TE_VecAdd3<typename L::vector_type> (l.a1, l.v1, l.a2, l.v2, r.scaling(), r.cast().vec());
156 }
157 template<typename L, typename R>
159 {
160  return TE_VecAdd3<typename L::vector_type> (r.scaling(), r.cast().vec(), l.a1, l.v1, l.a2, l.v2);
161 }
162 
163 template<typename L, typename R>
165 {
166  return TE_VecAdd3<typename L::vector_type> (l.a1, l.v1, l.a2, l.v2, -r.scaling(), r.cast().vec());
167 }
168 template<typename L, typename R>
170 {
171  return TE_VecAdd3<typename L::vector_type> (r.scaling(), r.cast().vec(), -l.a1, l.v1, -l.a2, l.v2);
172 }
173 
175 // alpha*(v1+v2)
176 
178 template<typename T>
180 {
181  return TE_VecAdd2<T> (t.a1*alpha, t.v1, t.a2*alpha, t.v2);
182 }
183 
185 template<typename T>
187 {
188  return TE_VecAdd2<T> (t.a1*alpha, t.v1, t.a2*alpha, t.v2);
189 }
190 
191 
193 template<typename T>
195 {
196  return TE_VecAdd2<T> (t.a1*alpha, t.v1, t.a2*alpha, t.v2, t.a3*alpha, t.v3);
197 }
198 
200 template<typename T>
202 {
203  return TE_VecAdd3<T> (t.a1*alpha, t.v1, t.a2*alpha, t.v2, t.a3*alpha, t.v3);
204 }
205 
206 }
207 
208 
209 #endif
Definition: te.h:49
double scaling() const
Definition: te.h:52
const T & cast() const
Definition: te.h:51
Definition: te.h:106
const T & v1
Definition: te.h:109
double a1
Definition: te.h:108
TE_VecAdd2(double a1_, const T &v1_, double a2_, const T &v2_)
Definition: te.h:112
double a2
Definition: te.h:110
const T & v2
Definition: te.h:111
Definition: te.h:119
const T & v3
Definition: te.h:126
double a2
Definition: te.h:123
TE_VecAdd3(double a1_, const T &v1_, double a2_, const T &v2_, double a3_, const T &v3_)
Definition: te.h:127
double a3
Definition: te.h:125
const T & v1
Definition: te.h:122
const T & v2
Definition: te.h:124
double a1
Definition: te.h:121
Definition: te.h:57
TE_VecScale(double a_, const T &v_)
Definition: te.h:66
double a
Definition: te.h:60
T vector_type
Definition: te.h:59
const T & v
Definition: te.h:61
double scaling() const
Definition: te.h:63
const T & vec() const
Definition: te.h:64
Definition: te.h:73
double scaling() const
Definition: te.h:76
T vector_type
Definition: te.h:75
const T & vec() const
Definition: te.h:77
number alpha
the ug namespace
MatVec_Expression< L, R > operator*(const AlphaMat_Expression< L > &l, const R &r)
create a MatVec_Expression by (alpha*MATRIX) * VECTOR
Definition: template_expressions.h:223
AlphaMatVec_X_Expression< L, operation_sub, R > operator-(const TE_AMV_X< L > &l, const TE_AMV_X< R > &r)
create AlphaMatVec_X_Expression<L, operation_minus, R> by conjunction of TE_AMV_X<L> + TE_AMV_X<R>
Definition: template_expressions.h:215
AlphaMatVec_X_Expression< L, operation_add, R > operator+(const TE_AMV_X< L > &l, const TE_AMV_X< R > &r)
create AlphaMatVec_X_Expression<L, operation_add, R> by conjunction of TE_AMV_X<L> + TE_AMV_X<R>
Definition: template_expressions.h:208