ug4
Loading...
Searching...
No Matches
bridge_mat_vec_operations.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-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// include bridge
35#include "bridge/bridge.h"
36#include "bridge/util.h"
38
39#ifndef BRIDGE_MAT_VEC_OPERATIONS_H_
40#define BRIDGE_MAT_VEC_OPERATIONS_H_
41
42namespace ug{
43
44namespace bridge{
45namespace AlgebraCommon{
46
47template<typename TAlgebra>
49{
50 typedef typename TAlgebra::vector_type vector_type;
51public:
53 {
54 scaling.push_back(scale1);
55 vecs.push_back(v1);
56 }
57 VecScaleAddClass(double scale1, SmartPtr<vector_type> v1, double scale2, SmartPtr<vector_type> v2)
58 {
59 scaling.push_back(scale1);
60 vecs.push_back(v1);
61 scaling.push_back(scale2);
62 vecs.push_back(v2);
63 }
64
66 {
67 scaling.push_back(scale1);
68 vecs.push_back(v1);
69 for(size_t i=0; i<vsac->size(); i++)
70 {
71 scaling.push_back(scale*vsac->scaling[i]);
72 vecs.push_back(vsac->vecs[i]);
73 }
74 }
75
77 {
78 scaling.push_back(scale1);
79 vecs.push_back(v1);
80 for(size_t i=0; i<vsac->size(); i++)
81 {
82 scaling.push_back(scale*vsac->scaling[i]);
83 vecs.push_back(vsac->vecs[i]);
84 }
85 }
86
88 {
89 for(size_t i=0; i<vsac->size(); i++)
90 {
91 scaling.push_back(scale*vsac->scaling[i]);
92 vecs.push_back(vsac->vecs[i]);
93 }
94 }
95
97
99 scaling(parent.scaling), vecs(parent.vecs)
100 { }
101
102
103 size_t size() const { return scaling.size(); }
104
106 {
107 SmartPtr<vector_type> p = vecs[0]->clone();
108 assign(p);
109 return p;
110 }
111
113 {
114#ifdef UG_PARALLEL
115 for(size_t i=0; i<size(); i++)
116 vecs[i]->change_storage_type(PST_CONSISTENT);
117#endif
118 if(size() == 1)
119 VecScaleAssign(*p, scaling[0], *vecs[0]);
120 else if(size() == 2)
121 VecScaleAdd(*p, scaling[0], *vecs[0], scaling[1], *vecs[1]);
122 else if(size() == 3)
123 VecScaleAdd(*p, scaling[0], *vecs[0], scaling[1], *vecs[1], scaling[2], *vecs[2]);
124 else
125 {
126 UG_THROW("not supported ATM.");
127 }
128 }
129private:
130 std::vector<double> scaling;
131 std::vector<SmartPtr<vector_type> > vecs;
132};
133
134template<typename TAlgebra>
139
140template<typename TAlgebra>
145
146
147template<typename TAlgebra>
152
153template<typename T>
155{
156 SmartPtr<T> v2 = v->clone();
157#ifdef UG_PARALLEL
158 v->change_storage_type(PST_CONSISTENT);
159#endif
160 op->apply(*v2, *v);
161 return v2;
162}
163
164
165template<typename TAlgebra>
167{
169 return VecProd2<TAlgebra>(v1, v2);
170}
171
172template<typename TAlgebra>
174{
176 return VecProd2<TAlgebra>(v1, v2);
177}
178
179template<typename TAlgebra>
181{
182 return v->norm();
183}
184
185
186template<typename TAlgebra>
188{
189 return v->maxnorm();
190}
191
192
193template<typename TAlgebra>
195{
197 return v->norm();
198}
199
200
201
203template<typename vector_t>
204inline void VecScaleAdd2(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2)
205{
206 VecScaleAdd(dest, alpha1, v1, alpha2, v2);
207}
208
210template<typename vector_t>
211inline void VecScaleAdd3(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2, double alpha3, const vector_t &v3)
212{
213 VecScaleAdd(dest, alpha1, v1, alpha2, v2, alpha3, v3);
214}
215
216}
217}
218}
219#endif /* BRIDGE_MAT_VEC_OPERATIONS_H_ */
parameterString p
Definition smart_pointer.h:108
describes a linear mapping X->Y
Definition linear_operator.h:80
Definition bridge_mat_vec_operations.h:49
SmartPtr< vector_type > eval()
Definition bridge_mat_vec_operations.h:105
std::vector< SmartPtr< vector_type > > vecs
Definition bridge_mat_vec_operations.h:131
VecScaleAddClass(double scale, SmartPtr< VecScaleAddClass< TAlgebra > > vsac, double scale1, SmartPtr< vector_type > v1)
Definition bridge_mat_vec_operations.h:65
VecScaleAddClass(double scale1, SmartPtr< vector_type > v1, double scale, SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:76
void assign(SmartPtr< vector_type > p)
Definition bridge_mat_vec_operations.h:112
std::vector< double > scaling
Definition bridge_mat_vec_operations.h:130
VecScaleAddClass(double scale1, SmartPtr< vector_type > v1)
Definition bridge_mat_vec_operations.h:52
TAlgebra::vector_type vector_type
Definition bridge_mat_vec_operations.h:50
VecScaleAddClass(double scale, SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:87
VecScaleAddClass(const VecScaleAddClass< TAlgebra > &parent)
Definition bridge_mat_vec_operations.h:98
VecScaleAddClass()
Definition bridge_mat_vec_operations.h:96
size_t size() const
Definition bridge_mat_vec_operations.h:103
VecScaleAddClass(double scale1, SmartPtr< vector_type > v1, double scale2, SmartPtr< vector_type > v2)
Definition bridge_mat_vec_operations.h:57
@ PST_CONSISTENT
Definition parallel_storage_type.h:68
#define UG_THROW(msg)
Definition error.h:57
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition math_vector_functions_common_impl.hpp:265
void Assign(SmartPtr< typename TAlgebra::vector_type > p, SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:135
double VecScaleAddProd2(SmartPtr< VecScaleAddClass< TAlgebra > > vsac, SmartPtr< typename TAlgebra::vector_type > v1)
Definition bridge_mat_vec_operations.h:173
SmartPtr< T > VecProdOp(SmartPtr< ILinearOperator< T, T > > op, SmartPtr< T > v)
Definition bridge_mat_vec_operations.h:154
double VecMaxNorm(SmartPtr< typename TAlgebra::vector_type > v)
Definition bridge_mat_vec_operations.h:187
double VecProd2(SmartPtr< typename TAlgebra::vector_type > v1, SmartPtr< typename TAlgebra::vector_type > v2)
Definition bridge_mat_vec_operations.h:148
void VecScaleAdd3(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2, double alpha3, const vector_t &v3)
calculates dest = alpha1*v1 + alpha2*v2 + alpha3*v3
Definition bridge_mat_vec_operations.h:211
void VecScaleAdd2(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2)
calculates dest = alpha1*v1 + alpha2*v2
Definition bridge_mat_vec_operations.h:204
double VecScaleAddProd1(SmartPtr< typename TAlgebra::vector_type > v1, SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:166
SmartPtr< typename TAlgebra::vector_type > Eval(SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:141
double VecScaleAddNorm(SmartPtr< VecScaleAddClass< TAlgebra > > vsac)
Definition bridge_mat_vec_operations.h:194
double VecNorm(SmartPtr< typename TAlgebra::vector_type > v)
Definition bridge_mat_vec_operations.h:180
the ug namespace
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition operations_vec.h:49