/[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 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (4 years, 11 months ago) by caltinay
File MIME type: text/plain
File size: 20669 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26