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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/DataExpanded.h revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC trunk/escript/src/DataExpanded.h revision 480 by jgs, Wed Feb 1 05:15:12 2006 UTC
# Line 1  Line 1 
1    // $Id$
2  /*  /*
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
# Line 11  Line 12 
12   *                                                                            *   *                                                                            *
13   ******************************************************************************   ******************************************************************************
14  */  */
15                                                                              
16  #if !defined  escript_DataExpanded_20040323_H  #if !defined escript_DataExpanded_20040323_H
17  #define escript_DataExpanded_20040323_H  #define escript_DataExpanded_20040323_H
18    
19  #include "DataAbstract.h"  #include "DataAbstract.h"
20  #include "DataBlocks2D.h"  #include "DataBlocks2D.h"
21  #include "DataArrayView.h"  #include "DataArrayView.h"
22    
 #include <boost/scoped_ptr.hpp>  
23  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
24    
25  namespace escript {  namespace escript {
26    
27    class DataConstant;  //
28    class DataTagged;  // Forward declarations of other Data types.
29    class DataConstant;
30    class DataTagged;
31    
32  /**  /**
33     \brief     \brief
34     Give a short description of what DataExpanded does.     Give a short description of what DataExpanded does.
35    
36     Description:     Description:
37     Give a detailed description of DataExpanded     Give a detailed description of DataExpanded.
38    
39     Template Parameters:     Template Parameters:
40     For templates describe any conditions that the parameters used in the     For templates describe any conditions that the parameters used in the
41     template must satisfy     template must satisfy.
42  */  */
43    
44  class DataExpanded : public DataAbstract{  class DataExpanded : public DataAbstract {
45    
46   public:   public:
47    
48    /**    /**
49       \brief       \brief
50       Copy constructor for DataExpanded. Performs a deep copy.       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    DataExpanded(const DataExpanded& other);    DataExpanded(const boost::python::numeric::array& value,
63                   const FunctionSpace& what);
64    
65    /**    /**
66       \brief       \brief
67       Construct a DataExpanded from a DataConstant       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    DataExpanded(const DataConstant& other);    DataExpanded(const DataArrayView& value,
80                   const FunctionSpace& what);
81    
82    /**    /**
83       \brief       \brief
84       Construct a DataExpanded from a DataTagged       Alternative constructor for DataExpanded that copies a slice from
85         another DataExpanded.
86    
87         \param other - Input - DataExpanded object to slice from.
88         \param region - Input - region to copy.
89    */    */
90    DataExpanded(const DataTagged& other);    DataExpanded(const DataExpanded& other,
91                   const DataArrayView::RegionType& region);
92    
93    /**    /**
94       \brief       \brief
95       Constructor for DataExpanded       Alternative constructor for DataExpanded objects.
96    
97       Description:       Description:
98       Constructor for DataExpanded       Alternative Constructor for DataExpanded objects.
99       \param value - Input - Data value for a single point.       \param what - Input - A description of what this data object represents.
100       \param what - Input - A description of what this data represents.       \param shape - Input - the shape of each data-point.
101         \param data - the array of data values for the data-points.
102    */    */
103    DataExpanded(const boost::python::numeric::array& value, const FunctionSpace& what);    DataExpanded(const FunctionSpace& what,
104                   const DataArrayView::ShapeType &shape,
105                   const DataArrayView::ValueType &data);
106    
107    /**    /**
108       \brief       \brief
109       Alternative constructor for DataExpanded       Copy constructor for DataExpanded.
110         Performs a deep copy from another DataExpanded.
      Description:  
      Alternative Constructor for DataExpanded  
      \param value - Input - Data value for a single point.  
      \param what - Input - A description of what this data represents.  
   
111    */    */
112    DataExpanded(const DataArrayView& value, const FunctionSpace& what);    DataExpanded(const DataExpanded& other);
113    
114    /**    /**
115       \brief       \brief
116       Alternative constructor for DataExpanded that copies a slice from       Copy constructor for DataExpanded.
117       another DataExpanded.       Construct a DataExpanded from a DataConstant.
118      */
119      DataExpanded(const DataConstant& other);
120    
121       \param other - Input - DataExpanded object to slice from    /**
122       \param region - Input - region to copy       \brief
123         Copy constructor for DataExpanded.
124         Construct a DataExpanded from a DataTagged.
125    */    */
126    DataExpanded(const DataExpanded& other, const DataArrayView::RegionType& region);    DataExpanded(const DataTagged& other);
127    
128    /**    /**
129       \brief       \brief
130       Destructor       Default destructor for DataExpanded.
131    */    */
132    virtual ~DataExpanded();    virtual
133      ~DataExpanded();
134    
135    /**    /**
136       \brief       \brief
137       Return a textual representation of the data       Return a textual representation of the data.
138    */    */
139    virtual std::string toString() const;    virtual
140      std::string
141      toString() const;
142    
143    /**    /**
144       \brief       \brief
# Line 112  class DataExpanded : public DataAbstract Line 146  class DataExpanded : public DataAbstract
146       The original data point value is used for all values of the new       The original data point value is used for all values of the new
147       data point.       data point.
148    */    */
149    void reshapeDataPoint(const DataArrayView::ShapeType& shape);    void
150      reshapeDataPoint(const DataArrayView::ShapeType& shape);
151    
152    /**    /**
153       \brief       \brief
154       Return the offset for the given sample. This is somewhat artificial notion       Return the offset for the given given data point. This returns
155       but returns the offset in bytes for the given point into the container       the offset in bytes for the given point into the container
156       holding the point data.       holding the point data.
157       \param sampleNo - Input - number of samples.  
158       \param dataPointNo - Input - Input.       \param sampleNo - Input - sample number.
159         \param dataPointNo - Input - data point number.
160    */    */
161    virtual DataArrayView::ValueType::size_type getPointOffset(int sampleNo, int dataPointNo) const;    virtual
162      DataArrayView::ValueType::size_type
163      getPointOffset(int sampleNo,
164                     int dataPointNo) const;
165    
166    /**    /**
167       \brief       \brief
168       Return a view into the data for the data point specified.       Return a view into the data array for the data point specified.
169    
170       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
171       operation       operation.
172       \param sampleNo - Input  
173       \param dataPointNo - Input       \param sampleNo - Input - sample number.
174       \return DataArrayView of the data point.       \param dataPointNo - Input - data point number.
175         \return DataArrayView for the data point.
176    */    */
177    DataArrayView getDataPoint(int sampleNo, int dataPointNo);    DataArrayView
178      getDataPoint(int sampleNo,
179                   int dataPointNo);
180    
181    /**    /**
182       \brief       \brief
183       Return the number of doubles stored for the Data       Return the number of doubles stored for the Data.
184    */    */
185    virtual ValueType::size_type getLength() const;    virtual
186      ValueType::size_type
187      getLength() const;
188    
189    /**    /**
190       \brief       \brief
191       Factory method that returns a newly created DataExpanded.       Factory method that returns a newly created DataExpanded.
192       The caller is reponsible for managing the object created.       The caller is reponsible for managing the object created.
193    
194       \param region - Input - Region to copy.       \param region - Input - Region to copy.
195    */    */
196    virtual DataAbstract* getSlice(const DataArrayView::RegionType& region) const;    virtual
197      DataAbstract*
198      getSlice(const DataArrayView::RegionType& region) const;
199    
200    /**    /**
201       \brief       \brief
202       Copy the specified region from the given value.       Copy the specified region from the given value.
203       \param value - Input - Data to copy from  
204         \param value - Input - Data object to copy from.
205       \param region - Input - Region to copy.       \param region - Input - Region to copy.
206    */    */
207    virtual void setSlice(const DataAbstract* value, const DataArrayView::RegionType& region);    virtual
208      void
209      setSlice(const DataAbstract* value,
210               const DataArrayView::RegionType& region);
211    
212      /**
213         \brief
214         Assign the given value to all data-points associated with the given
215         reference number.
216    
217         A reference number corresponds to a sample, and thus to all data-points
218         in that sample.
219    
220         If the given reference number does not correspond to any sample in this
221         Data object, an exception will be thrown.
222    
223         If the given value is a different shape to this Data object, an exception
224         will be thrown.
225    
226         \param ref - Input - reference number which determines sample numebr to
227                              assign given values to.
228         \param value - Input - Value to assign to data-point associated with
229                                the given reference number.
230      */
231      virtual
232      void
233      setRefValue(int ref,
234                  const DataArray& value);
235    
236      /**
237         \brief
238         Return the value of the first data-point in the sample associated with
239         the given reference number.
240    
241         A reference number corresponds to a sample, and thus to all data-points
242         in that sample. If there is more than one data-point per sample number
243         in this Data object, the value of the first data-point will be returned.
244    
245         If the given reference number does not correspond to any sample in this
246         Data object, an exception will be thrown.
247    
248         If the given value is a different shape to this Data object, an exception
249         will be thrown.
250    
251         \param ref - Input - reference number which determines sample number to
252                              read from.
253         \param value - Output - Object to receive data-points associated with
254                                the given reference number.
255      */
256      virtual
257      void
258      getRefValue(int ref,
259                  DataArray& value);
260    
261      /**
262        \brief
263        Archive the underlying data values to the file referenced
264        by ofstream. A count of the number of values expected to be written
265        is provided as a cross-check.
266    
267        The return value indicates success (0) or otherwise (1).
268      */
269      int
270      archiveData(std::ofstream& archiveFile,
271                  const DataArrayView::ValueType::size_type noValues) const;
272    
273      /**
274        \brief
275        Extract the number of values specified by noValues from the file
276        referenced by ifstream to the underlying data structure.
277    
278        The return value indicates success (0) or otherwise (1).
279      */
280      int
281      extractData(std::ifstream& archiveFile,
282                  const DataArrayView::ValueType::size_type noValues);
283    
284   protected:   protected:
285    
# Line 163  class DataExpanded : public DataAbstract Line 287  class DataExpanded : public DataAbstract
287    
288    /**    /**
289       \brief       \brief
290       Common initialisation called from constructors       Common initialisation called from constructors.
291    
292       Description:       Description:
293       Common initialisation called from constructors       Common initialisation called from constructors.
294    
295         Resizes the underlying data array to provide sufficient storage for the
296         given shape and number of data points, and creates the corresponding
297         DataArrayView of this data.
298    
299       \param shape - Input - The shape of the point data.       \param shape - Input - The shape of the point data.
300       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
301       \param noDataPointsPerSample - Input -       \param noDataPointsPerSample - Input - number of data points per sample.
302    */    */
303    void initialise(const DataArrayView::ShapeType& shape, int noSamples, int noDataPointsPerSample);    void
304      initialise(const DataArrayView::ShapeType& shape,
305                 int noSamples,
306                 int noDataPointsPerSample);
307    
308    /**    /**
309       \brief       \brief
310       Copy the given data point to all data points.       Copy the given data point value to all data points in this object.
311    
312       Description:       Description:
313       Copy the given data point to all data points.       Copy the given data point to all data points in this object.
314       \param value Input - Value for a single data point  
315         \param value Input - A single data point value.
316      */
317      void
318      copy(const DataArrayView& value);
319    
320      /**
321         \brief
322         Copy the given data point value given a numarray object to all data points in this object.
323    
324         Description:
325         Copy the given data point value given a numarray object to all data points in this object.
326    
327         \param value Input - A single data point value.
328      */
329      void
330      copy(const boost::python::numeric::array& value);
331    
332      /**
333         \brief
334         Copy the numarray object to the data points in this object.
335    
336         Description:
337         Copy the numarray object to the data points in this object.
338    
339         \param value Input - new values for the data points
340    */    */
341    void copy(const DataArrayView& value);    void
342    void copy(const boost::python::numeric::array& value);    copyAll(const boost::python::numeric::array& value);
343    
344    //    //
345    // The main data storage, a 2D array of data blocks    // The main data storage array, a 2D array of data blocks.
346      // noSamples * noDataPointsPerSample
347    DataBlocks2D m_data;    DataBlocks2D m_data;
348    
349  };  };
350    
351  } // end of namespace  } // end of namespace
 #endif  
   
   
   
352    
353    #endif

Legend:
Removed from v.100  
changed lines
  Added in v.480

  ViewVC Help
Powered by ViewVC 1.1.26