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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26