MFEM  v3.4
Finite element discretization library
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 #ifdef MFEM_USE_PUMI
28 class ParPumiMesh;
29 #endif
30 
31 /// Class for parallel meshes
32 class ParMesh : public Mesh
33 {
34 #ifdef MFEM_USE_PUMI
35  friend class ParPumiMesh;
36 #endif
37 protected:
38  ParMesh() : MyComm(0), NRanks(0), MyRank(-1),
39  have_face_nbr_data(false), pncmesh(NULL) {}
40 
41  MPI_Comm MyComm;
42  int NRanks, MyRank;
43 
46 
47  /// Shared objects in each group.
51 
52  /// Shared to local index mapping.
56 
57  /// Create from a nonconforming mesh.
58  ParMesh(const ParNCMesh &pncmesh);
59 
60  // Mark all tets to ensure consistency across MPI tasks; also mark the
61  // shared and boundary triangle faces using the consistently marked tets.
62  virtual void MarkTetMeshForRefinement(DSTable &v_to_v);
63 
64  /// Return a number(0-1) identifying how the given edge has been split
65  int GetEdgeSplittings(Element *edge, const DSTable &v_to_v, int *middle);
66  /// Return a number(0-4) identifying how the given face has been split
67  int GetFaceSplittings(Element *face, const DSTable &v_to_v, int *middle);
68 
70  int i, IsoparametricTransformation *ElTr);
71 
73  FaceElementTransformations* FETr, int face_type, int face_geom);
74 
75  /// Refine quadrilateral mesh.
76  virtual void QuadUniformRefinement();
77 
78  /// Refine a hexahedral mesh.
79  virtual void HexUniformRefinement();
80 
81  virtual void NURBSUniformRefinement();
82 
83  /// This function is not public anymore. Use GeneralRefinement instead.
84  virtual void LocalRefinement(const Array<int> &marked_el, int type = 3);
85 
86  /// This function is not public anymore. Use GeneralRefinement instead.
87  virtual void NonconformingRefinement(const Array<Refinement> &refinements,
88  int nc_limit = 0);
89 
90  virtual bool NonconformingDerefinement(Array<double> &elem_error,
91  double threshold, int nc_limit = 0,
92  int op = 1);
93  void DeleteFaceNbrData();
94 
95  bool WantSkipSharedMaster(const NCMesh::Master &master) const;
96 
97 public:
98  /** Copy constructor. Performs a deep copy of (almost) all data, so that the
99  source mesh can be modified (e.g. deleted, refined) without affecting the
100  new mesh. If 'copy_nodes' is false, use a shallow (pointer) copy for the
101  nodes, if present. */
102  explicit ParMesh(const ParMesh &pmesh, bool copy_nodes = true);
103 
104  ParMesh(MPI_Comm comm, Mesh &mesh, int *partitioning_ = NULL,
105  int part_method = 1);
106 
107  /// Read a parallel mesh, each MPI rank from its own file/stream.
108  /** The @a refine parameter is passed to the method Mesh::Finalize(). */
109  ParMesh(MPI_Comm comm, std::istream &input, bool refine = true);
110 
111  /// Create a uniformly refined (by any factor) version of @a orig_mesh.
112  /** @param[in] orig_mesh The starting coarse mesh.
113  @param[in] ref_factor The refinement factor, an integer > 1.
114  @param[in] ref_type Specify the positions of the new vertices. The
115  options are BasisType::ClosedUniform or
116  BasisType::GaussLobatto.
117 
118  The refinement data which can be accessed with GetRefinementTransforms()
119  is set to reflect the performed refinements.
120 
121  @note The constructed ParMesh is linear, i.e. it does not have nodes. */
122  ParMesh(ParMesh *orig_mesh, int ref_factor, int ref_type);
123 
124  MPI_Comm GetComm() const { return MyComm; }
125  int GetNRanks() const { return NRanks; }
126  int GetMyRank() const { return MyRank; }
127 
129 
130  // Face-neighbor elements and vertices
137  // Local face-neighbor elements and vertices ordered by face-neighbor
140 
142 
143  int GetNGroups() const { return gtopo.NGroups(); }
144 
145  ///@{ @name These methods require group > 0
146  int GroupNVertices(int group) { return group_svert.RowSize(group-1); }
147  int GroupNEdges(int group) { return group_sedge.RowSize(group-1); }
148  int GroupNFaces(int group) { return group_sface.RowSize(group-1); }
149 
150  int GroupVertex(int group, int i)
151  { return svert_lvert[group_svert.GetRow(group-1)[i]]; }
152  void GroupEdge(int group, int i, int &edge, int &o);
153  void GroupFace(int group, int i, int &face, int &o);
154  ///@}
155 
156  void GenerateOffsets(int N, HYPRE_Int loc_sizes[],
157  Array<HYPRE_Int> *offsets[]) const;
158 
159  void ExchangeFaceNbrData();
160  void ExchangeFaceNbrNodes();
161 
162  int GetNFaceNeighbors() const { return face_nbr_group.Size(); }
163  int GetFaceNbrGroup(int fn) const { return face_nbr_group[fn]; }
164  int GetFaceNbrRank(int fn) const;
165 
166  /** Similar to Mesh::GetFaceToElementTable with added face-neighbor elements
167  with indices offset by the local number of elements. */
169 
170  /** Get the FaceElementTransformations for the given shared face (edge 2D).
171  In the returned object, 1 and 2 refer to the local and the neighbor
172  elements, respectively. */
174  GetSharedFaceTransformations(int sf, bool fill2 = true);
175 
176  /// Return the number of shared faces (3D), edges (2D), vertices (1D)
177  int GetNSharedFaces() const;
178 
179  /// Return the local face index for the given shared face.
180  int GetSharedFace(int sface) const;
181 
182  /// See the remarks for the serial version in mesh.hpp
183  virtual void ReorientTetMesh();
184 
185  /// Utility function: sum integers from all processors (Allreduce).
186  virtual long ReduceInt(int value) const;
187 
188  /// Update the groups after tet refinement
189  void RefineGroups(const DSTable &v_to_v, int *middle);
190 
191  /// Load balance the mesh. NC meshes only.
192  void Rebalance();
193 
194  /** Print the part of the mesh in the calling processor adding the interface
195  as boundary (for visualization purposes) using the mfem v1.0 format. */
196  virtual void Print(std::ostream &out = mfem::out) const;
197 
198  /** Print the part of the mesh in the calling processor adding the interface
199  as boundary (for visualization purposes) using Netgen/Truegrid format .*/
200  virtual void PrintXG(std::ostream &out = mfem::out) const;
201 
202  /** Write the mesh to the stream 'out' on Process 0 in a form suitable for
203  visualization: the mesh is written as a disjoint mesh and the shared
204  boundary is added to the actual boundary; both the element and boundary
205  attributes are set to the processor number. */
206  void PrintAsOne(std::ostream &out = mfem::out);
207 
208  /// Old mesh format (Netgen/Truegrid) version of 'PrintAsOne'
209  void PrintAsOneXG(std::ostream &out = mfem::out);
210 
211  /// Returns the minimum and maximum corners of the mesh bounding box. For
212  /// high-order meshes, the geometry is refined first "ref" times.
213  void GetBoundingBox(Vector &p_min, Vector &p_max, int ref = 2);
214 
215  void GetCharacteristics(double &h_min, double &h_max,
216  double &kappa_min, double &kappa_max);
217 
218  /// Print various parallel mesh stats
219  virtual void PrintInfo(std::ostream &out = mfem::out);
220 
221  /// Save the mesh in a parallel mesh format.
222  void ParPrint(std::ostream &out) const;
223 
224  virtual int FindPoints(DenseMatrix& point_mat, Array<int>& elem_ids,
225  Array<IntegrationPoint>& ips, bool warn = true,
226  InverseElementTransformation *inv_trans = NULL);
227 
228  virtual ~ParMesh();
229 };
230 
231 }
232 
233 #endif // MFEM_USE_MPI
234 
235 #endif
void PrintAsOneXG(std::ostream &out=mfem::out)
Old mesh format (Netgen/Truegrid) version of &#39;PrintAsOne&#39;.
Definition: pmesh.cpp:3830
virtual ~ParMesh()
Definition: pmesh.cpp:4597
int NRanks
Definition: pmesh.hpp:42
virtual void ReorientTetMesh()
See the remarks for the serial version in mesh.hpp.
Definition: pmesh.cpp:2070
Array< Element * > face_nbr_elements
Definition: pmesh.hpp:135
Array< int > sface_lface
Definition: pmesh.hpp:55
virtual void LocalRefinement(const Array< int > &marked_el, int type=3)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2114
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:1913
void GetCharacteristics(double &h_min, double &h_max, double &kappa_min, double &kappa_max)
Definition: pmesh.cpp:4369
bool have_face_nbr_data
Definition: pmesh.hpp:131
Array< int > face_nbr_vertices_offset
Definition: pmesh.hpp:134
Array< int > face_nbr_group
Definition: pmesh.hpp:132
virtual void Print(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3427
The inverse transformation of a given ElementTransformation.
Definition: eltrans.hpp:108
virtual void MarkTetMeshForRefinement(DSTable &v_to_v)
Definition: pmesh.cpp:1076
int RowSize(int i) const
Definition: table.hpp:108
Array< int > sedge_ledge
Definition: pmesh.hpp:54
A parallel extension of the NCMesh class.
Definition: pncmesh.hpp:61
ParNCMesh * pncmesh
Definition: pmesh.hpp:141
Class for PUMI parallel meshes.
Definition: pumi.hpp:72
int GroupVertex(int group, int i)
Definition: pmesh.hpp:150
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:4557
void ExchangeFaceNbrData()
Definition: pmesh.cpp:1377
void Rebalance()
Load balance the mesh. NC meshes only.
Definition: pmesh.cpp:2745
void ParPrint(std::ostream &out) const
Save the mesh in a parallel mesh format.
Definition: pmesh.cpp:4493
Array< int > face_nbr_elements_offset
Definition: pmesh.hpp:133
MPI_Comm MyComm
Definition: pmesh.hpp:41
void GetBoundingBox(Vector &p_min, Vector &p_max, int ref=2)
Definition: pmesh.cpp:4353
Array< Element * > shared_edges
Definition: pmesh.hpp:44
virtual void NonconformingRefinement(const Array< Refinement > &refinements, int nc_limit=0)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2645
virtual long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition: pmesh.cpp:4486
void PrintAsOne(std::ostream &out=mfem::out)
Definition: pmesh.cpp:3555
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:1944
Table send_face_nbr_vertices
Definition: pmesh.hpp:139
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:1224
int GetNGroups() const
Definition: pmesh.hpp:143
int GetNFaceNeighbors() const
Definition: pmesh.hpp:162
Array< Element * > shared_faces
Definition: pmesh.hpp:45
int GroupNVertices(int group)
Definition: pmesh.hpp:146
virtual void QuadUniformRefinement()
Refine quadrilateral mesh.
Definition: pmesh.cpp:2965
virtual void HexUniformRefinement()
Refine a hexahedral mesh.
Definition: pmesh.cpp:3052
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
Definition: table.cpp:189
int GetSharedFace(int sface) const
Return the local face index for the given shared face.
Definition: pmesh.cpp:2048
MPI_Comm GetComm() const
Definition: pmesh.hpp:124
int GetMyRank() const
Definition: pmesh.hpp:126
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2029
void RefineGroups(const DSTable &v_to_v, int *middle)
Update the groups after tet refinement.
Definition: pmesh.cpp:2778
virtual bool NonconformingDerefinement(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition: pmesh.cpp:2697
Array< Vertex > face_nbr_vertices
Definition: pmesh.hpp:136
Table * GetFaceToAllElementTable() const
Definition: pmesh.cpp:1855
bool WantSkipSharedMaster(const NCMesh::Master &master) const
Definition: pmesh.cpp:3414
void GetFaceNbrElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: pmesh.cpp:1304
int GetNRanks() const
Definition: pmesh.hpp:125
int GetFaceNbrGroup(int fn) const
Definition: pmesh.hpp:163
void GroupFace(int group, int i, int &face, int &o)
Definition: pmesh.cpp:1059
Table group_sedge
Definition: pmesh.hpp:49
void ExchangeFaceNbrNodes()
Definition: pmesh.cpp:1780
virtual void PrintXG(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3219
Table group_svert
Shared objects in each group.
Definition: pmesh.hpp:48
int GroupNFaces(int group)
Definition: pmesh.hpp:148
int Size() const
Logical size of the array.
Definition: array.hpp:133
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:1202
void GroupEdge(int group, int i, int &edge, int &o)
Definition: pmesh.cpp:1051
Vector data type.
Definition: vector.hpp:48
int GetFaceNbrRank(int fn) const
Definition: pmesh.cpp:1838
void GenerateOffsets(int N, HYPRE_Int loc_sizes[], Array< HYPRE_Int > *offsets[]) const
Definition: pmesh.cpp:1261
Array< int > svert_lvert
Shared to local index mapping.
Definition: pmesh.hpp:53
int MyRank
Definition: pmesh.hpp:42
Table group_sface
Definition: pmesh.hpp:50
Table send_face_nbr_elements
Definition: pmesh.hpp:138
virtual void PrintInfo(std::ostream &out=mfem::out)
Print various parallel mesh stats.
Definition: pmesh.cpp:4382
void DeleteFaceNbrData()
Definition: pmesh.cpp:1356
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:128
Class for parallel meshes.
Definition: pmesh.hpp:32
Abstract data type element.
Definition: element.hpp:27
int GroupNEdges(int group)
Definition: pmesh.hpp:147
virtual void NURBSUniformRefinement()
Refine NURBS mesh.
Definition: pmesh.cpp:3211