ESScript  Revision_
finley/src/Mesh.h
Go to the documentation of this file.
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 #ifndef __FINLEY_MESH_H__
17 #define __FINLEY_MESH_H__
18 
19 /****************************************************************************
20 
21  Finley: Mesh
22 
23  A mesh is built from nodes and elements which are describing the
24  domain, the surface and point sources (the latter are needed to
25  establish links with other codes, in particular to particle
26  codes). The nodes are stored in a NodeFile and elements in an
27  ElementFile. Four ElementFiles containing the elements
28  describe the domain, surface, contact and point sources, respectively.
29  Notice that the surface elements do not necessarily cover the entire
30  surface of the domain.
31 
32  The element type is fixed by the reference element, see
33  ReferenceElement.h. The numbering of the nodes starts with 0.
34 
35  Important: it is assumed that every node appears in at least
36  one element or surface element and that any node used in an
37  element, surface element or as a point is specified in the
38  NodeFile, see also resolveNodeIds.
39 
40  In some cases it is useful to refer to a mesh entirely built from
41  order 1 (=linear) elements. The linear version of the mesh can be
42  accessed by referring to the first few nodes of each element
43  (thanks to the way the nodes are ordered). As the numbering of
44  these nodes is not continuous a relabeling vector is introduced
45  in the NodeFile. This feature is not fully implemented yet.
46 
47  All nodes and elements are tagged. The tag allows to group nodes and
48  elements. A typical application is to mark surface elements on a
49  certain portion of the domain with the same tag. All these surface
50  elements can then be assigned the same value e.g. for the pressure.
51 
52  The spatial dimensionality is determined by the type of elements
53  used and can be queried using getDim(). Notice that the element type
54  also determines the type of surface elements to be used.
55 
56 *****************************************************************************/
57 
58 #include "Finley.h"
59 #include "NodeFile.h"
60 #include "ElementFile.h"
61 #include "Util.h"
62 #include "paso/SystemMatrixPattern.h"
63 
64 #include <map>
65 #include <string>
66 
67 namespace escript {
68  class Data;
69 }
70 
71 namespace finley {
72 
73 typedef std::map<std::string, int> TagMap;
74 
75 /****************************************************************************/
76 
77 class Mesh
78 {
79 public:
80  Mesh(const std::string name, int numDim, Esys_MPIInfo *mpi_info);
81  ~Mesh();
82 
83  static Mesh* load(const std::string fname);
84  static Mesh* read(const std::string fname, int order, int reducedOrder,
85  bool optimize);
86  static Mesh* readGmsh(const std::string fname, int numDim, int order,
87  int reducedOrder, bool optimize,
88  bool useMacroElements);
89 
90  void write(const std::string fname) const;
91 
92  int getDim() const { return Nodes->numDim; }
93  int getStatus() const { return Nodes->status; }
94 
95  void addPoints(int numPoints, const double *points_ptr, const int *tags_ptr);
96  void addTagMap(const char* name, int tag_key);
97  int getTag(const char* name) const;
98  bool isValidTagName(const char* name) const;
99  Paso_SystemMatrixPattern* getPattern(bool reduce_row_order, bool reduce_col_order);
100  Paso_SystemMatrixPattern* makePattern(bool reduce_row_order, bool reduce_col_order);
101  void printInfo(bool);
102 
103  void setCoordinates(const escript::Data& newX);
104  void setElements(ElementFile *elements);
105  void setFaceElements(ElementFile *elements);
106  void setContactElements(ElementFile *elements);
107  void setPoints(ElementFile *elements);
108 
109  void prepare(bool optimize);
110  void resolveNodeIds();
111  void createMappings(const std::vector<int>& dofDistribution,
112  const std::vector<int>& nodeDistribution);
113  void markDOFsConnectedToRange(int* mask, int offset, int marker,
114  int firstDOF, int lastDOF, bool useLinear);
115 
116  void relabelElementNodes(const std::vector<int>&, int offset);
117 
118  void glueFaces(double safetyFactor, double tolerance, bool);
119  void joinFaces(double safetyFactor, double tolerance, bool);
120 
121  void findMatchingFaces(double, double, int*, int*, int*, int*);
122  void print();
123  int FindMinDegreeNode(Paso_SystemMatrixPattern* pattern_p, int* available, int indicator);
124  int getDegree(Paso_SystemMatrixPattern* pattern_p, int *label);
125 
126 
127 private:
128  void createColoring(const std::vector<int>& dofMap);
129  void distributeByRankOfDOF(const std::vector<int>& distribution);
130  void markNodes(std::vector<short>& mask, int offset, bool useLinear);
131  void optimizeDOFDistribution(std::vector<int>& distribution);
132  void optimizeDOFLabeling(const std::vector<int>& distribution);
134  void setOrders();
135  void updateTagList();
136 
137 public:
138  // the name of the mesh
139  std::string m_name;
144  // the table of the nodes
146  // the table of the elements
148  // the table of the face elements
150  // the table of the contact elements
152  // the table of points (treated as elements of dimension 0)
154  // the tag map mapping names to tag keys
156 
157  // pointers to the sparse matrix patterns
163 };
164 
165 // this structure is used for matching surface elements
167 {
168  int refId;
169  std::vector<double> x;
170 };
171 
172 
173 Mesh* Mesh_merge(const std::vector<Mesh*>& meshes);
174 
175 
176 } // namespace finley
177 
178 #endif // __FINLEY_MESH_H__
179