ug4
Loading...
Searching...
No Matches
operations_vec_on_index_set.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
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#ifndef __H__UG__LIB_ALGEBRA__OPERATIONS_VEC_ON_INDEX_SET__
34#define __H__UG__LIB_ALGEBRA__OPERATIONS_VEC_ON_INDEX_SET__
35
36#include "operations_vec.h"
37#include <vector>
38
39namespace ug
40{
41
43template<typename vector_t>
44inline void VecSet(vector_t &dest, number alpha,
45 const std::vector<size_t> vIndex)
46{
47 std::vector<size_t>::const_iterator iter = vIndex.begin();
48 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
49
50 for(; iter < iterEnd; ++iter)
51 {
52 const size_t i = *iter;
53 UG_ASSERT(i < dest.size(), "Index to large in index set.");
54 dest[i] = alpha;
55 }
56}
57
59template<typename vector_t>
60inline void VecScaleAssign(vector_t &dest,
61 number alpha1, const vector_t &v1,
62 const std::vector<size_t> vIndex)
63{
64 std::vector<size_t>::const_iterator iter = vIndex.begin();
65 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
66
67 for(; iter < iterEnd; ++iter)
68 {
69 const size_t i = *iter;
70 UG_ASSERT(i < dest.size(), "Index to large in index set.");
71 UG_ASSERT(i < v1.size(), "Index to large in index set.");
72 VecScaleAssign(dest[i], alpha1, v1[i]);
73 }
74}
75
77template<typename vector_t>
78inline void VecScaleAdd(vector_t &dest,
79 number alpha1, const vector_t &v1,
80 number alpha2, const vector_t &v2,
81 const std::vector<size_t> vIndex)
82{
83 std::vector<size_t>::const_iterator iter = vIndex.begin();
84 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
85
86 for(; iter < iterEnd; ++iter)
87 {
88 const size_t i = *iter;
89 UG_ASSERT(i < dest.size(), "Index to large in index set.");
90 UG_ASSERT(i < v1.size(), "Index to large in index set.");
91 UG_ASSERT(i < v2.size(), "Index to large in index set.");
92 VecScaleAdd(dest[i], alpha1, v1[i], alpha2, v2[i]);
93 }
94}
95
96
98template<typename vector_t>
99inline void VecScaleAdd(vector_t &dest,
100 number alpha1, const vector_t &v1,
101 number alpha2, const vector_t &v2,
102 number alpha3, const vector_t &v3,
103 const std::vector<size_t> vIndex)
104{
105 std::vector<size_t>::const_iterator iter = vIndex.begin();
106 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
107
108 for(; iter < iterEnd; ++iter)
109 {
110 const size_t i = *iter;
111 UG_ASSERT(i < dest.size(), "Index to large in index set.");
112 UG_ASSERT(i < v1.size(), "Index to large in index set.");
113 UG_ASSERT(i < v2.size(), "Index to large in index set.");
114 UG_ASSERT(i < v3.size(), "Index to large in index set.");
115 VecScaleAdd(dest[i], alpha1, v1[i], alpha2, v2[i], alpha3, v3[i]);
116 }
117}
118
119
120// VecProd
121
123template<typename vector_t>
124inline void VecProd(const vector_t &a, const vector_t &b,
125 number &sum, const std::vector<size_t> vIndex)
126{
127 std::vector<size_t>::const_iterator iter = vIndex.begin();
128 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
129
130 for(; iter < iterEnd; ++iter)
131 {
132 const size_t i = *iter;
133 UG_ASSERT(i < a.size(), "Index to large in index set.");
134 UG_ASSERT(i < b.size(), "Index to large in index set.");
135 VecProdAdd(a[i], b[i], sum);
136 }
137}
138
140template<typename vector_t>
141inline number VecProd(const vector_t &a, const vector_t &b,
142 const std::vector<size_t> vIndex)
143{
144 number sum=0;
145 VecProd(a, b, sum, vIndex);
146 return sum;
147}
148
149
151template<typename vector_t>
152inline void VecNormSquaredAdd(const vector_t &a, const vector_t &b,
153 number &sum, const std::vector<size_t> vIndex)
154{
155 std::vector<size_t>::const_iterator iter = vIndex.begin();
156 std::vector<size_t>::const_iterator iterEnd = vIndex.end();
157
158 for(; iter < iterEnd; ++iter)
159 {
160 const size_t i = *iter;
161 UG_ASSERT(i < a.size(), "Index to large in index set.");
162 VecNormSquaredAdd(a[i], sum);
163 }
164}
165
167template<typename vector_t>
168inline number VecNormSquared(const vector_t &a, const vector_t &b,
169 const std::vector<size_t> vIndex)
170{
171 number sum=0;
172 VecNormSquaredAdd(a, sum, vIndex);
173 return sum;
174}
175
176
177
178}
179
180#endif /* __H__UG__LIB_ALGEBRA__OPERATIONS_VEC_ON_INDEX_SET__ */
#define UG_ASSERT(expr, msg)
Definition assert.h:70
double number
Definition types.h:124
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition math_vector_functions_common_impl.hpp:539
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
the ug namespace
double VecProd(const double &a, const double &b)
returns scal<a, b>
Definition operations_vec.h:84
void VecNormSquaredAdd(const double &a, double &s)
calculates s += norm_2^2(a)
Definition operations_vec.h:106
double VecNormSquared(const double &a)
returns norm_2^2(a)
Definition operations_vec.h:100
void VecProdAdd(const double &a, const double &b, double &s)
calculates s += scal<a, b>
Definition operations_vec.h:70
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition operations_vec.h:49