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 finley_MeshAdapter_20040526_H |
17 |
#define finley_MeshAdapter_20040526_H |
18 |
#include "system_dep.h" |
19 |
|
20 |
extern "C" { |
21 |
#include "../Mesh.h" |
22 |
#include "../Finley.h" |
23 |
#include "../Assemble.h" |
24 |
#include "paso/SystemMatrix.h" |
25 |
#include "paso/SolverFCT.h" |
26 |
} |
27 |
|
28 |
#include "FinleyError.h" |
29 |
#include "FinleyAdapterException.h" |
30 |
|
31 |
#include "SystemMatrixAdapter.h" |
32 |
#include "TransportProblemAdapter.h" |
33 |
#include "escript/AbstractContinuousDomain.h" |
34 |
#include "escript/FunctionSpace.h" |
35 |
#include "escript/FunctionSpaceFactory.h" |
36 |
|
37 |
#include <boost/shared_ptr.hpp> |
38 |
#include <boost/python/dict.hpp> |
39 |
#include <boost/python/extract.hpp> |
40 |
|
41 |
#include <map> |
42 |
#include <vector> |
43 |
#include <string> |
44 |
#include <sstream> |
45 |
|
46 |
// |
47 |
// forward declarations |
48 |
class Data; |
49 |
|
50 |
//using namespace escript; |
51 |
|
52 |
namespace finley { |
53 |
|
54 |
struct null_deleter |
55 |
{ |
56 |
void operator()(void const *ptr) const |
57 |
{ |
58 |
} |
59 |
}; |
60 |
|
61 |
|
62 |
/** |
63 |
\brief |
64 |
MeshAdapter implements the AbstractContinuousDomain |
65 |
interface for the Finley library. |
66 |
|
67 |
Description: |
68 |
MeshAdapter implements the AbstractContinuousDomain |
69 |
interface for the Finley library. |
70 |
*/ |
71 |
|
72 |
class MeshAdapter : public escript::AbstractContinuousDomain { |
73 |
|
74 |
public: |
75 |
|
76 |
// |
77 |
// Codes for function space types supported |
78 |
static const int DegreesOfFreedom; |
79 |
static const int ReducedDegreesOfFreedom; |
80 |
static const int Nodes; |
81 |
static const int ReducedNodes; |
82 |
static const int Elements; |
83 |
static const int ReducedElements; |
84 |
static const int FaceElements; |
85 |
static const int ReducedFaceElements; |
86 |
static const int Points; |
87 |
static const int ContactElementsZero; |
88 |
static const int ReducedContactElementsZero; |
89 |
static const int ContactElementsOne; |
90 |
static const int ReducedContactElementsOne; |
91 |
|
92 |
/** |
93 |
\brief |
94 |
Constructor for MeshAdapter |
95 |
|
96 |
Description: |
97 |
Constructor for MeshAdapter. The pointer passed to MeshAdapter |
98 |
is deleted using a call to Finley_Mesh_free in the |
99 |
MeshAdapter destructor. |
100 |
|
101 |
Throws: |
102 |
May throw an exception derived from EsysException |
103 |
|
104 |
\param finleyMesh Input - A pointer to the externally constructed |
105 |
finley mesh.The pointer passed to MeshAdapter |
106 |
is deleted using a call to |
107 |
Finley_Mesh_free in the MeshAdapter |
108 |
destructor. |
109 |
*/ |
110 |
FINLEY_DLL_API |
111 |
MeshAdapter(Finley_Mesh* finleyMesh=0); |
112 |
|
113 |
/** |
114 |
\brief |
115 |
Copy constructor. |
116 |
*/ |
117 |
FINLEY_DLL_API |
118 |
MeshAdapter(const MeshAdapter& in); |
119 |
|
120 |
/** |
121 |
\brief |
122 |
Destructor for MeshAdapter. As specified in the constructor |
123 |
this calls Finley_Mesh_free for the pointer given to the |
124 |
constructor. |
125 |
*/ |
126 |
FINLEY_DLL_API |
127 |
~MeshAdapter(); |
128 |
|
129 |
/** |
130 |
\brief |
131 |
return the number of processors used for this domain |
132 |
*/ |
133 |
FINLEY_DLL_API |
134 |
virtual int getMPISize() const; |
135 |
/** |
136 |
\brief |
137 |
return the number MPI rank of this processor |
138 |
*/ |
139 |
|
140 |
FINLEY_DLL_API |
141 |
virtual int getMPIRank() const; |
142 |
|
143 |
/** |
144 |
\brief |
145 |
return this as an AbstractContinuousDomain. |
146 |
*/ |
147 |
inline const AbstractContinuousDomain& asAbstractContinuousDomain() const |
148 |
{ |
149 |
return *(static_cast<const AbstractContinuousDomain*>(this)); |
150 |
} |
151 |
|
152 |
/** |
153 |
\brief |
154 |
return this as an AbstractDomain. |
155 |
*/ |
156 |
inline const AbstractDomain& asAbstractDomain() const |
157 |
{ |
158 |
return *(static_cast<const AbstractDomain*>(this)); |
159 |
} |
160 |
|
161 |
/** |
162 |
\brief |
163 |
Write the current mesh to a file with the given name. |
164 |
\param fileName Input - The name of the file to write to. |
165 |
*/ |
166 |
FINLEY_DLL_API |
167 |
void write(const std::string& fileName) const; |
168 |
|
169 |
/** |
170 |
\brief |
171 |
Write the current mesh to a file with the given name. |
172 |
\param fileName Input - The name of the file to write to. |
173 |
*/ |
174 |
FINLEY_DLL_API |
175 |
void Print_Mesh_Info(const bool) const; |
176 |
|
177 |
/** |
178 |
\brief |
179 |
dumps the mesh to a file with the given name. |
180 |
\param fileName Input - The name of the file |
181 |
*/ |
182 |
FINLEY_DLL_API |
183 |
void dump(const std::string& fileName) const; |
184 |
|
185 |
/** |
186 |
\brief |
187 |
return the pointer to the underlying finley mesh structure |
188 |
*/ |
189 |
FINLEY_DLL_API |
190 |
Finley_Mesh* getFinley_Mesh() const; |
191 |
|
192 |
/** |
193 |
\brief |
194 |
Return the tag key for the given sample number. |
195 |
\param functionSpaceType Input - The function space type. |
196 |
\param sampleNo Input - The sample number. |
197 |
*/ |
198 |
FINLEY_DLL_API |
199 |
int getTagFromSampleNo(int functionSpaceType, int sampleNo) const; |
200 |
|
201 |
/** |
202 |
\brief |
203 |
Return the reference number of the given sample number. |
204 |
\param functionSpaceType Input - The function space type. |
205 |
*/ |
206 |
FINLEY_DLL_API |
207 |
int* borrowSampleReferenceIDs(int functionSpaceType) const; |
208 |
|
209 |
/** |
210 |
\brief |
211 |
Returns true if the given integer is a valid function space type |
212 |
for this domain. |
213 |
*/ |
214 |
FINLEY_DLL_API |
215 |
virtual bool isValidFunctionSpaceType(int functionSpaceType) const; |
216 |
|
217 |
/** |
218 |
\brief |
219 |
Return a description for this domain |
220 |
*/ |
221 |
FINLEY_DLL_API |
222 |
virtual std::string getDescription() const; |
223 |
|
224 |
/** |
225 |
\brief |
226 |
Return a description for the given function space type code |
227 |
*/ |
228 |
FINLEY_DLL_API |
229 |
virtual std::string functionSpaceTypeAsString(int functionSpaceType) const; |
230 |
|
231 |
/** |
232 |
\brief |
233 |
Build the table of function space type names |
234 |
*/ |
235 |
FINLEY_DLL_API |
236 |
void setFunctionSpaceTypeNames(); |
237 |
|
238 |
/** |
239 |
\brief |
240 |
Return a continuous FunctionSpace code |
241 |
*/ |
242 |
FINLEY_DLL_API |
243 |
virtual int getContinuousFunctionCode() const; |
244 |
|
245 |
/** |
246 |
\brief |
247 |
Return a continuous on reduced order nodes FunctionSpace code |
248 |
*/ |
249 |
FINLEY_DLL_API |
250 |
virtual int getReducedContinuousFunctionCode() const; |
251 |
|
252 |
/** |
253 |
\brief |
254 |
Return a function FunctionSpace code |
255 |
*/ |
256 |
FINLEY_DLL_API |
257 |
virtual int getFunctionCode() const; |
258 |
|
259 |
/** |
260 |
\brief |
261 |
Return a function with reduced integration order FunctionSpace code |
262 |
*/ |
263 |
FINLEY_DLL_API |
264 |
virtual int getReducedFunctionCode() const; |
265 |
|
266 |
/** |
267 |
\brief |
268 |
Return a function on boundary FunctionSpace code |
269 |
*/ |
270 |
FINLEY_DLL_API |
271 |
virtual int getFunctionOnBoundaryCode() const; |
272 |
|
273 |
/** |
274 |
\brief |
275 |
Return a function on boundary with reduced integration order FunctionSpace code |
276 |
*/ |
277 |
FINLEY_DLL_API |
278 |
virtual int getReducedFunctionOnBoundaryCode() const; |
279 |
|
280 |
/** |
281 |
\brief |
282 |
Return a FunctionOnContactZero code |
283 |
*/ |
284 |
FINLEY_DLL_API |
285 |
virtual int getFunctionOnContactZeroCode() const; |
286 |
|
287 |
/** |
288 |
\brief |
289 |
Return a FunctionOnContactZero code with reduced integration order |
290 |
*/ |
291 |
FINLEY_DLL_API |
292 |
virtual int getReducedFunctionOnContactZeroCode() const; |
293 |
|
294 |
/** |
295 |
\brief |
296 |
Return a FunctionOnContactOne code |
297 |
*/ |
298 |
FINLEY_DLL_API |
299 |
virtual int getFunctionOnContactOneCode() const; |
300 |
|
301 |
/** |
302 |
\brief |
303 |
Return a FunctionOnContactOne code with reduced integration order |
304 |
*/ |
305 |
FINLEY_DLL_API |
306 |
virtual int getReducedFunctionOnContactOneCode() const; |
307 |
|
308 |
/** |
309 |
\brief |
310 |
Return a Solution code |
311 |
*/ |
312 |
FINLEY_DLL_API |
313 |
virtual int getSolutionCode() const; |
314 |
|
315 |
/** |
316 |
\brief |
317 |
Return a ReducedSolution code |
318 |
*/ |
319 |
FINLEY_DLL_API |
320 |
virtual int getReducedSolutionCode() const; |
321 |
|
322 |
/** |
323 |
\brief |
324 |
Return a DiracDeltaFunction code |
325 |
*/ |
326 |
FINLEY_DLL_API |
327 |
virtual int getDiracDeltaFunctionCode() const; |
328 |
|
329 |
/** |
330 |
5B |
331 |
\brief |
332 |
*/ |
333 |
typedef std::map<int, std::string> FunctionSpaceNamesMapType; |
334 |
|
335 |
/** |
336 |
\brief |
337 |
*/ |
338 |
FINLEY_DLL_API |
339 |
virtual int getDim() const; |
340 |
|
341 |
/** |
342 |
\brief |
343 |
Return the number of data points per sample, and the number of samples as a pair. |
344 |
\param functionSpaceCode Input - |
345 |
*/ |
346 |
FINLEY_DLL_API |
347 |
virtual std::pair<int,int> getDataShape(int functionSpaceCode) const; |
348 |
|
349 |
/** |
350 |
\brief |
351 |
copies the location of data points into arg. The domain of arg has to match this. |
352 |
has to be implemented by the actual Domain adapter. |
353 |
*/ |
354 |
FINLEY_DLL_API |
355 |
virtual void setToX(escript::Data& arg) const; |
356 |
|
357 |
/** |
358 |
\brief |
359 |
sets a map from a clear tag name to a tag key |
360 |
\param name Input - tag name. |
361 |
\param tag Input - tag key. |
362 |
*/ |
363 |
FINLEY_DLL_API |
364 |
virtual void setTagMap(const std::string& name, int tag); |
365 |
|
366 |
/** |
367 |
\brief |
368 |
Return the tag key for tag name. |
369 |
\param name Input - tag name |
370 |
*/ |
371 |
FINLEY_DLL_API |
372 |
virtual int getTag(const std::string& name) const; |
373 |
|
374 |
/** |
375 |
\brief |
376 |
Returns true if name is a defined tage name. |
377 |
\param name Input - tag name to be checked. |
378 |
*/ |
379 |
FINLEY_DLL_API |
380 |
virtual bool isValidTagName(const std::string& name) const; |
381 |
|
382 |
/** |
383 |
\brief |
384 |
Returns all tag names in a single string sperated by commas |
385 |
*/ |
386 |
FINLEY_DLL_API |
387 |
virtual std::string showTagNames() const; |
388 |
|
389 |
/** |
390 |
\brief |
391 |
assigns new location to the domain |
392 |
*/ |
393 |
FINLEY_DLL_API |
394 |
virtual void setNewX(const escript::Data& arg); |
395 |
|
396 |
/** |
397 |
\brief |
398 |
interpolates data given on source onto target where source and target have to be given on the same domain. |
399 |
*/ |
400 |
FINLEY_DLL_API |
401 |
virtual void interpolateOnDomain(escript::Data& target,const escript::Data& source) const; |
402 |
FINLEY_DLL_API |
403 |
virtual bool probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const; |
404 |
|
405 |
/** |
406 |
\brief |
407 |
interpolates data given on source onto target where source and target are given on different domains. |
408 |
has to be implemented by the actual Domain adapter. |
409 |
*/ |
410 |
FINLEY_DLL_API |
411 |
virtual void interpolateACross(escript::Data& target, const escript::Data& source) const; |
412 |
FINLEY_DLL_API |
413 |
virtual bool probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const; |
414 |
|
415 |
/** |
416 |
\brief |
417 |
copies the surface normals at data points into out. The actual function space to be considered |
418 |
is defined by out. out has to be defined on this. |
419 |
*/ |
420 |
FINLEY_DLL_API |
421 |
virtual void setToNormal(escript::Data& out) const; |
422 |
|
423 |
/** |
424 |
\brief |
425 |
copies the size of samples into out. The actual function space to be considered |
426 |
is defined by out. out has to be defined on this. |
427 |
*/ |
428 |
FINLEY_DLL_API |
429 |
virtual void setToSize(escript::Data& out) const; |
430 |
|
431 |
/** |
432 |
\brief |
433 |
copies the gradient of arg into grad. The actual function space to be considered |
434 |
for the gradient is defined by grad. arg and grad have to be defined on this. |
435 |
*/ |
436 |
FINLEY_DLL_API |
437 |
virtual void setToGradient(escript::Data& grad,const escript::Data& arg) const; |
438 |
|
439 |
/** |
440 |
\brief |
441 |
copies the integrals of the function defined by arg into integrals. |
442 |
arg has to be defined on this. |
443 |
*/ |
444 |
FINLEY_DLL_API |
445 |
virtual void setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const; |
446 |
|
447 |
/** |
448 |
\brief |
449 |
return the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package |
450 |
and symmetric matrix is used. |
451 |
\param solver |
452 |
\param symmetry |
453 |
*/ |
454 |
FINLEY_DLL_API |
455 |
virtual int getSystemMatrixTypeId(const int solver, const int package, const bool symmetry) const; |
456 |
|
457 |
/** |
458 |
\brief |
459 |
returns true if data on this domain and a function space of type functionSpaceCode has to |
460 |
considered as cell centered data. |
461 |
*/ |
462 |
FINLEY_DLL_API |
463 |
virtual bool isCellOriented(int functionSpaceCode) const; |
464 |
|
465 |
/** |
466 |
\brief |
467 |
Saves a dictonary of Data objects to an OpenDX input file. The keywords are used as identifier |
468 |
|
469 |
This has to be implemented by the actual Domain adapter. |
470 |
*/ |
471 |
FINLEY_DLL_API |
472 |
virtual void saveDX(const std::string& filename,const boost::python::dict& arg) const; |
473 |
|
474 |
|
475 |
/** |
476 |
\brief |
477 |
Saves a dictonary of Data objects to an VTK XML input file. The keywords are used as identifier |
478 |
|
479 |
This has to be implemented by the actual Domain adapter. |
480 |
*/ |
481 |
FINLEY_DLL_API |
482 |
virtual void saveVTK(const std::string& filename,const boost::python::dict& arg) const; |
483 |
|
484 |
/** |
485 |
\brief |
486 |
returns the function space representation of the type functionSpaceCode on this domain |
487 |
as a vtkObject. |
488 |
*/ |
489 |
// vtkObject createVtkObject(int functionSpaceCode) const; |
490 |
|
491 |
/** |
492 |
\brief |
493 |
adds a PDE onto the stiffness matrix mat and a rhs |
494 |
*/ |
495 |
FINLEY_DLL_API |
496 |
virtual void addPDEToSystem( |
497 |
SystemMatrixAdapter& mat, escript::Data& rhs, |
498 |
const escript::Data& A, const escript::Data& B, const escript::Data& C, |
499 |
const escript::Data& D, const escript::Data& X, const escript::Data& Y, |
500 |
const escript::Data& d, const escript::Data& y, |
501 |
const escript::Data& d_contact, const escript::Data& y_contact) const; |
502 |
/** |
503 |
\brief |
504 |
adds a PDE onto the lumped stiffness matrix matrix |
505 |
*/ |
506 |
FINLEY_DLL_API |
507 |
virtual void addPDEToLumpedSystem( |
508 |
escript::Data& mat, |
509 |
const escript::Data& D, |
510 |
const escript::Data& d) const; |
511 |
|
512 |
/** |
513 |
\brief |
514 |
adds a PDE onto the stiffness matrix mat and a rhs |
515 |
*/ |
516 |
FINLEY_DLL_API |
517 |
virtual void addPDEToRHS(escript::Data& rhs, |
518 |
const escript::Data& X, const escript::Data& Y, |
519 |
const escript::Data& y, const escript::Data& y_contact) const; |
520 |
/** |
521 |
\brief |
522 |
adds a PDE onto a transport problem |
523 |
*/ |
524 |
|
525 |
FINLEY_DLL_API |
526 |
virtual void addPDEToTransportProblem( |
527 |
TransportProblemAdapter& tp, escript::Data& source, |
528 |
const escript::Data& M, |
529 |
const escript::Data& A, const escript::Data& B, const escript::Data& C,const escript::Data& D, |
530 |
const escript::Data& X,const escript::Data& Y, |
531 |
const escript::Data& d, const escript::Data& y, |
532 |
const escript::Data& d_contact,const escript::Data& y_contact) const; |
533 |
|
534 |
|
535 |
/** |
536 |
\brief |
537 |
creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros: |
538 |
*/ |
539 |
FINLEY_DLL_API |
540 |
SystemMatrixAdapter newSystemMatrix( |
541 |
const int row_blocksize, |
542 |
const escript::FunctionSpace& row_functionspace, |
543 |
const int column_blocksize, |
544 |
const escript::FunctionSpace& column_functionspace, |
545 |
const int type) const; |
546 |
/** |
547 |
\brief |
548 |
creates a TransportProblemAdapter |
549 |
|
550 |
*/ |
551 |
|
552 |
FINLEY_DLL_API |
553 |
TransportProblemAdapter newTransportProblem( |
554 |
const double theta, |
555 |
const double dt_max, |
556 |
const int blocksize, |
557 |
const escript::FunctionSpace& functionspace, |
558 |
const int type) const; |
559 |
|
560 |
/** |
561 |
\brief returns locations in the FEM nodes |
562 |
*/ |
563 |
FINLEY_DLL_API |
564 |
virtual escript::Data getX() const; |
565 |
|
566 |
/** |
567 |
\brief return boundary normals at the quadrature point on the face elements |
568 |
*/ |
569 |
FINLEY_DLL_API |
570 |
virtual escript::Data getNormal() const; |
571 |
|
572 |
/** |
573 |
\brief returns the element size |
574 |
*/ |
575 |
FINLEY_DLL_API |
576 |
virtual escript::Data getSize() const; |
577 |
|
578 |
/** |
579 |
\brief comparison operators |
580 |
*/ |
581 |
FINLEY_DLL_API |
582 |
virtual bool operator==(const AbstractDomain& other) const; |
583 |
FINLEY_DLL_API |
584 |
virtual bool operator!=(const AbstractDomain& other) const; |
585 |
|
586 |
/** |
587 |
\brief assigns new tag newTag to all samples of functionspace with a positive |
588 |
value of mask for any its sample point. |
589 |
|
590 |
*/ |
591 |
FINLEY_DLL_API |
592 |
virtual void setTags(const int functionSpaceType, const int newTag, const escript::Data& mask) const; |
593 |
|
594 |
protected: |
595 |
|
596 |
private: |
597 |
|
598 |
// |
599 |
// pointer to the externally created finley mesh |
600 |
boost::shared_ptr<Finley_Mesh> m_finleyMesh; |
601 |
|
602 |
static FunctionSpaceNamesMapType m_functionSpaceTypeNames; |
603 |
|
604 |
}; |
605 |
|
606 |
} // end of namespace |
607 |
|
608 |
#endif |