1 |
jgs |
82 |
// $Id$ |
2 |
|
|
/* |
3 |
elspeth |
615 |
************************************************************ |
4 |
|
|
* Copyright 2006 by ACcESS MNRF * |
5 |
|
|
* * |
6 |
|
|
* http://www.access.edu.au * |
7 |
|
|
* Primary Business: Queensland, Australia * |
8 |
|
|
* Licensed under the Open Software License version 3.0 * |
9 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php * |
10 |
|
|
* * |
11 |
|
|
************************************************************ |
12 |
|
|
|
13 |
jgs |
82 |
*/ |
14 |
jgs |
478 |
|
15 |
jgs |
106 |
#if !defined escript_DataAbstract_20040315_H |
16 |
jgs |
82 |
#define escript_DataAbstract_20040315_H |
17 |
woo409 |
757 |
#include "system_dep.h" |
18 |
jgs |
82 |
|
19 |
jgs |
474 |
#include "DataArrayView.h" |
20 |
|
|
#include "DataArray.h" |
21 |
|
|
#include "FunctionSpace.h" |
22 |
jgs |
82 |
|
23 |
|
|
#include <boost/scoped_ptr.hpp> |
24 |
jgs |
478 |
#include <boost/python/numeric.hpp> |
25 |
jgs |
480 |
|
26 |
jgs |
82 |
#include <string> |
27 |
jgs |
480 |
#include <fstream> |
28 |
jgs |
82 |
|
29 |
|
|
namespace escript { |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
\brief |
33 |
jgs |
117 |
DataAbstract provides an abstract interface for the class of containers |
34 |
jgs |
82 |
which hold ESyS data. |
35 |
|
|
|
36 |
|
|
Description: |
37 |
jgs |
117 |
DataAbstract provides an abstract interface for the class of containers |
38 |
jgs |
82 |
which hold ESyS data. The container may be thought of as a 2 dimensional |
39 |
jgs |
117 |
array of data points where one dimension corresponds to the number of samples |
40 |
|
|
and the other to the number of data points per sample as defined by the function |
41 |
|
|
space associated with each Data object. The data points themselves are arrays of |
42 |
|
|
doubles of rank 0-4. |
43 |
jgs |
82 |
*/ |
44 |
|
|
|
45 |
|
|
class DataAbstract { |
46 |
|
|
|
47 |
|
|
public: |
48 |
|
|
|
49 |
|
|
typedef DataArrayView::ValueType ValueType; |
50 |
|
|
typedef DataArrayView::ShapeType ShapeType; |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
\brief |
54 |
|
|
Constructor for DataAbstract. |
55 |
|
|
|
56 |
|
|
Description: |
57 |
|
|
Constructor for DataAbstract. |
58 |
jgs |
117 |
|
59 |
jgs |
82 |
\param what - Input - A description of what this data represents. |
60 |
|
|
*/ |
61 |
woo409 |
757 |
ESCRIPT_DLL_API |
62 |
jgs |
82 |
DataAbstract(const FunctionSpace& what); |
63 |
|
|
|
64 |
|
|
/** |
65 |
|
|
\brief |
66 |
|
|
Destructor for DataAbstract. |
67 |
|
|
*/ |
68 |
woo409 |
757 |
ESCRIPT_DLL_API |
69 |
jgs |
106 |
virtual |
70 |
|
|
~DataAbstract(); |
71 |
jgs |
82 |
|
72 |
|
|
/** |
73 |
|
|
\brief |
74 |
|
|
Write the data as a string. |
75 |
|
|
*/ |
76 |
woo409 |
757 |
ESCRIPT_DLL_API |
77 |
jgs |
82 |
virtual |
78 |
|
|
std::string |
79 |
|
|
toString() const = 0; |
80 |
|
|
|
81 |
|
|
/** |
82 |
|
|
\brief |
83 |
|
|
Return the number of data points per sample. |
84 |
|
|
*/ |
85 |
woo409 |
757 |
ESCRIPT_DLL_API |
86 |
jgs |
82 |
int |
87 |
|
|
getNumDPPSample() const; |
88 |
|
|
|
89 |
|
|
/** |
90 |
|
|
\brief |
91 |
|
|
Return the number of samples. |
92 |
|
|
*/ |
93 |
woo409 |
757 |
ESCRIPT_DLL_API |
94 |
jgs |
82 |
int |
95 |
|
|
getNumSamples() const; |
96 |
|
|
|
97 |
|
|
/** |
98 |
|
|
\brief |
99 |
|
|
Return the DataArrayView of the point data. This essentially contains |
100 |
|
|
the shape information for each data point although it also may be used |
101 |
|
|
to manipulate the point data. |
102 |
|
|
*/ |
103 |
woo409 |
757 |
ESCRIPT_DLL_API |
104 |
jgs |
117 |
DataArrayView& |
105 |
|
|
getPointDataView(); |
106 |
|
|
|
107 |
woo409 |
757 |
ESCRIPT_DLL_API |
108 |
jgs |
82 |
const DataArrayView& |
109 |
|
|
getPointDataView() const; |
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
\brief |
113 |
jgs |
117 |
Return the offset for the given sample. This returns the offset for the given |
114 |
|
|
point into the container holding the point data. Only really necessary to |
115 |
|
|
avoid creating many DataArrayView objects. |
116 |
|
|
|
117 |
jgs |
82 |
\param sampleNo - Input - sample number. |
118 |
jgs |
117 |
\param dataPointNo - Input - data point number. |
119 |
jgs |
82 |
*/ |
120 |
woo409 |
757 |
ESCRIPT_DLL_API |
121 |
jgs |
82 |
virtual |
122 |
|
|
ValueType::size_type |
123 |
|
|
getPointOffset(int sampleNo, |
124 |
|
|
int dataPointNo) const = 0; |
125 |
|
|
|
126 |
|
|
/** |
127 |
|
|
\brief |
128 |
jgs |
117 |
Return the sample data for the given sample number. |
129 |
jgs |
82 |
*/ |
130 |
woo409 |
757 |
ESCRIPT_DLL_API |
131 |
jgs |
82 |
double* |
132 |
|
|
getSampleData(ValueType::size_type sampleNo); |
133 |
|
|
|
134 |
|
|
/** |
135 |
|
|
\brief |
136 |
jgs |
117 |
Return the number of doubles stored for this Data object. |
137 |
jgs |
82 |
*/ |
138 |
woo409 |
757 |
ESCRIPT_DLL_API |
139 |
jgs |
82 |
virtual |
140 |
|
|
ValueType::size_type |
141 |
|
|
getLength() const = 0; |
142 |
|
|
|
143 |
|
|
/** |
144 |
|
|
\brief |
145 |
|
|
Return the sample data for the given tag key. |
146 |
|
|
NB: If the data isn't tagged an exception will be thrown. |
147 |
|
|
*/ |
148 |
woo409 |
757 |
ESCRIPT_DLL_API |
149 |
jgs |
82 |
virtual |
150 |
|
|
double* |
151 |
|
|
getSampleDataByTag(int tag); |
152 |
|
|
|
153 |
|
|
/** |
154 |
|
|
\brief |
155 |
jgs |
110 |
Assign the given value to the data-points(s) referenced by the given |
156 |
|
|
reference number. |
157 |
|
|
|
158 |
|
|
If this Data object cannot be accessed by reference numbers an |
159 |
|
|
exception will be thrown. |
160 |
|
|
|
161 |
|
|
\param ref - Input - reference number. |
162 |
|
|
\param value - Input - value to assign to data-points associated with |
163 |
|
|
the given reference number. |
164 |
|
|
*/ |
165 |
woo409 |
757 |
ESCRIPT_DLL_API |
166 |
jgs |
110 |
virtual |
167 |
|
|
void |
168 |
|
|
setRefValue(int ref, |
169 |
|
|
const DataArray& value); |
170 |
|
|
|
171 |
|
|
/** |
172 |
|
|
\brief |
173 |
|
|
Return the values associated with the data-point(s) referenced by the given |
174 |
|
|
reference number. |
175 |
|
|
|
176 |
|
|
If this Data object cannot be accessed by reference numbers an |
177 |
|
|
exception will be thrown. |
178 |
|
|
|
179 |
|
|
\param ref - Input - reference number. |
180 |
|
|
\param value - Output - object to receive data-points associated with |
181 |
|
|
the given reference number. |
182 |
|
|
*/ |
183 |
woo409 |
757 |
ESCRIPT_DLL_API |
184 |
jgs |
110 |
virtual |
185 |
|
|
void |
186 |
|
|
getRefValue(int ref, |
187 |
|
|
DataArray& value); |
188 |
|
|
|
189 |
|
|
/** |
190 |
|
|
\brief |
191 |
jgs |
117 |
Check this and the given RHS operands are compatible. Throws |
192 |
jgs |
82 |
an exception if they aren't. |
193 |
jgs |
117 |
|
194 |
jgs |
82 |
\param right - Input - The right hand side. |
195 |
|
|
*/ |
196 |
woo409 |
757 |
ESCRIPT_DLL_API |
197 |
jgs |
82 |
void |
198 |
|
|
operandCheck(const DataAbstract& right) const; |
199 |
|
|
|
200 |
|
|
/** |
201 |
|
|
\brief |
202 |
|
|
Return true if a valid sample point number. |
203 |
|
|
*/ |
204 |
woo409 |
757 |
ESCRIPT_DLL_API |
205 |
jgs |
82 |
bool |
206 |
|
|
validSamplePointNo(int samplePointNo) const; |
207 |
|
|
|
208 |
|
|
/** |
209 |
|
|
\brief |
210 |
jgs |
117 |
Return true if a valid sample number. |
211 |
jgs |
82 |
*/ |
212 |
woo409 |
757 |
ESCRIPT_DLL_API |
213 |
jgs |
82 |
bool |
214 |
|
|
validSampleNo(int sampleNo) const; |
215 |
|
|
|
216 |
|
|
/** |
217 |
|
|
\brief |
218 |
|
|
Return a view into the data for the data point specified. |
219 |
|
|
NOTE: Construction of the DataArrayView is a relatively expensive |
220 |
|
|
operation. |
221 |
jgs |
117 |
|
222 |
|
|
\param sampleNo - Input - the sample number. |
223 |
|
|
\param dataPointNo - Input - the data point number. |
224 |
jgs |
82 |
*/ |
225 |
woo409 |
757 |
ESCRIPT_DLL_API |
226 |
jgs |
82 |
virtual |
227 |
jgs |
106 |
DataArrayView |
228 |
jgs |
117 |
getDataPoint(int sampleNo, |
229 |
jgs |
106 |
int dataPointNo) = 0; |
230 |
jgs |
82 |
|
231 |
|
|
/** |
232 |
|
|
\brief |
233 |
jgs |
117 |
Return the function space associated with this Data object. |
234 |
jgs |
82 |
*/ |
235 |
woo409 |
757 |
ESCRIPT_DLL_API |
236 |
jgs |
117 |
const |
237 |
|
|
FunctionSpace& |
238 |
jgs |
82 |
getFunctionSpace() const; |
239 |
|
|
|
240 |
|
|
/** |
241 |
|
|
\brief |
242 |
jgs |
117 |
Return the given slice from this object. |
243 |
|
|
|
244 |
|
|
NB: The caller is responsible for managing the object created. |
245 |
jgs |
82 |
*/ |
246 |
woo409 |
757 |
ESCRIPT_DLL_API |
247 |
jgs |
82 |
virtual |
248 |
|
|
DataAbstract* |
249 |
|
|
getSlice(const DataArrayView::RegionType& region) const = 0; |
250 |
|
|
|
251 |
|
|
/** |
252 |
|
|
\brief |
253 |
jgs |
117 |
Copy the specified region from the given object. |
254 |
|
|
|
255 |
jgs |
82 |
\param value - Input - Data to copy from |
256 |
|
|
\param region - Input - Region to copy. |
257 |
|
|
*/ |
258 |
woo409 |
757 |
ESCRIPT_DLL_API |
259 |
jgs |
82 |
virtual |
260 |
|
|
void |
261 |
|
|
setSlice(const DataAbstract* value, |
262 |
|
|
const DataArrayView::RegionType& region) = 0; |
263 |
|
|
|
264 |
|
|
/** |
265 |
|
|
\brief |
266 |
jgs |
117 |
Reshape the data points if they are currently rank 0. |
267 |
jgs |
82 |
Will throw an exception if the data points are not rank 0. |
268 |
|
|
The original data point value is used for all values of the new |
269 |
|
|
data point. |
270 |
|
|
*/ |
271 |
woo409 |
757 |
ESCRIPT_DLL_API |
272 |
jgs |
82 |
virtual |
273 |
|
|
void |
274 |
jgs |
117 |
reshapeDataPoint(const ShapeType& shape) = 0; |
275 |
jgs |
82 |
|
276 |
|
|
/** |
277 |
|
|
\brief |
278 |
|
|
setTaggedValue |
279 |
|
|
|
280 |
|
|
Description: |
281 |
|
|
Assign the given value to the given tag. |
282 |
jgs |
117 |
|
283 |
|
|
NB: If the data isn't tagged an exception will be thrown. |
284 |
|
|
|
285 |
jgs |
82 |
\param tagKey - Input - Integer key. |
286 |
|
|
\param value - Input - Single DataArrayView value to be assigned to the tag. |
287 |
|
|
*/ |
288 |
woo409 |
757 |
ESCRIPT_DLL_API |
289 |
jgs |
82 |
virtual |
290 |
|
|
void |
291 |
|
|
setTaggedValue(int tagKey, |
292 |
|
|
const DataArrayView& value); |
293 |
|
|
|
294 |
jgs |
123 |
/** |
295 |
|
|
\brief |
296 |
|
|
Archive the underlying data values to the file referenced |
297 |
|
|
by ofstream. A count of the number of values expected to be written |
298 |
|
|
is provided as a cross-check. |
299 |
|
|
|
300 |
|
|
The return value indicates success (0) or otherwise (1). |
301 |
|
|
*/ |
302 |
woo409 |
757 |
ESCRIPT_DLL_API |
303 |
jgs |
123 |
virtual |
304 |
|
|
int |
305 |
|
|
archiveData(std::ofstream& archiveFile, |
306 |
|
|
const ValueType::size_type noValues) const; |
307 |
|
|
|
308 |
|
|
/** |
309 |
|
|
\brief |
310 |
|
|
Extract the number of values specified by noValues from the file |
311 |
|
|
referenced by ifstream to the underlying data structure. |
312 |
|
|
|
313 |
|
|
The return value indicates success (0) or otherwise (1). |
314 |
|
|
*/ |
315 |
woo409 |
757 |
ESCRIPT_DLL_API |
316 |
jgs |
123 |
virtual |
317 |
|
|
int |
318 |
|
|
extractData(std::ifstream& archiveFile, |
319 |
|
|
const ValueType::size_type noValues); |
320 |
|
|
|
321 |
jgs |
126 |
/** |
322 |
|
|
\brief |
323 |
|
|
Copy the numarray object to the data points in this object. |
324 |
|
|
|
325 |
|
|
Description: |
326 |
|
|
Copy the numarray object to the data points in this object. |
327 |
|
|
|
328 |
|
|
\param value Input - new values for the data points |
329 |
|
|
*/ |
330 |
woo409 |
757 |
ESCRIPT_DLL_API |
331 |
jgs |
126 |
virtual void |
332 |
|
|
copyAll(const boost::python::numeric::array& value); |
333 |
|
|
|
334 |
jgs |
149 |
/** |
335 |
|
|
\brief |
336 |
|
|
Return the tag number associated with the given data-point number. |
337 |
jgs |
126 |
|
338 |
jgs |
149 |
If the object cannot be referenced by tag numbers, an exception |
339 |
|
|
will be thrown. |
340 |
|
|
*/ |
341 |
woo409 |
757 |
ESCRIPT_DLL_API |
342 |
jgs |
149 |
virtual |
343 |
|
|
int |
344 |
|
|
getTagNumber(int dpno); |
345 |
|
|
|
346 |
gross |
576 |
/** |
347 |
|
|
\brief |
348 |
ksteube |
775 |
Computes a symmetric matrix (A + AT) / 2 |
349 |
|
|
|
350 |
|
|
\param ev - Output - a symmetric matrix |
351 |
|
|
|
352 |
|
|
*/ |
353 |
gross |
800 |
ESCRIPT_DLL_API |
354 |
ksteube |
775 |
virtual void |
355 |
|
|
symmetric(DataAbstract* ev); |
356 |
|
|
|
357 |
|
|
/** |
358 |
|
|
\brief |
359 |
|
|
Computes a nonsymmetric matrix (A - AT) / 2 |
360 |
|
|
|
361 |
|
|
\param ev - Output - a nonsymmetric matrix |
362 |
|
|
|
363 |
|
|
*/ |
364 |
gross |
800 |
ESCRIPT_DLL_API |
365 |
ksteube |
775 |
virtual void |
366 |
|
|
nonsymmetric(DataAbstract* ev); |
367 |
|
|
|
368 |
|
|
/** |
369 |
|
|
\brief |
370 |
|
|
Computes the trace of a matrix |
371 |
|
|
|
372 |
|
|
\param ev - Output - the trace of a matrix |
373 |
|
|
|
374 |
|
|
*/ |
375 |
gross |
800 |
ESCRIPT_DLL_API |
376 |
ksteube |
775 |
virtual void |
377 |
gross |
800 |
trace(DataAbstract* ev, int axis_offset); |
378 |
ksteube |
775 |
|
379 |
|
|
/** |
380 |
|
|
\brief |
381 |
|
|
Transpose each data point of this Data object around the given axis. |
382 |
|
|
|
383 |
|
|
\param ev - Output - the transpose of a matrix |
384 |
|
|
|
385 |
|
|
*/ |
386 |
gross |
800 |
ESCRIPT_DLL_API |
387 |
ksteube |
775 |
virtual void |
388 |
|
|
transpose(DataAbstract* ev, int axis_offset); |
389 |
|
|
|
390 |
|
|
/** |
391 |
|
|
\brief |
392 |
gross |
800 |
swaps components axis_offset and axis_offset+1 |
393 |
|
|
|
394 |
|
|
\param ev - Output - swapped components |
395 |
|
|
|
396 |
|
|
*/ |
397 |
|
|
ESCRIPT_DLL_API |
398 |
|
|
virtual void |
399 |
|
|
swap(DataAbstract* ev, int axis_offset); |
400 |
|
|
|
401 |
|
|
/** |
402 |
|
|
\brief |
403 |
gross |
576 |
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev |
404 |
|
|
|
405 |
|
|
\param ev - Output - eigenvalues in increasing order at each data point |
406 |
|
|
|
407 |
|
|
*/ |
408 |
woo409 |
757 |
ESCRIPT_DLL_API |
409 |
gross |
576 |
virtual void |
410 |
|
|
eigenvalues(DataAbstract* ev); |
411 |
|
|
|
412 |
|
|
/** |
413 |
|
|
\brief |
414 |
|
|
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V |
415 |
|
|
|
416 |
|
|
\param ev - Output - eigenvalues in increasing order at each data point |
417 |
|
|
\param V - Output - corresponding eigenvectors. They are normalized such that their length is one |
418 |
|
|
and the first nonzero component is positive. |
419 |
|
|
\param tol - Input - eigenvalue with relative distance tol are treated as equal. |
420 |
|
|
|
421 |
|
|
*/ |
422 |
|
|
|
423 |
woo409 |
757 |
ESCRIPT_DLL_API |
424 |
gross |
576 |
virtual void |
425 |
|
|
eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13); |
426 |
|
|
|
427 |
jgs |
82 |
protected: |
428 |
|
|
|
429 |
|
|
/** |
430 |
|
|
\brief |
431 |
jgs |
117 |
Set the pointDataView DataArrayView associated with this object. |
432 |
|
|
|
433 |
jgs |
121 |
\param input - Input - The point data view. DataAbstract takes ownership |
434 |
jgs |
82 |
of the DataArrayView provided. It will delete it when it is destructed. |
435 |
|
|
*/ |
436 |
woo409 |
757 |
ESCRIPT_DLL_API |
437 |
jgs |
82 |
void |
438 |
|
|
setPointDataView(const DataArrayView& input); |
439 |
|
|
|
440 |
woo409 |
757 |
ESCRIPT_DLL_API |
441 |
jgs |
119 |
void |
442 |
|
|
resetPointDataView(); |
443 |
|
|
|
444 |
jgs |
82 |
private: |
445 |
|
|
|
446 |
jgs |
117 |
// |
447 |
|
|
// The number of samples in this Data object. |
448 |
|
|
// This is derived directly from the FunctionSpace. |
449 |
jgs |
82 |
int m_noSamples; |
450 |
|
|
|
451 |
|
|
// |
452 |
jgs |
117 |
// The number of data points per sample in this Data object. |
453 |
|
|
// This is derived directly from the FunctionSpace. |
454 |
|
|
int m_noDataPointsPerSample; |
455 |
|
|
|
456 |
|
|
// |
457 |
|
|
// The DataArrayView of the data array associated with this object. |
458 |
|
|
// The data array is defined only in child classes of this class, it |
459 |
|
|
// is not defined in this abstract parent class. |
460 |
jgs |
82 |
boost::scoped_ptr<DataArrayView> m_pointDataView; |
461 |
|
|
|
462 |
|
|
// |
463 |
jgs |
117 |
// A FunctionSpace which provides a description of the data associated |
464 |
|
|
// with this Data object. |
465 |
jgs |
82 |
FunctionSpace m_functionSpace; |
466 |
|
|
|
467 |
|
|
}; |
468 |
|
|
|
469 |
|
|
inline |
470 |
|
|
bool |
471 |
jgs |
106 |
DataAbstract::validSamplePointNo(int samplePointNo) const |
472 |
jgs |
82 |
{ |
473 |
|
|
return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample)); |
474 |
|
|
} |
475 |
|
|
|
476 |
|
|
inline |
477 |
|
|
bool |
478 |
|
|
DataAbstract::validSampleNo(int sampleNo) const |
479 |
|
|
{ |
480 |
|
|
return ((0 <= sampleNo) && (sampleNo < m_noSamples)); |
481 |
|
|
} |
482 |
|
|
|
483 |
|
|
inline |
484 |
|
|
DataAbstract::ValueType::value_type* |
485 |
|
|
DataAbstract::getSampleData(ValueType::size_type sampleNo) |
486 |
|
|
{ |
487 |
|
|
return &(m_pointDataView->getData(getPointOffset(sampleNo,0))); |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
inline |
491 |
|
|
int |
492 |
|
|
DataAbstract::getNumDPPSample() const |
493 |
|
|
{ |
494 |
|
|
return m_noDataPointsPerSample; |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
inline |
498 |
|
|
int |
499 |
|
|
DataAbstract::getNumSamples() const |
500 |
|
|
{ |
501 |
|
|
return m_noSamples; |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
inline |
505 |
jgs |
106 |
const |
506 |
|
|
FunctionSpace& |
507 |
jgs |
82 |
DataAbstract::getFunctionSpace() const |
508 |
|
|
{ |
509 |
|
|
return m_functionSpace; |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
inline |
513 |
jgs |
106 |
const |
514 |
|
|
DataArrayView& |
515 |
jgs |
82 |
DataAbstract::getPointDataView() const |
516 |
|
|
{ |
517 |
|
|
return *(m_pointDataView.get()); |
518 |
|
|
} |
519 |
|
|
|
520 |
|
|
inline |
521 |
|
|
DataArrayView& |
522 |
|
|
DataAbstract::getPointDataView() |
523 |
|
|
{ |
524 |
|
|
return *(m_pointDataView.get()); |
525 |
|
|
} |
526 |
|
|
} // end of namespace |
527 |
jgs |
117 |
|
528 |
jgs |
82 |
#endif |