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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2766 - (hide annotations)
Mon Nov 23 05:10:53 2009 UTC (9 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 10432 byte(s)
inf, sup and Lsup now correctly handle +-infinity.
They also will return NaN if any part of their input is NaN.

This will break unit tests since it exposes the hidden bug (#447 in mantis)

This code relies on the ability to test for NaNs.
To do this it makes use of macros and functions from C99.
If you do not have a C99 compiler, then you will probably get the old behaviour.
That is, you won't know when you have NaNs.


Also did minor tweak to saveDataCSV doco.
1 jgs 480
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 jgs 102 #if !defined escript_DataExpanded_20040323_H
16 jgs 82 #define escript_DataExpanded_20040323_H
17 woo409 757 #include "system_dep.h"
18 jgs 82
19 jfenwick 2005 #include "DataReady.h"
20 jgs 82 #include "DataBlocks2D.h"
21    
22     namespace escript {
23    
24 jgs 117 //
25     // Forward declarations of other Data types.
26 jgs 102 class DataConstant;
27     class DataTagged;
28 jgs 82
29     /**
30     \brief
31     Give a short description of what DataExpanded does.
32    
33     Description:
34 jgs 117 Give a detailed description of DataExpanded.
35 jgs 82
36     Template Parameters:
37     For templates describe any conditions that the parameters used in the
38 jgs 117 template must satisfy.
39 jgs 82 */
40    
41 jfenwick 2005 class DataExpanded : public DataReady {
42 jgs 82
43 jfenwick 2005 typedef DataReady parent;
44    
45 jgs 82 public:
46    
47     /**
48     \brief
49 jgs 117 Constructor for DataExpanded.
50 jgs 82
51 jgs 117 Description:
52     Constructor for DataExpanded.
53 jgs 82
54 jgs 117 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 jgs 82
58 jfenwick 2271 \param value - Input - The value of a single data point.
59 jgs 82 \param what - Input - A description of what this data represents.
60     */
61 woo409 757 ESCRIPT_DLL_API
62 jfenwick 2271 DataExpanded(const WrappedArray& value,
63 jgs 102 const FunctionSpace& what);
64 jgs 82
65     /**
66     \brief
67     Alternative constructor for DataExpanded that copies a slice from
68     another DataExpanded.
69    
70 jgs 102 \param other - Input - DataExpanded object to slice from.
71     \param region - Input - region to copy.
72 jgs 82 */
73 woo409 757 ESCRIPT_DLL_API
74 jgs 102 DataExpanded(const DataExpanded& other,
75 jfenwick 1796 const DataTypes::RegionType& region);
76 jgs 82
77     /**
78     \brief
79 jgs 119 Alternative constructor for DataExpanded objects.
80    
81     Description:
82     Alternative Constructor for DataExpanded objects.
83     \param what - Input - A description of what this data object represents.
84     \param shape - Input - the shape of each data-point.
85 jgs 122 \param data - the array of data values for the data-points.
86 jfenwick 1796
87     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.
88 jgs 119 */
89 woo409 757 ESCRIPT_DLL_API
90 jgs 119 DataExpanded(const FunctionSpace& what,
91 jfenwick 1796 const DataTypes::ShapeType &shape,
92     const DataTypes::ValueType &data);
93 jgs 119
94     /**
95     \brief
96 jgs 117 Copy constructor for DataExpanded.
97     Performs a deep copy from another DataExpanded.
98 jgs 82 */
99 woo409 757 ESCRIPT_DLL_API
100 jgs 117 DataExpanded(const DataExpanded& other);
101    
102     /**
103     \brief
104     Copy constructor for DataExpanded.
105     Construct a DataExpanded from a DataConstant.
106     */
107 woo409 757 ESCRIPT_DLL_API
108 jgs 117 DataExpanded(const DataConstant& other);
109    
110     /**
111     \brief
112     Copy constructor for DataExpanded.
113     Construct a DataExpanded from a DataTagged.
114     */
115 woo409 757 ESCRIPT_DLL_API
116 jgs 117 DataExpanded(const DataTagged& other);
117    
118     /**
119     \brief
120     Default destructor for DataExpanded.
121     */
122 woo409 757 ESCRIPT_DLL_API
123 jgs 102 virtual
124     ~DataExpanded();
125 jgs 82
126 jfenwick 2005 ESCRIPT_DLL_API
127     bool
128     isExpanded() const
129     {
130     return true;
131     };
132    
133 jfenwick 2271 ESCRIPT_DLL_API
134     bool
135     actsExpanded() const
136     {
137     return true;
138     }
139    
140 jgs 82 /**
141 jfenwick 2766 \brief Return true if any value in the data contains a NaN.
142     */
143     ESCRIPT_DLL_API
144     bool
145     hasNaN() const;
146    
147     /**
148 jgs 82 \brief
149 jgs 117 Return a textual representation of the data.
150 jgs 82 */
151 woo409 757 ESCRIPT_DLL_API
152 jgs 102 virtual
153     std::string
154     toString() const;
155 jfenwick 1799
156     /**
157     \brief Return a deep copy of the current object.
158     */
159     ESCRIPT_DLL_API
160     virtual
161     DataAbstract*
162     deepCopy();
163    
164    
165 gross 950 /**
166     \brief
167     dumps the object into a netCDF file
168     */
169     ESCRIPT_DLL_API
170     virtual
171     void
172     dump(const std::string fileName) const;
173 jgs 82
174 jfenwick 2742
175     /**
176     \brief invert square matricies
177     \param out - Where to store the results
178     */
179     ESCRIPT_DLL_API
180     virtual void
181     matrixInverse(DataAbstract* out) const;
182    
183 gross 1118 /**
184     \brief
185     sets all values to zero
186     */
187     ESCRIPT_DLL_API
188     virtual
189     void
190     setToZero();
191    
192 jgs 82 /**
193     \brief
194 jgs 117 Return the offset for the given given data point. This returns
195     the offset in bytes for the given point into the container
196 jgs 82 holding the point data.
197 jgs 117
198     \param sampleNo - Input - sample number.
199     \param dataPointNo - Input - data point number.
200 jgs 82 */
201 woo409 757 ESCRIPT_DLL_API
202 jgs 102 virtual
203 jfenwick 1796 DataTypes::ValueType::size_type
204 jgs 102 getPointOffset(int sampleNo,
205     int dataPointNo) const;
206 jgs 82
207 jfenwick 2005 ESCRIPT_DLL_API
208     virtual
209     DataTypes::ValueType::size_type
210     getPointOffset(int sampleNo,
211     int dataPointNo);
212    
213 jfenwick 1796 /**
214     \brief
215     Return a a reference to the underlying DataVector.
216 jgs 82 */
217 jfenwick 1796
218 woo409 757 ESCRIPT_DLL_API
219 jfenwick 1796 DataTypes::ValueType&
220 jfenwick 2271 getVectorRW();
221 jgs 82
222 jfenwick 1796 ESCRIPT_DLL_API
223     const DataTypes::ValueType&
224 jfenwick 2271 getVectorRO() const;
225 jfenwick 1796
226    
227 jfenwick 2271
228 jgs 82 /**
229     \brief
230 jgs 102 Return the number of doubles stored for the Data.
231 jgs 82 */
232 woo409 757 ESCRIPT_DLL_API
233 jgs 102 virtual
234     ValueType::size_type
235     getLength() const;
236 jgs 82
237     /**
238     \brief
239     Factory method that returns a newly created DataExpanded.
240     The caller is reponsible for managing the object created.
241 jgs 117
242 jgs 82 \param region - Input - Region to copy.
243     */
244 woo409 757 ESCRIPT_DLL_API
245 jgs 102 virtual
246     DataAbstract*
247 jfenwick 1796 getSlice(const DataTypes::RegionType& region) const;
248 jgs 82
249     /**
250     \brief
251     Copy the specified region from the given value.
252 jgs 117
253     \param value - Input - Data object to copy from.
254 jgs 82 \param region - Input - Region to copy.
255     */
256 woo409 757 ESCRIPT_DLL_API
257 jgs 102 virtual
258     void
259     setSlice(const DataAbstract* value,
260 jfenwick 1796 const DataTypes::RegionType& region);
261 jgs 82
262 gross 580 /**
263     \brief
264 gross 1358 setTaggedValue
265    
266     Description:
267     uses tag to set a new value
268    
269     \param tagKey - Input - Integer key.
270 jfenwick 1796 \param pointshape - Input - The shape of the value parameter
271 jfenwick 2521 \param value - Input -
272     \param dataOffset - Input - where in the value parameter to start reading the data point value.
273 gross 1358 */
274 jfenwick 1796 void
275 gross 1358 setTaggedValue(int tagKey,
276 jfenwick 1796 const DataTypes::ShapeType& pointshape,
277     const DataTypes::ValueType& value,
278     int dataOffset=0);
279 gross 1358
280 jfenwick 1796
281    
282 gross 1358 /**
283     \brief
284 ksteube 775 Computes a symmetric matrix (A + AT) / 2
285    
286     \param ev - Output - symmetric matrix
287    
288     */
289 gross 800 ESCRIPT_DLL_API
290 ksteube 775 virtual void
291     symmetric(DataAbstract* ev);
292    
293     /**
294     \brief
295     Computes a nonsymmetric matrix (A - AT) / 2
296    
297     \param ev - Output - nonsymmetric matrix
298    
299     */
300 gross 800 ESCRIPT_DLL_API
301 ksteube 775 virtual void
302     nonsymmetric(DataAbstract* ev);
303    
304     /**
305     \brief
306     Computes the trace of a matrix
307    
308     \param ev - Output - trace of your matrix
309 jfenwick 2521 \param axis_offset -
310 ksteube 775
311     */
312 gross 800 ESCRIPT_DLL_API
313 ksteube 775 virtual void
314 gross 800 trace(DataAbstract* ev, int axis_offset);
315 ksteube 775
316     /**
317     \brief
318     Transpose each data point of this Data object around the given axis.
319    
320     \param ev - Output - transpose of your matrix
321 jfenwick 2521 \param axis_offset -
322 ksteube 775 */
323 gross 800 ESCRIPT_DLL_API
324 ksteube 775 virtual void
325     transpose(DataAbstract* ev, int axis_offset);
326    
327     /**
328     \brief
329 gross 804 swaps components axis0 and axis1
330 gross 800
331     \param ev - Output - swapped components
332 jfenwick 2521 \param axis0
333     \param axis1
334 gross 800 */
335     ESCRIPT_DLL_API
336     virtual void
337 gross 804 swapaxes(DataAbstract* ev, int axis0, int axis1);
338 gross 800
339    
340     /**
341     \brief
342 gross 580 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
343    
344     \param ev - Output - eigenvalues in increasing order at each data point
345    
346     */
347 woo409 757 ESCRIPT_DLL_API
348 gross 580 virtual void
349     eigenvalues(DataAbstract* ev);
350    
351     /**
352     \brief
353     solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
354    
355     \param ev - Output - eigenvalues in increasing order at each data point
356     \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
357     and the first nonzero component is positive.
358     \param tol - Input - eigenvalue with relative distance tol are treated as equal.
359    
360     */
361    
362 woo409 757 ESCRIPT_DLL_API
363 gross 580 virtual void
364     eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
365    
366 gross 1487 /**
367     * \brief
368     * reorders data sample ordered by reference_ids to the ordering of the functions space
369     *
370     * \param reference_ids - Input - reference_ids used for current ordering
371     * */
372     ESCRIPT_DLL_API
373     virtual void
374     reorderByReferenceIDs(int *reference_ids);
375 gross 580
376 gross 1487
377    
378 jgs 82 protected:
379    
380     private:
381    
382     /**
383     \brief
384 jgs 117 Common initialisation called from constructors.
385 jgs 82
386     Description:
387 jgs 117 Common initialisation called from constructors.
388    
389     Resizes the underlying data array to provide sufficient storage for the
390     given shape and number of data points, and creates the corresponding
391     DataArrayView of this data.
392    
393 jgs 82 \param noSamples - Input - number of samples.
394 jgs 117 \param noDataPointsPerSample - Input - number of data points per sample.
395 jgs 82 */
396 jgs 102 void
397 jfenwick 1796 initialise(int noSamples,
398 jgs 102 int noDataPointsPerSample);
399 jgs 82
400     /**
401     \brief
402 jgs 126 Copy the given data point value to all data points in this object.
403 jgs 82
404     Description:
405 jgs 117 Copy the given data point to all data points in this object.
406    
407     \param value Input - A single data point value.
408 jgs 82 */
409 jgs 102 void
410 jfenwick 1796 copy(const DataConstant& value);
411 jgs 82
412 jfenwick 1796
413    
414 jgs 126 /**
415     \brief
416 jfenwick 2458 Copy the given data point value to all data points in this object.
417 jgs 126
418     \param value Input - A single data point value.
419     */
420 jfenwick 2271
421 jgs 102 void
422 jfenwick 2271 copy(const WrappedArray& value);
423 jgs 102
424 jgs 126
425 gross 921 /**
426     \brief
427 gross 922 Copy a double value to the data point dataPointNo of sample sampleNo in this object.
428    
429     Description:
430     Copy a double value to the data point dataPointNo of sample sampleNo in this object.
431    
432     \param sampleNo Input - sample number
433     \param dataPointNo Input - data point of the sample
434     \param value Input - new values for the data point
435     */
436     ESCRIPT_DLL_API
437     virtual void
438     copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
439    
440    
441     /**
442     \brief
443 jfenwick 2458 Copy the value to the data point dataPointNo of sample sampleNo in this object.
444 gross 921
445     \param sampleNo Input - sample number
446     \param dataPointNo Input - data point of the sample
447     \param value Input - new values for the data point
448     */
449 jfenwick 2271 ESCRIPT_DLL_API
450     virtual void
451     copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
452 gross 921
453 jgs 82 //
454 jgs 117 // The main data storage array, a 2D array of data blocks.
455     // noSamples * noDataPointsPerSample
456 jgs 82 DataBlocks2D m_data;
457    
458     };
459    
460     } // end of namespace
461 jgs 102
462 jgs 100 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26