1 |
// $Id$ |
2 |
/* |
3 |
************************************************************ |
4 |
* Copyright 2006 by ACcESS MNRF * |
5 |
* * |
6 |
* http://www.access.edu.au * |
7 |
* Primary Business: Queensland, Australia * |
8 |
* Licensed under the Open Software License version 3.0 * |
9 |
* http://www.opensource.org/licenses/osl-3.0.php * |
10 |
* * |
11 |
************************************************************ |
12 |
*/ |
13 |
|
14 |
#if !defined bruce_Bruce_20050829_H |
15 |
#define bruce_Bruce_20050829_H |
16 |
|
17 |
#include "AbstractDomain.h" |
18 |
#include "AbstractContinuousDomain.h" |
19 |
#include "FunctionSpace.h" |
20 |
#include "Data.h" |
21 |
|
22 |
#include <string> |
23 |
#include <vector> |
24 |
|
25 |
namespace bruce { |
26 |
|
27 |
/** |
28 |
\brief |
29 |
Bruce implements a structured AbstractContinuousDomain. |
30 |
|
31 |
Description: |
32 |
Bruce implements a structured AbstractContinuousDomain. |
33 |
*/ |
34 |
|
35 |
class Bruce : public escript::AbstractContinuousDomain { |
36 |
|
37 |
public: |
38 |
|
39 |
// |
40 |
// Codes for function space types supported |
41 |
static const int ContinuousFunction; // data is on the nodes |
42 |
static const int Function; // data is on the cell centres |
43 |
|
44 |
// |
45 |
// Type of FunctionSpaceNamesMap |
46 |
typedef std::map<int, std::string> FunctionSpaceNamesMapType; |
47 |
|
48 |
// |
49 |
// Types for the dimension vectors |
50 |
typedef std::vector<double> DimVec; |
51 |
|
52 |
/** |
53 |
\brief |
54 |
Default constructor for Bruce. |
55 |
|
56 |
Description: |
57 |
Default constructor for Bruce. |
58 |
Creates a null Bruce object. |
59 |
*/ |
60 |
Bruce(); |
61 |
|
62 |
/** |
63 |
\brief |
64 |
Constructor for Bruce. |
65 |
|
66 |
Description: |
67 |
Constructor for Bruce. |
68 |
|
69 |
The point "origin" specifies the location of the origin |
70 |
of the domain specified by this object. The dimensionality of this |
71 |
point determines the dimensionality of the space the domain occupies. |
72 |
|
73 |
The vectors v0,v1,v2 specify the axis in |
74 |
of the domain of this Bruce object. If v2 is an empty vector, this |
75 |
object is a two dimensional domain. If v1 is also an empty vector, |
76 |
this object is a one dimensional domain. If v0 is also an empty |
77 |
vector, this is a point domain. |
78 |
|
79 |
The integers n0,n1,n2 specify the dumber of data-points along each |
80 |
axis in the domain. |
81 |
*/ |
82 |
Bruce(DimVec v0, DimVec v1, DimVec v2, |
83 |
int n0, int n1, int n2, |
84 |
DimVec origin); |
85 |
|
86 |
/** |
87 |
\brief |
88 |
Copy constructor. |
89 |
*/ |
90 |
Bruce(const Bruce& other); |
91 |
|
92 |
/** |
93 |
\brief |
94 |
Destructor for Bruce. |
95 |
*/ |
96 |
~Bruce(); |
97 |
|
98 |
/** |
99 |
\brief |
100 |
Return this as an AbstractContinuousDomain. |
101 |
*/ |
102 |
inline |
103 |
const AbstractContinuousDomain& |
104 |
asAbstractContinuousDomain() const |
105 |
{ |
106 |
return *(static_cast<const AbstractContinuousDomain*>(this)); |
107 |
} |
108 |
|
109 |
/** |
110 |
\brief |
111 |
Return this as an AbstractDomain. |
112 |
*/ |
113 |
inline |
114 |
const AbstractDomain& |
115 |
asAbstractDomain() const |
116 |
{ |
117 |
return *(static_cast<const AbstractDomain*>(this)); |
118 |
} |
119 |
|
120 |
/** |
121 |
\brief |
122 |
Return a description for this domain. |
123 |
*/ |
124 |
virtual |
125 |
inline |
126 |
std::string |
127 |
getDescription() const |
128 |
{ |
129 |
return "Bruce"; |
130 |
} |
131 |
|
132 |
/** |
133 |
\brief |
134 |
Returns true if the given integer is a valid function space type |
135 |
for this domain. |
136 |
*/ |
137 |
virtual |
138 |
bool |
139 |
isValidFunctionSpaceType(int functionSpaceCode) const; |
140 |
|
141 |
/** |
142 |
\brief |
143 |
Return a description for the given function space type code. |
144 |
*/ |
145 |
virtual |
146 |
std::string |
147 |
functionSpaceTypeAsString(int functionSpaceCode) const; |
148 |
|
149 |
/** |
150 |
\brief |
151 |
Return a continuous FunctionSpace code. |
152 |
*/ |
153 |
virtual |
154 |
inline |
155 |
int |
156 |
getContinuousFunctionCode() const |
157 |
{ |
158 |
return ContinuousFunction; |
159 |
} |
160 |
|
161 |
/** |
162 |
\brief |
163 |
Return a function FunctionSpace code. |
164 |
*/ |
165 |
virtual |
166 |
inline |
167 |
int |
168 |
getFunctionCode() const |
169 |
{ |
170 |
return Function; |
171 |
} |
172 |
|
173 |
/** |
174 |
\brief |
175 |
Return the spatial dimension of the mesh. |
176 |
*/ |
177 |
virtual |
178 |
inline |
179 |
int |
180 |
getDim() const |
181 |
{ |
182 |
return m_origin.size(); |
183 |
} |
184 |
|
185 |
/** |
186 |
\brief |
187 |
Return the number of data points per sample, and the number of samples |
188 |
needed to represent data on parts of the mesh. |
189 |
*/ |
190 |
virtual |
191 |
std::pair<int,int> |
192 |
getDataShape(int functionSpaceCode) const; |
193 |
|
194 |
/** |
195 |
\brief |
196 |
Return the number of samples |
197 |
needed to represent data on parts of the mesh. |
198 |
*/ |
199 |
int |
200 |
getNumSamples(int functionSpaceCode) const; |
201 |
|
202 |
/** |
203 |
\brief |
204 |
Return the number of data-points per sample |
205 |
needed to represent data on parts of the mesh. |
206 |
*/ |
207 |
inline |
208 |
int |
209 |
getNumDataPointsPerSample(int functionSpaceCode) const |
210 |
{ |
211 |
return 1; |
212 |
} |
213 |
|
214 |
/** |
215 |
\brief |
216 |
Returns the locations in the domain of the FEM nodes. |
217 |
*/ |
218 |
virtual |
219 |
escript::Data |
220 |
getX() const; |
221 |
|
222 |
/** |
223 |
\brief |
224 |
Copies the location of data points on the domain into out. |
225 |
*/ |
226 |
virtual |
227 |
void |
228 |
setToX(escript::Data& out) const; |
229 |
|
230 |
/** |
231 |
\brief |
232 |
Returns the element size. |
233 |
*/ |
234 |
virtual |
235 |
escript::Data |
236 |
getSize() const; |
237 |
|
238 |
/** |
239 |
\brief |
240 |
Copies the size of samples into out. |
241 |
*/ |
242 |
virtual |
243 |
void |
244 |
setToSize(escript::Data& out) const; |
245 |
|
246 |
/** |
247 |
\brief |
248 |
Copies the gradient of arg into grad. The actual function space to be considered |
249 |
for the gradient is defined by grad. arg and grad have to be defined on this. |
250 |
*/ |
251 |
virtual |
252 |
void |
253 |
setToGradient(escript::Data& grad, |
254 |
const escript::Data& arg) const; |
255 |
|
256 |
/** |
257 |
\brief |
258 |
Comparison operators. |
259 |
*/ |
260 |
virtual bool operator==(const AbstractDomain& other) const; |
261 |
virtual bool operator!=(const AbstractDomain& other) const; |
262 |
|
263 |
/* |
264 |
\brief |
265 |
Return the tag key for the given sample number. |
266 |
NB: tags are not implemented on Bruce, so this method always returns 0. |
267 |
*/ |
268 |
virtual |
269 |
inline |
270 |
int |
271 |
getTagFromSampleNo(int functionSpaceCode, |
272 |
int sampleNo) const |
273 |
{ |
274 |
return 0; |
275 |
} |
276 |
|
277 |
/** |
278 |
\brief |
279 |
Return the reference number of the given sample number. |
280 |
*/ |
281 |
virtual |
282 |
int |
283 |
getReferenceNoFromSampleNo(int functionSpaceCode, |
284 |
int sampleNo) const; |
285 |
|
286 |
/** |
287 |
\brief |
288 |
Saves a dictionary of Data objects to a VTK XML input file. |
289 |
The dictionary consists of pairs of Data objects plus a name |
290 |
for each. Each Data object must be defined on this domain. |
291 |
*/ |
292 |
virtual |
293 |
void |
294 |
saveVTK(const std::string& filename, |
295 |
const boost::python::dict& dataDict) const; |
296 |
|
297 |
/** |
298 |
\brief |
299 |
Interpolates data given on source onto target where source and target |
300 |
have to be given on the same domain. |
301 |
*/ |
302 |
virtual |
303 |
void |
304 |
interpolateOnDomain(escript::Data& target, |
305 |
const escript::Data& source) const; |
306 |
|
307 |
virtual |
308 |
bool |
309 |
probeInterpolationOnDomain(int functionSpaceType_source, |
310 |
int functionSpaceType_target) const; |
311 |
|
312 |
/** |
313 |
\brief |
314 |
Interpolates data given on source onto target where source and target |
315 |
are given on different domains. |
316 |
*/ |
317 |
virtual |
318 |
void |
319 |
interpolateACross(escript::Data& target, |
320 |
const escript::Data& source) const; |
321 |
|
322 |
virtual |
323 |
bool |
324 |
probeInterpolationACross(int functionSpaceType_source, |
325 |
const AbstractDomain& targetDomain, |
326 |
int functionSpaceType_target) const; |
327 |
|
328 |
protected: |
329 |
|
330 |
/** |
331 |
\brief |
332 |
Build the table of function space type names. |
333 |
*/ |
334 |
void |
335 |
setFunctionSpaceTypeNames(); |
336 |
|
337 |
/** |
338 |
\brief |
339 |
Ensure the parameters supplied to the constructor are valid. |
340 |
*/ |
341 |
bool |
342 |
checkParameters(); |
343 |
|
344 |
/** |
345 |
\brief |
346 |
Check if all components of vector are zero. |
347 |
*/ |
348 |
static |
349 |
bool |
350 |
isZero(DimVec vec); |
351 |
|
352 |
private: |
353 |
|
354 |
// |
355 |
// vectors describing axis of the domain |
356 |
DimVec m_v0, m_v1, m_v2; |
357 |
|
358 |
// |
359 |
// number of data points in each axial direction of the domain |
360 |
int m_n0, m_n1, m_n2; |
361 |
|
362 |
// |
363 |
// the coordinates of the origin of the domain |
364 |
DimVec m_origin; |
365 |
|
366 |
// |
367 |
// map from FunctionSpace codes to names |
368 |
static FunctionSpaceNamesMapType m_functionSpaceTypeNames; |
369 |
|
370 |
}; |
371 |
|
372 |
} // end of namespace |
373 |
|
374 |
#endif |