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