/[escript]/trunk/escript/src/DataAbstract.h
ViewVC logotype

Contents of /trunk/escript/src/DataAbstract.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (11 years, 10 months ago) by ksteube
File MIME type: text/plain
File size: 12007 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26