/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataExpanded.h
ViewVC logotype

Contents of /branches/arrayview_from_1695_trunk/escript/src/DataExpanded.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1724 - (show annotations)
Mon Aug 25 05:38:57 2008 UTC (11 years ago) by jfenwick
File MIME type: text/plain
File size: 12144 byte(s)
Branch commit

Moved createShapeErrorMessage() into DataTypes.h
Modified functions in DataAlgorithm.h to use non-DataArrayView accesses.

Added getVector() to each of DataTagged, DataConstant, DataExpanded - This method returns 
the underlying DataVector by reference/constant reference. Note that this method does not 
exist in DataAbstract so (at the momement) in order to pull the data from something you 
need to know what you are looking at. (Lower level access is still possible via double* 
though).

DataTagged now has a getOffsetForTag method and a getDefaultOffset method.

DataMaths.h - A new file containing the reductionOps etc from DataArrayView (but without 
requiring DAV).
This file requires significant commenting improvements.


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_DataExpanded_20040323_H
17 #define escript_DataExpanded_20040323_H
18 #include "system_dep.h"
19
20 #include "DataAbstract.h"
21 #include "DataBlocks2D.h"
22 #include "DataArrayView.h"
23
24 #include <boost/python/numeric.hpp>
25
26 namespace escript {
27
28 //
29 // Forward declarations of other Data types.
30 class DataConstant;
31 class DataTagged;
32
33 /**
34 \brief
35 Give a short description of what DataExpanded does.
36
37 Description:
38 Give a detailed description of DataExpanded.
39
40 Template Parameters:
41 For templates describe any conditions that the parameters used in the
42 template must satisfy.
43 */
44
45 class DataExpanded : public DataAbstract {
46
47 public:
48
49 /**
50 \brief
51 Constructor for DataExpanded.
52
53 Description:
54 Constructor for DataExpanded.
55
56 The given single data value is copied to all the data points in
57 this data object, where the number of data points is defined by
58 the given function space.
59
60 \param value - Input - A single data value.
61 \param what - Input - A description of what this data represents.
62 */
63 ESCRIPT_DLL_API
64 DataExpanded(const boost::python::numeric::array& value,
65 const FunctionSpace& what);
66
67 /**
68 \brief
69 Alternative constructor for DataExpanded.
70
71 Description:
72 Alternative Constructor for DataExpanded.
73
74 The given single data value is copied to all the data points in
75 this data object, where the number of data points is defined by
76 the given function space.
77
78 \param value - Input - A single data value.
79 \param what - Input - A description of what this data represents.
80 */
81 ESCRIPT_DLL_API
82 DataExpanded(const DataArrayView& value,
83 const FunctionSpace& what);
84
85 /**
86 \brief
87 Alternative constructor for DataExpanded that copies a slice from
88 another DataExpanded.
89
90 \param other - Input - DataExpanded object to slice from.
91 \param region - Input - region to copy.
92 */
93 ESCRIPT_DLL_API
94 DataExpanded(const DataExpanded& other,
95 const DataTypes::RegionType& region);
96
97 /**
98 \brief
99 Alternative constructor for DataExpanded objects.
100
101 Description:
102 Alternative Constructor for DataExpanded objects.
103 \param what - Input - A description of what this data object represents.
104 \param shape - Input - the shape of each data-point.
105 \param data - the array of data values for the data-points.
106 */
107 ESCRIPT_DLL_API
108 DataExpanded(const FunctionSpace& what,
109 const DataTypes::ShapeType &shape,
110 const DataTypes::ValueType &data);
111
112 /**
113 \brief
114 Copy constructor for DataExpanded.
115 Performs a deep copy from another DataExpanded.
116 */
117 ESCRIPT_DLL_API
118 DataExpanded(const DataExpanded& other);
119
120 /**
121 \brief
122 Copy constructor for DataExpanded.
123 Construct a DataExpanded from a DataConstant.
124 */
125 ESCRIPT_DLL_API
126 DataExpanded(const DataConstant& other);
127
128 /**
129 \brief
130 Copy constructor for DataExpanded.
131 Construct a DataExpanded from a DataTagged.
132 */
133 ESCRIPT_DLL_API
134 DataExpanded(const DataTagged& other);
135
136 /**
137 \brief
138 Default destructor for DataExpanded.
139 */
140 ESCRIPT_DLL_API
141 virtual
142 ~DataExpanded();
143
144 /**
145 \brief
146 Return a textual representation of the data.
147 */
148 ESCRIPT_DLL_API
149 virtual
150 std::string
151 toString() const;
152 /**
153 \brief
154 dumps the object into a netCDF file
155 */
156 ESCRIPT_DLL_API
157 virtual
158 void
159 dump(const std::string fileName) const;
160
161 /**
162 \brief
163 sets all values to zero
164 */
165 ESCRIPT_DLL_API
166 virtual
167 void
168 setToZero();
169
170 /**
171 \brief
172 Return the offset for the given given data point. This returns
173 the offset in bytes for the given point into the container
174 holding the point data.
175
176 \param sampleNo - Input - sample number.
177 \param dataPointNo - Input - data point number.
178 */
179 ESCRIPT_DLL_API
180 virtual
181 DataTypes::ValueType::size_type
182 getPointOffset(int sampleNo,
183 int dataPointNo) const;
184
185 /**
186 \brief
187 Return a view into the data array for the data point specified.
188
189 NOTE: Construction of the DataArrayView is a relatively expensive
190 operation.
191
192 \param sampleNo - Input - sample number.
193 \param dataPointNo - Input - data point number.
194 \return DataArrayView for the data point.
195 */
196 ESCRIPT_DLL_API
197 DataArrayView
198 getDataPoint(int sampleNo,
199 int dataPointNo);
200
201
202 /**
203 \brief
204 Return a a reference to the underlying DataVector.
205 */
206
207 ESCRIPT_DLL_API
208 DataTypes::ValueType&
209 getVector();
210
211 ESCRIPT_DLL_API
212 const DataTypes::ValueType&
213 getVector() const;
214
215
216 /**
217 \brief
218 Return the number of doubles stored for the Data.
219 */
220 ESCRIPT_DLL_API
221 virtual
222 ValueType::size_type
223 getLength() const;
224
225 /**
226 \brief
227 Factory method that returns a newly created DataExpanded.
228 The caller is reponsible for managing the object created.
229
230 \param region - Input - Region to copy.
231 */
232 ESCRIPT_DLL_API
233 virtual
234 DataAbstract*
235 getSlice(const DataTypes::RegionType& region) const;
236
237 /**
238 \brief
239 Copy the specified region from the given value.
240
241 \param value - Input - Data object to copy from.
242 \param region - Input - Region to copy.
243 */
244 ESCRIPT_DLL_API
245 virtual
246 void
247 setSlice(const DataAbstract* value,
248 const DataTypes::RegionType& region);
249
250 /**
251 \brief
252 Archive the underlying data values to the file referenced
253 by ofstream. A count of the number of values expected to be written
254 is provided as a cross-check.
255
256 The return value indicates success (0) or otherwise (1).
257 */
258 ESCRIPT_DLL_API
259 int
260 archiveData(std::ofstream& archiveFile,
261 const DataTypes::ValueType::size_type noValues) const;
262
263 /**
264 \brief
265 Extract the number of values specified by noValues from the file
266 referenced by ifstream to the underlying data structure.
267
268 The return value indicates success (0) or otherwise (1).
269 */
270 ESCRIPT_DLL_API
271 int
272 extractData(std::ifstream& archiveFile,
273 const DataTypes::ValueType::size_type noValues);
274
275 /**
276 \brief
277 setTaggedValue
278
279 Description:
280 uses tag to set a new value
281
282 \param tagKey - Input - Integer key.
283 \param value - Input - Single DataArrayView value to be assigned to the tag.
284 */
285 ESCRIPT_DLL_API
286 virtual
287 void
288 setTaggedValue(int tagKey,
289 const DataArrayView& value);
290
291
292
293 /**
294 \brief
295 setTaggedValue
296
297 Description:
298 uses tag to set a new value
299
300 \param tagKey - Input - Integer key.
301 \param pointshape - Input - The shape of the value parameter
302 \param value - Input - .
303 */
304 void
305 setTaggedValue(int tagKey,
306 const DataTypes::ShapeType& pointshape,
307 const DataTypes::ValueType& value,
308 int dataOffset=0);
309
310
311
312 /**
313 \brief
314 Computes a symmetric matrix (A + AT) / 2
315
316 \param ev - Output - symmetric matrix
317
318 */
319 ESCRIPT_DLL_API
320 virtual void
321 symmetric(DataAbstract* ev);
322
323 /**
324 \brief
325 Computes a nonsymmetric matrix (A - AT) / 2
326
327 \param ev - Output - nonsymmetric matrix
328
329 */
330 ESCRIPT_DLL_API
331 virtual void
332 nonsymmetric(DataAbstract* ev);
333
334 /**
335 \brief
336 Computes the trace of a matrix
337
338 \param ev - Output - trace of your matrix
339
340 */
341 ESCRIPT_DLL_API
342 virtual void
343 trace(DataAbstract* ev, int axis_offset);
344
345 /**
346 \brief
347 Transpose each data point of this Data object around the given axis.
348
349 \param ev - Output - transpose of your matrix
350
351 */
352 ESCRIPT_DLL_API
353 virtual void
354 transpose(DataAbstract* ev, int axis_offset);
355
356 /**
357 \brief
358 swaps components axis0 and axis1
359
360 \param ev - Output - swapped components
361
362 */
363 ESCRIPT_DLL_API
364 virtual void
365 swapaxes(DataAbstract* ev, int axis0, int axis1);
366
367
368 /**
369 \brief
370 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
371
372 \param ev - Output - eigenvalues in increasing order at each data point
373
374 */
375 ESCRIPT_DLL_API
376 virtual void
377 eigenvalues(DataAbstract* ev);
378
379 /**
380 \brief
381 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
382
383 \param ev - Output - eigenvalues in increasing order at each data point
384 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
385 and the first nonzero component is positive.
386 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
387
388 */
389
390 ESCRIPT_DLL_API
391 virtual void
392 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
393
394 /**
395 * \brief
396 * reorders data sample ordered by reference_ids to the ordering of the functions space
397 *
398 * \param reference_ids - Input - reference_ids used for current ordering
399 * */
400 ESCRIPT_DLL_API
401 virtual void
402 reorderByReferenceIDs(int *reference_ids);
403
404
405
406 protected:
407
408 private:
409
410 /**
411 \brief
412 Common initialisation called from constructors.
413
414 Description:
415 Common initialisation called from constructors.
416
417 Resizes the underlying data array to provide sufficient storage for the
418 given shape and number of data points, and creates the corresponding
419 DataArrayView of this data.
420
421 \param shape - Input - The shape of the point data.
422 \param noSamples - Input - number of samples.
423 \param noDataPointsPerSample - Input - number of data points per sample.
424 */
425 void
426 initialise(const DataTypes::ShapeType& shape,
427 int noSamples,
428 int noDataPointsPerSample);
429
430 /**
431 \brief
432 Copy the given data point value to all data points in this object.
433
434 Description:
435 Copy the given data point to all data points in this object.
436
437 \param value Input - A single data point value.
438 */
439 void
440 copy(const DataArrayView& value);
441
442 /**
443 \brief
444 Copy the given data point value given a numarray object to all data points in this object.
445
446 Description:
447 Copy the given data point value given a numarray object to all data points in this object.
448
449 \param value Input - A single data point value.
450 */
451 void
452 copy(const boost::python::numeric::array& value);
453
454 /**
455 \brief
456 Copy the numarray object to the data points in this object.
457
458 Description:
459 Copy the numarray object to the data points in this object.
460
461 \param value Input - new values for the data points
462 */
463 void
464 copyAll(const boost::python::numeric::array& value);
465
466 /**
467 \brief
468 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
469
470 Description:
471 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
472
473 \param sampleNo Input - sample number
474 \param dataPointNo Input - data point of the sample
475 \param value Input - new values for the data point
476 */
477 ESCRIPT_DLL_API
478 virtual void
479 copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
480
481
482 /**
483 \brief
484 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
485
486 Description:
487 Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
488
489 \param sampleNo Input - sample number
490 \param dataPointNo Input - data point of the sample
491 \param value Input - new values for the data point
492 */
493 void
494 copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
495
496 //
497 // The main data storage array, a 2D array of data blocks.
498 // noSamples * noDataPointsPerSample
499 DataBlocks2D m_data;
500
501 };
502
503 } // end of namespace
504
505 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26