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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (show annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 1 month ago) by gross
File MIME type: text/plain
File size: 12714 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26