/[escript]/branches/trilinos_from_5897/dudley/src/Mesh.h
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/Mesh.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6078 by caltinay, Thu Mar 10 07:04:41 2016 UTC revision 6079 by caltinay, Mon Mar 21 12:22:38 2016 UTC
# Line 17  Line 17 
17  #ifndef __DUDLEY_MESH_H__  #ifndef __DUDLEY_MESH_H__
18  #define __DUDLEY_MESH_H__  #define __DUDLEY_MESH_H__
19    
20  /****************************************************************************/  /****************************************************************************
21    
22  /* Dudley: Mesh */     Dudley: Mesh
23    
24  /* A mesh is built from nodes and elements which are describing the     A mesh is built from nodes and elements which are describing the
25     domain, the surface and point sources. (the latter are needed to     domain, the surface and point sources (the latter are needed to
26     establish links with other codes, in particular to particle     establish links with other codes, in particular to particle
27     codes). The nodes are stored a Dudley_NodeFile and elements in a     codes). The nodes are stored in a NodeFile and elements in an
28     Dudley_ElementFile. A Dudley_NodeFile and three Dudley_ElementFile     ElementFile. A NodeFile and three ElementFiles containing the
29     containing the elements describing the domain, surface and point     elements describe the domain, surface and point sources,
30     sources respectively. Notice that the surface elements do not     respectively. Notice that the surface elements do not necessarily
31     necessarily cover the entire surface of the domain. */     cover the entire surface of the domain.
32    
33  /* The element type is fixed by the reference element, see     The element type is fixed by the reference element, see
34     ReferenceElement.h. The numbering of the nodes starts with 0. */     ReferenceElement.h. The numbering of the nodes starts with 0.
35    
36  /* Important: it is assumed that every node is appearing in at least     Important: it is assumed that every node appears in at least
37     one element or surface element and that any node used in an     one element or surface element and that any node used in an
38     element, surface element or as a point is specified in the     element, surface element or as a point is specified in the
39     Dudley_Node, see also Dudley_resolveNodeIds. */     NodeFile, see also Dudley_resolveNodeIds.
40    
41  /* In some cases it is useful to refer to a mesh entirly built from     In some cases it is useful to refer to a mesh entirly built from
42     order 1 (=linear) elements. The linear version of the mesh can be     order 1 (=linear) elements. The linear version of the mesh can be
43     accessed by referning to the first few nodes of each element     accessed by referning to the first few nodes of each element
44     (thanks to the way the nodes are ordered). As the numbering of     (thanks to the way the nodes are ordered). As the numbering of
45     these nodes is not continuous a relabeling vectors are introduced     these nodes is not continuous a relabeling vector is introduced
46     in the Dudley_NodeFile. This feature is not fully implemented     in the NodeFile. This feature is not fully implemented yet.
    yet. */  
47    
48  /* allnodes and elements are tagged. the tag allows to group nodes and     All nodes and elements are tagged. The tag allows to group nodes and
49     elements. A typical application is to mark surface elements on a     elements. A typical application is to mark surface elements on a
50     certain portion of the domain with the same tag. All these surface     certain portion of the domain with the same tag. All these surface
51     elements can then assigned the same value eg. for the pressure. */     elements can then assigned the same value e.g. for the pressure.
52    
53  /* Thespacial dimension is determined by the type of elements     The spatial dimensionality is determined by the type of elements
54     used. The spacial dimension should be accessed by the function     used and can be queried using the function Dudley_Mesh_getDim.
55     Dudley_Mesh_getDim. Notice that the element type also determines     Notice that the element type also determines the type of surface
56     the type of surface elements to be used. */     elements to be used.
57    
58  /****************************************************************************/  *****************************************************************************/
59    
60  #include "Dudley.h"  #include "Dudley.h"
61  #include "ElementFile.h"  #include "ElementFile.h"
# Line 72  Line 71 
71    
72  namespace dudley {  namespace dudley {
73    
74  /*  this struct holds a mesh: */  typedef std::map<std::string, int> TagMap;
 struct Dudley_Mesh {  
     char *Name;                 /* the name of the mesh */  
     dim_t reference_counter;    /* counts the number of references to the mesh; */  
     dim_t approximationOrder;  
     dim_t reducedApproximationOrder;  
     dim_t integrationOrder;  
     dim_t reducedIntegrationOrder;  
     Dudley_NodeFile *Nodes;     /* the table of the nodes */  
     Dudley_ElementFile *Elements;       /* the table of the elements */  
     Dudley_ElementFile *FaceElements;   /* the table of the face elements */  
     Dudley_ElementFile *Points; /* the table of points (treated as elements of dimension 0) */  
     Dudley_TagMap *TagMap;      /* the tag map mapping names to tag keys */  
   
     /* pointer to the sparse matrix pattern */  
   
     paso::SystemMatrixPattern_ptr FullFullPattern;  
     paso::SystemMatrixPattern_ptr FullReducedPattern;  
     paso::SystemMatrixPattern_ptr ReducedFullPattern;  
     paso::SystemMatrixPattern_ptr ReducedReducedPattern;  
     escript::JMPI MPIInfo;  
 };  
   
 typedef struct Dudley_Mesh Dudley_Mesh;  
75    
76  /* these structures are used for matching surfaces elements: */  class Mesh
77    {
78  struct Dudley_Mesh_findMatchingFaces_center {  public:
79      index_t refId;      Mesh(const std::string name, int numDim, escript::JMPI mpi_info);
80      double x[3];      ~Mesh();
81  };  
82  typedef struct Dudley_Mesh_findMatchingFaces_center Dudley_Mesh_findMatchingFaces_center;      static Mesh* read(escript::JMPI mpiInfo, const std::string& filename,
83                          bool optimize);
84        static Mesh* readGmsh(escript::JMPI mpiInfo, const std::string& filename,
85                              int numDim, bool optimize);
86    
87        /// writes the mesh to the external file filename using the Dudley file
88        /// format
89        void write(const std::string& filename) const;
90    
91        int getDim() const { return Nodes->numDim; }
92        int getStatus() const { return Nodes->status; }
93    
94        void addPoints(int numPoints, const double *points_ptr, const int *tags_ptr);
95        void addTagMap(const std::string& name, int tag_key);
96        int getTag(const std::string& name) const;
97        bool isValidTagName(const std::string& name) const;
98    
99        /// returns a reference to the paso matrix pattern
100        paso::SystemMatrixPattern_ptr getPasoPattern();
101    
102        void printInfo(bool);
103        void print();
104    
105        /// assigns new coordinates to the nodes
106        void setCoordinates(const escript::Data& newX);
107        void setElements(ElementFile* elements);
108        void setFaceElements(ElementFile* elements);
109        void setPoints(ElementFile* elements);
110    
111        void prepare(bool optimize);
112    
113        /// Initially the element nodes refer to the numbering defined by the
114        /// global id assigned to the nodes in the NodeFile. It is also not ensured
115        /// that all nodes referred by an element are actually available on the
116        /// process. At the output, a local node labeling is used and all nodes are
117        /// available. In particular the numbering of the element nodes is between
118        /// 0 and Nodes->numNodes.
119        /// The function does not create a distribution of the degrees of freedom.
120        void resolveNodeIds();
121    
122        void createMappings(const std::vector<index_t>& dofDistribution,
123                            const std::vector<index_t>& nodeDistribution);
124    
125        /// assigns new node reference numbers to all element files.
126        /// If k is the old node, the new node is newNode[k-offset].
127        void relabelElementNodes(const index_t* newNode, index_t offset);
128    
 /************************************************************************************/  
   
 /*  interfaces: */  
 Dudley_Mesh *Dudley_Mesh_alloc(char *name, dim_t numDim, escript::JMPI& mpi_info);  
 Dudley_Mesh *Dudley_Mesh_reference(Dudley_Mesh *);  
 dim_t Dudley_Mesh_getDim(Dudley_Mesh *);  
 void Dudley_Mesh_free(Dudley_Mesh *);  
   
 void Dudley_Mesh_addTagMap(Dudley_Mesh * mesh_p, const char *name, index_t tag_key);  
 index_t Dudley_Mesh_getTag(Dudley_Mesh * mesh_p, const char *name);  
 bool Dudley_Mesh_isValidTagName(Dudley_Mesh * mesh_p, const char *name);  
 void Dudley_Mesh_distributeByRankOfDOF(Dudley_Mesh * in, dim_t * distribution);  
 paso::SystemMatrixPattern_ptr Dudley_getPattern(Dudley_Mesh * mesh, bool reduce_row_order, bool reduce_col_order);  
 paso::SystemMatrixPattern_ptr Dudley_makePattern(Dudley_Mesh * mesh, bool reduce_row_order, bool reduce_col_order);  
129  #ifdef USE_TRILINOS  #ifdef USE_TRILINOS
130  /// creates and returns a Trilinos CRS graph suitable to build a sparse      /// creates and returns a Trilinos CRS graph suitable to build a sparse
131  /// matrix      /// matrix
132  esys_trilinos::const_TrilinosGraph_ptr createTrilinosGraph(Dudley_Mesh* mesh);      esys_trilinos::const_TrilinosGraph_ptr createTrilinosGraph() const;
133  #endif  #endif
134    
135  void Dudley_Mesh_write(Dudley_Mesh *, char *);  private:
136  void Dudley_Mesh_dump(Dudley_Mesh * in, char *fname);      paso::SystemMatrixPattern_ptr makePasoPattern() const;
137  void Dudley_PrintMesh_Info(Dudley_Mesh *, bool);      void createColoring(const index_t* dofMap);
138  Dudley_Mesh *Dudley_Mesh_load(char *fname);      void distributeByRankOfDOF(const std::vector<index_t>& distribution);
139  Dudley_Mesh *Dudley_Mesh_read(char *, index_t, index_t, bool);      void markNodes(std::vector<short>& mask, index_t offset) const;
140  Dudley_Mesh *Dudley_Mesh_readGmsh(char *, index_t, index_t, index_t, bool);      void optimizeDOFDistribution(std::vector<index_t>& distribution);
141  void Dudley_Mesh_setOrders(Dudley_Mesh * in);      void optimizeDOFLabeling(const std::vector<index_t>& distribution);
142        void optimizeElementOrdering();
143  void Dudley_Mesh_setCoordinates(Dudley_Mesh *, const escript::Data*);      void updateTagList();
144  void Dudley_Mesh_setElements(Dudley_Mesh * self, Dudley_ElementFile * elements);      void printElementInfo(const ElementFile* e, const std::string& title,
145  void Dudley_Mesh_setFaceElements(Dudley_Mesh * self, Dudley_ElementFile * elements);                            const std::string& defaultType, bool full) const;
146  void Dudley_Mesh_setPoints(Dudley_Mesh * self, Dudley_ElementFile * elements);  
147        void writeElementInfo(std::ostream& stream, const ElementFile* e,
148  void Dudley_Mesh_optimizeDOFDistribution(Dudley_Mesh * in, dim_t * distribution);                            const std::string& defaultType) const;
149  void Dudley_Mesh_prepare(Dudley_Mesh * in, bool optimize);  
150  void Dudley_Mesh_createColoring(Dudley_Mesh * in, index_t * node_localDOF_map);  public:
151  void Dudley_Mesh_optimizeElementOrdering(Dudley_Mesh * in);      /// the name of the mesh
152  void Dudley_Mesh_resolveNodeIds(Dudley_Mesh *);      std::string m_name;
153  void Dudley_Mesh_createMappings(Dudley_Mesh * in, index_t * dof_distribution, index_t * node_distribution);      int approximationOrder;
154  void Dudley_Mesh_createNodeFileMappings(Dudley_Mesh * in, dim_t numReducedNodes, index_t * indexReducedNodes,      int integrationOrder;
155                                          index_t * dof_first_component, index_t * nodes_first_component);      int reducedIntegrationOrder;
156  void Dudley_Mesh_markDOFsConnectedToRange(index_t * mask, index_t offset, index_t marker, index_t firstDOF,      // the table of the nodes
157                                            index_t lastDOF, Dudley_Mesh * in, bool useLinear);      NodeFile* Nodes;
158        // the table of the elements
159  void Dudley_Mesh_optimizeDOFLabeling(Dudley_Mesh *, dim_t *);      ElementFile* Elements;
160        // the table of the face elements
161  Dudley_Mesh *Dudley_Mesh_merge(dim_t, Dudley_Mesh **);      ElementFile* FaceElements;
162        // the table of points (treated as elements of dimension 0)
163  void Dudley_Mesh_relableElementNodes(int *, int, Dudley_Mesh *);      ElementFile* Points;
164  void Dudley_Mesh_markNodes(int *, int, Dudley_Mesh *, bool);      // the tag map mapping names to tag keys
165        TagMap tagMap;
166  void Dudley_Mesh_glueFaces(Dudley_Mesh * self, double safety_factor, double tolerance, bool);  
167  void Dudley_Mesh_joinFaces(Dudley_Mesh * self, double safety_factor, double tolerance, bool);      // pointer to the sparse matrix pattern
168        paso::SystemMatrixPattern_ptr pasoPattern;
169  int Dudley_Mesh_findMatchingFaces_compar(const void *, const void *);      escript::JMPI MPIInfo;
170  void Dudley_Mesh_findMatchingFaces(Dudley_NodeFile *, Dudley_ElementFile *, double, double, int *, int *, int *, int *);  };
 void Dudley_Mesh_print(Dudley_Mesh * in);  
 void Dudley_Mesh_optimizeNodeLabeling(Dudley_Mesh * mesh_p);  
 dim_t Dudley_Mesh_FindMinDegreeNode(paso::SystemMatrixPattern_ptr pattern_p, index_t * available, index_t indicator);  
 index_t Dudley_Mesh_getDegree(paso::SystemMatrixPattern_ptr pattern_p, index_t * label);  
 void Dudley_Mesh_setTagsInUse(Dudley_Mesh * in);  
 int Dudley_Mesh_getStatus(Dudley_Mesh * in);  
171    
172  } // namespace dudley  } // namespace dudley
173    

Legend:
Removed from v.6078  
changed lines
  Added in v.6079

  ViewVC Help
Powered by ViewVC 1.1.26