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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 758 - (hide annotations)
Mon Jun 26 13:52:42 2006 UTC (15 years, 3 months ago) by woo409
File MIME type: text/plain
File size: 6066 byte(s)
+ Added PASO_MPI conditional compilation guard to prevent inclusion of mpi.h when not using mpi.
Trunk now compiles and runs on both win32 and linux.
1 jgs 117 /*
2 elspeth 615 ************************************************************
3     * Copyright 2006 by ACcESS MNRF *
4     * *
5     * http://www.access.edu.au *
6     * Primary Business: Queensland, Australia *
7     * Licensed under the Open Software License version 3.0 *
8     * http://www.opensource.org/licenses/osl-3.0.php *
9     * *
10     ************************************************************
11 jgs 117 */
12 jgs 121
13 jgs 117 #if !defined escript_DataVector_20050324_H
14     #define escript_DataVector_20050324_H
15 woo409 757 #include "system_dep.h"
16 jgs 117
17 robwdcock 682 #include "esysUtils/EsysAssert.h"
18 jgs 474
19 woo409 758 #ifdef PASO_MPI
20 bcumming 751 #include <mpi.h>
21 woo409 758 #endif
22 jgs 117 #include <vector>
23 jgs 474 #include <iostream>
24     #include <fstream>
25 jgs 117
26     namespace escript {
27    
28     /**
29     \brief
30     DataVector implements an arbitrarily long vector of data values.
31 jgs 121 DataVector is the underlying data container for Data objects.
32 jgs 117
33     Description:
34     DataVector provides an implementation of a vector of data values for use
35     by DataBlocks2D and DataArrayView. Hiding the vector in this container
36     allows different implementations to be swapped in without disrupting the
37 jgs 121 client classes.
38 jgs 117 */
39    
40 woo409 757 class ESCRIPT_DLL_API DataVector {
41 jgs 117
42     public:
43    
44     //
45     // The type of the elements stored in the vector.
46     typedef double ElementType;
47    
48     //
49     // The underlying type used to implement the vector.
50 jgs 121 typedef ElementType * ValueType;
51 jgs 117
52     //
53 jgs 121 // Various types exported to clients of this class.
54     typedef ElementType value_type;
55     typedef long size_type;
56     typedef ElementType & reference;
57     typedef const ElementType & const_reference;
58 jgs 117
59     /**
60     \brief
61     Default constructor for DataVector.
62    
63     Description:
64     Constructs an empty DataVector object.
65     */
66     DataVector();
67    
68     /**
69     \brief
70     Copy constructor for DataVector.
71    
72     Description:
73     Constructs a DataVector object which is a copy of the
74     given DataVector object.
75     */
76     DataVector(const DataVector& other);
77    
78     /**
79     \brief
80     Constructor for DataVector.
81    
82     Description:
83     Constructs a DataVector object of length "size" with all elements
84 jgs 121 initilised to "val".
85 jgs 117
86     \param size - Input - Number of elements in the vector.
87 jgs 121 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
88     \param blockSize - Input - size of blocks within the vector, overall vector
89     size must be a precise multiple of the block size. Default is 1.
90 jgs 151
91     In escript::Data, blocksize corresponds to the number of elements required to hold all
92     the data-points for a sample, ie: the product of the dimensions of a data-point and the
93     number of data-points per sample. Size is the total number of elements required to hold
94     all elements for all data-points in the given object, ie: number of samples * blocksize.
95 jgs 117 */
96 jgs 121 DataVector(const size_type size,
97     const value_type val=0.0,
98     const size_type blockSize=1);
99 jgs 117
100     /**
101     \brief
102     Default destructor for DataVector.
103    
104     Description:
105     Destroys the current DataVector object.
106     */
107     ~DataVector();
108    
109     /**
110     \brief
111     Resize the DataVector to the given length "newSize".
112     All current data is lost. All elements in the new DataVector are
113 jgs 121 initialised to "newVal".
114 jgs 117
115     \param newSize - Input - New size for the vector.
116 jgs 121 \param newVal - Input - New initial value for all elements in the vector.
117     \param newBlockSize - Input - New block size for the vector.
118 jgs 117 */
119     void
120 jgs 121 resize(const size_type newSize,
121     const value_type newVal=0.0,
122     const size_type newBlockSize=1);
123 jgs 117
124     /**
125     \brief
126     Return the number of elements in this DataVector.
127     */
128     inline
129 jgs 121 size_type
130 jgs 117 size() const;
131    
132     /**
133     \brief
134     DataVector assignment operator "=".
135     Assign the given DataVector object to this.
136     */
137     DataVector&
138     operator=(const DataVector& other);
139    
140     /**
141     \brief
142     DataVector equality comparison operator "==".
143     Return true if the given DataVector is equal to this.
144     */
145     bool
146 jgs 121 operator==(const DataVector& other) const;
147 jgs 117
148     /**
149     \brief
150     DataVector inequality comparison operator "!=".
151     Return true if the given DataVector is not equal to this.
152     */
153     bool
154 jgs 121 operator!=(const DataVector& other) const;
155 jgs 117
156     /**
157     \brief
158     Return a reference to the element at position i in this DataVector.
159     Will throw an exception if an invalid index "i" is given.
160    
161     NB: access to the element one past the end of the vector is permitted
162     in order to provide a facility equivalent to an end() pointer.
163     */
164     inline
165 jgs 121 reference
166     operator[](const size_type i);
167 jgs 117
168     inline
169 jgs 121 const_reference
170     operator[](const size_type i) const;
171 jgs 117
172 jgs 123 /**
173     \brief
174     Archive the data managed by this DataVector to the file referenced
175     by ofstream. A count of the number of values expected to be written
176     is provided as a cross-check.
177    
178 bcumming 751
179 jgs 123 The return value indicates success (0) or otherwise (1).
180     */
181     int
182     archiveData(std::ofstream& archiveFile,
183     const size_type noValues) const;
184    
185     /**
186     \brief
187     Extract the number of values specified by noValues from the file
188     referenced by ifstream to this DataVector.
189    
190     The return value indicates success (0) or otherwise (1).
191     */
192     int
193     extractData(std::ifstream& archiveFile,
194     const size_type noValues);
195    
196 jgs 117 protected:
197    
198     private:
199    
200 jgs 121 size_type m_size;
201     size_type m_dim;
202     size_type m_N;
203    
204 jgs 117 //
205     // The container for the elements contained in this DataVector.
206 jgs 121 ValueType m_array_data;
207 jgs 117 };
208    
209     inline
210 jgs 121 DataVector::size_type
211 jgs 117 DataVector::size() const
212     {
213 jgs 121 return m_size;
214 jgs 117 }
215    
216     inline
217 jgs 121 DataVector::reference
218     DataVector::operator[](const DataVector::size_type i)
219 jgs 117 {
220 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
221     return m_array_data[i];
222 jgs 117 }
223    
224     inline
225 jgs 121 DataVector::const_reference
226     DataVector::operator[](const DataVector::size_type i) const
227 jgs 117 {
228 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
229     return m_array_data[i];
230 jgs 117 }
231    
232     } // end of namespace
233    
234     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26