MFEM  v3.3
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 "mesh.hpp"
21 #include "pncmesh.hpp"
22 #include <iostream>
23 
24 namespace mfem
25 {
26 
27 /// Class for parallel meshes
28 class ParMesh : public Mesh
29 {
30 protected:
31  ParMesh() : MyComm(0), NRanks(0), MyRank(-1),
32  have_face_nbr_data(false), pncmesh(NULL) {}
33 
34  MPI_Comm MyComm;
35  int NRanks, MyRank;
36 
39 
40  /// Shared objects in each group.
44 
45  /// Shared to local index mapping.
49 
50  /// Create from a nonconforming mesh.
51  ParMesh(const ParNCMesh &pncmesh);
52 
53  // Mark all tets to ensure consistency across MPI tasks; also mark the
54  // shared and boundary triangle faces using the consistently marked tets.
55  virtual void MarkTetMeshForRefinement(DSTable &v_to_v);
56 
57  /// Return a number(0-1) identifying how the given edge has been split
58  int GetEdgeSplittings(Element *edge, const DSTable &v_to_v, int *middle);
59  /// Return a number(0-4) identifying how the given face has been split
60  int GetFaceSplittings(Element *face, const DSTable &v_to_v, int *middle);
61 
63  int i, IsoparametricTransformation *ElTr);
64 
66  FaceElementTransformations* FETr, int face_type, int face_geom);
67 
68  /// Refine quadrilateral mesh.
69  virtual void QuadUniformRefinement();
70 
71  /// Refine a hexahedral mesh.
72  virtual void HexUniformRefinement();
73 
74  virtual void NURBSUniformRefinement();
75 
76  /// This function is not public anymore. Use GeneralRefinement instead.
77  virtual void LocalRefinement(const Array<int> &marked_el, int type = 3);
78 
79  /// This function is not public anymore. Use GeneralRefinement instead.
80  virtual void NonconformingRefinement(const Array<Refinement> &refinements,
81  int nc_limit = 0);
82 
83  virtual bool NonconformingDerefinement(Array<double> &elem_error,
84  double threshold, int nc_limit = 0,
85  int op = 1);
86  void DeleteFaceNbrData();
87 
88  bool WantSkipSharedMaster(const NCMesh::Master &master) const;
89 
90 public:
91  /** Copy constructor. Performs a deep copy of (almost) all data, so that the
92  source mesh can be modified (e.g. deleted, refined) without affecting the
93  new mesh. If 'copy_nodes' is false, use a shallow (pointer) copy for the
94  nodes, if present. */
95  explicit ParMesh(const ParMesh &pmesh, bool copy_nodes = true);
96 
97  ParMesh(MPI_Comm comm, Mesh &mesh, int *partitioning_ = NULL,
98  int part_method = 1);
99 
100  /// Read a parallel mesh, each MPI rank from its own file/stream.
101  ParMesh(MPI_Comm comm, std::istream &input);
102 
103  /// Create a uniformly refined (by any factor) version of @a orig_mesh.
104  /** @param[in] orig_mesh The starting coarse mesh.
105  @param[in] ref_factor The refinement factor, an integer > 1.
106  @param[in] ref_type Specify the positions of the new vertices. The
107  options are BasisType::ClosedUniform or
108  BasisType::GaussLobatto.
109 
110  The refinement data which can be accessed with GetRefinementTransforms()
111  is set to reflect the performed refinements.
112 
113  @note The constructed ParMesh is linear, i.e. it does not have nodes. */
114  ParMesh(ParMesh *orig_mesh, int ref_factor, int ref_type);
115 
116  MPI_Comm GetComm() const { return MyComm; }
117  int GetNRanks() const { return NRanks; }
118  int GetMyRank() const { return MyRank; }
119 
121 
122  // Face-neighbor elements and vertices
129  // Local face-neighbor elements and vertices ordered by face-neighbor
132 
134 
135  int GetNGroups() const { return gtopo.NGroups(); }
136 
137  ///@{ @name These methods require group > 0
138  int GroupNVertices(int group) { return group_svert.RowSize(group-1); }
139  int GroupNEdges(int group) { return group_sedge.RowSize(group-1); }
140  int GroupNFaces(int group) { return group_sface.RowSize(group-1); }
141 
142  int GroupVertex(int group, int i)
143  { return svert_lvert[group_svert.GetRow(group-1)[i]]; }
144  void GroupEdge(int group, int i, int &edge, int &o);
145  void GroupFace(int group, int i, int &face, int &o);
146  ///@}
147 
148  void GenerateOffsets(int N, HYPRE_Int loc_sizes[],
149  Array<HYPRE_Int> *offsets[]) const;
150 
151  void ExchangeFaceNbrData();
152  void ExchangeFaceNbrNodes();
153 
154  int GetNFaceNeighbors() const { return face_nbr_group.Size(); }
155  int GetFaceNbrGroup(int fn) const { return face_nbr_group[fn]; }
156  int GetFaceNbrRank(int fn) const;
157 
158  /** Similar to Mesh::GetFaceToElementTable with added face-neighbor elements
159  with indices offset by the local number of elements. */
161 
162  /** Get the FaceElementTransformations for the given shared face (edge 2D).
163  In the returned object, 1 and 2 refer to the local and the neighbor
164  elements, respectively. */
166  GetSharedFaceTransformations(int sf, bool fill2 = true);
167 
168  /// Return the number of shared faces (3D), edges (2D), vertices (1D)
169  int GetNSharedFaces() const;
170 
171  /// Return the local face index for the given shared face.
172  int GetSharedFace(int sface) const;
173 
174  /// See the remarks for the serial version in mesh.hpp
175  virtual void ReorientTetMesh();
176 
177  /// Utility function: sum integers from all processors (Allreduce).
178  virtual long ReduceInt(int value) const;
179 
180  /// Update the groups after tet refinement
181  void RefineGroups(const DSTable &v_to_v, int *middle);
182 
183  /// Load balance the mesh. NC meshes only.
184  void Rebalance();
185 
186  /** Print the part of the mesh in the calling processor adding the interface
187  as boundary (for visualization purposes) using the mfem v1.0 format. */
188  virtual void Print(std::ostream &out = std::cout) const;
189 
190  /** Print the part of the mesh in the calling processor adding the interface
191  as boundary (for visualization purposes) using Netgen/Truegrid format .*/
192  virtual void PrintXG(std::ostream &out = std::cout) const;
193 
194  /** Write the mesh to the stream 'out' on Process 0 in a form suitable for
195  visualization: the mesh is written as a disjoint mesh and the shared
196  boundary is added to the actual boundary; both the element and boundary
197  attributes are set to the processor number. */
198  void PrintAsOne(std::ostream &out = std::cout);
199 
200  /// Old mesh format (Netgen/Truegrid) version of 'PrintAsOne'
201  void PrintAsOneXG(std::ostream &out = std::cout);
202 
203  /// Print various parallel mesh stats
204  virtual void PrintInfo(std::ostream &out = std::cout);
205 
206  /// Save the mesh in a parallel mesh format.
207  void ParPrint(std::ostream &out) const;
208 
209  virtual ~ParMesh();
210 };
211 
212 }
213 
214 #endif // MFEM_USE_MPI
215 
216 #endif
int GetNFaceNeighbors() const
Definition: pmesh.hpp:154
int Size() const
Logical size of the array.
Definition: array.hpp:109
virtual ~ParMesh()
Definition: pmesh.cpp:4496
int NRanks
Definition: pmesh.hpp:35
int GetNGroups() const
Definition: pmesh.hpp:135
virtual void ReorientTetMesh()
See the remarks for the serial version in mesh.hpp.
Definition: pmesh.cpp:2046
Array< Element * > face_nbr_elements
Definition: pmesh.hpp:127
int GetNSharedFaces() const
Return the number of shared faces (3D), edges (2D), vertices (1D)
Definition: pmesh.cpp:2005
Array< int > sface_lface
Definition: pmesh.hpp:48
virtual void LocalRefinement(const Array< int > &marked_el, int type=3)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2090
ElementTransformation * GetGhostFaceTransformation(FaceElementTransformations *FETr, int face_type, int face_geom)
Definition: pmesh.cpp:1890
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
Definition: table.cpp:179
bool have_face_nbr_data
Definition: pmesh.hpp:123
Array< int > face_nbr_vertices_offset
Definition: pmesh.hpp:126
Array< int > face_nbr_group
Definition: pmesh.hpp:124
virtual void MarkTetMeshForRefinement(DSTable &v_to_v)
Definition: pmesh.cpp:1054
Array< int > sedge_ledge
Definition: pmesh.hpp:47
bool WantSkipSharedMaster(const NCMesh::Master &master) const
Definition: pmesh.cpp:3382
A parallel extension of the NCMesh class.
Definition: pncmesh.hpp:65
ParNCMesh * pncmesh
Definition: pmesh.hpp:133
int GetNRanks() const
Definition: pmesh.hpp:117
int GroupVertex(int group, int i)
Definition: pmesh.hpp:142
void ExchangeFaceNbrData()
Definition: pmesh.cpp:1354
void PrintAsOne(std::ostream &out=std::cout)
Definition: pmesh.cpp:3523
void Rebalance()
Load balance the mesh. NC meshes only.
Definition: pmesh.cpp:2713
Array< int > face_nbr_elements_offset
Definition: pmesh.hpp:125
MPI_Comm MyComm
Definition: pmesh.hpp:34
Array< Element * > shared_edges
Definition: pmesh.hpp:37
virtual void NonconformingRefinement(const Array< Refinement > &refinements, int nc_limit=0)
This function is not public anymore. Use GeneralRefinement instead.
Definition: pmesh.cpp:2613
int GetSharedFace(int sface) const
Return the local face index for the given shared face.
Definition: pmesh.cpp:2024
FaceElementTransformations * GetSharedFaceTransformations(int sf, bool fill2=true)
Definition: pmesh.cpp:1920
Table send_face_nbr_vertices
Definition: pmesh.hpp:131
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:1202
Array< Element * > shared_faces
Definition: pmesh.hpp:38
int GroupNVertices(int group)
Definition: pmesh.hpp:138
virtual void QuadUniformRefinement()
Refine quadrilateral mesh.
Definition: pmesh.cpp:2933
virtual void HexUniformRefinement()
Refine a hexahedral mesh.
Definition: pmesh.cpp:3020
int GetFaceNbrGroup(int fn) const
Definition: pmesh.hpp:155
int GetMyRank() const
Definition: pmesh.hpp:118
void RefineGroups(const DSTable &v_to_v, int *middle)
Update the groups after tet refinement.
Definition: pmesh.cpp:2746
MPI_Comm GetComm() const
Definition: pmesh.hpp:116
virtual bool NonconformingDerefinement(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition: pmesh.cpp:2665
Array< Vertex > face_nbr_vertices
Definition: pmesh.hpp:128
virtual long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition: pmesh.cpp:4425
virtual void PrintInfo(std::ostream &out=std::cout)
Print various parallel mesh stats.
Definition: pmesh.cpp:4321
virtual void PrintXG(std::ostream &out=std::cout) const
Definition: pmesh.cpp:3187
void GetFaceNbrElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: pmesh.cpp:1282
void GroupFace(int group, int i, int &face, int &o)
Definition: pmesh.cpp:1037
Table group_sedge
Definition: pmesh.hpp:42
void ExchangeFaceNbrNodes()
Definition: pmesh.cpp:1757
Table group_svert
Shared objects in each group.
Definition: pmesh.hpp:41
int GroupNFaces(int group)
Definition: pmesh.hpp:140
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:1180
void GroupEdge(int group, int i, int &edge, int &o)
Definition: pmesh.cpp:1029
void GenerateOffsets(int N, HYPRE_Int loc_sizes[], Array< HYPRE_Int > *offsets[]) const
Definition: pmesh.cpp:1239
void PrintAsOneXG(std::ostream &out=std::cout)
Old mesh format (Netgen/Truegrid) version of &#39;PrintAsOne&#39;.
Definition: pmesh.cpp:3798
Array< int > svert_lvert
Shared to local index mapping.
Definition: pmesh.hpp:46
int MyRank
Definition: pmesh.hpp:35
int RowSize(int i) const
Definition: table.hpp:102
Table group_sface
Definition: pmesh.hpp:43
Table send_face_nbr_elements
Definition: pmesh.hpp:130
Table * GetFaceToAllElementTable() const
Definition: pmesh.cpp:1832
void DeleteFaceNbrData()
Definition: pmesh.cpp:1333
GroupTopology gtopo
Definition: pmesh.hpp:120
void ParPrint(std::ostream &out) const
Save the mesh in a parallel mesh format.
Definition: pmesh.cpp:4432
Class for parallel meshes.
Definition: pmesh.hpp:28
Abstract data type element.
Definition: element.hpp:27
int GetFaceNbrRank(int fn) const
Definition: pmesh.cpp:1815
int GroupNEdges(int group)
Definition: pmesh.hpp:139
virtual void NURBSUniformRefinement()
Refine NURBS mesh.
Definition: pmesh.cpp:3179
virtual void Print(std::ostream &out=std::cout) const
Definition: pmesh.cpp:3395