Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
40namespace ug{
41// 'tors
42
43template<typename T, size_t n>
47
48
49template<typename T, size_t nT>
51{
52 assert(n == nT);
53}
54
55template<typename T, size_t n>
57{
58 for(size_type i=0; i<n; i++)
59 values[i] = other[i];
60}
61
62template<typename T, size_t n>
66
67// capacity
68
69template<typename T, size_t n>
70inline size_t
72{
73 return n;
74}
75
76
77template<typename T, size_t n>
78inline bool
79FixedArray1<T, n>::resize(size_t newN, bool bCopyValues)
80{
81 assert(newN == n);
82 return newN == n;
83}
84
85
86template<typename T, size_t n>
87inline bool
89{
90 assert(newN <= n);
91 return newN <= n;
92}
93
94
95// Element access
96template<typename T, size_t n>
97inline T &
99{
100 assert(i<n);
101 return values[i];
102}
103
104template<typename T, size_t n>
105inline const T &
107{
108 assert(i<n);
109 return values[i];
110}
111
112// output
113
114template<typename T, size_t n>
115std::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
129template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
133
134
135template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
137{
138 assert(rows == rowsT && cols == colsT);
139}
140
141template<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];
148template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
153// Capacity
154
155template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
156inline size_t
161
162template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
163inline size_t
165{
166 return colsT;
167}
168
169
170template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
171inline bool
172FixedArray2<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
182template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
183inline 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
194template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
195inline 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/*
207template<typename T, size_t rowsT, size_t colsT>
208T &
209FixedArray2<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
216template<typename T, size_t rowsT, size_t colsT>
217T &
218FixedArray2<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
226template<typename T, size_t rowsT, size_t colsT>
227const T &
228FixedArray2<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
235template<typename T, size_t rowsT, size_t colsT>
236const T &
237FixedArray2<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
247template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
248std::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 << "[";
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