MFEM  v3.4
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 #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  ParMesh(MPI_Comm comm, std::istream &input);
109 
110  /// Create a uniformly refined (by any factor) version of @a orig_mesh.
111  /** @param[in] orig_mesh The starting coarse mesh.
112  @param[in] ref_factor The refinement factor, an integer > 1.
113  @param[in] ref_type Specify the positions of the new vertices. The
114  options are BasisType::ClosedUniform or
115  BasisType::GaussLobatto.
116 
117  The refinement data which can be accessed with GetRefinementTransforms()
118  is set to reflect the performed refinements.
119 
120  @note The constructed ParMesh is linear, i.e. it does not have nodes. */
121  ParMesh(ParMesh *orig_mesh, int ref_factor, int ref_type);
122 
123  MPI_Comm GetComm() const { return MyComm; }
124  int GetNRanks() const { return NRanks; }
125  int GetMyRank() const { return MyRank; }
126 
128 
129  // Face-neighbor elements and vertices
136  // Local face-neighbor elements and vertices ordered by face-neighbor
139 
141 
142  int GetNGroups() const { return gtopo.NGroups(); }
143 
144  ///@{ @name These methods require group > 0
145  int GroupNVertices(int group) { return group_svert.RowSize(group-1); }
146  int GroupNEdges(int group) { return group_sedge.RowSize(group-1); }
147  int GroupNFaces(int group) { return group_sface.RowSize(group-1); }
148 
149  int GroupVertex(int group, int i)
150  { return svert_lvert[group_svert.GetRow(group-1)[i]]; }
151  void GroupEdge(int group, int i, int &edge, int &o);
152  void GroupFace(int group, int i, int &face, int &o);
153  ///@}
154 
155  void GenerateOffsets(int N, HYPRE_Int loc_sizes[],
156  Array<HYPRE_Int> *offsets[]) const;
157 
158  void ExchangeFaceNbrData();
159  void ExchangeFaceNbrNodes();
160 
161  int GetNFaceNeighbors() const { return face_nbr_group.Size(); }
162  int GetFaceNbrGroup(int fn) const { return face_nbr_group[fn]; }
163  int GetFaceNbrRank(int fn) const;
164 
165  /** Similar to Mesh::GetFaceToElementTable with added face-neighbor elements
166  with indices offset by the local number of elements. */
168 
169  /** Get the FaceElementTransformations for the given shared face (edge 2D).
170  In the returned object, 1 and 2 refer to the local and the neighbor
171  elements, respectively. */
173  GetSharedFaceTransformations(int sf, bool fill2 = true);
174 
175  /// Return the number of shared faces (3D), edges (2D), vertices (1D)
176  int GetNSharedFaces() const;
177 
178  /// Return the local face index for the given shared face.
179  int GetSharedFace(int sface) const;
180 
181  /// See the remarks for the serial version in mesh.hpp
182  virtual void ReorientTetMesh();
183 
184  /// Utility function: sum integers from all processors (Allreduce).
185  virtual long ReduceInt(int value) const;
186 
187  /// Update the groups after tet refinement
188  void RefineGroups(const DSTable &v_to_v, int *middle);
189 
190  /// Load balance the mesh. NC meshes only.
191  void Rebalance();
192 
193  /** Print the part of the mesh in the calling processor adding the interface
194  as boundary (for visualization purposes) using the mfem v1.0 format. */
195  virtual void Print(std::ostream &out = mfem::out) const;
196 
197  /** Print the part of the mesh in the calling processor adding the interface
198  as boundary (for visualization purposes) using Netgen/Truegrid format .*/
199  virtual void PrintXG(std::ostream &out = mfem::out) const;
200 
201  /** Write the mesh to the stream 'out' on Process 0 in a form suitable for
202  visualization: the mesh is written as a disjoint mesh and the shared
203  boundary is added to the actual boundary; both the element and boundary
204  attributes are set to the processor number. */
205  void PrintAsOne(std::ostream &out = mfem::out);
206 
207  /// Old mesh format (Netgen/Truegrid) version of 'PrintAsOne'
208  void PrintAsOneXG(std::ostream &out = mfem::out);
209 
210  /// Returns the minimum and maximum corners of the mesh bounding box. For
211  /// high-order meshes, the geometry is refined first "ref" times.
212  void GetBoundingBox(Vector &p_min, Vector &p_max, int ref = 2);
213 
214  void GetCharacteristics(double &h_min, double &h_max,
215  double &kappa_min, double &kappa_max);
216 
217  /// Print various parallel mesh stats
218  virtual void PrintInfo(std::ostream &out = mfem::out);
219 
220  /// Save the mesh in a parallel mesh format.
221  void ParPrint(std::ostream &out) const;
222 
223  virtual int FindPoints(DenseMatrix& point_mat, Array<int>& elem_ids,
224  Array<IntegrationPoint>& ips, bool warn = true,
225  InverseElementTransformation *inv_trans = NULL);
226 
227  virtual ~ParMesh();
228 };
229 
230 }
231 
232 #endif // MFEM_USE_MPI
233 
234 #endif
int GetNFaceNeighbors() const
Definition: pmesh.hpp:161
void PrintAsOneXG(std::ostream &out=mfem::out)
Old mesh format (Netgen/Truegrid) version of &#39;PrintAsOne&#39;.
Definition: pmesh.cpp:3831
int Size() const
Logical size of the array.
Definition: array.hpp:133
virtual ~ParMesh()
Definition: pmesh.cpp:4598
int NRanks
Definition: pmesh.hpp:42
int GetNGroups() const
Definition: pmesh.hpp:142
virtual void ReorientTetMesh()
See the remarks for the serial version in mesh.hpp.
Definition: pmesh.cpp:2071
Array< Element * > face_nbr_elements
Definition: pmesh.hpp:134
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2030
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:2115
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:1914
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
Definition: table.cpp:189
void GetCharacteristics(double &h_min, double &h_max, double &kappa_min, double &kappa_max)
Definition: pmesh.cpp:4370
bool have_face_nbr_data
Definition: pmesh.hpp:130
Array< int > face_nbr_vertices_offset
Definition: pmesh.hpp:133
Array< int > face_nbr_group
Definition: pmesh.hpp:131
The inverse transformation of a given ElementTransformation.
Definition: eltrans.hpp:108
virtual void MarkTetMeshForRefinement(DSTable &v_to_v)
Definition: pmesh.cpp:1077
Array< int > sedge_ledge
Definition: pmesh.hpp:54
bool WantSkipSharedMaster(const NCMesh::Master &master) const
Definition: pmesh.cpp:3415
A parallel extension of the NCMesh class.
Definition: pncmesh.hpp:61
ParNCMesh * pncmesh
Definition: pmesh.hpp:140
Class for PUMI parallel meshes.
Definition: pumi.hpp:72
int GetNRanks() const
Definition: pmesh.hpp:124
int GroupVertex(int group, int i)
Definition: pmesh.hpp:149
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:4558
void ExchangeFaceNbrData()
Definition: pmesh.cpp:1378
void Rebalance()
Load balance the mesh. NC meshes only.
Definition: pmesh.cpp:2746
Array< int > face_nbr_elements_offset
Definition: pmesh.hpp:132
MPI_Comm MyComm
Definition: pmesh.hpp:41
void GetBoundingBox(Vector &p_min, Vector &p_max, int ref=2)
Definition: pmesh.cpp:4354
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:2646
int GetSharedFace(int sface) const
Return the local face index for the given shared face.
Definition: pmesh.cpp:2049
void PrintAsOne(std::ostream &out=mfem::out)
Definition: pmesh.cpp:3556
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:1945
Table send_face_nbr_vertices
Definition: pmesh.hpp:138
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:1225
virtual void Print(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3428
Array< Element * > shared_faces
Definition: pmesh.hpp:45
int GroupNVertices(int group)
Definition: pmesh.hpp:145
virtual void QuadUniformRefinement()
Refine quadrilateral mesh.
Definition: pmesh.cpp:2966
virtual void HexUniformRefinement()
Refine a hexahedral mesh.
Definition: pmesh.cpp:3053
int GetFaceNbrGroup(int fn) const
Definition: pmesh.hpp:162
int GetMyRank() const
Definition: pmesh.hpp:125
void RefineGroups(const DSTable &v_to_v, int *middle)
Update the groups after tet refinement.
Definition: pmesh.cpp:2779
MPI_Comm GetComm() const
Definition: pmesh.hpp:123
virtual bool NonconformingDerefinement(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition: pmesh.cpp:2698
Array< Vertex > face_nbr_vertices
Definition: pmesh.hpp:135
virtual long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition: pmesh.cpp:4487
void GetFaceNbrElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: pmesh.cpp:1305
void GroupFace(int group, int i, int &face, int &o)
Definition: pmesh.cpp:1060
Table group_sedge
Definition: pmesh.hpp:49
void ExchangeFaceNbrNodes()
Definition: pmesh.cpp:1781
Table group_svert
Shared objects in each group.
Definition: pmesh.hpp:48
int GroupNFaces(int group)
Definition: pmesh.hpp:147
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:1203
virtual void PrintXG(std::ostream &out=mfem::out) const
Definition: pmesh.cpp:3220
void GroupEdge(int group, int i, int &edge, int &o)
Definition: pmesh.cpp:1052
Vector data type.
Definition: vector.hpp:48
void GenerateOffsets(int N, HYPRE_Int loc_sizes[], Array< HYPRE_Int > *offsets[]) const
Definition: pmesh.cpp:1262
Array< int > svert_lvert
Shared to local index mapping.
Definition: pmesh.hpp:53
int MyRank
Definition: pmesh.hpp:42
int RowSize(int i) const
Definition: table.hpp:108
Table group_sface
Definition: pmesh.hpp:50
Table send_face_nbr_elements
Definition: pmesh.hpp:137
virtual void PrintInfo(std::ostream &out=mfem::out)
Print various parallel mesh stats.
Definition: pmesh.cpp:4383
Table * GetFaceToAllElementTable() const
Definition: pmesh.cpp:1856
void DeleteFaceNbrData()
Definition: pmesh.cpp:1357
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:127
void ParPrint(std::ostream &out) const
Save the mesh in a parallel mesh format.
Definition: pmesh.cpp:4494
Class for parallel meshes.
Definition: pmesh.hpp:32
Abstract data type element.
Definition: element.hpp:27
int GetFaceNbrRank(int fn) const
Definition: pmesh.cpp:1839
int GroupNEdges(int group)
Definition: pmesh.hpp:146
virtual void NURBSUniformRefinement()
Refine NURBS mesh.
Definition: pmesh.cpp:3212