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

Contents of /trunk/escript/src/FunctionSpace.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1455 - (show annotations)
Thu Feb 28 17:19:44 2008 UTC (11 years, 8 months ago) by phornby
File MIME type: text/plain
File size: 7752 byte(s)
Merge of branches/windows_from_1431_trunk.

Revamp of the exception system.
Fix unused vars and signed/unsigned comparisons.
defined a macro THROW(ARG) in the system_dep.h's to
deal with the expectations of declarations on different architectures.

Details in the logs of branches/windows_from_1431_trunk.

pre-merge snapshot of the trunk in tags/trunk_at_1452


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 const 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 // yes, yes I know, but the test case is in another
282 // linkage unit external to the dll.
283 // This IS supposed to be a temporary fix until a more
284 // robust solution is implemented.
285 ESCRIPT_DLL_API
286 FunctionSpace&
287 operator=(const FunctionSpace& other);
288
289 //
290 // static null domain value
291 static const NullDomain nullDomainValue;
292
293 //
294 // function space domain
295 const AbstractDomain* m_domain;
296
297 //
298 // function space type code.
299 int m_functionSpaceType;
300
301 //
302 // return value of toString.
303 // Made mutable for recalculation by calls to toString.
304 // This is supposed to be conceptually immutable,
305 // and the mutable declaration is intended to admit lazy init. in the
306 // 1st call to toString()
307 // Unfortunately, the existance of operator=() breaks
308 // the imutability of FunctionSpace, so the current toString()
309 // implementation is in fact an abuse of "mutable".
310 // So why not just return a std::strin & do away with this class member?
311 //
312 // 1. even if an anonymous copy of the value is returned instead of a const
313 // reference, that value can find it's way into another DLL, especially
314 // in this environment.
315 // 2. This is especially true of exceptions that are fed said anaonymous
316 // copy as the retun value of a function into the argument of the
317 // exception constructor that expects a const reference.
318 // 3. What happens is that the exception object is left holding
319 // a reference to an onject that is going to get creamed
320 // during stack unwind.
321 // 4. returning a class value from a stack local is frowned upon anyway,
322 // this is just one reason not to do it.
323 // 5. There are a number of patters, all well known to C++ programmers
324 // for avoiding the practice.
325
326 mutable std::string type_str;
327
328 };
329
330 } // end of namespace
331
332 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26