escript  Revision_
Mesh.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 #ifndef __FINLEY_MESH_H__
00018 #define __FINLEY_MESH_H__
00019 
00020 /****************************************************************************
00021 
00022    Finley: Mesh
00023 
00024    A mesh is built from nodes and elements which are describing the
00025    domain, the surface and point sources (the latter are needed to
00026    establish links with other codes, in particular to particle
00027    codes). The nodes are stored in a NodeFile and elements in an
00028    ElementFile. Four ElementFiles containing the elements
00029    describe the domain, surface, contact and point sources, respectively.
00030    Notice that the surface elements do not necessarily cover the entire
00031    surface of the domain.
00032 
00033    The element type is fixed by the reference element, see
00034    ReferenceElement.h. The numbering of the nodes starts with 0.
00035 
00036    Important: it is assumed that every node appears in at least
00037    one element or surface element and that any node used in an
00038    element, surface element or as a point is specified in the
00039    NodeFile, see also resolveNodeIds.
00040 
00041    In some cases it is useful to refer to a mesh entirely built from
00042    order 1 (=linear) elements. The linear version of the mesh can be
00043    accessed by referring to the first few nodes of each element
00044    (thanks to the way the nodes are ordered). As the numbering of
00045    these nodes is not continuous a relabeling vector is introduced
00046    in the NodeFile. This feature is not fully implemented yet.
00047 
00048    All nodes and elements are tagged. The tag allows to group nodes and
00049    elements. A typical application is to mark surface elements on a
00050    certain portion of the domain with the same tag. All these surface
00051    elements can then be assigned the same value e.g. for the pressure.
00052 
00053    The spatial dimensionality is determined by the type of elements
00054    used and can be queried using getDim(). Notice that the element type
00055    also determines the type of surface elements to be used.
00056 
00057 *****************************************************************************/
00058 
00059 #include "Finley.h"
00060 #include "NodeFile.h"
00061 #include "ElementFile.h"
00062 #include "Util.h"
00063 #include "paso/SystemMatrixPattern.h"
00064 
00065 #include <map>
00066 #include <string>
00067 
00068 namespace escript {
00069     class Data;
00070 }
00071 
00072 namespace finley {
00073 
00074 typedef std::map<std::string, int> TagMap;
00075 
00076 /****************************************************************************/
00077 
00078 class Mesh
00079 {
00080 public:
00081     Mesh(const std::string name, int numDim, Esys_MPIInfo *mpi_info);
00082     ~Mesh();
00083 
00084     static Mesh* load(const std::string fname);
00085     static Mesh* read(const std::string fname, int order, int reducedOrder,
00086                       bool optimize);
00087     static Mesh* readGmsh(const std::string fname, int numDim, int order,
00088                           int reducedOrder, bool optimize,
00089                           bool useMacroElements);
00090 
00091     void write(const std::string fname) const;
00092 
00093     int getDim() const { return Nodes->numDim; }
00094     int getStatus() const { return Nodes->status; }
00095 
00096     void addPoints(int numPoints, const double *points_ptr, const int *tags_ptr);
00097     void addTagMap(const char* name, int tag_key);
00098     int getTag(const char* name) const;
00099     bool isValidTagName(const char* name) const;
00100     paso::SystemMatrixPattern_ptr getPattern(bool reduce_row_order, bool reduce_col_order);
00101     paso::SystemMatrixPattern_ptr makePattern(bool reduce_row_order, bool reduce_col_order);
00102     void printInfo(bool);
00103 
00104     void setCoordinates(const escript::Data& newX);
00105     void setElements(ElementFile *elements);
00106     void setFaceElements(ElementFile *elements);
00107     void setContactElements(ElementFile *elements);
00108     void setPoints(ElementFile *elements);
00109 
00110     void prepare(bool optimize);
00111     void resolveNodeIds();
00112     void createMappings(const std::vector<int>& dofDistribution,
00113                         const std::vector<int>& nodeDistribution);
00114     void markDOFsConnectedToRange(int* mask, int offset, int marker,
00115                                   int firstDOF, int lastDOF, bool useLinear);
00116     
00117     void relabelElementNodes(const std::vector<int>&, int offset);
00118 
00119     void glueFaces(double safetyFactor, double tolerance, bool);
00120     void joinFaces(double safetyFactor, double tolerance, bool);
00121 
00122     void findMatchingFaces(double, double, int*, int*, int*, int*);
00123     void print();
00124 
00125 private:
00126     void createColoring(const std::vector<int>& dofMap);
00127     void distributeByRankOfDOF(const std::vector<int>& distribution);
00128     void markNodes(std::vector<short>& mask, int offset, bool useLinear);
00129     void optimizeDOFDistribution(std::vector<int>& distribution);
00130     void optimizeDOFLabeling(const std::vector<int>& distribution);
00131     void optimizeElementOrdering();
00132     void setOrders();
00133     void updateTagList();
00134 
00135 public:
00136     // the name of the mesh
00137     std::string m_name;
00138     int approximationOrder;
00139     int reducedApproximationOrder;
00140     int integrationOrder;
00141     int reducedIntegrationOrder;
00142     // the table of the nodes
00143     NodeFile* Nodes;
00144     // the table of the elements
00145     ElementFile* Elements;
00146     // the table of the face elements
00147     ElementFile* FaceElements;
00148     // the table of the contact elements
00149     ElementFile* ContactElements;
00150     // the table of points (treated as elements of dimension 0)
00151     ElementFile* Points;
00152     // the tag map mapping names to tag keys
00153     TagMap tagMap;
00154 
00155     // pointers to the sparse matrix patterns
00156     paso::SystemMatrixPattern_ptr FullFullPattern;
00157     paso::SystemMatrixPattern_ptr FullReducedPattern;
00158     paso::SystemMatrixPattern_ptr ReducedFullPattern;
00159     paso::SystemMatrixPattern_ptr ReducedReducedPattern;
00160     Esys_MPIInfo *MPIInfo;
00161 };
00162 
00163 // this structure is used for matching surface elements
00164 struct FaceCenter
00165 {
00166    int refId;
00167    std::vector<double> x;
00168 };
00169 
00170 
00171 Mesh* Mesh_merge(const std::vector<Mesh*>& meshes);
00172 
00173 
00174 } // namespace finley
00175 
00176 #endif // __FINLEY_MESH_H__
00177