escript  Revision_4925
finley/src/Mesh.h
Go to the documentation of this file.
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 #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, Esys_MPIInfo *mpi_info);
82  ~Mesh();
83 
84  static Mesh* load(const std::string fname);
85  static Mesh* read(const std::string fname, int order, int reducedOrder,
86  bool optimize);
87  static Mesh* readGmsh(const std::string fname, int numDim, int order,
88  int reducedOrder, bool optimize,
89  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<int>& dofDistribution,
113  const std::vector<int>& nodeDistribution);
114  void markDOFsConnectedToRange(int* mask, int offset, int marker,
115  int firstDOF, int lastDOF, bool useLinear);
116 
117  void relabelElementNodes(const std::vector<int>&, int 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<int>& dofMap);
127  void distributeByRankOfDOF(const std::vector<int>& distribution);
128  void markNodes(std::vector<short>& mask, int offset, bool useLinear);
129  void optimizeDOFDistribution(std::vector<int>& distribution);
130  void optimizeDOFLabeling(const std::vector<int>& distribution);
132  void setOrders();
133  void updateTagList();
134 
135 public:
136  // the name of the mesh
137  std::string m_name;
142  // the table of the nodes
144  // the table of the elements
146  // the table of the face elements
148  // the table of the contact elements
150  // the table of points (treated as elements of dimension 0)
152  // the tag map mapping names to tag keys
154 
155  // pointers to the sparse matrix patterns
161 };
162 
163 // this structure is used for matching surface elements
165 {
166  int refId;
167  std::vector<double> x;
168 };
169 
170 
171 Mesh* Mesh_merge(const std::vector<Mesh*>& meshes);
172 
173 
174 } // namespace finley
175 
176 #endif // __FINLEY_MESH_H__
177 
int getStatus() const
Definition: finley/src/Mesh.h:94
void createColoring(const std::vector< int > &dofMap)
tries to reduce the number of colours for all element files
Definition: finley/src/Mesh.cpp:453
Esys_MPIInfo * MPIInfo
Definition: finley/src/Mesh.h:160
std::map< std::string, int > TagMap
Definition: finley/src/Mesh.h:74
void glueFaces(double safetyFactor, double tolerance, bool)
Definition: Mesh_glueFaces.cpp:30
paso::SystemMatrixPattern_ptr makePattern(bool reduce_row_order, bool reduce_col_order)
Definition: finley/src/Mesh_getPattern.cpp:70
static Mesh * readGmsh(const std::string fname, int numDim, int order, int reducedOrder, bool optimize, bool useMacroElements)
Definition: finley/src/Mesh_readGmsh.cpp:33
paso::SystemMatrixPattern_ptr FullFullPattern
Definition: finley/src/Mesh.h:156
void joinFaces(double safetyFactor, double tolerance, bool)
Definition: Mesh_joinFaces.cpp:30
int numDim
number of spatial dimensions
Definition: finley/src/NodeFile.h:112
int status
Definition: finley/src/NodeFile.h:149
void setFaceElements(ElementFile *elements)
Definition: finley/src/Mesh.cpp:65
int getDim() const
Definition: finley/src/Mesh.h:93
int integrationOrder
Definition: finley/src/Mesh.h:140
Definition: finley/src/Mesh.h:164
int getTag(const char *name) const
Definition: finley/src/Mesh.cpp:601
Struct that holds MPI communicator, rank, size and a tag counter.
Definition: Esys_MPI.h:48
void markNodes(std::vector< short > &mask, int offset, bool useLinear)
Definition: finley/src/Mesh.cpp:286
void setContactElements(ElementFile *elements)
Definition: finley/src/Mesh.cpp:71
void print()
prints the mesh details to standard output
Definition: finley/src/Mesh.cpp:197
void printInfo(bool)
Definition: finley/src/Mesh_write.cpp:130
void addTagMap(const char *name, int tag_key)
Definition: finley/src/Mesh.cpp:596
TagMap tagMap
Definition: finley/src/Mesh.h:153
int refId
Definition: finley/src/Mesh.h:166
void findMatchingFaces(double, double, int *, int *, int *, int *)
Definition: finley/src/Mesh_findMatchingFaces.cpp:58
void distributeByRankOfDOF(const std::vector< int > &distribution)
Definition: finley/src/Mesh.cpp:137
ElementFile * Elements
Definition: finley/src/Mesh.h:145
void write(const std::string fname) const
writes the mesh to the external file fname using the Finley file format
Definition: finley/src/Mesh_write.cpp:29
static Mesh * read(const std::string fname, int order, int reducedOrder, bool optimize)
Definition: finley/src/Mesh_read.cpp:38
boost::shared_ptr< SystemMatrixPattern > SystemMatrixPattern_ptr
Definition: SystemMatrixPattern.h:38
paso::SystemMatrixPattern_ptr ReducedFullPattern
Definition: finley/src/Mesh.h:158
ElementFile * Points
Definition: finley/src/Mesh.h:151
ElementFile * FaceElements
Definition: finley/src/Mesh.h:147
void createMappings(const std::vector< int > &dofDistribution, const std::vector< int > &nodeDistribution)
creates node mappings without (re-)distributing anything
Definition: finley/src/Mesh.cpp:123
paso::SystemMatrixPattern_ptr getPattern(bool reduce_row_order, bool reduce_col_order)
returns a reference to the matrix pattern
Definition: finley/src/Mesh_getPattern.cpp:30
std::vector< double > x
Definition: finley/src/Mesh.h:167
Data represents a collection of datapoints.
Definition: Data.h:71
Definition: finley/src/NodeFile.h:31
~Mesh()
destructor
Definition: finley/src/Mesh.cpp:48
void prepare(bool optimize)
prepares the mesh for further use
Definition: finley/src/Mesh.cpp:393
static Mesh * load(const std::string fname)
int approximationOrder
Definition: finley/src/Mesh.h:138
bool isValidTagName(const char *name) const
Definition: finley/src/Mesh.cpp:614
void setOrders()
Definition: finley/src/Mesh.cpp:83
void markDOFsConnectedToRange(int *mask, int offset, int marker, int firstDOF, int lastDOF, bool useLinear)
Definition: finley/src/Mesh.cpp:294
void resolveNodeIds()
Definition: finley/src/Mesh.cpp:497
void relabelElementNodes(const std::vector< int > &, int offset)
assigns new node reference numbers to all element files
Definition: finley/src/Mesh.cpp:489
paso::SystemMatrixPattern_ptr FullReducedPattern
Definition: finley/src/Mesh.h:157
paso::SystemMatrixPattern_ptr ReducedReducedPattern
Definition: finley/src/Mesh.h:159
void updateTagList()
regenerates list of tags in use for node file and element files
Definition: finley/src/Mesh.cpp:479
Mesh * Mesh_merge(const std::vector< Mesh * > &meshes)
Definition: Mesh_merge.cpp:32
void addPoints(int numPoints, const double *points_ptr, const int *tags_ptr)
Definition: Mesh_addPoints.cpp:44
void optimizeDOFDistribution(std::vector< int > &distribution)
Definition: finley/src/Mesh_optimizeDOFDistribution.cpp:65
void setCoordinates(const escript::Data &newX)
sets new coordinates for the nodes
Definition: finley/src/Mesh.cpp:591
void optimizeDOFLabeling(const std::vector< int > &distribution)
optimizes the labeling of the DOFs on each processor
Definition: finley/src/Mesh.cpp:310
int reducedIntegrationOrder
Definition: finley/src/Mesh.h:141
void setElements(ElementFile *elements)
Definition: finley/src/Mesh.cpp:59
NodeFile * Nodes
Definition: finley/src/Mesh.h:143
Mesh(const std::string name, int numDim, Esys_MPIInfo *mpi_info)
Definition: finley/src/Mesh.cpp:30
int reducedApproximationOrder
Definition: finley/src/Mesh.h:139
void optimizeElementOrdering()
redistributes elements to minimize communication during assemblage
Definition: finley/src/Mesh.cpp:466
void setPoints(ElementFile *elements)
Definition: finley/src/Mesh.cpp:77
ElementFile * ContactElements
Definition: finley/src/Mesh.h:149
Definition: finley/src/Mesh.h:78
std::string m_name
Definition: finley/src/Mesh.h:137
Definition: finley/src/ElementFile.h:60