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

Contents of /branches/diaplayground/finley/src/CPPAdapter/MeshAdapter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5122 - (show annotations)
Thu Aug 21 04:32:39 2014 UTC (4 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 22002 byte(s)
Fast-forward to latest trunk to be able to use both Paso or cusp.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26