/[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 4114 - (show annotations)
Fri Dec 14 04:24:46 2012 UTC (6 years, 8 months ago) by caltinay
File MIME type: text/plain
File size: 20861 byte(s)
Time to remove deprecated saveVTK/DX methods from Data and Domain.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26