/[escript]/branches/windows_from_1456_trunk_1580_merged_in/escript/src/FunctionSpace.h
ViewVC logotype

Contents of /branches/windows_from_1456_trunk_1580_merged_in/escript/src/FunctionSpace.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1604 - (show annotations)
Sat Jun 14 10:06:31 2008 UTC (11 years, 2 months ago) by phornby
File MIME type: text/plain
File size: 6243 byte(s)
Undo a hack for debugging std::string return values.
Problem on windows now understood.
FunctionSpace still suffers a mutability problem
of a very subtle nature.
If python does an __str__() and gets a type string, then
a later operator= mutates its type, the string held by python will
no longer be valid. This could cause programming errors.
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_FunctionSpace_20040323_H
17 #define escript_FunctionSpace_20040323_H
18 #include "system_dep.h"
19
20 #include "AbstractDomain.h"
21 #include "NullDomain.h"
22
23 #include <string>
24
25 // This stops the friend declaration below from looking like a
26 // declaration of escript::FunctionSpaceTestCase.
27
28 class FunctionSpaceTestCase;
29
30 namespace escript {
31
32 //
33 // Forward declaration for class Data.
34 class Data;
35
36 /**
37 \brief
38 Give a short description of what FunctionSpace does.
39
40 Description:
41 Give a detailed description of FunctionSpace.
42
43 Template Parameters:
44 For templates describe any conditions that the parameters used in the
45 template must satisfy.
46 */
47
48 class FunctionSpace {
49
50 // These are using operator=()
51 friend class AbstractSystemMatrix;
52 friend class AbstractTransportProblem;
53 friend class ::FunctionSpaceTestCase;
54
55 public:
56 /**
57 \brief
58 Default constructor for FunctionSpace.
59
60 Description:
61 Default constructor for FunctionSpace
62 Generates a function space with a null domain.
63
64 Preconditions:
65 Describe any preconditions.
66
67 Throws:
68 Describe any exceptions thrown.
69 */
70 ESCRIPT_DLL_API
71 FunctionSpace();
72
73 /**
74 \brief
75 Constructor for FunctionSpace.
76
77 Description:
78 Constructor for FunctionSpace.
79
80 NOTE: The FunctionSpace class relies on the domain existing
81 for the lifetime of the FunctionSpace object. ie: domain must
82 be an externally managed object (!).
83 */
84 ESCRIPT_DLL_API
85 FunctionSpace(const AbstractDomain& domain,
86 int functionSpaceType);
87
88 /**
89 \brief
90 Return the function space type code.
91 */
92 ESCRIPT_DLL_API
93 int
94 getTypeCode() const;
95
96 /**
97 \brief
98 Return the function space domain.
99 */
100 ESCRIPT_DLL_API
101 const
102 AbstractDomain&
103 getDomain() const;
104
105
106
107 /**
108 \brief assigns new tag newTag to all samples with a positive
109 value of mask for any its sample point.
110
111 */
112 ESCRIPT_DLL_API
113 void setTags(const int newTag, const escript::Data& mask) const;
114
115
116 /**
117 \brief
118 Return the shape of the data needed to represent the function space.
119 */
120 ESCRIPT_DLL_API
121 std::pair<int,int>
122 getDataShape() const;
123
124 /**
125 \brief
126 Comparison operator.
127 Return true if function spaces are equal.
128 ie: Same domain and same function space type.
129 */
130 ESCRIPT_DLL_API
131 bool
132 operator==(const FunctionSpace& other) const;
133
134 ESCRIPT_DLL_API
135 bool
136 operator!=(const FunctionSpace& other) const;
137
138 /**
139 \brief
140 Return a text description of the function space.
141 NOTE: In the python interface, the reference return value policy is
142 copy const reference. This mens that if the python string value
143 is assigned to a python variable, it's value (python) value will not
144 change, even if operator=() changes this Function space object.
145 Consequently, it is possible for python to keep a wrong value for this
146 string!
147 Worse still is that operator=() is exposed to python in escriptcpp.cpp.
148 */
149 ESCRIPT_DLL_API
150 std::string
151 toString() const;
152
153 //#define DEBUG_PY_STRINGS
154
155 #ifdef DEBUG_PY_STRINGS
156 /**
157 \brief
158 Return a text description of the function space
159 as a python string.
160 NOTE: This code was used to debug a conversion of
161 std::string to python string problem on windows.
162 An alternative approach was sought.
163 */
164 ESCRIPT_DLL_API
165 PyObject *
166 toPyString() const;
167 #endif
168
169 /**
170 \brief
171 Return the tag associated with the given sample number.
172 */
173 ESCRIPT_DLL_API
174 int
175 getTagFromSampleNo(int sampleNo) const;
176
177 /**
178 \brief
179 Return the tag associated with the given data-point number.
180 */
181 ESCRIPT_DLL_API
182 int
183 getTagFromDataPointNo(int dataPointNo) const;
184
185 /**
186 \brief
187 Return the reference number associated with the given sample number.
188 This function is not efficient. It is better to first call
189 borrowSampleReferenceIDs and then when iterating over sampleNo to use sampleNo as an offset.
190 */
191 ESCRIPT_DLL_API
192 inline
193 int
194 getReferenceIDOfSample(int sampleNo) const
195 {
196 return borrowSampleReferenceIDs()[sampleNo];
197 }
198 /**
199 \brief
200 Return a borrowed reference to the list of sample reference IDs
201 */
202 ESCRIPT_DLL_API
203 int*
204 borrowSampleReferenceIDs() const;
205
206 /**
207 \brief
208 Return the spatial locations of the data points.
209 */
210 ESCRIPT_DLL_API
211 escript::Data
212 getX() const;
213
214 /**
215 \brief
216 Return the surface normal field.
217 */
218 ESCRIPT_DLL_API
219 escript::Data
220 getNormal() const;
221
222 /**
223 \brief
224 Return the sample size (e.g. the diameter of elements, radius of particles).
225 */
226 ESCRIPT_DLL_API
227 escript::Data
228 getSize() const;
229
230 /**
231 \brief
232 Return the number of samples.
233 */
234 ESCRIPT_DLL_API
235 inline
236 int
237 getNumSamples() const {
238 return getDataShape().second;
239 }
240
241 /**
242 \brief
243 Return the number of data points per sample.
244 */
245 ESCRIPT_DLL_API
246 inline
247 int
248 getNumDPPSample() const {
249 return getNumDataPointsPerSample();
250 }
251
252 ESCRIPT_DLL_API
253 inline
254 int
255 getNumDataPointsPerSample() const {
256 return getDataShape().first;
257 }
258
259 /**
260 \brief
261 Return the spatial dimension of the underlying domain.
262 */
263 ESCRIPT_DLL_API
264 inline
265 int
266 getDim() const {
267 return getDomain().getDim();
268 }
269
270 protected:
271
272 private:
273 /**
274 \brief
275 Assignment operator.
276 NOTE: Assignment copies the domain object pointer
277 as this object is managed externally to this class.
278 Also, breaks the non-mutability of FunctionSpace
279 assumed by toString().
280 */
281 ESCRIPT_DLL_API
282 FunctionSpace&
283 operator=(const FunctionSpace& other);
284
285 //
286 // static null domain value
287 static const NullDomain nullDomainValue;
288
289 //
290 // function space domain
291 const AbstractDomain* m_domain;
292
293 //
294 // function space type code.
295 int m_functionSpaceType;
296
297 };
298
299 } // end of namespace
300
301 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26