/[escript]/trunk/finley/src/CPPAdapter/MeshAdapter.h
ViewVC logotype

Contents of /trunk/finley/src/CPPAdapter/MeshAdapter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4492 - (show annotations)
Tue Jul 2 01:44:11 2013 UTC (5 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 20770 byte(s)
Finley changes that were held back while in release mode - moved more stuff
into finley namespace.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 #if !defined finley_MeshAdapter_20040526_H
18 #define finley_MeshAdapter_20040526_H
19 #include "system_dep.h"
20
21 #include "finley/Mesh.h"
22 #include "finley/Finley.h"
23 #include "finley/Assemble.h"
24 #include "esysUtils/Esys_MPI.h"
25
26 #include "FinleyError.h"
27 #include "FinleyAdapterException.h"
28
29 #include <pasowrap/SystemMatrixAdapter.h>
30 #include <pasowrap/TransportProblemAdapter.h>
31 #include "escript/AbstractContinuousDomain.h"
32 #include "escript/FunctionSpace.h"
33 #include "escript/FunctionSpaceFactory.h"
34
35 #include <boost/shared_ptr.hpp>
36 #include <boost/python/dict.hpp>
37 #include <boost/python/extract.hpp>
38
39 #include <map>
40 #include <vector>
41 #include <string>
42 #include <sstream>
43
44 namespace finley {
45
46 // These are friends implemented in MeshAdapterFactory.cpp
47 // They are only fwd declared here so that vis.studio will accept the freind decls
48 FINLEY_DLL_API
49 escript::Domain_ptr brick(int n0,int n1,int n2,int order,
50 double l0,double l1,double l2,
51 int periodic0,int periodic1,
52 int periodic2,
53 int integrationOrder,
54 int reducedIntegrationOrder,
55 int useElementsOnFace,
56 int useFullElementOrder,
57 int optimize,
58 const std::vector<double>& points,
59 const std::vector<int>& tags,
60 const std::map<std::string, int>& tagnamestonums
61 );
62
63 FINLEY_DLL_API
64 escript::Domain_ptr rectangle(int n0,int n1,int order,
65 double l0, double l1,
66 int periodic0,int periodic1,
67 int integrationOrder,
68 int reducedIntegrationOrder,
69 int useElementsOnFace,
70 int useFullElementOrder,
71 int optimize,
72 const std::vector<double>& points,
73 const std::vector<int>& tags,
74 const std::map<std::string, int>& tagnamestonums);
75
76 }
77
78
79
80 namespace finley {
81
82 struct null_deleter
83 {
84 void operator()(void const *ptr) const
85 {
86 }
87 };
88
89
90 /**
91 \brief implements the AbstractContinuousDomain interface for the Finley
92 library.
93 */
94
95 class MeshAdapter : public escript::AbstractContinuousDomain {
96
97 public:
98
99 //
100 // Codes for function space types supported
101 static const int DegreesOfFreedom;
102 static const int ReducedDegreesOfFreedom;
103 static const int Nodes;
104 static const int ReducedNodes;
105 static const int Elements;
106 static const int ReducedElements;
107 static const int FaceElements;
108 static const int ReducedFaceElements;
109 static const int Points;
110 static const int ContactElementsZero;
111 static const int ReducedContactElementsZero;
112 static const int ContactElementsOne;
113 static const int ReducedContactElementsOne;
114
115 /**
116 \brief
117 Constructor for MeshAdapter
118
119 Description:
120 Constructor for MeshAdapter. The pointer passed to MeshAdapter
121 is deleted using a call to Finley_Mesh_free in the
122 MeshAdapter destructor.
123
124 Throws:
125 May throw an exception derived from EsysException
126
127 \param finleyMesh Input - A pointer to the externally constructed
128 finley mesh.The pointer passed to MeshAdapter
129 is deleted using a call to
130 Finley_Mesh_free in the MeshAdapter
131 destructor.
132 */
133 FINLEY_DLL_API
134 MeshAdapter(Finley_Mesh* finleyMesh=0);
135
136 /**
137 \brief
138 Copy constructor.
139 */
140 FINLEY_DLL_API
141 MeshAdapter(const MeshAdapter& in);
142
143 /**
144 \brief
145 Destructor for MeshAdapter. As specified in the constructor
146 this calls Finley_Mesh_free for the pointer given to the
147 constructor.
148 */
149 FINLEY_DLL_API
150 ~MeshAdapter();
151
152 /**
153 \brief
154 return the number of processors used for this domain
155 */
156 FINLEY_DLL_API
157 virtual int getMPISize() const;
158 /**
159 \brief
160 return the number MPI rank of this processor
161 */
162
163 FINLEY_DLL_API
164 virtual int getMPIRank() const;
165
166 /**
167 \brief
168 If compiled for MPI then execute an MPI_Barrier, else do nothing
169 */
170
171 FINLEY_DLL_API
172 virtual void MPIBarrier() const;
173
174 /**
175 \brief
176 Return true if on MPI processor 0, else false
177 */
178
179 FINLEY_DLL_API
180 virtual bool onMasterProcessor() const;
181
182 FINLEY_DLL_API
183 #ifdef ESYS_MPI
184 MPI_Comm
185 #else
186 unsigned int
187 #endif
188 getMPIComm() const;
189
190 /**
191 \brief
192 Write the current mesh to a file with the given name.
193 \param fileName Input - The name of the file to write to.
194 */
195 FINLEY_DLL_API
196 void write(const std::string& fileName) const;
197
198 /**
199 \brief
200 \param full
201 */
202 FINLEY_DLL_API
203 void Print_Mesh_Info(const bool full=false) const;
204
205 /**
206 \brief
207 dumps the mesh to a file with the given name.
208 \param fileName Input - The name of the file
209 */
210 FINLEY_DLL_API
211 void dump(const std::string& fileName) const;
212
213 /**
214 \brief
215 return the pointer to the underlying finley mesh structure
216 */
217 FINLEY_DLL_API
218 Finley_Mesh* getFinley_Mesh() const;
219
220 /**
221 \brief
222 Return the tag key for the given sample number.
223 \param functionSpaceType Input - The function space type.
224 \param sampleNo Input - The sample number.
225 */
226 FINLEY_DLL_API
227 int getTagFromSampleNo(int functionSpaceType, int sampleNo) const;
228
229 /**
230 \brief
231 Return the reference number of the given sample number.
232 \param functionSpaceType Input - The function space type.
233 */
234 FINLEY_DLL_API
235 const int* borrowSampleReferenceIDs(int functionSpaceType) const;
236
237 /**
238 \brief
239 Returns true if the given integer is a valid function space type
240 for this domain.
241 */
242 FINLEY_DLL_API
243 virtual bool isValidFunctionSpaceType(int functionSpaceType) const;
244
245 /**
246 \brief
247 Return a description for this domain
248 */
249 FINLEY_DLL_API
250 virtual std::string getDescription() const;
251
252 /**
253 \brief
254 Return a description for the given function space type code
255 */
256 FINLEY_DLL_API
257 virtual std::string functionSpaceTypeAsString(int functionSpaceType) const;
258
259 /**
260 \brief
261 Build the table of function space type names
262 */
263 FINLEY_DLL_API
264 void setFunctionSpaceTypeNames();
265
266 /**
267 \brief
268 Return a continuous FunctionSpace code
269 */
270 FINLEY_DLL_API
271 virtual int getContinuousFunctionCode() const;
272
273 /**
274 \brief
275 Return a continuous on reduced order nodes FunctionSpace code
276 */
277 FINLEY_DLL_API
278 virtual int getReducedContinuousFunctionCode() const;
279
280 /**
281 \brief
282 Return a function FunctionSpace code
283 */
284 FINLEY_DLL_API
285 virtual int getFunctionCode() const;
286
287 /**
288 \brief
289 Return a function with reduced integration order FunctionSpace code
290 */
291 FINLEY_DLL_API
292 virtual int getReducedFunctionCode() const;
293
294 /**
295 \brief
296 Return a function on boundary FunctionSpace code
297 */
298 FINLEY_DLL_API
299 virtual int getFunctionOnBoundaryCode() const;
300
301 /**
302 \brief
303 Return a function on boundary with reduced integration order FunctionSpace code
304 */
305 FINLEY_DLL_API
306 virtual int getReducedFunctionOnBoundaryCode() const;
307
308 /**
309 \brief
310 Return a FunctionOnContactZero code
311 */
312 FINLEY_DLL_API
313 virtual int getFunctionOnContactZeroCode() const;
314
315 /**
316 \brief
317 Return a FunctionOnContactZero code with reduced integration order
318 */
319 FINLEY_DLL_API
320 virtual int getReducedFunctionOnContactZeroCode() const;
321
322 /**
323 \brief
324 Return a FunctionOnContactOne code
325 */
326 FINLEY_DLL_API
327 virtual int getFunctionOnContactOneCode() const;
328
329 /**
330 \brief
331 Return a FunctionOnContactOne code with reduced integration order
332 */
333 FINLEY_DLL_API
334 virtual int getReducedFunctionOnContactOneCode() const;
335
336 /**
337 \brief
338 Return a Solution code
339 */
340 FINLEY_DLL_API
341 virtual int getSolutionCode() const;
342
343 /**
344 \brief
345 Return a ReducedSolution code
346 */
347 FINLEY_DLL_API
348 virtual int getReducedSolutionCode() const;
349
350 /**
351 \brief
352 Return a DiracDeltaFunctions code
353 */
354 FINLEY_DLL_API
355 virtual int getDiracDeltaFunctionsCode() const;
356
357 /**
358 5B
359 \brief
360 */
361 typedef std::map<int, std::string> FunctionSpaceNamesMapType;
362
363 /**
364 \brief
365 */
366 FINLEY_DLL_API
367 virtual int getDim() const;
368
369 /**
370 \brief
371 Returns a status indicator of the domain. The status identifier should be unique over
372 the live time if the object but may be updated if changes to the domain happen, e.g.
373 modifications to its geometry.
374
375 This has to be implemented by the actual Domain adapter.
376 */
377 FINLEY_DLL_API
378 virtual StatusType getStatus() const;
379
380
381 /**
382 \brief
383 Return the number of data points summed across all MPI processes
384 */
385 FINLEY_DLL_API
386 virtual int getNumDataPointsGlobal() const;
387
388 /**
389 \brief
390 Return the number of data points per sample, and the number of samples as a pair.
391 \param functionSpaceCode Input -
392 */
393 FINLEY_DLL_API
394 virtual std::pair<int,int> getDataShape(int functionSpaceCode) const;
395
396 /**
397 \brief
398 copies the location of data points into arg. The domain of arg has to match this.
399 has to be implemented by the actual Domain adapter.
400 */
401 FINLEY_DLL_API
402 virtual void setToX(escript::Data& arg) const;
403
404 /**
405 \brief
406 sets a map from a clear tag name to a tag key
407 \param name Input - tag name.
408 \param tag Input - tag key.
409 */
410 FINLEY_DLL_API
411 virtual void setTagMap(const std::string& name, int tag);
412
413 /**
414 \brief
415 Return the tag key for tag name.
416 \param name Input - tag name
417 */
418 FINLEY_DLL_API
419 virtual int getTag(const std::string& name) const;
420
421 /**
422 \brief
423 Returns true if name is a defined tage name.
424 \param name Input - tag name to be checked.
425 */
426 FINLEY_DLL_API
427 virtual bool isValidTagName(const std::string& name) const;
428
429 /**
430 \brief
431 Returns all tag names in a single string sperated by commas
432 */
433 FINLEY_DLL_API
434 virtual std::string showTagNames() const;
435
436 /**
437 \brief
438 assigns new location to the domain
439 */
440 FINLEY_DLL_API
441 virtual void setNewX(const escript::Data& arg);
442
443 /**
444 \brief
445 interpolates data given on source onto target where source and target have to be given on the same domain.
446 */
447 FINLEY_DLL_API
448 virtual void interpolateOnDomain(escript::Data& target,const escript::Data& source) const;
449
450
451 FINLEY_DLL_API
452 virtual bool probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const;
453
454 FINLEY_DLL_API
455 virtual signed char preferredInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const;
456
457
458
459 /**
460 \brief given a vector of FunctionSpace typecodes, pass back a code which then can all be interpolated to.
461 \return true is result is valid, false if not
462 */
463 FINLEY_DLL_API
464 bool
465 commonFunctionSpace(const std::vector<int>& fs, int& resultcode) const;
466
467 /**
468 \brief
469 interpolates data given on source onto target where source and target are given on different domains.
470 has to be implemented by the actual Domain adapter.
471 */
472 FINLEY_DLL_API
473 virtual void interpolateACross(escript::Data& target, const escript::Data& source) const;
474
475 /**
476 \brief determines whether interpolation from source to target is possible.
477 Must be implemented by the actual Domain adapter
478 */
479 FINLEY_DLL_API
480 virtual bool probeInterpolationACross(int functionSpaceType_source,const escript::AbstractDomain& targetDomain, int functionSpaceType_target) const;
481
482 /**
483 \brief
484 copies the surface normals at data points into out. The actual function space to be considered
485 is defined by out. out has to be defined on this.
486 */
487 FINLEY_DLL_API
488 virtual void setToNormal(escript::Data& out) const;
489
490 /**
491 \brief
492 copies the size of samples into out. The actual function space to be considered
493 is defined by out. out has to be defined on this.
494 */
495 FINLEY_DLL_API
496 virtual void setToSize(escript::Data& out) const;
497
498 /**
499 \brief
500 copies the gradient of arg into grad. The actual function space to be considered
501 for the gradient is defined by grad. arg and grad have to be defined on this.
502 */
503 FINLEY_DLL_API
504 virtual void setToGradient(escript::Data& grad,const escript::Data& arg) const;
505
506 /**
507 \brief
508 copies the integrals of the function defined by arg into integrals.
509 arg has to be defined on this.
510 */
511 FINLEY_DLL_API
512 virtual void setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const;
513
514 /**
515 \brief
516 return the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, perconditioner,
517 and symmetric matrix is used.
518 \param solver
519 \param preconditioner
520 \param package
521 \param symmetry
522 */
523 FINLEY_DLL_API
524 virtual int getSystemMatrixTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const;
525
526 /**
527 \brief
528 return the identifier of the transport problem type to be used when a particular solver, perconditioner, package
529 and symmetric matrix is used.
530 \param solver
531 \param preconditioner
532 \param package
533 \param symmetry
534 */
535 FINLEY_DLL_API
536 virtual int getTransportTypeId(const int solver, const int preconditioner, const int package, const bool symmetry) const;
537
538 /**
539 \brief
540 returns true if data on this domain and a function space of type functionSpaceCode has to
541 considered as cell centered data.
542 */
543 FINLEY_DLL_API
544 virtual bool isCellOriented(int functionSpaceCode) const;
545
546
547 FINLEY_DLL_API
548 virtual bool ownSample(int fs_code, index_t id) const;
549
550 /**
551 \brief
552 returns the function space representation of the type functionSpaceCode on this domain
553 as a vtkObject.
554 */
555 // vtkObject createVtkObject(int functionSpaceCode) const;
556
557 /**
558 \brief
559 adds a PDE onto the stiffness matrix mat and a rhs
560 */
561 FINLEY_DLL_API
562 virtual void addPDEToSystem(
563 escript::AbstractSystemMatrix& mat, escript::Data& rhs,
564 const escript::Data& A, const escript::Data& B, const escript::Data& C,
565 const escript::Data& D, const escript::Data& X, const escript::Data& Y,
566 const escript::Data& d, const escript::Data& y,
567 const escript::Data& d_contact, const escript::Data& y_contact,
568 const escript::Data& d_dirac, const escript::Data& y_dirac) const;
569 /**
570 \brief
571 adds a PDE onto the lumped stiffness matrix matrix
572 */
573 FINLEY_DLL_API
574 virtual void addPDEToLumpedSystem(
575 escript::Data& mat,
576 const escript::Data& D,
577 const escript::Data& d,
578 const escript::Data& d_dirac,
579 const bool useHRZ) const;
580
581 /**
582 \brief
583 adds a PDE onto the stiffness matrix mat and a rhs
584 */
585 FINLEY_DLL_API
586 virtual void addPDEToRHS(escript::Data& rhs,
587 const escript::Data& X, const escript::Data& Y,
588 const escript::Data& y, const escript::Data& y_contact, const escript::Data& y_dirac) const;
589 /**
590 \brief
591 adds a PDE onto a transport problem
592 */
593
594 FINLEY_DLL_API
595 virtual void addPDEToTransportProblem(
596 escript::AbstractTransportProblem& tp, escript::Data& source,
597 const escript::Data& M,
598 const escript::Data& A, const escript::Data& B, const escript::Data& C,const escript::Data& D,
599 const escript::Data& X,const escript::Data& Y,
600 const escript::Data& d, const escript::Data& y,
601 const escript::Data& d_contact,const escript::Data& y_contact, const escript::Data& d_dirac,const escript::Data& y_dirac) const;
602
603
604 /**
605 \brief
606 creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros:
607 */
608 FINLEY_DLL_API
609 escript::ASM_ptr newSystemMatrix(
610 const int row_blocksize,
611 const escript::FunctionSpace& row_functionspace,
612 const int column_blocksize,
613 const escript::FunctionSpace& column_functionspace,
614 const int type) const;
615 /**
616 \brief
617 creates a TransportProblemAdapter
618
619 */
620
621 FINLEY_DLL_API
622 escript::ATP_ptr newTransportProblem(
623 const int blocksize,
624 const escript::FunctionSpace& functionspace,
625 const int type) const;
626
627 /**
628 \brief returns locations in the FEM nodes
629 */
630 FINLEY_DLL_API
631 virtual escript::Data getX() const;
632
633 /**
634 \brief return boundary normals at the quadrature point on the face elements
635 */
636 FINLEY_DLL_API
637 virtual escript::Data getNormal() const;
638
639 /**
640 \brief returns the element size
641 */
642 FINLEY_DLL_API
643 virtual escript::Data getSize() const;
644
645 /**
646 \brief comparison operators
647 */
648 FINLEY_DLL_API
649 virtual bool operator==(const escript::AbstractDomain& other) const;
650 FINLEY_DLL_API
651 virtual bool operator!=(const escript::AbstractDomain& other) const;
652
653 /**
654 \brief assigns new tag newTag to all samples of functionspace with a positive
655 value of mask for any its sample point.
656
657 */
658 FINLEY_DLL_API
659 virtual void setTags(const int functionSpaceType, const int newTag, const escript::Data& mask) const;
660
661 /**
662 \brief
663 return the number of tags in use and a pointer to an array with the number of tags in use
664 */
665 FINLEY_DLL_API
666 virtual int getNumberOfTagsInUse(int functionSpaceCode) const;
667
668 FINLEY_DLL_API
669 virtual const int* borrowListOfTagsInUse(int functionSpaceCode) const;
670
671
672 /**
673 \brief Checks if this domain allows tags for the specified functionSpaceCode.
674 */
675 FINLEY_DLL_API
676 virtual
677 bool canTag(int functionSpaceCode) const;
678
679 /**
680 \brief returns the approximation order used for a function space functionSpaceCode
681 */
682
683 FINLEY_DLL_API
684 virtual
685 int getApproximationOrder(const int functionSpaceCode) const;
686
687 FINLEY_DLL_API
688 bool supportsContactElements() const;
689
690
691 private:
692
693 /**
694 \brief adds points to support more Dirac delta function.
695
696 Do NOT call these at any time other than construction!
697 Using them later creates consistancy problems
698 */
699 FINLEY_DLL_API
700 void addDiracPoints( const std::vector<double>& points, const std::vector<int>& tags) const;
701 // FINLEY_DLL_API
702 // void addDiracPoint( const boost::python::list& points, const int tag=-1) const;
703 // FINLEY_DLL_API
704 // void addDiracPointWithTagName( const boost::python::list& points, const std::string& tag) const;
705
706 protected:
707
708 private:
709 //
710 // pointer to the externally created finley mesh
711 boost::shared_ptr<Finley_Mesh> m_finleyMesh;
712
713 // This is only provided so that the friends below can add tags during construction
714 // do not use for any other purpose
715 boost::shared_ptr<Finley_Mesh> getMesh()
716 {
717 return m_finleyMesh;
718 }
719
720 static FunctionSpaceNamesMapType m_functionSpaceTypeNames;
721
722 friend escript::Domain_ptr finley::brick(int n0,int n1,int n2,int order,
723 double l0,double l1,double l2,
724 int periodic0,int periodic1,
725 int periodic2,
726 int integrationOrder,
727 int reducedIntegrationOrder,
728 int useElementsOnFace,
729 int useFullElementOrder,
730 int optimize,
731 const std::vector<double>& points,
732 const std::vector<int>& tags,
733 const std::map<std::string, int>& tagnamestonums
734 );
735
736
737 friend escript::Domain_ptr finley::rectangle(int n0,int n1,int order,
738 double l0, double l1,
739 int periodic0,int periodic1,
740 int integrationOrder,
741 int reducedIntegrationOrder,
742 int useElementsOnFace,
743 int useFullElementOrder,
744 int optimize,
745 const std::vector<double>& points,
746 const std::vector<int>& tags,
747 const std::map<std::string, int>& tagnamestonums);
748 };
749
750 // Do not use this class. It is a convenience wrapper for the dataexporter.
751 class FINLEY_DLL_API ReferenceElementSetWrapper {
752 public:
753 ReferenceElementSetWrapper(ElementTypeId id, index_t order,
754 index_t reducedOrder);
755 ~ReferenceElementSetWrapper();
756
757 ReferenceElementSet* getElementSet() const { return m_refSet; }
758
759 private:
760 ReferenceElementSet* m_refSet;
761 };
762
763
764 } // end of namespace
765
766 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26