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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1799 - (show annotations)
Wed Sep 17 06:33:18 2008 UTC (10 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 11679 byte(s)
Added Data::copySelf() [Note: this is exposed as copy() in python].
This method returns a pointer to a deep copy of the target.
There are c++ tests but no python tests for this yet.

All DataAbstracts now have a deepCopy() which simplifies the 
implementation of the compy methods.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26