Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
densevector_impl.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#ifndef __H__UG__COMMON__DENSEVECTOR_IMPL_H__
35#define __H__UG__COMMON__DENSEVECTOR_IMPL_H__
36
38
39namespace ug{
40
41template<typename TStorage>
43{
44 operator=(alpha);
45}
46
47template<typename TStorage>
51
52// operations with vectors
53template<typename TStorage>
56{
57 if(this == &rhs) return *this;
58 if(size() != rhs.size()) resize(rhs.size());
59
60 for(size_type i=0; i<size(); i++)
61 entry(i) = rhs[i];
62 return *this;
63}
64
65
66template<typename TStorage>
69{
70 for(size_type i=0; i<size(); i++)
71 entry(i) += rhs[i];
72 return *this;
73}
74
75
76template<typename TStorage>
79{
80 for(size_type i=0; i<size(); i++)
81 entry(i) -= rhs[i];
82 return *this;
83}
84
85
86// operations with scalars
87template<typename TStorage>
88template<typename T>
91{
92 for(size_t i=0; i<size(); i++)
93 entry(i) = alpha;
94 return *this;
95}
96
97template<typename TStorage>
100{
101 for(size_t i=0; i<size(); i++)
102 entry(i) += alpha;
103 return *this;
104}
105
106template<typename TStorage>
107DenseVector<TStorage> &
109{
110 for(size_t i=0; i<size(); i++)
111 entry(i) -= alpha;
112 return *this;
113}
114
115template<typename TStorage>
116template<typename T>
117DenseVector<TStorage> &
119{
120 for(size_t i=0; i<size(); i++)
121 entry(i) *= alpha;
122 return *this;
123}
124
125
126template<typename TStorage>
129{
130 for(size_t i=0; i<size(); i++)
131 entry(i) /= alpha;
133 return *this;
134}
136template<typename TStorage>
138{
139 UG_LOG(name << " = vector([");
140 for(size_t i=0; i<size(); ++i)
141 {
142 if(i > 0) UG_LOG(", ");
143 UG_LOG(entry(i));
144 }
145 UG_LOG("]);\n");
146}
147
148// views
149// methods
150
151
152template<typename TStorage>
153std::ostream &operator << (std::ostream &out, const DenseVector<TStorage> &vec)
154{
155 out << "[";
156 for(size_t i=0; i<vec.size(); i++)
157 out << " " << vec[i];
158 out << " ] ";
159// out << "(" << vec.size() << ")";
160 return out;
161}
162
164
165template<typename TStorage>
166template<typename Type>
169{
170 VectorAssign(*this, t);
171 return *this;
172}
173
174
175
176template<size_t n> inline void Serialize(std::ostream &buff, const DenseVector<FixedArray1<number, n> > &vec)
177{
178 buff.write((char*)&vec, sizeof(vec));
179}
180
181template<size_t n> inline void Deserialize(std::istream &buff, DenseVector<FixedArray1<number, n> > &vec)
182{
183 buff.read((char*)&vec, sizeof(vec));
184}
185
186
187template<typename T> inline void Serialize(std::ostream &buff, const DenseVector<VariableArray1<T> > &vec)
188{
189 size_t s = vec.size();
190 buff.write((char*)&s, sizeof(s));
191 for(size_t i=0; i<s; i++)
192 Serialize(buff, vec[i]);
193}
194
195template<typename T> inline void Deserialize(std::istream &buff, DenseVector<VariableArray1<double> > &vec)
196{
197 size_t s;
198 buff.read((char*)&s, sizeof(s));
199 vec.resize(s);
200 for(size_t i=0; i<s; i++)
201 Deserialize(buff, vec[i]);
202}
203
204
205template<typename T >
207{
208 for(size_t r=0; r<v.size(); r++)
209 if(IsFiniteAndNotTooBig(v[r]) == false) return false;
210
211 return true;
212}
213
214
215//MAKE_TEMPLATE_OPERATORS_VECTOR2(typename TStorage, DenseVector<TStorage>);
216
217}
218
219#endif // __H__UG__COMMON__DENSEVECTOR_IMPL_H__
parameterString s
location name
Definition checkpoint_util.lua:128
Definition densevector.h:101
this_type & operator-=(const this_type &rhs)
Definition densevector_impl.h:78
this_type & operator=(const this_type &rhs)
Definition densevector_impl.h:55
DenseVector(double alpha=0.0)
Definition densevector_impl.h:42
this_type & operator*=(const T &alpha)
void maple_print(const char *name)
Definition densevector_impl.h:137
DenseVector< TStorage > & assign(const Type &t)
Definition densevector_impl.h:168
this_type & operator/=(const value_type &alpha)
Definition densevector_impl.h:128
TStorage::size_type size_type
Definition densevector.h:104
TStorage::value_type value_type
Definition densevector.h:103
this_type & operator+=(const this_type &rhs)
Definition densevector_impl.h:68
Definition fixed_array.h:56
Definition variable_array.h:59
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition math_matrix.cpp:38
#define UG_LOG(msg)
Definition log.h:367
the ug namespace
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition restart_bridge.cpp:112
bool IsFiniteAndNotTooBig(double d)
Definition number_util.h:39
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition restart_bridge.cpp:103
void VectorAssign(vector_t &dest, double alpha1, const MatVec_Expression< matrix_t, vector_t > &m1, double alpha2, const MatVec_Expression< matrix_t, vector_t > &m2, double alpha3, const vector_t2 &v3)
v = Mv + Mv + v
Definition operations_transform.h:51
bool resize(size_t newRows, size_t newCols)