Line data Source code
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>
44 0 : FixedArray1<T, n>::FixedArray1()
45 : {
46 0 : }
47 :
48 :
49 : template<typename T, size_t nT>
50 : FixedArray1<T, nT>::FixedArray1(size_t n)
51 : {
52 : assert(n == nT);
53 : }
54 :
55 : template<typename T, size_t n>
56 0 : FixedArray1<T, n>::FixedArray1(const FixedArray1<T, n> &other)
57 : {
58 0 : for(size_type i=0; i<n; i++)
59 0 : values[i] = other[i];
60 : }
61 :
62 : template<typename T, size_t n>
63 : FixedArray1<T, n>::~FixedArray1()
64 : {
65 : }
66 :
67 : // capacity
68 :
69 : template<typename T, size_t n>
70 : inline size_t
71 : FixedArray1<T, n>::size() const
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 &
98 : FixedArray1<T, n>::operator[](size_t i)
99 : {
100 : assert(i<n);
101 0 : return values[i];
102 : }
103 :
104 : template<typename T, size_t n>
105 : inline const T &
106 : FixedArray1<T, n>::operator[](size_t i) const
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 :
125 : ////////////////////////////////////////////////////////////////////////////////
126 :
127 : // 'tors
128 :
129 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
130 0 : FixedArray2<T, rowsT, colsT, T_ordering>::FixedArray2()
131 : {
132 0 : }
133 :
134 :
135 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
136 : FixedArray2<T, rowsT, colsT, T_ordering>::FixedArray2(size_t rows, size_t cols)
137 : {
138 : assert(rows == rowsT && cols == colsT);
139 : }
140 :
141 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
142 0 : FixedArray2<T, rowsT, colsT, T_ordering>::FixedArray2(const FixedArray2<T, rowsT, colsT, T_ordering> &other)
143 : {
144 0 : for(size_type i=0; i<rowsT*colsT; i++)
145 0 : values[i] = other.values[i];
146 : }
147 :
148 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
149 : FixedArray2<T, rowsT, colsT, T_ordering>::~FixedArray2()
150 : {
151 : }
152 :
153 : // Capacity
154 :
155 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
156 : inline size_t
157 : FixedArray2<T, rowsT, colsT, T_ordering>::num_rows() const
158 : {
159 : return rowsT;
160 : }
161 :
162 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
163 : inline size_t
164 : FixedArray2<T, rowsT, colsT, T_ordering>::num_cols() const
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 0 : 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 &
184 : FixedArray2<T, rowsT, colsT, T_ordering>::operator()(size_t r, size_t c)
185 : {
186 : assert(r<rowsT);
187 : assert(c<colsT);
188 : if(T_ordering == RowMajor)
189 : return values[c+r*colsT];
190 : else
191 0 : return values[r+c*rowsT];
192 : }
193 :
194 : template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering>
195 : inline const T &
196 : FixedArray2<T, rowsT, colsT, T_ordering>::operator()(size_t r, size_t c) const
197 : {
198 : assert(r<rowsT);
199 : assert(c<colsT);
200 : if(T_ordering == RowMajor)
201 : return values[c+r*colsT];
202 : else
203 0 : 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__
|