MFEM  v3.3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
pmesh.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_PMESH
13 #define MFEM_PMESH
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "../general/communication.hpp"
20 #include "../general/globals.hpp"
21 #include "mesh.hpp"
22 #include "pncmesh.hpp"
23 #include <iostream>
24 
25 namespace mfem
26 {
27 
28 /// Class for parallel meshes
29 class ParMesh : public Mesh
30 {
31 protected:
32  ParMesh() : MyComm(0), NRanks(0), MyRank(-1),
33  have_face_nbr_data(false), pncmesh(NULL) {}
34 
35  MPI_Comm MyComm;
36  int NRanks, MyRank;
37 
40 
41  /// Shared objects in each group.
45 
46  /// Shared to local index mapping.
50 
51  /// Create from a nonconforming mesh.
52  ParMesh(const ParNCMesh &pncmesh);
53 
54  // Mark all tets to ensure consistency across MPI tasks; also mark the
55  // shared and boundary triangle faces using the consistently marked tets.
56  virtual void MarkTetMeshForRefinement(DSTable &v_to_v);
57 
58  /// Return a number(0-1) identifying how the given edge has been split
59  int GetEdgeSplittings(Element *edge, const DSTable &v_to_v, int *middle);
60  /// Return a number(0-4) identifying how the given face has been split
61  int GetFaceSplittings(Element *face, const DSTable &v_to_v, int *middle);
62 
64  int i, IsoparametricTransformation *ElTr);
65 
67  FaceElementTransformations* FETr, int face_type, int face_geom);
68 
69  /// Refine quadrilateral mesh.
70  virtual void QuadUniformRefinement();
71 
72  /// Refine a hexahedral mesh.
73  virtual void HexUniformRefinement();
74 
75  virtual void NURBSUniformRefinement();
76 
77  /// This function is not public anymore. Use GeneralRefinement instead.
78  virtual void LocalRefinement(const Array<int> &marked_el, int type = 3);
79 
80  /// This function is not public anymore. Use GeneralRefinement instead.
81  virtual void NonconformingRefinement(const Array<Refinement> &refinements,
82  int nc_limit = 0);
83 
84  virtual bool NonconformingDerefinement(Array<double> &elem_error,
85  double threshold, int nc_limit = 0,
86  int op = 1);
87  void DeleteFaceNbrData();
88 
89  bool WantSkipSharedMaster(const NCMesh::Master &master) const;
90 
91 public:
92  /** Copy constructor. Performs a deep copy of (almost) all data, so that the
93  source mesh can be modified (e.g. deleted, refined) without affecting the
94  new mesh. If 'copy_nodes' is false, use a shallow (pointer) copy for the
95  nodes, if present. */
96  explicit ParMesh(const ParMesh &pmesh, bool copy_nodes = true);
97 
98  ParMesh(MPI_Comm comm, Mesh &mesh, int *partitioning_ = NULL,
99  int part_method = 1);
100 
101  /// Read a parallel mesh, each MPI rank from its own file/stream.
102  ParMesh(MPI_Comm comm, std::istream &input);
103 
104  /// Create a uniformly refined (by any factor) version of @a orig_mesh.
105  /** @param[in] orig_mesh The starting coarse mesh.
106  @param[in] ref_factor The refinement factor, an integer > 1.
107  @param[in] ref_type Specify the positions of the new vertices. The
108  options are BasisType::ClosedUniform or
109  BasisType::GaussLobatto.
110 
111  The refinement data which can be accessed with GetRefinementTransforms()
112  is set to reflect the performed refinements.
113 
114  @note The constructed ParMesh is linear, i.e. it does not have nodes. */
115  ParMesh(ParMesh *orig_mesh, int ref_factor, int ref_type);
116 
117  MPI_Comm GetComm() const { return MyComm; }
118  int GetNRanks() const { return NRanks; }
119  int GetMyRank() const { return MyRank; }
120 
122 
123  // Face-neighbor elements and vertices
130  // Local face-neighbor elements and vertices ordered by face-neighbor
133 
135 
136  int GetNGroups() const { return gtopo.NGroups(); }
137 
138  ///@{ @name These methods require group > 0
139  int GroupNVertices(int group) { return group_svert.RowSize(group-1); }
140  int GroupNEdges(int group) { return group_sedge.RowSize(group-1); }
141  int GroupNFaces(int group) { return group_sface.RowSize(group-1); }
142 
143  int GroupVertex(int group, int i)
144  { return svert_lvert[group_svert.GetRow(group-1)[i]]; }
145  void GroupEdge(int group, int i, int &edge, int &o);
146  void GroupFace(int group, int i, int &face, int &o);
147  ///@}
148 
149  void GenerateOffsets(int N, HYPRE_Int loc_sizes[],
150  Array<HYPRE_Int> *offsets[]) const;
151 
152  void ExchangeFaceNbrData();
153  void ExchangeFaceNbrNodes();
154 
155  int GetNFaceNeighbors() const { return face_nbr_group.Size(); }
156  int GetFaceNbrGroup(int fn) const { return face_nbr_group[fn]; }
157  int GetFaceNbrRank(int fn) const;
158 
159  /** Similar to Mesh::GetFaceToElementTable with added face-neighbor elements
160  with indices offset by the local number of elements. */
162 
163  /** Get the FaceElementTransformations for the given shared face (edge 2D).
164  In the returned object, 1 and 2 refer to the local and the neighbor
165  elements, respectively. */
167  GetSharedFaceTransformations(int sf, bool fill2 = true);
168 
169  /// Return the number of shared faces (3D), edges (2D), vertices (1D)
170  int GetNSharedFaces() const;
171 
172  /// Return the local face index for the given shared face.
173  int GetSharedFace(int sface) const;
174 
175  /// See the remarks for the serial version in mesh.hpp
176  virtual void ReorientTetMesh();
177 
178  /// Utility function: sum integers from all processors (Allreduce).
179  virtual long ReduceInt(int value) const;
180 
181  /// Update the groups after tet refinement
182  void RefineGroups(const DSTable &v_to_v, int *middle);
183 
184  /// Load balance the mesh. NC meshes only.
185  void Rebalance();
186 
187  /** Print the part of the mesh in the calling processor adding the interface
188  as boundary (for visualization purposes) using the mfem v1.0 format. */
189  virtual void Print(std::ostream &out = mfem::out) const;
190 
191  /** Print the part of the mesh in the calling processor adding the interface
192  as boundary (for visualization purposes) using Netgen/Truegrid format .*/
193  virtual void PrintXG(std::ostream &out = mfem::out) const;
194 
195  /** Write the mesh to the stream 'out' on Process 0 in a form suitable for
196  visualization: the mesh is written as a disjoint mesh and the shared
197  boundary is added to the actual boundary; both the element and boundary
198  attributes are set to the processor number. */
199  void PrintAsOne(std::ostream &out = mfem::out);
200 
201  /// Old mesh format (Netgen/Truegrid) version of 'PrintAsOne'
202  void PrintAsOneXG(std::ostream &out = mfem::out);
203 
204  /// Returns the minimum and maximum corners of the mesh bounding box. For
205  /// high-order meshes, the geometry is refined first "ref" times.
206  void GetBoundingBox(Vector &p_min, Vector &p_max, int ref = 2);
207 
208  void GetCharacteristics(double &h_min, double &h_max,
209  double &kappa_min, double &kappa_max);
210 
211  /// Print various parallel mesh stats
212  virtual void PrintInfo(std::ostream &out = mfem::out);
213 
214  /// Save the mesh in a parallel mesh format.
215  void ParPrint(std::ostream &out) const;
216 
217  virtual int FindPoints(DenseMatrix& point_mat, Array<int>& elem_ids,
218  Array<IntegrationPoint>& ips, bool warn = true,
219  InverseElementTransformation *inv_trans = NULL);
220 
221  virtual ~ParMesh();
222 };
223 
224 }
225 
226 #endif // MFEM_USE_MPI
227 
228 #endif
int GetNFaceNeighbors() const
Definition: pmesh.hpp:155
void PrintAsOneXG(std::ostream &out=mfem::out)
Old mesh format (Netgen/Truegrid) version of &#39;PrintAsOne&#39;.
Definition: pmesh.cpp:3802
int Size() const
Logical size of the array.
Definition: array.hpp:110
virtual ~ParMesh()
Definition: pmesh.cpp:4569
int NRanks
Definition: pmesh.hpp:36
int GetNGroups() const
Definition: pmesh.hpp:136
virtual void ReorientTetMesh()
See the remarks for the serial version in mesh.hpp.
Definition: pmesh.cpp:2050
Array< Element * > face_nbr_elements
Definition: pmesh.hpp:128
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2009
Array< int > sface_lface
Definition: pmesh.hpp:49
virtual void LocalRefinement(const Array< int > &marked_el, int type=3)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2094
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
ElementTransformation * GetGhostFaceTransformation(FaceElementTransformations *FETr, int face_type, int face_geom)
Definition: pmesh.cpp:1893
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
Definition: table.cpp:179
void GetCharacteristics(double &h_min, double &h_max, double &kappa_min, double &kappa_max)
Definition: pmesh.cpp:4341
bool have_face_nbr_data
Definition: pmesh.hpp:124
Array< int > face_nbr_vertices_offset
Definition: pmesh.hpp:127
Array< int > face_nbr_group
Definition: pmesh.hpp:125
The inverse transformation of a given ElementTransformation.
Definition: eltrans.hpp:108
virtual void MarkTetMeshForRefinement(DSTable &v_to_v)
Definition: pmesh.cpp:1056
Array< int > sedge_ledge
Definition: pmesh.hpp:48
bool WantSkipSharedMaster(const NCMesh::Master &master) const
Definition: pmesh.cpp:3386
A parallel extension of the NCMesh class.
Definition: pncmesh.hpp:65
ParNCMesh * pncmesh
Definition: pmesh.hpp:134
int GetNRanks() const
Definition: pmesh.hpp:118
int GroupVertex(int group, int i)
Definition: pmesh.hpp:143
virtual int FindPoints(DenseMatrix &point_mat, Array< int > &elem_ids, Array< IntegrationPoint > &ips, bool warn=true, InverseElementTransformation *inv_trans=NULL)
Find the ids of the elements that contain the given points, and their corresponding reference coordin...
Definition: pmesh.cpp:4529
void ExchangeFaceNbrData()
Definition: pmesh.cpp:1357
void Rebalance()
Load balance the mesh. NC meshes only.
Definition: pmesh.cpp:2717
Array< int > face_nbr_elements_offset
Definition: pmesh.hpp:126
MPI_Comm MyComm
Definition: pmesh.hpp:35
void GetBoundingBox(Vector &p_min, Vector &p_max, int ref=2)
Definition: pmesh.cpp:4325
Array< Element * > shared_edges
Definition: pmesh.hpp:38
virtual void NonconformingRefinement(const Array< Refinement > &refinements, int nc_limit=0)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2617
int GetSharedFace(int sface) const
Return the local face index for the given shared face.
Definition: pmesh.cpp:2028
void PrintAsOne(std::ostream &out=mfem::out)
Definition: pmesh.cpp:3527
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:1924
Table send_face_nbr_vertices
Definition: pmesh.hpp:132
int GetFaceSplittings(Element *face, const DSTable &v_to_v, int *middle)
Return a number(0-4) identifying how the given face has been split.
Definition: pmesh.cpp:1204
virtual void Print(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3399
Array< Element * > shared_faces
Definition: pmesh.hpp:39
int GroupNVertices(int group)
Definition: pmesh.hpp:139
virtual void QuadUniformRefinement()
Refine quadrilateral mesh.
Definition: pmesh.cpp:2937
virtual void HexUniformRefinement()
Refine a hexahedral mesh.
Definition: pmesh.cpp:3024
int GetFaceNbrGroup(int fn) const
Definition: pmesh.hpp:156
int GetMyRank() const
Definition: pmesh.hpp:119
void RefineGroups(const DSTable &v_to_v, int *middle)
Update the groups after tet refinement.
Definition: pmesh.cpp:2750
MPI_Comm GetComm() const
Definition: pmesh.hpp:117
virtual bool NonconformingDerefinement(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition: pmesh.cpp:2669
Array< Vertex > face_nbr_vertices
Definition: pmesh.hpp:129
virtual long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition: pmesh.cpp:4458
void GetFaceNbrElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: pmesh.cpp:1284
void GroupFace(int group, int i, int &face, int &o)
Definition: pmesh.cpp:1039
Table group_sedge
Definition: pmesh.hpp:43
void ExchangeFaceNbrNodes()
Definition: pmesh.cpp:1760
Table group_svert
Shared objects in each group.
Definition: pmesh.hpp:42
int GroupNFaces(int group)
Definition: pmesh.hpp:141
int NGroups() const
int GetEdgeSplittings(Element *edge, const DSTable &v_to_v, int *middle)
Return a number(0-1) identifying how the given edge has been split.
Definition: pmesh.cpp:1182
virtual void PrintXG(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3191
void GroupEdge(int group, int i, int &edge, int &o)
Definition: pmesh.cpp:1031
Vector data type.
Definition: vector.hpp:41
void GenerateOffsets(int N, HYPRE_Int loc_sizes[], Array< HYPRE_Int > *offsets[]) const
Definition: pmesh.cpp:1241
Array< int > svert_lvert
Shared to local index mapping.
Definition: pmesh.hpp:47
int MyRank
Definition: pmesh.hpp:36
int RowSize(int i) const
Definition: table.hpp:105
Table group_sface
Definition: pmesh.hpp:44
Table send_face_nbr_elements
Definition: pmesh.hpp:131
virtual void PrintInfo(std::ostream &out=mfem::out)
Print various parallel mesh stats.
Definition: pmesh.cpp:4354
Table * GetFaceToAllElementTable() const
Definition: pmesh.cpp:1835
void DeleteFaceNbrData()
Definition: pmesh.cpp:1336
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:64
GroupTopology gtopo
Definition: pmesh.hpp:121
void ParPrint(std::ostream &out) const
Save the mesh in a parallel mesh format.
Definition: pmesh.cpp:4465
Class for parallel meshes.
Definition: pmesh.hpp:29
Abstract data type element.
Definition: element.hpp:27
int GetFaceNbrRank(int fn) const
Definition: pmesh.cpp:1818
int GroupNEdges(int group)
Definition: pmesh.hpp:140
virtual void NURBSUniformRefinement()
Refine NURBS mesh.
Definition: pmesh.cpp:3183