escript  Revision_
finley/src/Mesh.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 #ifndef __FINLEY_MESH_H__
18 #define __FINLEY_MESH_H__
19 
20 /****************************************************************************
21 
22  Finley: Mesh
23 
24  A mesh is built from nodes and elements which are describing the
25  domain, the surface and point sources (the latter are needed to
26  establish links with other codes, in particular to particle
27  codes). The nodes are stored in a NodeFile and elements in an
28  ElementFile. Four ElementFiles containing the elements
29  describe the domain, surface, contact and point sources, respectively.
30  Notice that the surface elements do not necessarily cover the entire
31  surface of the domain.
32 
33  The element type is fixed by the reference element, see
34  ReferenceElement.h. The numbering of the nodes starts with 0.
35 
36  Important: it is assumed that every node appears in at least
37  one element or surface element and that any node used in an
38  element, surface element or as a point is specified in the
39  NodeFile, see also resolveNodeIds.
40 
41  In some cases it is useful to refer to a mesh entirely built from
42  order 1 (=linear) elements. The linear version of the mesh can be
43  accessed by referring to the first few nodes of each element
44  (thanks to the way the nodes are ordered). As the numbering of
45  these nodes is not continuous a relabeling vector is introduced
46  in the NodeFile. This feature is not fully implemented yet.
47 
48  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
50  certain portion of the domain with the same tag. All these surface
51  elements can then be assigned the same value e.g. for the pressure.
52 
53  The spatial dimensionality is determined by the type of elements
54  used and can be queried using getDim(). Notice that the element type
55  also determines the type of surface elements to be used.
56 
57 *****************************************************************************/
58 
59 #include "Finley.h"
60 #include "NodeFile.h"
61 #include "ElementFile.h"
62 #include "Util.h"
63 #include "paso/SystemMatrixPattern.h"
64 
65 #include <map>
66 #include <string>
67 
68 namespace escript {
69  class Data;
70 }
71 
72 namespace finley {
73 
74 typedef std::map<std::string, int> TagMap;
75 
76 /****************************************************************************/
77 
78 class Mesh
79 {
80 public:
81  Mesh(const std::string name, int numDim, esysUtils::JMPI& mpi_info);
82  ~Mesh();
83 
84  static Mesh* load(esysUtils::JMPI& mpi_info, const std::string fname);
85  static Mesh* read(esysUtils::JMPI& mpi_info, const std::string fname,
86  int order, int reducedOrder, bool optimize);
87  static Mesh* readGmsh(esysUtils::JMPI& mpi_info, const std::string fname,
88  int numDim, int order, int reducedOrder,
89  bool optimize, bool useMacroElements);
90 
91  void write(const std::string fname) const;
92 
93  int getDim() const { return Nodes->numDim; }
94  int getStatus() const { return Nodes->status; }
95 
96  void addPoints(int numPoints, const double *points_ptr, const int *tags_ptr);
97  void addTagMap(const char* name, int tag_key);
98  int getTag(const char* name) const;
99  bool isValidTagName(const char* name) const;
100  paso::SystemMatrixPattern_ptr getPattern(bool reduce_row_order, bool reduce_col_order);
101  paso::SystemMatrixPattern_ptr makePattern(bool reduce_row_order, bool reduce_col_order);
102  void printInfo(bool);
103 
104  void setCoordinates(const escript::Data& newX);
105  void setElements(ElementFile *elements);
106  void setFaceElements(ElementFile *elements);
107  void setContactElements(ElementFile *elements);
108  void setPoints(ElementFile *elements);
109 
110  void prepare(bool optimize);
111  void resolveNodeIds();
112  void createMappings(const std::vector<index_t>& dofDistribution,
113  const std::vector<index_t>& nodeDistribution);
114  void markDOFsConnectedToRange(int* mask, int offset, int marker,
115  index_t firstDOF, index_t lastDOF, bool useLinear);
116 
117  void relabelElementNodes(const std::vector<index_t>&, index_t offset);
118 
119  void glueFaces(double safetyFactor, double tolerance, bool);
120  void joinFaces(double safetyFactor, double tolerance, bool);
121 
122  void findMatchingFaces(double, double, int*, int*, int*, int*);
123  void print();
124 
125 private:
126  void createColoring(const std::vector<index_t>& dofMap);
127  void distributeByRankOfDOF(const std::vector<index_t>& distribution);
128  void markNodes(std::vector<short>& mask, int offset, bool useLinear);
129  void optimizeDOFDistribution(std::vector<index_t>& distribution);
130  void optimizeDOFLabeling(const std::vector<index_t>& distribution);
131  void optimizeElementOrdering();
132  void setOrders();
133  void updateTagList();
134  void printElementInfo(const ElementFile* e, const std::string title,
135  const std::string defaultType, bool full) const;
136 
137  void writeElementInfo(std::ostream& stream, const ElementFile* e,
138  const std::string defaultType) const;
139 
140  static Mesh* readGmshSlave(esysUtils::JMPI& mpi_info, const std::string fname,
141  int numDim, int order, int reducedOrder,
142  bool optimize, bool useMacroElements);
143  static Mesh* readGmshMaster(esysUtils::JMPI& mpi_info, const std::string fname,
144  int numDim, int order, int reducedOrder,
145  bool optimize, bool useMacroElements);
146 
147 public:
148  // the name of the mesh
149  std::string m_name;
154  // the table of the nodes
156  // the table of the elements
158  // the table of the face elements
160  // the table of the contact elements
162  // the table of points (treated as elements of dimension 0)
164  // the tag map mapping names to tag keys
165  TagMap tagMap;
166 
167  // pointers to the sparse matrix patterns
173 };
174 
175 // this structure is used for matching surface elements
177 {
178  int refId;
179  std::vector<double> x;
180 };
181 
182 
183 Mesh* Mesh_merge(const std::vector<Mesh*>& meshes);
184 
185 
186 } // namespace finley
187 
188 #endif // __FINLEY_MESH_H__
189 
int getStatus() const
Definition: finley/src/Mesh.h:94
std::map< std::string, int > TagMap
Definition: finley/src/Mesh.h:74
paso::SystemMatrixPattern_ptr FullFullPattern
Definition: finley/src/Mesh.h:168
Domain_ptr glueFaces(const boost::python::list &meshList, double safety_factor, double tolerance, bool optimize)
Detects matching faces in the mesh, removes them from the mesh and joins the elements touched by the ...
Definition: finley/src/CPPAdapter/MeshAdapterFactory.cpp:953
int getDim() const
Definition: finley/src/Mesh.h:93
Definition: AbstractContinuousDomain.cpp:24
int integrationOrder
Definition: finley/src/Mesh.h:152
Definition: finley/src/Mesh.h:176
Domain_ptr joinFaces(const boost::python::list &meshList, double safety_factor, double tolerance, bool optimize)
Detects matching faces in the mesh and replaces them by joint elements.
Definition: finley/src/CPPAdapter/MeshAdapterFactory.cpp:969
TagMap tagMap
Definition: finley/src/Mesh.h:165
int refId
Definition: finley/src/Mesh.h:178
ElementFile * Elements
Definition: finley/src/Mesh.h:157
Definition: finley/src/Assemble.h:32
boost::shared_ptr< SystemMatrixPattern > SystemMatrixPattern_ptr
Definition: SystemMatrixPattern.h:38
Domain_ptr readGmsh(const std::string &fileName, int numDim, int integrationOrder, int reducedIntegrationOrder, int optimize, int useMacroElements)
Read a gmsh mesh file.
Definition: dudley/src/CPPAdapter/MeshAdapterFactory.cpp:436
paso::SystemMatrixPattern_ptr ReducedFullPattern
Definition: finley/src/Mesh.h:170
ElementFile * Points
Definition: finley/src/Mesh.h:163
ElementFile * FaceElements
Definition: finley/src/Mesh.h:159
std::vector< double > x
Definition: finley/src/Mesh.h:179
Data represents a collection of datapoints.
Definition: Data.h:68
Definition: finley/src/NodeFile.h:30
int getTag(unsigned char sourcex, unsigned char sourcey, unsigned char sourcez, unsigned char targetx, unsigned char targety, unsigned char targetz)
Definition: blocktools.cpp:412
int approximationOrder
Definition: finley/src/Mesh.h:150
int index_t
Definition: types.h:24
Data load(const std::string fileName, const AbstractDomain &domain)
reads Data on domain from file in netCDF format
Definition: DataFactory.cpp:184
paso::SystemMatrixPattern_ptr FullReducedPattern
Definition: finley/src/Mesh.h:169
paso::SystemMatrixPattern_ptr ReducedReducedPattern
Definition: finley/src/Mesh.h:171
Definition: Ripley.h:46
Mesh * Mesh_merge(const std::vector< Mesh * > &meshes)
Definition: Mesh_merge.cpp:36
int reducedIntegrationOrder
Definition: finley/src/Mesh.h:153
NodeFile * Nodes
Definition: finley/src/Mesh.h:155
int reducedApproximationOrder
Definition: finley/src/Mesh.h:151
boost::shared_ptr< JMPI_ > JMPI
Definition: Esys_MPI.h:79
ElementFile * ContactElements
Definition: finley/src/Mesh.h:161
Definition: finley/src/Mesh.h:78
std::string m_name
Definition: finley/src/Mesh.h:149
Definition: finley/src/ElementFile.h:60
esysUtils::JMPI MPIInfo
Definition: finley/src/Mesh.h:172