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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1455 - (hide annotations)
Thu Feb 28 17:19:44 2008 UTC (11 years, 7 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 jgs 115
2 ksteube 1312 /* $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 jgs 115 #if !defined escript_FunctionSpace_20040323_H
17 jgs 82 #define escript_FunctionSpace_20040323_H
18 woo409 757 #include "system_dep.h"
19 jgs 82
20 jgs 474 #include "AbstractDomain.h"
21     #include "NullDomain.h"
22 jgs 82
23     #include <string>
24    
25 phornby 1455 // This stops the friend declaration below from looking like a
26     // declaration of escript::FunctionSpaceTestCase.
27    
28 trankine 1426 class FunctionSpaceTestCase;
29    
30 jgs 82 namespace escript {
31    
32 jgs 117 //
33     // Forward declaration for class Data.
34     class Data;
35 jgs 82
36     /**
37     \brief
38     Give a short description of what FunctionSpace does.
39    
40     Description:
41 jgs 117 Give a detailed description of FunctionSpace.
42 jgs 82
43     Template Parameters:
44     For templates describe any conditions that the parameters used in the
45 jgs 117 template must satisfy.
46 jgs 82 */
47    
48 trankine 1426 class FunctionSpace {
49 jgs 82
50 trankine 1426 // These are using operator=()
51     friend class AbstractSystemMatrix;
52     friend class AbstractTransportProblem;
53     friend class ::FunctionSpaceTestCase;
54    
55 jgs 82 public:
56     /**
57     \brief
58 jgs 117 Default constructor for FunctionSpace.
59 jgs 82
60     Description:
61     Default constructor for FunctionSpace
62     Generates a function space with a null domain.
63    
64     Preconditions:
65 jgs 117 Describe any preconditions.
66 jgs 82
67     Throws:
68 jgs 117 Describe any exceptions thrown.
69 jgs 82 */
70 trankine 1426 ESCRIPT_DLL_API
71 jgs 82 FunctionSpace();
72    
73     /**
74     \brief
75 jgs 117 Constructor for FunctionSpace.
76 jgs 82
77     Description:
78     Constructor for FunctionSpace.
79 jgs 115
80 jgs 82 NOTE: The FunctionSpace class relies on the domain existing
81 jgs 115 for the lifetime of the FunctionSpace object. ie: domain must
82     be an externally managed object (!).
83 jgs 82 */
84 trankine 1426 ESCRIPT_DLL_API
85 jgs 117 FunctionSpace(const AbstractDomain& domain,
86     int functionSpaceType);
87 jgs 82
88     /**
89     \brief
90     Return the function space type code.
91     */
92 trankine 1426 ESCRIPT_DLL_API
93 jgs 117 int
94     getTypeCode() const;
95 jgs 82
96     /**
97     \brief
98     Return the function space domain.
99     */
100 trankine 1426 ESCRIPT_DLL_API
101 jgs 117 const
102     AbstractDomain&
103     getDomain() const;
104 jgs 82
105    
106 gross 767
107 jgs 82 /**
108 gross 767 \brief assigns new tag newTag to all samples with a positive
109     value of mask for any its sample point.
110    
111     */
112 trankine 1426 ESCRIPT_DLL_API
113 gross 767 void setTags(const int newTag, const escript::Data& mask) const;
114    
115    
116     /**
117 jgs 82 \brief
118     Return the shape of the data needed to represent the function space.
119     */
120 trankine 1426 ESCRIPT_DLL_API
121 jgs 117 std::pair<int,int>
122     getDataShape() const;
123 jgs 82
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 trankine 1426 ESCRIPT_DLL_API
131 jgs 117 bool
132     operator==(const FunctionSpace& other) const;
133 jgs 82
134 trankine 1426 ESCRIPT_DLL_API
135 jgs 117 bool
136     operator!=(const FunctionSpace& other) const;
137    
138 jgs 82 /**
139     \brief
140 jgs 115 Return a text description of the function space.
141 phornby 1455 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 jgs 82 */
149 trankine 1426 ESCRIPT_DLL_API
150     const std::string &
151 jgs 117 toString() const;
152 ksteube 1312
153 trankine 1426 //#define DEBUG_PY_STRINGS
154    
155     #ifdef DEBUG_PY_STRINGS
156 jgs 82 /**
157     \brief
158 trankine 1426 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 jgs 82 Return the tag associated with the given sample number.
172     */
173 trankine 1426 ESCRIPT_DLL_API
174 jgs 117 int
175     getTagFromSampleNo(int sampleNo) const;
176 jgs 115
177 jgs 110 /**
178     \brief
179 jgs 149 Return the tag associated with the given data-point number.
180 jgs 110 */
181 trankine 1426 ESCRIPT_DLL_API
182 jgs 117 int
183 jgs 149 getTagFromDataPointNo(int dataPointNo) const;
184    
185     /**
186     \brief
187     Return the reference number associated with the given sample number.
188 gross 964 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 jgs 149 */
191 trankine 1426 ESCRIPT_DLL_API
192 gross 964 inline
193 jgs 149 int
194 gross 964 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 trankine 1426 ESCRIPT_DLL_API
203 gross 964 int*
204     borrowSampleReferenceIDs() const;
205 jgs 82
206     /**
207     \brief
208 jgs 149 Return the spatial locations of the data points.
209 jgs 82 */
210 trankine 1426 ESCRIPT_DLL_API
211 jgs 117 escript::Data
212     getX() const;
213 jgs 149
214 jgs 82 /**
215     \brief
216     Return the surface normal field.
217     */
218 trankine 1426 ESCRIPT_DLL_API
219 jgs 117 escript::Data
220     getNormal() const;
221 jgs 82
222     /**
223     \brief
224     Return the sample size (e.g. the diameter of elements, radius of particles).
225     */
226 trankine 1426 ESCRIPT_DLL_API
227 jgs 117 escript::Data
228     getSize() const;
229 jgs 82
230     /**
231     \brief
232 jgs 115 Return the number of samples.
233 jgs 82 */
234 trankine 1426 ESCRIPT_DLL_API
235 jgs 117 inline
236     int
237     getNumSamples() const {
238 jgs 82 return getDataShape().second;
239     }
240    
241     /**
242     \brief
243     Return the number of data points per sample.
244     */
245 trankine 1426 ESCRIPT_DLL_API
246 jgs 117 inline
247     int
248     getNumDPPSample() const {
249 jgs 82 return getNumDataPointsPerSample();
250     }
251 jgs 149
252 trankine 1426 ESCRIPT_DLL_API
253 jgs 117 inline
254     int
255     getNumDataPointsPerSample() const {
256 jgs 82 return getDataShape().first;
257     }
258    
259     /**
260     \brief
261     Return the spatial dimension of the underlying domain.
262     */
263 trankine 1426 ESCRIPT_DLL_API
264 jgs 117 inline
265     int
266     getDim() const {
267 jgs 82 return getDomain().getDim();
268     }
269 jgs 115
270 jgs 82 protected:
271    
272     private:
273 trankine 1426 /**
274     \brief
275     Assignment operator.
276     NOTE: Assignment copies the domain object pointer
277     as this object is managed externally to this class.
278 phornby 1455 Also, breaks the non-mutability of FunctionSpace
279     assumed by toString().
280 trankine 1426 */
281     // yes, yes I know, but the test case is in another
282     // linkage unit external to the dll.
283 phornby 1455 // This IS supposed to be a temporary fix until a more
284     // robust solution is implemented.
285 trankine 1426 ESCRIPT_DLL_API
286     FunctionSpace&
287     operator=(const FunctionSpace& other);
288 jgs 82
289     //
290     // static null domain value
291 trankine 1426 static const NullDomain nullDomainValue;
292 jgs 82
293     //
294     // function space domain
295     const AbstractDomain* m_domain;
296 jgs 149
297 jgs 82 //
298     // function space type code.
299     int m_functionSpaceType;
300    
301 trankine 1426 //
302     // return value of toString.
303 phornby 1455 // 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 trankine 1426 mutable std::string type_str;
327    
328 jgs 82 };
329    
330     } // end of namespace
331 jgs 117
332 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26