ESScript  Revision_4488
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 Finley_NodeFile and elements in a
27  Finley_ElementFile. Four Finley_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  Finley_NodeFile, see also Finley_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 Finley_NodeFile. This feature is not fully implemented
46  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 dimension is determined by the type of elements
54  used. The spatial dimension should be accessed by the function
55  Finley_Mesh_getDim. Notice that the element type also determines
56  the type of surface elements to be used.
57 
58 *****************************************************************************/
59 
60 #include "Finley.h"
61 #include "NodeFile.h"
62 #include "ElementFile.h"
63 #include "Util.h"
64 #include "paso/SystemMatrixPattern.h"
65 
66 #ifdef ESYS_MPI
67 #include "esysUtils/Esys_MPI.h"
68 #endif
69 
70 #include <map>
71 #include <string>
72 
73 namespace escript {
74  class Data;
75 }
76 
77 namespace finley {
78  typedef std::map<std::string, int> TagMap;
79 }
80 
81 using namespace finley;
82 
83 /****************************************************************************/
84 
86 struct Finley_Mesh {
87  char* Name; // the name of the mesh
88  int reference_counter; // counts the number of references to the mesh
93  NodeFile* Nodes; // the table of the nodes
94  ElementFile* Elements; // the table of the elements
95  ElementFile* FaceElements; // the table of the face elements
96  ElementFile* ContactElements; // the table of the contact elements
97  ElementFile* Points; // the table of points (treated as elements of dimension 0)
98  TagMap tagMap; // the tag map mapping names to tag keys
99 
100  // pointer to the sparse matrix pattern
106 };
107 
108 typedef struct Finley_Mesh Finley_Mesh;
109 
110 // these structures are used for matching surface elements:
112  int refId;
113  double x[MAX_numDim];
114 };
116 
117 /****************************************************************************/
118 
119 // interfaces:
120 Finley_Mesh* Finley_Mesh_alloc(char* name,int numDim, Esys_MPIInfo *mpi_info);
124 
125 void Finley_Mesh_addTagMap(Finley_Mesh *mesh_p,const char* name, int tag_key);
126 int Finley_Mesh_getTag(Finley_Mesh *mesh_p,const char* name);
127 bool Finley_Mesh_isValidTagName(Finley_Mesh *mesh_p, const char* name);
128 void Finley_Mesh_distributeByRankOfDOF(Finley_Mesh* in, int *distribution);
129 Paso_SystemMatrixPattern* Finley_getPattern(Finley_Mesh *mesh,bool_t reduce_row_order, bool_t reduce_col_order);
130 Paso_SystemMatrixPattern* Finley_makePattern(Finley_Mesh *mesh,bool_t reduce_row_order, bool_t reduce_col_order);
131 void Finley_Mesh_write(Finley_Mesh*, const char*);
132 void Finley_Mesh_dump(Finley_Mesh *in, char* fname);
134 Finley_Mesh* Finley_Mesh_load(char* fname);
135 Finley_Mesh* Finley_Mesh_read(char*,int, int, bool_t);
136 Finley_Mesh* Finley_Mesh_readGmsh(char*,int, int, int, bool_t, bool_t);
138 
140 void Finley_Mesh_setElements(Finley_Mesh* self,ElementFile *elements);
143 void Finley_Mesh_setPoints(Finley_Mesh* self,ElementFile *elements);
144 
145 void Finley_Mesh_optimizeDOFDistribution(Finley_Mesh* in,int *distribution);
146 void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize);
147 void Finley_Mesh_createColoring(Finley_Mesh* in, int *node_localDOF_map);
150 void Finley_Mesh_createMappings(Finley_Mesh* in, int *dof_distribution, int *node_distribution);
151 void Finley_Mesh_createNodeFileMappings(Finley_Mesh* in, int numReducedNodes, int* indexReducedNodes, int* dof_first_component, int* nodes_first_component);
152 void Finley_Mesh_markDOFsConnectedToRange(int* mask, int offset, int marker,int firstDOF,int lastDOF,Finley_Mesh* in, bool_t useLinear);
153 
155 
156 
158 
160 void Finley_Mesh_markNodes(int*,int,Finley_Mesh*,int);
161 
162 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t);
163 void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t);
164 
165 int Finley_Mesh_findMatchingFaces_compar(const void*,const void*);
166 void Finley_Mesh_findMatchingFaces(finley::NodeFile*,ElementFile *,double,double, int*, int*,int*,int*);
169 int Finley_Mesh_FindMinDegreeNode(Paso_SystemMatrixPattern* pattern_p,int* available,int indicator);
170 int Finley_Mesh_getDegree(Paso_SystemMatrixPattern* pattern_p, int *label);
171 
174 void Finley_Mesh_addPoints(Finley_Mesh* mesh, const int numPoints, const double *points_ptr, const int *tags_ptr);
175 
176 #endif // __FINLEY_MESH_H__
177