ug4
fixed_array_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__FIXED_ARRAY_IMPL_H__
35 #define __H__UG__COMMON__FIXED_ARRAY_IMPL_H__
36 
37 #include "storage.h"
38 #include "fixed_array.h"
39 
40 namespace ug{
41 // 'tors
42 
43 template<typename T, size_t n>
45 {
46 }
47 
48 
49 template<typename T, size_t nT>
51 {
52  assert(n == nT);
53 }
54 
55 template<typename T, size_t n>
57 {
58  for(size_type i=0; i<n; i++)
59  values[i] = other[i];
60 }
61 
62 template<typename T, size_t n>
64 {
65 }
66 
67 // capacity
68 
69 template<typename T, size_t n>
70 inline size_t
72 {
73  return n;
74 }
75 
76 
77 template<typename T, size_t n>
78 inline bool
79 FixedArray1<T, n>::resize(size_t newN, bool bCopyValues)
80 {
81  assert(newN == n);
82  return newN == n;
83 }
84 
85 
86 template<typename T, size_t n>
87 inline bool
88 FixedArray1<T, n>::reserve(size_t newN) const
89 {
90  assert(newN <= n);
91  return newN <= n;
92 }
93 
94 
95 // Element access
96 template<typename T, size_t n>
97 inline T &
99 {
100  assert(i<n);
101  return values[i];
102 }
103 
104 template<typename T, size_t n>
105 inline const T &
107 {
108  assert(i<n);
109  return values[i];
110 }
111 
112 // output
113 
114 template<typename T, size_t n>
115 std::ostream &operator << (std::ostream &out, const FixedArray1<T, n> &arr)
116 {
117  out << "FixedArray (n=" << n << ") [ ";
118  for(typename FixedArray1<T, n>::size_type i=0; i<arr.size(); i++)
119  out << arr[i] << " ";
120  out << "]";
121  return out;
122 }
123 
124 
126 
127 // 'tors
128 
129 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
131 {
132 }
133 
134 
135 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
137 {
138  assert(rows == rowsT && cols == colsT);
139 }
140 
141 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
143 {
144  for(size_type i=0; i<rowsT*colsT; i++)
145  values[i] = other.values[i];
146 }
147 
148 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
150 {
151 }
152 
153 // Capacity
154 
155 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
156 inline size_t
158 {
159  return rowsT;
160 }
161 
162 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
163 inline size_t
165 {
166  return colsT;
167 }
168 
169 
170 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
171 inline bool
172 FixedArray2<T, rowsT, colsT, T_ordering>::resize(size_t newRows, size_t newCols, bool bCopyValues)
173 {
174  assert(newCols == colsT && newRows == rowsT);
175  return newCols == colsT && newRows == rowsT;
176 }
177 
178 
179 
180 // Element access
181 
182 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
183 inline T &
185 {
186  assert(r<rowsT);
187  assert(c<colsT);
188  if(T_ordering == RowMajor)
189  return values[c+r*colsT];
190  else
191  return values[r+c*rowsT];
192 }
193 
194 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
195 inline const T &
197 {
198  assert(r<rowsT);
199  assert(c<colsT);
200  if(T_ordering == RowMajor)
201  return values[c+r*colsT];
202  else
203  return values[r+c*rowsT];
204 }
205 
206 /*
207 template<typename T, size_t rowsT, size_t colsT>
208 T &
209 FixedArray2<T, rowsT, colsT, ColMajor>::operator()(size_t r, size_t c)
210 {
211  assert(r>=0 && r<rowsT);
212  assert(c>=0 && c<colsT);
213  return values[c+r*colsT];
214 }
215 
216 template<typename T, size_t rowsT, size_t colsT>
217 T &
218 FixedArray2<T, rowsT, colsT, RowMajor>::operator()(size_t r, size_t c)
219 {
220  assert(r>=0 && r<rowsT);
221  assert(c>=0 && c<colsT);
222  return values[r+c*rowsT];
223 }
224 
225 
226 template<typename T, size_t rowsT, size_t colsT>
227 const T &
228 FixedArray2<T, rowsT, colsT, ColMajor>::operator()(size_t r, size_t c) const
229 {
230  assert(r>=0 && r<rowsT);
231  assert(c>=0 && c<colsT);
232  return values[c+r*colsT];
233 }
234 
235 template<typename T, size_t rowsT, size_t colsT>
236 const T &
237 FixedArray2<T, rowsT, colsT, RowMajor>::operator()(size_t r, size_t c) const
238 {
239  assert(r>=0 && r<rowsT);
240  assert(c>=0 && c<colsT);
241  return values[r+c*rowsTT];
242 }*/
243 
244 
245 // output
246 
247 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
248 std::ostream &operator << (std::ostream &out, const FixedArray2<T, rowsT, colsT, T_ordering> &arr)
249 {
250  //out << "FixedArray2 (" << rowsT << "x" << colsT << "), " << ((T_ordering == ColMajor) ? "ColMajor" : "RowMajor") << endl;
251  out << "[";
252  typedef typename FixedArray2<T, rowsT, colsT, T_ordering>::size_type size_type;
253  for(size_type r=0; r<arr.num_rows(); r++)
254  {
255  for(size_type c=0; c<arr.num_cols(); c++)
256  out << arr(r, c) << " ";
257  if(r != arr.num_rows()-1) out << "| ";
258  }
259  out << "]";
260 
261  return out;
262 }
263 
264 }
265 #endif // __H__UG__COMMON__FIXED_ARRAY_IMPL_H__
Definition: fixed_array.h:56
bool resize(size_type newN, bool bCopyValues=true)
Definition: fixed_array_impl.h:79
bool reserve(size_type newN) const
Definition: fixed_array_impl.h:88
const T & operator[](size_type i) const
Definition: fixed_array_impl.h:106
size_t size_type
Definition: fixed_array.h:59
size_type size() const
Definition: fixed_array_impl.h:71
FixedArray1()
Definition: fixed_array_impl.h:44
~FixedArray1()
Definition: fixed_array_impl.h:63
Definition: fixed_array.h:135
FixedArray2()
Definition: fixed_array_impl.h:130
size_type num_rows() const
Definition: fixed_array_impl.h:157
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: fixed_array_impl.h:172
~FixedArray2()
Definition: fixed_array_impl.h:149
size_t size_type
Definition: fixed_array.h:138
const T & operator()(size_type r, size_type c) const
Definition: fixed_array_impl.h:196
size_type num_cols() const
Definition: fixed_array_impl.h:164
T values[rowsT *colsT]
Definition: fixed_array.h:210
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
the ug namespace
@ RowMajor
Definition: storage.h:48