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_DataConstant_20040323_H |
17 |
#define escript_DataConstant_20040323_H |
18 |
#include "system_dep.h" |
19 |
|
20 |
#include "DataAbstract.h" |
21 |
#include "DataArrayView.h" |
22 |
|
23 |
#include <boost/python/numeric.hpp> |
24 |
|
25 |
namespace escript { |
26 |
|
27 |
/** |
28 |
\brief |
29 |
DataConstant stores a single data point which represents the entire |
30 |
function space. |
31 |
|
32 |
Description: |
33 |
DataConstant stores a single data point which represents the entire |
34 |
function space. |
35 |
*/ |
36 |
class DataConstant : public DataAbstract { |
37 |
|
38 |
public: |
39 |
|
40 |
/** |
41 |
\brief |
42 |
Constructor for DataConstant objects. |
43 |
|
44 |
Description: |
45 |
Constructor for DataConstant objects. |
46 |
|
47 |
\param value - Input - Data value for a single point. |
48 |
\param what - Input - A description of what this data object represents. |
49 |
*/ |
50 |
ESCRIPT_DLL_API |
51 |
DataConstant(const boost::python::numeric::array& value, |
52 |
const FunctionSpace& what); |
53 |
|
54 |
/** |
55 |
\brief |
56 |
Copy constructor. Performs a deep copy. |
57 |
*/ |
58 |
ESCRIPT_DLL_API |
59 |
DataConstant(const DataConstant& other); |
60 |
|
61 |
/** |
62 |
\brief |
63 |
Alternative constructor for DataConstant objects. |
64 |
|
65 |
Description: |
66 |
Alternative Constructor for DataConstant objects. |
67 |
\param value - Input - Data value for a single point. |
68 |
\param what - Input - A description of what this data object represents. |
69 |
*/ |
70 |
ESCRIPT_DLL_API |
71 |
DataConstant(const DataArrayView& value, |
72 |
const FunctionSpace& what); |
73 |
|
74 |
/** |
75 |
\brief |
76 |
Alternative constructor for DataConstant objects. |
77 |
|
78 |
Description: |
79 |
Alternative Constructor for DataConstant objects. |
80 |
\param other - Input - Data object to copy from. |
81 |
\param region - Input - region to copy. |
82 |
*/ |
83 |
ESCRIPT_DLL_API |
84 |
DataConstant(const DataConstant& other, |
85 |
const DataArrayView::RegionType& region); |
86 |
|
87 |
/** |
88 |
\brief |
89 |
Alternative constructor for DataConstant objects. |
90 |
|
91 |
Description: |
92 |
Alternative Constructor for DataConstant objects. |
93 |
\param what - Input - A description of what this data object represents. |
94 |
\param shape - Input - the shape of each data-point. |
95 |
\param data - the data values for each data-point. |
96 |
*/ |
97 |
ESCRIPT_DLL_API |
98 |
DataConstant(const FunctionSpace& what, |
99 |
const DataArrayView::ShapeType &shape, |
100 |
const DataArrayView::ValueType &data); |
101 |
|
102 |
/** |
103 |
\brief |
104 |
Write the data as a string. |
105 |
*/ |
106 |
ESCRIPT_DLL_API |
107 |
std::string |
108 |
toString() const; |
109 |
/** |
110 |
\brief |
111 |
dumps the object into a netCDF file |
112 |
*/ |
113 |
ESCRIPT_DLL_API |
114 |
virtual |
115 |
void |
116 |
dump(const std::string fileName) const; |
117 |
|
118 |
/** |
119 |
\brief |
120 |
sets all values to zero |
121 |
*/ |
122 |
ESCRIPT_DLL_API |
123 |
virtual |
124 |
void |
125 |
setToZero(); |
126 |
|
127 |
/** |
128 |
\brief |
129 |
Return the offset for the given sample. This is a somewhat artificial notion |
130 |
but returns the offset in bytes for the given point into the container |
131 |
holding the point data. Only really necessary to avoid many DataArrayView |
132 |
objects. |
133 |
\param sampleNo - Input - sample number. |
134 |
\param dataPointNo - Input - data point number for the sample. |
135 |
*/ |
136 |
ESCRIPT_DLL_API |
137 |
virtual |
138 |
DataArrayView::ValueType::size_type |
139 |
getPointOffset(int sampleNo, |
140 |
int dataPointNo) const; |
141 |
|
142 |
/** |
143 |
\brief |
144 |
Return a view into the data for the data point specified. |
145 |
\param sampleNo - Input - sample number. |
146 |
\param dataPointNo - Input - data point number for the sample. |
147 |
*/ |
148 |
ESCRIPT_DLL_API |
149 |
virtual |
150 |
DataArrayView |
151 |
getDataPoint(int sampleNo, |
152 |
int dataPointNo); |
153 |
|
154 |
/** |
155 |
\brief |
156 |
Return the number of doubles stored for the Data object. |
157 |
*/ |
158 |
ESCRIPT_DLL_API |
159 |
virtual |
160 |
DataArrayView::ValueType::size_type |
161 |
getLength() const; |
162 |
|
163 |
/** |
164 |
\brief |
165 |
Factory method that returns a newly created DataConstant object |
166 |
sliced from the specified region of this object. |
167 |
The caller is reponsible for managing the object created. |
168 |
\param region - Input - region to slice from this object. |
169 |
*/ |
170 |
ESCRIPT_DLL_API |
171 |
virtual |
172 |
DataAbstract* |
173 |
getSlice(const DataArrayView::RegionType& region) const; |
174 |
|
175 |
/** |
176 |
\brief |
177 |
Copy the specified region from the given value. |
178 |
\param value - Input - Data object to copy from. |
179 |
\param region - Input - Region to copy. |
180 |
*/ |
181 |
ESCRIPT_DLL_API |
182 |
virtual |
183 |
void |
184 |
setSlice(const DataAbstract* value, |
185 |
const DataArrayView::RegionType& region); |
186 |
|
187 |
/** |
188 |
\brief |
189 |
Archive the underlying data values to the file referenced |
190 |
by ofstream. A count of the number of values expected to be written |
191 |
is provided as a cross-check. |
192 |
|
193 |
The return value indicates success (0) or otherwise (1). |
194 |
*/ |
195 |
ESCRIPT_DLL_API |
196 |
int |
197 |
archiveData(std::ofstream& archiveFile, |
198 |
const DataArrayView::ValueType::size_type noValues) const; |
199 |
|
200 |
/** |
201 |
\brief |
202 |
Extract the number of values specified by noValues from the file |
203 |
referenced by ifstream to the underlying data structure. |
204 |
|
205 |
The return value indicates success (0) or otherwise (1). |
206 |
*/ |
207 |
ESCRIPT_DLL_API |
208 |
int |
209 |
extractData(std::ifstream& archiveFile, |
210 |
const DataArrayView::ValueType::size_type noValues); |
211 |
|
212 |
/** |
213 |
\brief |
214 |
Computes a symmetric matrix (A + AT) / 2 |
215 |
|
216 |
\param ev - Output - symmetric matrix |
217 |
|
218 |
*/ |
219 |
ESCRIPT_DLL_API |
220 |
virtual void |
221 |
symmetric(DataAbstract* ev); |
222 |
|
223 |
/** |
224 |
\brief |
225 |
Computes a nonsymmetric matrix (A - AT) / 2 |
226 |
|
227 |
\param ev - Output - nonsymmetric matrix |
228 |
|
229 |
*/ |
230 |
ESCRIPT_DLL_API |
231 |
virtual void |
232 |
nonsymmetric(DataAbstract* ev); |
233 |
|
234 |
/** |
235 |
\brief |
236 |
Computes the trace of a matrix |
237 |
|
238 |
\param ev - Output - trace of matrix |
239 |
|
240 |
*/ |
241 |
ESCRIPT_DLL_API |
242 |
virtual void |
243 |
trace(DataAbstract* ev, int axis_offset); |
244 |
|
245 |
/** |
246 |
\brief |
247 |
Transpose each data point of this Data object around the given axis. |
248 |
|
249 |
\param ev - Output - transpose of matrix |
250 |
|
251 |
*/ |
252 |
ESCRIPT_DLL_API |
253 |
virtual void |
254 |
transpose(DataAbstract* ev, int axis_offset); |
255 |
|
256 |
/** |
257 |
\brief |
258 |
swaps components axis0 and axis1 |
259 |
|
260 |
\param ev - Output - swapped components |
261 |
|
262 |
*/ |
263 |
ESCRIPT_DLL_API |
264 |
virtual void |
265 |
swapaxes(DataAbstract* ev, int axis0, int axis1); |
266 |
|
267 |
|
268 |
/** |
269 |
\brief |
270 |
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev |
271 |
|
272 |
\param ev - Output - eigenvalues in increasing order at each data point |
273 |
|
274 |
*/ |
275 |
ESCRIPT_DLL_API |
276 |
virtual void |
277 |
eigenvalues(DataAbstract* ev); |
278 |
|
279 |
/** |
280 |
\brief |
281 |
solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V |
282 |
|
283 |
\param ev - Output - eigenvalues in increasing order at each data point |
284 |
\param V - Output - corresponding eigenvectors. They are normalized such that their length is one |
285 |
and the first nonzero component is positive. |
286 |
\param tol - Input - eigenvalue with relative distance tol are treated as equal. |
287 |
|
288 |
*/ |
289 |
|
290 |
ESCRIPT_DLL_API |
291 |
virtual void |
292 |
eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13); |
293 |
|
294 |
|
295 |
protected: |
296 |
|
297 |
private: |
298 |
// |
299 |
// the actual data |
300 |
DataArrayView::ValueType m_data; |
301 |
|
302 |
}; |
303 |
|
304 |
} // end of namespace |
305 |
#endif |