ug4
scalar_subvector_adapter.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Author: Arne Nägel
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 SCALAR_SUBVECTOR_ADAPTER_HH_
34 #define SCALAR_SUBVECTOR_ADAPTER_HH_
35 
36 #include <cstdlib>
37 
41 
42 #ifdef UG_PARALLEL
44 #endif
45 
47 namespace ug{
48 
49 // provides an interface for matrix of algebra type B for matrices originally of algebra type A
50 // allows to access a CPUBlockAlgebra (AT) as a scalar CPUAlgebra (ST)
51 
52 template<class InVT, class ST>
54 public:
58 
60 
61  inline const value_type &operator [] (size_t i) const
62  { return BlockRef(m_src[i], m_alpha); }
63 
64  void print(const char * const text = NULL) const
65  { m_src.print(text);}
66 
67  size_t size() const
68  { return (m_src.size());}
69 
70 private:
72  const size_t m_alpha;
73 };
74 
75 template<class InVT, class ST=CPUAlgebra::vector_type>
77 
78 public:
82  //typedef typename ST::vector_type::const_row_iterator const_row_iterator
83 
85 
86  inline value_type &operator [] (size_t i)
87  { return BlockRef(m_src[i], m_alpha); }
88 
89  inline const value_type &operator [] (size_t i) const
90  { return BlockRef(m_src[i], m_alpha); }
91 
92  void resize(size_t newSize, bool bCopyValues=true)
93  {
94  m_src.resize_exactly(newSize, bCopyValues);
95  }
96  void reserve(size_t newCapacity, bool bCopyValues=true)
97  {
98  m_src.reserve_exactly(newCapacity, bCopyValues);
99  }
100  void print(const char * const text = NULL) const
101  {
102  m_src.print(text);
103  }
104 
105  void set_random(double from, double to)
106  {
107  for(size_t i=0; i<size(); i++)
108  BlockRef(m_src[i], m_alpha) = urand(from, to);
109  }
110 
111  size_t size() const {return (m_src.size());}
112 private:
114  const size_t m_alpha;
115 };
116 
117 
118 // partielle Spezialisierung fuer CPUAlgebra
119 template<>
122 { return m_src[i]; }
123 
124 #ifdef UG_PARALLEL
125 template<>
128 { return m_src[i]; }
129 #endif
130 
131 } // namespace ug
132 
133 #endif /* SPARSEMATRIXPROXY_HH_ */
Definition: scalar_subvector_adapter.hh:53
InVT encapsulated_vector_type
Definition: scalar_subvector_adapter.hh:55
size_t size() const
Definition: scalar_subvector_adapter.hh:67
const size_t m_alpha
Definition: scalar_subvector_adapter.hh:72
void print(const char *const text=NULL) const
Definition: scalar_subvector_adapter.hh:64
const encapsulated_vector_type & m_src
Definition: scalar_subvector_adapter.hh:71
ConstScalarSubVectorAdapter(const encapsulated_vector_type &vec, size_t alpha)
Definition: scalar_subvector_adapter.hh:59
const value_type & operator[](size_t i) const
Definition: scalar_subvector_adapter.hh:61
static const int blockSize
Definition: scalar_subvector_adapter.hh:57
ST::vector_type::value_type value_type
Definition: scalar_subvector_adapter.hh:56
Definition: scalar_subvector_adapter.hh:76
value_type & operator[](size_t i)
Definition: scalar_subvector_adapter.hh:86
ScalarSubVectorAdapter(encapsulated_vector_type &vec, size_t alpha)
Definition: scalar_subvector_adapter.hh:84
ST::vector_type::value_type value_type
Definition: scalar_subvector_adapter.hh:80
void print(const char *const text=NULL) const
Definition: scalar_subvector_adapter.hh:100
void set_random(double from, double to)
Definition: scalar_subvector_adapter.hh:105
InVT encapsulated_vector_type
Definition: scalar_subvector_adapter.hh:79
const size_t m_alpha
Definition: scalar_subvector_adapter.hh:114
void resize(size_t newSize, bool bCopyValues=true)
Definition: scalar_subvector_adapter.hh:92
size_t size() const
Definition: scalar_subvector_adapter.hh:111
void reserve(size_t newCapacity, bool bCopyValues=true)
Definition: scalar_subvector_adapter.hh:96
encapsulated_vector_type & m_src
Definition: scalar_subvector_adapter.hh:113
static const int blockSize
Definition: scalar_subvector_adapter.hh:81
number alpha
TNumber urand(TNumber lowerBound, TNumber upperBound)
uniform distributed random numbers in [lowerBound, upperBound[. Use srand to set a seed.
Definition: math_util_impl.hpp:67
the ug namespace
double & BlockRef(T &vec, size_t i)
Definition: blocks.h:66
T value_type
Definition: sparsematrix_interface.h:2
Definition: cpu_algebra_types.h:77
Definition: communication_policies.h:58