/[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 1773 - (show annotations)
Tue Sep 9 02:52:26 2008 UTC (13 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 12288 byte(s)
Branch commit

Fixed some bugs.
Code now passes all_tests.
Next step is to test under OMP and MPI


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26