MFEM  v4.6.0
Finite element discretization library
mesh.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_MESH
13 #define MFEM_MESH
14 
15 #include "../config/config.hpp"
16 #include "../general/stable3d.hpp"
17 #include "../general/globals.hpp"
18 #include "triangle.hpp"
19 #include "tetrahedron.hpp"
20 #include "vertex.hpp"
21 #include "vtk.hpp"
22 #include "ncmesh.hpp"
23 #include "../fem/eltrans.hpp"
24 #include "../fem/coefficient.hpp"
25 #include "../general/zstr.hpp"
26 #ifdef MFEM_USE_ADIOS2
27 #include "../general/adios2stream.hpp"
28 #endif
29 #include <iostream>
30 
31 namespace mfem
32 {
33 
34 // Data type mesh
35 
36 class GeometricFactors;
37 class FaceGeometricFactors;
38 class KnotVector;
39 class NURBSExtension;
40 class FiniteElementSpace;
41 class GridFunction;
42 struct Refinement;
43 
44 /** An enum type to specify if interior or boundary faces are desired. */
45 enum class FaceType : bool {Interior, Boundary};
46 
47 #ifdef MFEM_USE_MPI
48 class ParMesh;
49 class ParNCMesh;
50 #endif
51 
52 class Mesh
53 {
54 #ifdef MFEM_USE_MPI
55  friend class ParMesh;
56  friend class ParNCMesh;
57 #endif
58  friend class NCMesh;
59  friend class NURBSExtension;
60 
61 #ifdef MFEM_USE_ADIOS2
62  friend class adios2stream;
63 #endif
64 
65 protected:
66  int Dim;
67  int spaceDim;
68 
71  /** These variables store the number of Interior and Boundary faces. Calling
72  fes->GetMesh()->GetNBE() doesn't return the expected value in 3D because
73  periodic meshes in 3D have some of their faces marked as boundary for
74  visualization purpose in GLVis. */
76 
77  int meshgen; // see MeshGenerator()
78  int mesh_geoms; // sum of (1 << geom) for all geom of all dimensions
79 
80  // Counter for Mesh transformations: refinement, derefinement, rebalancing.
81  // Used for checking during Update operations on objects depending on the
82  // Mesh, such as FiniteElementSpace, GridFunction, etc.
83  long sequence;
84 
86  // Vertices are only at the corners of elements, where you would expect them
87  // in the lowest-order mesh. In some cases, e.g. in a Mesh that defines the
88  // patch topology for a NURBS mesh (see LoadPatchTopo()) the vertices may be
89  // empty while NumOfVertices is positive.
93 
94  /** @brief This structure stores the low level information necessary to
95  interpret the configuration of elements on a specific face. This
96  information can be accessed using methods like GetFaceElements(),
97  GetFaceInfos(), FaceIsInterior(), etc.
98 
99  For accessing higher level deciphered information look at
100  Mesh::FaceInformation, and its accessor Mesh::GetFaceInformation().
101 
102  Each face contains information on the indices, local reference faces,
103  orientations, and potential nonconformity for the two neighboring
104  elements on a face.
105  Each face can either be an interior, boundary, or shared interior face.
106  Each interior face is shared by two elements referred as Elem1 and Elem2.
107  For boundary faces only the information on Elem1 is relevant.
108  Shared interior faces correspond to faces where Elem1 and Elem2 are
109  distributed on different MPI ranks.
110  Regarding conformity, three cases are distinguished, conforming faces,
111  nonconforming slave faces, and nonconforming master faces. Master and
112  slave referring to the coarse and fine elements respectively on a
113  nonconforming face.
114  Nonconforming slave faces always have the slave element as Elem1 and
115  the master element as Elem2. On the other side, nonconforming master
116  faces always have the master element as Elem1, and one of the slave
117  element as Elem2. Except for ghost nonconforming slave faces, where
118  Elem1 is the master side and Elem2 is the slave side.
119 
120  The indices of Elem1 and Elem2 can be indirectly extracted from
121  FaceInfo::Elem1No and FaceInfo::Elem2No, read the note below for special
122  cases on the index of Elem2.
123 
124  The local face identifiers are deciphered from FaceInfo::Elem1Inf and
125  FaceInfo::Elem2Inf through the formula: LocalFaceIndex = ElemInf/64,
126  the semantic of the computed local face identifier can be found in
127  fem/geom.cpp. The local face identifier corresponds to an index
128  in the Constants<Geometry>::Edges arrays for 2D element geometries, and
129  to an index in the Constants<Geometry>::FaceVert arrays for 3D element
130  geometries.
131 
132  The orientation of each element relative to a face is obtained through
133  the formula: Orientation = ElemInf%64, the semantic of the orientation
134  can also be found in fem/geom.cpp. The orientation corresponds to
135  an index in the Constants<Geometry>::Orient arrays, providing the
136  sequence of vertices identifying the orientation of an edge/face. By
137  convention the orientation of Elem1 is always set to 0, serving as the
138  reference orientation. The orientation of Elem2 relatively to Elem1 is
139  therefore determined just by using the orientation of Elem2. An important
140  special case is the one of nonconforming faces, the orientation should
141  be composed with the PointMatrix, which also contains orientation
142  information. A special treatment should be done for 2D, the orientation
143  in the PointMatrix is not included, therefore when applying the
144  PointMatrix transformation, the PointMatrix should be flipped, except for
145  shared nonconforming slave faces where the transformation can be applied
146  as is.
147 
148  Another special case is the case of shared nonconforming faces. Ghost
149  faces use a different design based on so called "ghost" faces.
150  Ghost faces, as their name suggest are very well hidden, and they
151  usually have a separate interface from "standard" faces.
152  */
153  struct FaceInfo
154  {
155  // Inf = 64 * LocalFaceIndex + FaceOrientation
157  int NCFace; /* -1 if this is a regular conforming/boundary face;
158  index into 'nc_faces_info' if >= 0. */
159  };
160  // NOTE: in NC meshes, master faces have Elem2No == -1. Slave faces on the
161  // other hand have Elem2No and Elem2Inf set to the master face's element and
162  // its local face number.
163  //
164  // A local face is one generated from a local element and has index i in
165  // faces_info such that i < GetNumFaces(). Also, Elem1No always refers to the
166  // element (slave or master, in the nonconforming case) that generated the
167  // face.
168  // Classification of a local (non-ghost) face based on its FaceInfo:
169  // - Elem2No >= 0 --> local interior face; can be either:
170  // - NCFace == -1 --> conforming face, or
171  // - NCFace >= 0 --> nonconforming slave face; Elem2No is the index of
172  // the master volume element; Elem2Inf%64 is 0, see the note in
173  // Mesh::GenerateNCFaceInfo().
174  // - Elem2No < 0 --> local "boundary" face; can be one of:
175  // - NCFace == -1 --> conforming face; can be either:
176  // - Elem2Inf < 0 --> true boundary face (no element on side 2)
177  // - Elem2Inf >= 0 --> shared face where element 2 is a face-neighbor
178  // element with index -1-Elem2No. This state is initialized by
179  // ParMesh::ExchangeFaceNbrData().
180  // - NCFace >= 0 --> nonconforming face; can be one of:
181  // - Elem2Inf < 0 --> master nonconforming face, interior or shared;
182  // In this case, Elem2No is -1; see GenerateNCFaceInfo().
183  // - Elem2Inf >= 0 --> shared slave nonconforming face where element 2
184  // is the master face-neighbor element with index -1-Elem2No; see
185  // ParNCMesh::GetFaceNeighbors().
186  //
187  // A ghost face is a nonconforming face that is generated by a non-local,
188  // i.e. ghost, element. A ghost face has index i in faces_info such that
189  // i >= GetNumFaces().
190  // Classification of a ghost (non-local) face based on its FaceInfo:
191  // - Elem1No == -1 --> master ghost face? These ghost faces also have:
192  // Elem2No == -1, Elem1Inf == Elem2Inf == -1, and NCFace == -1.
193  // - Elem1No >= 0 --> slave ghost face; Elem1No is the index of the local
194  // master side element, i.e. side 1 IS NOT the side that generated the
195  // face. Elem2No is < 0 and -1-Elem2No is the index of the ghost
196  // face-neighbor element that generated this slave ghost face. In this
197  // case, Elem2Inf >= 0 and NCFace >= 0.
198  // Relevant methods: GenerateFaces(), GenerateNCFaceInfo(),
199  // ParNCMesh::GetFaceNeighbors(),
200  // ParMesh::ExchangeFaceNbrData()
201 
202  struct NCFaceInfo
203  {
204  bool Slave; // true if this is a slave face, false if master face
205  int MasterFace; // if Slave, this is the index of the master face
206  // If not Slave, 'MasterFace' is the local face index of this master face
207  // as a face in the unique adjacent element.
208  const DenseMatrix* PointMatrix; // if Slave, position within master face
209  // (NOTE: PointMatrix points to a matrix owned by NCMesh.)
210 
211  NCFaceInfo() = default;
212 
213  NCFaceInfo(bool slave, int master, const DenseMatrix* pm)
214  : Slave(slave), MasterFace(master), PointMatrix(pm) {}
215  };
216 
219 
224  Table *bel_to_edge; // for 3D
226 
227  // Note that the following tables are owned by this class and should not be
228  // deleted by the caller. Of these three tables, only face_edge and
229  // edge_vertex are returned by access functions.
230  mutable Table *face_to_elem; // Used by FindFaceNeighbors, not returned.
231  mutable Table *face_edge; // Returned by GetFaceEdgeTable().
232  mutable Table *edge_vertex; // Returned by GetEdgeVertexTable().
233 
238 
239  // refinement embeddings for forward compatibility with NCMesh
241 
242  // Nodes are only active for higher order meshes, and share locations with
243  // the vertices, plus all the higher- order control points within the
244  // element and along the edges and on the faces.
247 
248  static const int vtk_quadratic_tet[10];
249  static const int vtk_quadratic_pyramid[13];
250  static const int vtk_quadratic_wedge[18];
251  static const int vtk_quadratic_hex[27];
252 
253 #ifdef MFEM_USE_MEMALLOC
254  friend class Tetrahedron;
256 #endif
257 
258  // used during NC mesh initialization only
260 
261 public:
269 
271 
272  /// A list of all unique element attributes used by the Mesh.
274  /// A list of all unique boundary attributes used by the Mesh.
276 
277  NURBSExtension *NURBSext; ///< Optional NURBS mesh extension.
278  NCMesh *ncmesh; ///< Optional nonconforming mesh extension.
279  Array<GeometricFactors*> geom_factors; ///< Optional geometric factors.
280  Array<FaceGeometricFactors*> face_geom_factors; /**< Optional face geometric
281  factors. */
282 
283  // Global parameter that can be used to control the removal of unused
284  // vertices performed when reading a mesh in MFEM format. The default value
285  // (true) is set in mesh_readers.cpp.
287 
288 protected:
290 
291  void Init();
292  void InitTables();
293  void SetEmpty(); // Init all data members with empty values
294  void DestroyTables();
296  void DestroyPointers(); // Delete data specifically allocated by class Mesh.
297  void Destroy(); // Delete all owned data.
298  void ResetLazyData();
299 
300  Element *ReadElementWithoutAttr(std::istream &);
301  static void PrintElementWithoutAttr(const Element *, std::ostream &);
302 
303  Element *ReadElement(std::istream &);
304  static void PrintElement(const Element *, std::ostream &);
305 
306  // Readers for different mesh formats, used in the Load() method.
307  // The implementations of these methods are in mesh_readers.cpp.
308  void ReadMFEMMesh(std::istream &input, int version, int &curved);
309  void ReadLineMesh(std::istream &input);
310  void ReadNetgen2DMesh(std::istream &input, int &curved);
311  void ReadNetgen3DMesh(std::istream &input);
312  void ReadTrueGridMesh(std::istream &input);
313  void CreateVTKMesh(const Vector &points, const Array<int> &cell_data,
314  const Array<int> &cell_offsets,
315  const Array<int> &cell_types,
316  const Array<int> &cell_attributes,
317  int &curved, int &read_gf, bool &finalize_topo);
318  void ReadVTKMesh(std::istream &input, int &curved, int &read_gf,
319  bool &finalize_topo);
320  void ReadXML_VTKMesh(std::istream &input, int &curved, int &read_gf,
321  bool &finalize_topo, const std::string &xml_prefix="");
322  void ReadNURBSMesh(std::istream &input, int &curved, int &read_gf);
323  void ReadInlineMesh(std::istream &input, bool generate_edges = false);
324  void ReadGmshMesh(std::istream &input, int &curved, int &read_gf);
325  /* Note NetCDF (optional library) is used for reading cubit files */
326 #ifdef MFEM_USE_NETCDF
327  void ReadCubit(const char *filename, int &curved, int &read_gf);
328 #endif
329 
330  /// Determine the mesh generator bitmask #meshgen, see MeshGenerator().
331  /** Also, initializes #mesh_geoms. */
332  void SetMeshGen();
333 
334  /// Return the length of the segment from node i to node j.
335  double GetLength(int i, int j) const;
336 
337  void MarkForRefinement();
339  void GetEdgeOrdering(DSTable &v_to_v, Array<int> &order);
340  virtual void MarkTetMeshForRefinement(DSTable &v_to_v);
341 
342  // Methods used to prepare and apply permutation of the mesh nodes assuming
343  // that the mesh elements may be rotated (e.g. to mark triangle or tet edges
344  // for refinement) between the two calls - PrepareNodeReorder() and
345  // DoNodeReorder(). The latter method assumes that the 'faces' have not been
346  // updated after the element rotations.
347  void PrepareNodeReorder(DSTable **old_v_to_v, Table **old_elem_vert);
348  void DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert);
349 
351  STable3D *GetElementToFaceTable(int ret_ftbl = 0);
352 
353  /** Red refinement. Element with index i is refined. The default
354  red refinement for now is Uniform. */
355  void RedRefinement(int i, const DSTable &v_to_v,
356  int *edge1, int *edge2, int *middle)
357  { UniformRefinement(i, v_to_v, edge1, edge2, middle); }
358 
359  /** Green refinement. Element with index i is refined. The default
360  refinement for now is Bisection. */
361  void GreenRefinement(int i, const DSTable &v_to_v,
362  int *edge1, int *edge2, int *middle)
363  { Bisection(i, v_to_v, edge1, edge2, middle); }
364 
365  /// Bisect a triangle: element with index @a i is bisected.
366  void Bisection(int i, const DSTable &, int *, int *, int *);
367 
368  /// Bisect a tetrahedron: element with index @a i is bisected.
369  void Bisection(int i, HashTable<Hashed2> &);
370 
371  /// Bisect a boundary triangle: boundary element with index @a i is bisected.
372  void BdrBisection(int i, const HashTable<Hashed2> &);
373 
374  /** Uniform Refinement. Element with index i is refined uniformly. */
375  void UniformRefinement(int i, const DSTable &, int *, int *, int *);
376 
377  /** @brief Averages the vertices with given @a indexes and saves the result
378  in #vertices[result]. */
379  void AverageVertices(const int *indexes, int n, int result);
380 
382  int FindCoarseElement(int i);
383 
384  /** @brief Update the nodes of a curved mesh after the topological part of a
385  Mesh::Operation, such as refinement, has been performed. */
386  /** If Nodes GridFunction is defined, i.e. not NULL, this method calls
387  NodesUpdated().
388 
389  @note Unlike the similarly named public method NodesUpdated() this
390  method modifies the mesh nodes (if they exist) and calls NodesUpdated().
391  */
392  void UpdateNodes();
393 
394  /// Helper to set vertex coordinates given a high-order curvature function.
395  void SetVerticesFromNodes(const GridFunction *nodes);
396 
397  void UniformRefinement2D_base(bool update_nodes = true);
398 
399  /// Refine a mixed 2D mesh uniformly.
401 
402  /* If @a f2qf is not NULL, adds all quadrilateral faces to @a f2qf which
403  represents a "face-to-quad-face" index map. When all faces are quads, the
404  array @a f2qf is kept empty since it is not needed. */
405  void UniformRefinement3D_base(Array<int> *f2qf = NULL,
406  DSTable *v_to_v_p = NULL,
407  bool update_nodes = true);
408 
409  /// Refine a mixed 3D mesh uniformly.
411 
412  /// Refine NURBS mesh.
413  virtual void NURBSUniformRefinement();
414 
415  /// This function is not public anymore. Use GeneralRefinement instead.
416  virtual void LocalRefinement(const Array<int> &marked_el, int type = 3);
417 
418  /// This function is not public anymore. Use GeneralRefinement instead.
419  virtual void NonconformingRefinement(const Array<Refinement> &refinements,
420  int nc_limit = 0);
421 
422  /// NC version of GeneralDerefinement.
423  virtual bool NonconformingDerefinement(Array<double> &elem_error,
424  double threshold, int nc_limit = 0,
425  int op = 1);
426  /// Derefinement helper.
427  double AggregateError(const Array<double> &elem_error,
428  const int *fine, int nfine, int op);
429 
430  /// Read NURBS patch/macro-element mesh
431  void LoadPatchTopo(std::istream &input, Array<int> &edge_to_knot);
432 
433  void UpdateNURBS();
434 
435  void PrintTopo(std::ostream &out, const Array<int> &e_to_k) const;
436 
437  /// Used in GetFaceElementTransformations (...)
440  int i);
442  int i);
443  /// Used in GetFaceElementTransformations (...)
445  int i);
446  /// Used in GetFaceElementTransformations (...)
448  int i);
449  /// Used in GetFaceElementTransformations (...)
451  int i);
452  /// Used in GetFaceElementTransformations (...)
454  int i);
455  /// Used in GetFaceElementTransformations (...)
457  int i);
458  /// Used in GetFaceElementTransformations (...)
460  int i);
461 
462  /** Used in GetFaceElementTransformations to account for the fact that a
463  slave face occupies only a portion of its master face. */
465  const FaceInfo &fi, bool is_ghost);
466 
467  bool IsSlaveFace(const FaceInfo &fi) const;
468 
469  /// Returns the orientation of "test" relative to "base"
470  static int GetTriOrientation (const int * base, const int * test);
471 
472  /// Returns the orientation of "base" relative to "test"
473  /// In other words: GetTriOrientation(test, base) should equal
474  /// InvertTriOrientation(GetTriOrientation(base, test))
475  static int InvertTriOrientation(int ori);
476 
477  /// Returns the orientation of "c" relative to "a" by composing
478  /// previously computed orientations relative to an intermediate
479  /// set "b".
480  static int ComposeTriOrientations(int ori_a_b, int ori_b_c);
481 
482  /// Returns the orientation of "test" relative to "base"
483  static int GetQuadOrientation (const int * base, const int * test);
484 
485  /// Returns the orientation of "base" relative to "test"
486  /// In other words: GetQuadOrientation(test, base) should equal
487  /// InvertQuadOrientation(GetQuadOrientation(base, test))
488  static int InvertQuadOrientation(int ori);
489 
490  /// Returns the orientation of "c" relative to "a" by composing
491  /// previously computed orientations relative to an intermediate
492  /// set "b".
493  static int ComposeQuadOrientations(int ori_a_b, int ori_b_c);
494 
495  /// Returns the orientation of "test" relative to "base"
496  static int GetTetOrientation (const int * base, const int * test);
497 
498  static void GetElementArrayEdgeTable(const Array<Element*> &elem_array,
499  const DSTable &v_to_v,
500  Table &el_to_edge);
501 
502  /** Return element to edge table and the indices for the boundary edges.
503  The entries in the table are ordered according to the order of the
504  nodes in the elements. For example, if T is the element to edge table
505  T(i, 0) gives the index of edge in element i that connects vertex 0
506  to vertex 1, etc. Returns the number of the edges. */
508 
509  /// Used in GenerateFaces()
510  void AddPointFaceElement(int lf, int gf, int el);
511 
512  void AddSegmentFaceElement (int lf, int gf, int el, int v0, int v1);
513 
514  void AddTriangleFaceElement (int lf, int gf, int el,
515  int v0, int v1, int v2);
516 
517  void AddQuadFaceElement (int lf, int gf, int el,
518  int v0, int v1, int v2, int v3);
519  /** For a serial Mesh, return true if the face is interior. For a parallel
520  ParMesh return true if the face is interior or shared. In parallel, this
521  method only works if the face neighbor data is exchanged. */
522  bool FaceIsTrueInterior(int FaceNo) const
523  {
524  return FaceIsInterior(FaceNo) || (faces_info[FaceNo].Elem2Inf >= 0);
525  }
526 
527  void FreeElement(Element *E);
528 
529  void GenerateFaces();
530  void GenerateNCFaceInfo();
531 
532  /// Begin construction of a mesh
533  void InitMesh(int Dim_, int spaceDim_, int NVert, int NElem, int NBdrElem);
534 
535  // Used in the methods FinalizeXXXMesh() and FinalizeTopology()
536  void FinalizeCheck();
537 
538  void Loader(std::istream &input, int generate_edges = 0,
539  std::string parse_tag = "");
540 
541  // If NURBS mesh, write NURBS format. If NCMesh, write mfem v1.1 format.
542  // If section_delimiter is empty, write mfem v1.0 format. Otherwise, write
543  // mfem v1.2 format with the given section_delimiter at the end.
544  void Printer(std::ostream &out = mfem::out,
545  std::string section_delimiter = "") const;
546 
547  /** Creates mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into
548  nx*ny*nz hexahedra if type=HEXAHEDRON or into 6*nx*ny*nz tetrahedrons if
549  type=TETRAHEDRON. The parameter @a sfc_ordering controls how the elements
550  (when type=HEXAHEDRON) are ordered: true - use space-filling curve
551  ordering, or false - use lexicographic ordering. */
552  void Make3D(int nx, int ny, int nz, Element::Type type,
553  double sx, double sy, double sz, bool sfc_ordering);
554 
555  /** Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny
556  quadrilaterals if type = QUADRILATERAL or into 2*nx*ny triangles if
557  type = TRIANGLE. If generate_edges = 0 (default) edges are not generated,
558  if 1 edges are generated. The parameter @a sfc_ordering controls how the
559  elements (when type=QUADRILATERAL) are ordered: true - use space-filling
560  curve ordering, or false - use lexicographic ordering. */
561  void Make2D(int nx, int ny, Element::Type type, double sx, double sy,
562  bool generate_edges, bool sfc_ordering);
563 
564  /// Creates a 1D mesh for the interval [0,sx] divided into n equal intervals.
565  void Make1D(int n, double sx = 1.0);
566 
567  /// Internal function used in Mesh::MakeRefined
568  void MakeRefined_(Mesh &orig_mesh, const Array<int> ref_factors,
569  int ref_type);
570 
571  /// Initialize vertices/elements/boundary/tables from a nonconforming mesh.
572  void InitFromNCMesh(const NCMesh &ncmesh);
573 
574  /// Create from a nonconforming mesh.
575  explicit Mesh(const NCMesh &ncmesh);
576 
577  // used in GetElementData() and GetBdrElementData()
578  void GetElementData(const Array<Element*> &elem_array, int geom,
579  Array<int> &elem_vtx, Array<int> &attr) const;
580 
581  double GetElementSize(ElementTransformation *T, int type = 0);
582 
583  // Internal helper used in MakeSimplicial (and ParMesh::MakeSimplicial).
584  void MakeSimplicial_(const Mesh &orig_mesh, int *vglobal);
585 
586 public:
587 
588  /// @anchor mfem_Mesh_ctors
589  /// @name Standard Mesh constructors and related methods
590  ///
591  /// These constructors and assignment operators accept mesh information in
592  /// a variety of common forms. For more specialized constructors see
593  /// @ref mfem_Mesh_named_ctors "Named mesh constructors".
594  /// @{
595  Mesh() { SetEmpty(); }
596 
597  /** Copy constructor. Performs a deep copy of (almost) all data, so that the
598  source mesh can be modified (e.g. deleted, refined) without affecting the
599  new mesh. If 'copy_nodes' is false, use a shallow (pointer) copy for the
600  nodes, if present. */
601  explicit Mesh(const Mesh &mesh, bool copy_nodes = true);
602 
603  /// Move constructor, useful for using a Mesh as a function return value.
604  Mesh(Mesh &&mesh);
605 
606  /// Move assignment operator.
607  Mesh& operator=(Mesh &&mesh);
608 
609  /// Explicitly delete the copy assignment operator.
610  Mesh& operator=(const Mesh &mesh) = delete;
611 
612  /// Construct a Mesh from the given primary data.
613  /** The array @a vertices is used as external data, i.e. the Mesh does not
614  copy the data and will not delete the pointer.
615 
616  The data from the other arrays is copied into the internal Mesh data
617  structures.
618 
619  This method calls the method FinalizeTopology(). The method Finalize()
620  may be called after this constructor and after optionally setting the
621  Mesh nodes. */
622  Mesh(double *vertices, int num_vertices,
623  int *element_indices, Geometry::Type element_type,
624  int *element_attributes, int num_elements,
625  int *boundary_indices, Geometry::Type boundary_type,
626  int *boundary_attributes, int num_boundary_elements,
627  int dimension, int space_dimension = -1);
628 
629  /** @anchor mfem_Mesh_init_ctor
630  @brief _Init_ constructor: begin the construction of a Mesh object.
631 
632  Construct a shell of a mesh object allocating space to store pointers to
633  the vertices, elements, and boundary elements. The vertices and elements
634  themselves can later be added using methods from the
635  @ref mfem_Mesh_construction "Mesh construction" group.
636  */
637  Mesh(int Dim_, int NVert, int NElem, int NBdrElem = 0, int spaceDim_ = -1)
638  {
639  if (spaceDim_ == -1) { spaceDim_ = Dim_; }
640  InitMesh(Dim_, spaceDim_, NVert, NElem, NBdrElem);
641  }
642 
643  /** Creates mesh by reading a file in MFEM, Netgen, or VTK format. If
644  generate_edges = 0 (default) edges are not generated, if 1 edges are
645  generated. See also @a Mesh::LoadFromFile. */
646  explicit Mesh(const std::string &filename, int generate_edges = 0,
647  int refine = 1, bool fix_orientation = true);
648 
649  /** Creates mesh by reading data stream in MFEM, Netgen, or VTK format. If
650  generate_edges = 0 (default) edges are not generated, if 1 edges are
651  generated. */
652  explicit Mesh(std::istream &input, int generate_edges = 0, int refine = 1,
653  bool fix_orientation = true);
654 
655  /// Create a disjoint mesh from the given mesh array
656  ///
657  /// @note Data is copied from the meshes in @a mesh_array.
658  Mesh(Mesh *mesh_array[], int num_pieces);
659 
660  /** This is similar to the mesh constructor with the same arguments, but here
661  the current mesh is destroyed and another one created based on the data
662  stream again given in MFEM, Netgen, or VTK format. If generate_edges = 0
663  (default) edges are not generated, if 1 edges are generated. */
664  /// \see mfem::ifgzstream() for on-the-fly decompression of compressed ascii
665  /// inputs.
666  virtual void Load(std::istream &input, int generate_edges = 0,
667  int refine = 1, bool fix_orientation = true)
668  {
669  Loader(input, generate_edges);
670  Finalize(refine, fix_orientation);
671  }
672 
673  /// Swaps internal data with another mesh. By default, non-geometry members
674  /// like 'ncmesh' and 'NURBSExt' are only swapped when 'non_geometry' is set.
675  void Swap(Mesh& other, bool non_geometry);
676 
677  /// Clear the contents of the Mesh.
678  void Clear() { Destroy(); SetEmpty(); }
679 
680  /// Destroys Mesh.
681  virtual ~Mesh() { DestroyPointers(); }
682 
683  /// @}
684 
685  /** @anchor mfem_Mesh_named_ctors @name Named mesh constructors.
686 
687  Each of these constructors uses the move constructor, and can be used as
688  the right-hand side of an assignment when creating new meshes. For more
689  general mesh constructors see
690  @ref mfem_Mesh_ctors "Standard mesh constructors".*/
691  ///@{
692 
693  /** Creates mesh by reading a file in MFEM, Netgen, or VTK format. If
694  generate_edges = 0 (default) edges are not generated, if 1 edges are
695  generated.
696 
697  @note @a filename is not cached by the Mesh object and can be
698  safely deleted following this function call.
699  */
700  static Mesh LoadFromFile(const std::string &filename,
701  int generate_edges = 0, int refine = 1,
702  bool fix_orientation = true);
703 
704  /** Creates 1D mesh , divided into n equal intervals. */
705  static Mesh MakeCartesian1D(int n, double sx = 1.0);
706 
707  /** Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny
708  quadrilaterals if type = QUADRILATERAL or into 2*nx*ny triangles if
709  type = TRIANGLE. If generate_edges = 0 (default) edges are not generated,
710  if 1 edges are generated. If scf_ordering = true (default), elements are
711  ordered along a space-filling curve, instead of row by row. */
712  static Mesh MakeCartesian2D(
713  int nx, int ny, Element::Type type, bool generate_edges = false,
714  double sx = 1.0, double sy = 1.0, bool sfc_ordering = true);
715 
716  /** Creates mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into
717  nx*ny*nz hexahedra if type=HEXAHEDRON or into 6*nx*ny*nz tetrahedrons if
718  type=TETRAHEDRON. If sfc_ordering = true (default), elements are ordered
719  along a space-filling curve, instead of row by row and layer by layer. */
720  static Mesh MakeCartesian3D(
721  int nx, int ny, int nz, Element::Type type,
722  double sx = 1.0, double sy = 1.0, double sz = 1.0,
723  bool sfc_ordering = true);
724 
725  /// Create a refined (by any factor) version of @a orig_mesh.
726  /** @param[in] orig_mesh The starting coarse mesh.
727  @param[in] ref_factor The refinement factor, an integer > 1.
728  @param[in] ref_type Specify the positions of the new vertices. The
729  options are BasisType::ClosedUniform or
730  BasisType::GaussLobatto.
731 
732  The refinement data which can be accessed with GetRefinementTransforms()
733  is set to reflect the performed refinements.
734 
735  @note The constructed Mesh is straight-sided. */
736  static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type);
737 
738  /// Create a refined mesh, where each element of the original mesh may be
739  /// refined by a different factor.
740  /** @param[in] orig_mesh The starting coarse mesh.
741  @param[in] ref_factors An array of integers whose size is the number of
742  elements of @a orig_mesh. The @a ith element of
743  @a orig_mesh is refined by refinement factor
744  @a ref_factors[i].
745  @param[in] ref_type Specify the positions of the new vertices. The
746  options are BasisType::ClosedUniform or
747  BasisType::GaussLobatto.
748 
749  The refinement data which can be accessed with GetRefinementTransforms()
750  is set to reflect the performed refinements.
751 
752  @note The constructed Mesh is straight-sided. */
753  /// refined @a ref_factors[i] times in each dimension.
754  static Mesh MakeRefined(Mesh &orig_mesh, const Array<int> &ref_factors,
755  int ref_type);
756 
757  /** Create a mesh by splitting each element of @a orig_mesh into simplices.
758  Quadrilaterals are split into two triangles, prisms are split into
759  3 tetrahedra, and hexahedra are split into either 5 or 6 tetrahedra
760  depending on the configuration.
761  @warning The curvature of the original mesh is not carried over to the
762  new mesh. Periodic meshes are not supported. */
763  static Mesh MakeSimplicial(const Mesh &orig_mesh);
764 
765  /// Create a periodic mesh by identifying vertices of @a orig_mesh.
766  /** Each vertex @a i will be mapped to vertex @a v2v[i], such that all
767  vertices that are coincident under the periodic mapping get mapped to
768  the same index. The mapping @a v2v can be generated from translation
769  vectors using Mesh::CreatePeriodicVertexMapping.
770  @note MFEM requires that each edge of the resulting mesh be uniquely
771  identifiable by a pair of distinct vertices. As a consequence, periodic
772  boundaries must be connected by at least three edges. */
773  static Mesh MakePeriodic(const Mesh &orig_mesh, const std::vector<int> &v2v);
774 
775  ///@}
776 
777  /** @anchor mfem_Mesh_construction
778  @name Methods for piecewise Mesh construction.
779 
780  These methods are intended to be used with the @ref mfem_Mesh_init_ctor
781  "init constructor". */
782  ///@{
783 
784  /// @note The returned object should be deleted by the caller.
785  Element *NewElement(int geom);
786 
787  int AddVertex(double x, double y = 0.0, double z = 0.0);
788  int AddVertex(const double *coords);
789  int AddVertex(const Vector &coords);
790  /// Mark vertex @a i as nonconforming, with parent vertices @a p1 and @a p2.
791  void AddVertexParents(int i, int p1, int p2);
792 
793  int AddSegment(int v1, int v2, int attr = 1);
794  int AddSegment(const int *vi, int attr = 1);
795 
796  int AddTriangle(int v1, int v2, int v3, int attr = 1);
797  int AddTriangle(const int *vi, int attr = 1);
798  int AddTri(const int *vi, int attr = 1) { return AddTriangle(vi, attr); }
799 
800  int AddQuad(int v1, int v2, int v3, int v4, int attr = 1);
801  int AddQuad(const int *vi, int attr = 1);
802 
803  int AddTet(int v1, int v2, int v3, int v4, int attr = 1);
804  int AddTet(const int *vi, int attr = 1);
805 
806  int AddWedge(int v1, int v2, int v3, int v4, int v5, int v6, int attr = 1);
807  int AddWedge(const int *vi, int attr = 1);
808 
809  int AddPyramid(int v1, int v2, int v3, int v4, int v5, int attr = 1);
810  int AddPyramid(const int *vi, int attr = 1);
811 
812  int AddHex(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8,
813  int attr = 1);
814  int AddHex(const int *vi, int attr = 1);
815  void AddHexAsTets(const int *vi, int attr = 1);
816  void AddHexAsWedges(const int *vi, int attr = 1);
817  void AddHexAsPyramids(const int *vi, int attr = 1);
818 
819  /// The parameter @a elem should be allocated using the NewElement() method
820  /// @note Ownership of @a elem will pass to the Mesh object
821  int AddElement(Element *elem);
822  /// The parameter @a elem should be allocated using the NewElement() method
823  /// @note Ownership of @a elem will pass to the Mesh object
824  int AddBdrElement(Element *elem);
825 
826  int AddBdrSegment(int v1, int v2, int attr = 1);
827  int AddBdrSegment(const int *vi, int attr = 1);
828 
829  int AddBdrTriangle(int v1, int v2, int v3, int attr = 1);
830  int AddBdrTriangle(const int *vi, int attr = 1);
831 
832  int AddBdrQuad(int v1, int v2, int v3, int v4, int attr = 1);
833  int AddBdrQuad(const int *vi, int attr = 1);
834  void AddBdrQuadAsTriangles(const int *vi, int attr = 1);
835 
836  int AddBdrPoint(int v, int attr = 1);
837 
839  /// Finalize the construction of a triangular Mesh.
840  void FinalizeTriMesh(int generate_edges = 0, int refine = 0,
841  bool fix_orientation = true);
842  /// Finalize the construction of a quadrilateral Mesh.
843  void FinalizeQuadMesh(int generate_edges = 0, int refine = 0,
844  bool fix_orientation = true);
845  /// Finalize the construction of a tetrahedral Mesh.
846  void FinalizeTetMesh(int generate_edges = 0, int refine = 0,
847  bool fix_orientation = true);
848  /// Finalize the construction of a wedge Mesh.
849  void FinalizeWedgeMesh(int generate_edges = 0, int refine = 0,
850  bool fix_orientation = true);
851  /// Finalize the construction of a hexahedral Mesh.
852  void FinalizeHexMesh(int generate_edges = 0, int refine = 0,
853  bool fix_orientation = true);
854  /// Finalize the construction of any type of Mesh.
855  /** This method calls FinalizeTopology() and Finalize(). */
856  void FinalizeMesh(int refine = 0, bool fix_orientation = true);
857 
858  ///@}
859 
860  /// @name Mesh consistency methods
861  /// @{
862 
863  /** @brief Finalize the construction of the secondary topology (connectivity)
864  data of a Mesh. */
865  /** This method does not require any actual coordinate data (either vertex
866  coordinates for linear meshes or node coordinates for meshes with nodes)
867  to be available. However, the data generated by this method is generally
868  required by the FiniteElementSpace class.
869 
870  After calling this method, setting the Mesh vertices or nodes, it may be
871  appropriate to call the method Finalize(). */
872  void FinalizeTopology(bool generate_bdr = true);
873 
874  /// Finalize the construction of a general Mesh.
875  /** This method will:
876  - check and optionally fix the orientation of regular elements
877  - check and fix the orientation of boundary elements
878  - assume that #vertices are defined, if #Nodes == NULL
879  - assume that #Nodes are defined, if #Nodes != NULL.
880  @param[in] refine If true, prepare the Mesh for conforming refinement of
881  triangular or tetrahedral meshes.
882  @param[in] fix_orientation
883  If true, fix the orientation of inverted mesh elements
884  by permuting their vertices.
885 
886  Before calling this method, call FinalizeTopology() and ensure that the
887  Mesh vertices or nodes are set. */
888  virtual void Finalize(bool refine = false, bool fix_orientation = false);
889 
890  /// @brief Determine the sets of unique attribute values in domain and
891  /// boundary elements.
892  ///
893  /// Separately scan the domain and boundary elements to generate unique,
894  /// sorted sets of the element attribute values present in the mesh and
895  /// store these in the Mesh::attributes and Mesh::bdr_attributes arrays.
896  virtual void SetAttributes();
897 
898  /// Check (and optionally attempt to fix) the orientation of the elements
899  /** @param[in] fix_it If `true`, attempt to fix the orientations of some
900  elements: triangles, quads, and tets.
901  @return The number of elements with wrong orientation.
902 
903  @note For meshes with nodes (e.g. high-order or periodic meshes), fixing
904  the element orientations may require additional permutation of the nodal
905  GridFunction of the mesh which is not performed by this method. Instead,
906  the method Finalize() should be used with the parameter
907  @a fix_orientation set to `true`.
908 
909  @note This method performs a simple check if an element is inverted, e.g.
910  for most elements types, it checks if the Jacobian of the mapping from
911  the reference element is non-negative at the center of the element. */
912  int CheckElementOrientation(bool fix_it = true);
913 
914  /// Check the orientation of the boundary elements
915  /** @return The number of boundary elements with wrong orientation. */
916  int CheckBdrElementOrientation(bool fix_it = true);
917 
918  /** This method modifies a tetrahedral mesh so that Nedelec spaces of order
919  greater than 1 can be defined on the mesh. Specifically, we
920  1) rotate all tets in the mesh so that the vertices {v0, v1, v2, v3}
921  satisfy: v0 < v1 < min(v2, v3).
922  2) rotate all boundary triangles so that the vertices {v0, v1, v2}
923  satisfy: v0 < min(v1, v2).
924 
925  @note Refinement does not work after a call to this method! */
926  MFEM_DEPRECATED virtual void ReorientTetMesh();
927 
928  /// Remove unused vertices and rebuild mesh connectivity.
929  void RemoveUnusedVertices();
930 
931  /** Remove boundary elements that lie in the interior of the mesh, i.e. that
932  have two adjacent faces in 3D, or edges in 2D. */
934 
935  /// @}
936 
937  /// @name Element ordering methods
938  /// @{
939 
940  /** This is our integration with the Gecko library. The method finds an
941  element ordering that will increase memory coherency by putting elements
942  that are in physical proximity closer in memory. It can also be used to
943  obtain a space-filling curve ordering for ParNCMesh partitioning.
944  @param[out] ordering Output element ordering.
945  @param iterations Total number of V cycles. The ordering may improve with
946  more iterations. The best iteration is returned at the end.
947  @param window Initial window size. This determines the number of
948  permutations tested at each multigrid level and strongly influences the
949  quality of the result, but the cost of increasing 'window' is exponential.
950  @param period The window size is incremented every 'period' iterations.
951  @param seed Seed for initial random ordering (0 = skip random reorder).
952  @param verbose Print the progress of the optimization to mfem::out.
953  @param time_limit Optional time limit for the optimization, in seconds.
954  When reached, ordering from the best iteration so far is returned
955  (0 = no limit).
956  @return The final edge product cost of the ordering. The function may be
957  called in an external loop with different seeds, and the best ordering can
958  then be retained. */
959  double GetGeckoElementOrdering(Array<int> &ordering,
960  int iterations = 4, int window = 4,
961  int period = 2, int seed = 0,
962  bool verbose = false, double time_limit = 0);
963 
964  /** Return an ordering of the elements that approximately follows the Hilbert
965  curve. The method performs a spatial (Hilbert) sort on the centers of all
966  elements and returns the resulting sequence, which can then be passed to
967  ReorderElements. This is a cheap alternative to GetGeckoElementOrdering.*/
968  void GetHilbertElementOrdering(Array<int> &ordering);
969 
970  /** Rebuilds the mesh with a different order of elements. For each element i,
971  the array ordering[i] contains its desired new index. Note that the method
972  reorders vertices, edges and faces along with the elements. */
973  void ReorderElements(const Array<int> &ordering, bool reorder_vertices = true);
974 
975  /// @}
976 
977  /// @anchor mfem_Mesh_deprecated_ctors @name Deprecated mesh constructors
978  ///
979  /// These constructors have been deprecated in favor of
980  /// @ref mfem_Mesh_named_ctors "Named mesh constructors".
981  /// @{
982 
983  /// Deprecated: see @a MakeCartesian3D.
984  MFEM_DEPRECATED
985  Mesh(int nx, int ny, int nz, Element::Type type, bool generate_edges = false,
986  double sx = 1.0, double sy = 1.0, double sz = 1.0,
987  bool sfc_ordering = true)
988  {
989  Make3D(nx, ny, nz, type, sx, sy, sz, sfc_ordering);
990  Finalize(true); // refine = true
991  }
992 
993  /// Deprecated: see @a MakeCartesian2D.
994  MFEM_DEPRECATED
995  Mesh(int nx, int ny, Element::Type type, bool generate_edges = false,
996  double sx = 1.0, double sy = 1.0, bool sfc_ordering = true)
997  {
998  Make2D(nx, ny, type, sx, sy, generate_edges, sfc_ordering);
999  Finalize(true); // refine = true
1000  }
1001 
1002  /// Deprecated: see @a MakeCartesian1D.
1003  MFEM_DEPRECATED
1004  explicit Mesh(int n, double sx = 1.0)
1005  {
1006  Make1D(n, sx);
1007  // Finalize(); // reminder: not needed
1008  }
1009 
1010  /// Deprecated: see @a MakeRefined.
1011  MFEM_DEPRECATED
1012  Mesh(Mesh *orig_mesh, int ref_factor, int ref_type);
1013 
1014  /// @}
1015 
1016  /// @name Information about the mesh as a whole
1017  /// @{
1018 
1019  /// @brief Dimension of the reference space used within the elements
1020  int Dimension() const { return Dim; }
1021 
1022  /// @brief Dimension of the physical space containing the mesh
1023  int SpaceDimension() const { return spaceDim; }
1024 
1025  /// Equals 1 + num_holes - num_loops
1026  inline int EulerNumber() const
1028  /// Equals 1 - num_holes
1029  inline int EulerNumber2D() const
1030  { return NumOfVertices - NumOfEdges + NumOfElements; }
1031 
1032  /** @brief Get the mesh generator/type.
1033 
1034  The purpose of this is to be able to quickly tell what type of elements
1035  one has in the mesh. Examination of this bitmask along with knowledge
1036  of the mesh dimension can be used to identify which element types are
1037  present.
1038 
1039  @return A bitmask:
1040  - bit 0 - simplices are present in the mesh (triangles, tets),
1041  - bit 1 - tensor product elements are present in the mesh (quads, hexes),
1042  - bit 2 - the mesh has wedge elements.
1043  - bit 3 - the mesh has pyramid elements.
1044 
1045  In parallel, the result takes into account elements on all processors.
1046  */
1047  inline int MeshGenerator() { return meshgen; }
1048 
1049  /// Checks if the mesh has boundary elements
1050  virtual bool HasBoundaryElements() const { return (NumOfBdrElements > 0); }
1051 
1052  /** @brief Return true iff the given @a geom is encountered in the mesh.
1053  Geometries of dimensions lower than Dimension() are counted as well. */
1054  bool HasGeometry(Geometry::Type geom) const
1055  { return mesh_geoms & (1 << geom); }
1056 
1057  /** @brief Return the number of geometries of the given dimension present in
1058  the mesh. */
1059  /** For a parallel mesh only the local geometries are counted. */
1060  int GetNumGeometries(int dim) const;
1061 
1062  /// Return all element geometries of the given dimension present in the mesh.
1063  /** For a parallel mesh only the local geometries are returned.
1064 
1065  The returned geometries are sorted. */
1066  void GetGeometries(int dim, Array<Geometry::Type> &el_geoms) const;
1067 
1068  /// Returns the minimum and maximum corners of the mesh bounding box.
1069  /** For high-order meshes, the geometry is first refined @a ref times. */
1070  void GetBoundingBox(Vector &min, Vector &max, int ref = 2);
1071 
1072  void GetCharacteristics(double &h_min, double &h_max,
1073  double &kappa_min, double &kappa_max,
1074  Vector *Vh = NULL, Vector *Vk = NULL);
1075 
1076  /// @}
1077 
1078  /// @name Information concerning numbers of mesh entities
1079  /// @{
1080 
1081  /** @brief Returns number of vertices. Vertices are only at the corners of
1082  elements, where you would expect them in the lowest-order mesh. */
1083  inline int GetNV() const { return NumOfVertices; }
1084 
1085  /// Returns number of elements.
1086  inline int GetNE() const { return NumOfElements; }
1087 
1088  /// Returns number of boundary elements.
1089  inline int GetNBE() const { return NumOfBdrElements; }
1090 
1091  /// Return the number of edges.
1092  inline int GetNEdges() const { return NumOfEdges; }
1093 
1094  /// Return the number of faces in a 3D mesh.
1095  inline int GetNFaces() const { return NumOfFaces; }
1096 
1097  /// Return the number of faces (3D), edges (2D) or vertices (1D).
1098  int GetNumFaces() const;
1099 
1100  /** @brief Return the number of faces (3D), edges (2D) or vertices (1D)
1101  including ghost faces. */
1102  int GetNumFacesWithGhost() const;
1103 
1104  /** @brief Returns the number of faces according to the requested type, does
1105  not count master nonconforming faces.
1106 
1107  If type==Boundary returns only the number of true boundary faces
1108  contrary to GetNBE() that returns all "boundary" elements which may
1109  include actual interior faces.
1110  Similarly, if type==Interior, only the true interior faces are counted
1111  excluding all master nonconforming faces. */
1112  virtual int GetNFbyType(FaceType type) const;
1113 
1114  /// Return the total (global) number of elements.
1115  long long GetGlobalNE() const { return ReduceInt(NumOfElements); }
1116 
1117  /// @}
1118 
1119  /// @name Access to individual mesh entities
1120  /// @{
1121 
1122  /// @brief Return pointer to vertex i's coordinates.
1123  /// @warning For high-order meshes (when #Nodes != NULL) vertices may not be
1124  /// updated and should not be used!
1125  const double *GetVertex(int i) const { return vertices[i](); }
1126 
1127  /// @brief Return pointer to vertex i's coordinates.
1128  ///
1129  /// @warning For high-order meshes (when Nodes != NULL) vertices may not
1130  /// being updated and should not be used!
1131  ///
1132  /// @note The pointer returned by this function can be used to
1133  /// alter vertex locations but the pointer itself should not be
1134  /// changed by the caller.
1135  double *GetVertex(int i) { return vertices[i](); }
1136 
1137  /// @brief Return pointer to the i'th element object
1138  ///
1139  /// The index @a i should be in the range [0, this->Mesh::GetNE())
1140  ///
1141  /// In parallel, @a i is the local element index which is in the
1142  /// same range mentioned above.
1143  const Element *GetElement(int i) const { return elements[i]; }
1144 
1145  /// @brief Return pointer to the i'th element object
1146  ///
1147  /// @note Provides read/write access to the i'th element object so
1148  /// that element attributes or connectivity can be adjusted. However,
1149  /// the Element object itself should not be deleted by the caller.
1150  Element *GetElement(int i) { return elements[i]; }
1151 
1152  /// @brief Return pointer to the i'th boundary element object
1153  ///
1154  /// The index @a i should be in the range [0, this->Mesh::GetNBE())
1155  ///
1156  /// In parallel, @a i is the local boundary element index which is
1157  /// in the same range mentioned above.
1158  const Element *GetBdrElement(int i) const { return boundary[i]; }
1159 
1160  /// @brief Return pointer to the i'th boundary element object
1161  ///
1162  /// @note Provides read/write access to the i'th boundary element object so
1163  /// that boundary attributes or connectivity can be adjusted. However,
1164  /// the Element object itself should not be deleted by the caller.
1165  Element *GetBdrElement(int i) { return boundary[i]; }
1166 
1167  const Element *GetFace(int i) const { return faces[i]; }
1168 
1169  /// @}
1170 
1171  /// @name Access to groups of mesh entities
1172  /// @{
1173 
1174  const Element* const *GetElementsArray() const
1175  { return elements.GetData(); }
1176 
1177  void GetElementData(int geom, Array<int> &elem_vtx, Array<int> &attr) const
1178  { GetElementData(elements, geom, elem_vtx, attr); }
1179 
1180  void GetBdrElementData(int geom, Array<int> &bdr_elem_vtx,
1181  Array<int> &bdr_attr) const
1182  { GetElementData(boundary, geom, bdr_elem_vtx, bdr_attr); }
1183 
1184  /// @}
1185 
1186  /// @name Access information concerning individual mesh entites
1187  /// @{
1188 
1189  /// Return the attribute of element i.
1190  int GetAttribute(int i) const { return elements[i]->GetAttribute(); }
1191 
1192  /// Set the attribute of element i.
1193  void SetAttribute(int i, int attr) { elements[i]->SetAttribute(attr); }
1194 
1195  /// Return the attribute of boundary element i.
1196  int GetBdrAttribute(int i) const { return boundary[i]->GetAttribute(); }
1197 
1198  /// Set the attribute of boundary element i.
1199  void SetBdrAttribute(int i, int attr) { boundary[i]->SetAttribute(attr); }
1200 
1201  /// Return the attribute of patch i, for a NURBS mesh.
1202  int GetPatchAttribute(int i) const;
1203 
1204  /// Set the attribute of patch i, for a NURBS mesh.
1205  void SetPatchAttribute(int i, int attr);
1206 
1207  /// Return the attribute of patch boundary element i, for a NURBS mesh.
1208  int GetPatchBdrAttribute(int i) const;
1209 
1210  /// Set the attribute of patch boundary element i, for a NURBS mesh.
1211  void SetPatchBdrAttribute(int i, int attr);
1212 
1213  /// Returns the type of element i.
1214  Element::Type GetElementType(int i) const;
1215 
1216  /// Returns the type of boundary element i.
1217  Element::Type GetBdrElementType(int i) const;
1218 
1219  /// Deprecated in favor of Mesh::GetFaceGeometry
1220  MFEM_DEPRECATED Geometry::Type GetFaceGeometryType(int Face) const
1221  { return GetFaceGeometry(Face); }
1222 
1223  Element::Type GetFaceElementType(int Face) const;
1224 
1225  /// Return the Geometry::Type associated with face @a i.
1226  Geometry::Type GetFaceGeometry(int i) const;
1227 
1229  {
1230  return elements[i]->GetGeometryType();
1231  }
1232 
1234  {
1235  return boundary[i]->GetGeometryType();
1236  }
1237 
1238  /// Deprecated in favor of Mesh::GetFaceGeometry
1239  MFEM_DEPRECATED Geometry::Type GetFaceBaseGeometry(int i) const
1240  { return GetFaceGeometry(i); }
1241 
1243  { return GetElementGeometry(i); }
1244 
1246  { return GetBdrElementGeometry(i); }
1247 
1248  /// Return true if the given face is interior. @sa FaceIsTrueInterior().
1249  bool FaceIsInterior(int FaceNo) const
1250  {
1251  return (faces_info[FaceNo].Elem2No >= 0);
1252  }
1253 
1254  /** @brief Get the size of the i-th element relative to the perfect
1255  reference element. */
1256  double GetElementSize(int i, int type = 0);
1257 
1258  double GetElementSize(int i, const Vector &dir);
1259 
1260  double GetElementVolume(int i);
1261 
1262  void GetElementCenter(int i, Vector &center);
1263 
1264  /** Compute the Jacobian of the transformation from the perfect
1265  reference element at the given integration point (defaults to the
1266  center of the element if no integration point is specified) */
1267  void GetElementJacobian(int i, DenseMatrix &J,
1268  const IntegrationPoint *ip = NULL);
1269 
1270  /// @}
1271 
1272  /// List of mesh geometries stored as Array<Geometry::Type>.
1273  class GeometryList : public Array<Geometry::Type>
1274  {
1275  protected:
1277  public:
1278  /// Construct a GeometryList of all element geometries in @a mesh.
1280  : Array<Geometry::Type>(geom_buf, Geometry::NumGeom)
1281  { mesh.GetGeometries(mesh.Dimension(), *this); }
1282  /** @brief Construct a GeometryList of all geometries of dimension @a dim
1283  in @a mesh. */
1284  GeometryList(Mesh &mesh, int dim)
1285  : Array<Geometry::Type>(geom_buf, Geometry::NumGeom)
1286  { mesh.GetGeometries(dim, *this); }
1287  };
1288 
1289  /// @name Access connectivity for individual mesh entites
1290  /// @{
1291 
1292  /// Returns the indices of the vertices of element i.
1293  void GetElementVertices(int i, Array<int> &v) const
1294  { elements[i]->GetVertices(v); }
1295 
1296  /// Returns the indices of the vertices of boundary element i.
1297  void GetBdrElementVertices(int i, Array<int> &v) const
1298  { boundary[i]->GetVertices(v); }
1299 
1300  /// Return the indices and the orientations of all edges of element i.
1301  void GetElementEdges(int i, Array<int> &edges, Array<int> &cor) const;
1302 
1303  /// Return the indices and the orientations of all edges of bdr element i.
1304  void GetBdrElementEdges(int i, Array<int> &edges, Array<int> &cor) const;
1305 
1306  /** Return the indices and the orientations of all edges of face i.
1307  Works for both 2D (face=edge) and 3D faces. */
1308  void GetFaceEdges(int i, Array<int> &edges, Array<int> &o) const;
1309 
1310  /// Returns the indices of the vertices of face i.
1311  void GetFaceVertices(int i, Array<int> &vert) const
1312  {
1313  if (Dim == 1)
1314  {
1315  vert.SetSize(1); vert[0] = i;
1316  }
1317  else
1318  {
1319  faces[i]->GetVertices(vert);
1320  }
1321  }
1322 
1323  /// Returns the indices of the vertices of edge i.
1324  void GetEdgeVertices(int i, Array<int> &vert) const;
1325 
1326  /// Return the indices and the orientations of all faces of element i.
1327  void GetElementFaces(int i, Array<int> &faces, Array<int> &ori) const;
1328 
1329  /** @brief Returns the sorted, unique indices of elements sharing a face with
1330  element @a elem, including @a elem. */
1331  Array<int> FindFaceNeighbors(const int elem) const;
1332 
1333  /// Return the index and the orientation of the face of bdr element i. (3D)
1334  void GetBdrElementFace(int i, int *f, int *o) const;
1335 
1336  /** Return the vertex index of boundary element i. (1D)
1337  Return the edge index of boundary element i. (2D)
1338  Return the face index of boundary element i. (3D) */
1339  int GetBdrElementEdgeIndex(int i) const;
1340 
1341  /** @brief For the given boundary element, bdr_el, return its adjacent
1342  element and its info, i.e. 64*local_bdr_index+bdr_orientation.
1343 
1344  The returned bdr_orientation is that of the boundary element relative to
1345  the respective face element.
1346 
1347  @sa GetBdrElementAdjacentElement2() */
1348  void GetBdrElementAdjacentElement(int bdr_el, int &el, int &info) const;
1349 
1350  /** @brief For the given boundary element, bdr_el, return its adjacent
1351  element and its info, i.e. 64*local_bdr_index+inverse_bdr_orientation.
1352 
1353  The returned inverse_bdr_orientation is the inverse of the orientation of
1354  the boundary element relative to the respective face element. In other
1355  words this is the orientation of the face element relative to the
1356  boundary element.
1357 
1358  @sa GetBdrElementAdjacentElement() */
1359  void GetBdrElementAdjacentElement2(int bdr_el, int &el, int &info) const;
1360 
1361  /// Return the local face index for the given boundary face.
1362  int GetBdrFace(int BdrElemNo) const;
1363 
1364  /// @}
1365 
1366  /// @name Access connectivity data
1367  /// @{
1368 
1369  /// The returned Table should be deleted by the caller
1371 
1372  /// Return the "face"-element Table. Here "face" refers to face (3D),
1373  /// edge (2D), or vertex (1D).
1374  /// The returned Table should be deleted by the caller.
1375  Table *GetFaceToElementTable() const;
1376 
1377  /// Returns the face-to-edge Table (3D)
1378  ///
1379  /// @note The returned object should NOT be deleted by the caller.
1380  Table *GetFaceEdgeTable() const;
1381 
1382  /// Returns the edge-to-vertex Table (3D)
1383  /// @note The returned object should NOT be deleted by the caller.
1384  Table *GetEdgeVertexTable() const;
1385 
1386  /** Return vertex to vertex table. The connections stored in the table
1387  are from smaller to bigger vertex index, i.e. if i<j and (i, j) is
1388  in the table, then (j, i) is not stored.
1389 
1390  @note This data is not stored internally as a Table. The Table passed as
1391  an argument is populated using the EdgeVertex Table (see GetEdgeVertexTable)
1392  if available or the element connectivity.
1393  */
1394  void GetVertexToVertexTable(DSTable &) const;
1395 
1396  const Table &ElementToElementTable();
1397 
1398  const Table &ElementToFaceTable() const;
1399 
1400  const Table &ElementToEdgeTable() const;
1401 
1402  Array<int> GetFaceToBdrElMap() const;
1403 
1404  ///@}
1405 
1406  /// @brief Return FiniteElement for reference element of the specified type
1407  ///
1408  /// @note The returned object is a pointer to a global object and
1409  /// should not be deleted by the caller.
1411 
1412  /// @anchor mfem_Mesh_elem_trans
1413  /// @name Access the coordinate transformation for individual elements
1414  ///
1415  /// See also the methods related to
1416  /// @ref mfem_Mesh_geom_factors "Geometric Factors" for accessing
1417  /// information cached at quadrature points.
1418  /// @{
1419 
1420  /// Builds the transformation defining the i-th element in @a ElTr.
1421  /// @a ElTr must be allocated in advance and will be owned by the caller.
1423 
1424  /// Returns a pointer to the transformation defining the i-th element.
1425  ///
1426  /// @note The returned object is owned by the class and is shared, i.e.,
1427  /// calling this function resets pointers obtained from previous calls.
1428  /// Also, this pointer should NOT be deleted by the caller.
1430 
1431  /// Builds the transformation defining the i-th element in @a ElTr
1432  /// assuming position of the vertices/nodes are given by @a nodes.
1433  /// @a ElTr must be allocated in advance and will be owned by the caller.
1434  void GetElementTransformation(int i, const Vector &nodes,
1436 
1437  /// Returns a pointer to the transformation defining the i-th boundary
1438  /// element.
1439  /// @note The returned object is owned by the class and is shared, i.e.,
1440  /// calling this function resets pointers obtained from previous calls.
1441  /// Also, the returned object should NOT be deleted by the caller.
1443 
1444  /// Builds the transformation defining the i-th boundary element in @a ElTr.
1445  /// @a ElTr must be allocated in advance and will be owned by the caller.
1447 
1448  /// Builds the transformation defining the i-th face element in @a FTr.
1449  /// @a FTr must be allocated in advance and will be owned by the caller.
1451 
1452  /** @brief A helper method that constructs a transformation from the
1453  reference space of a face to the reference space of an element. */
1454  /** The local index of the face as a face in the element and its orientation
1455  are given by the input parameter @a info, as @a info = 64*loc_face_idx +
1456  loc_face_orientation. */
1457  void GetLocalFaceTransformation(int face_type, int elem_type,
1459  int info);
1460 
1461  /// Returns a pointer to the transformation defining the given face element.
1462  /// @note The returned object is owned by the class and is shared, i.e.,
1463  /// calling this function resets pointers obtained from previous calls.
1464  /// Also, the returned object should NOT be deleted by the caller.
1466 
1467  /// Builds the transformation defining the i-th edge element in @a EdTr.
1468  /// @a EdTr must be allocated in advance and will be owned by the caller.
1470 
1471  /// Returns a pointer to the transformation defining the given edge element.
1472  /// @note The returned object is owned by the class and is shared, i.e.,
1473  /// calling this function resets pointers obtained from previous calls.
1474  /// Also, the returned object should NOT be deleted by the caller.
1476 
1477  /// Returns (a pointer to an object containing) the following data:
1478  ///
1479  /// 1) Elem1No - the index of the first element that contains this face this
1480  /// is the element that has the same outward unit normal vector as the
1481  /// face;
1482  ///
1483  /// 2) Elem2No - the index of the second element that contains this face this
1484  /// element has outward unit normal vector as the face multiplied with -1;
1485  ///
1486  /// 3) Elem1, Elem2 - pointers to the ElementTransformation's of the first
1487  /// and the second element respectively;
1488  ///
1489  /// 4) Face - pointer to the ElementTransformation of the face;
1490  ///
1491  /// 5) Loc1, Loc2 - IntegrationPointTransformation's mapping the face
1492  /// coordinate system to the element coordinate system (both in their
1493  /// reference elements). Used to transform IntegrationPoints from face to
1494  /// element. More formally, let:
1495  /// TL1, TL2 be the transformations represented by Loc1, Loc2,
1496  /// TE1, TE2 - the transformations represented by Elem1, Elem2,
1497  /// TF - the transformation represented by Face, then
1498  /// TF(x) = TE1(TL1(x)) = TE2(TL2(x)) for all x in the reference face.
1499  ///
1500  /// 6) FaceGeom - the base geometry for the face.
1501  ///
1502  /// The mask specifies which fields in the structure to return:
1503  /// mask & 1 - Elem1, mask & 2 - Elem2
1504  /// mask & 4 - Loc1, mask & 8 - Loc2, mask & 16 - Face.
1505  /// These mask values are defined in the ConfigMasks enum type as part of the
1506  /// FaceElementTransformations class in fem/eltrans.hpp.
1507  ///
1508  /// @note The returned object is owned by the class and is shared, i.e.,
1509  /// calling this function resets pointers obtained from previous calls.
1510  /// Also, this pointer should NOT be deleted by the caller.
1512  int FaceNo,
1513  int mask = 31);
1514 
1515  /// See GetFaceElementTransformations().
1516  /// @note The returned object should NOT be deleted by the caller.
1518  {
1519  if (faces_info[FaceNo].Elem2No < 0) { return NULL; }
1520  return GetFaceElementTransformations (FaceNo);
1521  }
1522 
1523  /// Builds the transformation defining the given boundary face.
1524  /// @note The returned object should NOT be deleted by the caller.
1526 
1527  /// @}
1528 
1529  /// @anchor mfem_Mesh_geom_factors
1530  /// @name Access the coordinate transformation at quadrature points
1531  ///
1532  /// See also methods related to
1533  /// @ref mfem_Mesh_elem_trans "Element-wise coordinate transformation".
1534  /// @{
1535 
1536  /** @brief Return the mesh geometric factors corresponding to the given
1537  integration rule.
1538 
1539  The IntegrationRule used with GetGeometricFactors needs to remain valid
1540  until the internally stored GeometricFactors objects are destroyed (by
1541  calling Mesh::DeleteGeometricFactors(), Mesh::NodesUpdated(), or the Mesh
1542  destructor).
1543 
1544  If the device MemoryType parameter @a d_mt is specified, then the
1545  returned object will use that type unless it was previously allocated
1546  with a different type.
1547 
1548  The returned pointer points to an internal object that may be invalidated
1549  by mesh operations such as refinement, vertex/node movement, etc. Since
1550  not all such modifications can be tracked by the Mesh class (e.g. when
1551  using the pointer returned by GetNodes() to change the nodes) one needs
1552  to account for such changes by calling the method NodesUpdated() which,
1553  in particular, will call DeleteGeometricFactors(). */
1555  const IntegrationRule& ir,
1556  const int flags,
1558 
1559  /** @brief Return the mesh geometric factors for the faces corresponding
1560  to the given integration rule.
1561 
1562  The IntegrationRule used with GetFaceGeometricFactors needs to remain
1563  valid until the internally stored FaceGeometricFactors objects are
1564  destroyed (by either calling Mesh::DeleteGeometricFactors(),
1565  Mesh::NodesUpdated(), or the Mesh destructor).
1566 
1567  If the device MemoryType parameter @a d_mt is specified, then the
1568  returned object will use that type unless it was previously allocated
1569  with a different type.
1570 
1571  The returned pointer points to an internal object that may be invalidated
1572  by mesh operations such as refinement, vertex/node movement, etc. Since
1573  not all such modifications can be tracked by the Mesh class (e.g. when
1574  using the pointer returned by GetNodes() to change the nodes) one needs
1575  to account for such changes by calling the method NodesUpdated() which,
1576  in particular, will call DeleteGeometricFactors(). */
1578  const IntegrationRule& ir,
1579  const int flags,
1580  FaceType type,
1582 
1583  /// Destroy all GeometricFactors stored by the Mesh.
1584  /** This method can be used to force recomputation of the GeometricFactors,
1585  for example, after the mesh nodes are modified externally.
1586 
1587  @note In general, the preferred method for resetting the GeometricFactors
1588  should be to call NodesUpdated(). */
1589  void DeleteGeometricFactors();
1590 
1591  /// @}
1592 
1593  /** This enumerated type describes the three main face topologies:
1594  - Boundary, for faces on the boundary of the computational domain,
1595  - Conforming, for conforming faces interior to the computational domain,
1596  - Nonconforming, for nonconforming faces interior to the computational
1597  domain. */
1598  enum class FaceTopology { Boundary,
1599  Conforming,
1600  Nonconforming,
1601  NA
1602  };
1603 
1604  /** This enumerated type describes the location of the two elements sharing a
1605  face, Local meaning that the element is local to the MPI rank, FaceNbr
1606  meaning that the element is distributed on a different MPI rank, this
1607  typically means that methods with FaceNbr should be used to access the
1608  relevant information, e.g., ParFiniteElementSpace::GetFaceNbrElementVDofs.
1609  */
1610  enum class ElementLocation { Local, FaceNbr, NA };
1611 
1612  /** This enumerated type describes the topological relation of an element to
1613  a face:
1614  - Coincident meaning that the element's face is topologically equal to
1615  the mesh face.
1616  - Superset meaning that the element's face is topologically coarser than
1617  the mesh face, i.e., the element's face contains the mesh face.
1618  - Subset meaning that the element's face is topologically finer than the
1619  mesh face, i.e., the element's face is contained in the mesh face.
1620  Superset and Subset are only relevant for nonconforming faces.
1621  Master nonconforming faces have a conforming element on one side, and a
1622  fine element on the other side. Slave nonconforming faces have a
1623  conforming element on one side, and a coarse element on the other side.
1624  */
1626 
1627  /** This enumerated type describes the corresponding FaceInfo internal
1628  representation (encoded cases), c.f. FaceInfo's documentation:
1629  Classification of a local (non-ghost) face based on its FaceInfo:
1630  - Elem2No >= 0 --> local interior face; can be either:
1631  - NCFace == -1 --> LocalConforming,
1632  - NCFace >= 0 --> LocalSlaveNonconforming,
1633  - Elem2No < 0 --> local "boundary" face; can be one of:
1634  - NCFace == -1 --> conforming face; can be either:
1635  - Elem2Inf < 0 --> Boundary,
1636  - Elem2Inf >= 0 --> SharedConforming,
1637  - NCFace >= 0 --> nonconforming face; can be one of:
1638  - Elem2Inf < 0 --> MasterNonconforming (shared or not shared),
1639  - Elem2Inf >= 0 --> SharedSlaveNonconforming.
1640  Classification of a ghost (non-local) face based on its FaceInfo:
1641  - Elem1No == -1 --> GhostMaster (includes other unused ghost faces),
1642  - Elem1No >= 0 --> GhostSlave.
1643  */
1644  enum class FaceInfoTag { Boundary,
1650  GhostSlave,
1651  GhostMaster
1652  };
1653 
1654  /** @brief This structure is used as a human readable output format that
1655  decipheres the information contained in Mesh::FaceInfo when using the
1656  Mesh::GetFaceInformation() method.
1657 
1658  The element indices in this structure don't need further processing,
1659  contrary to the ones obtained through Mesh::GetFacesElements and can
1660  directly be used, e.g., Elem1 and Elem2 indices.
1661  Likewise the orientations for Elem1 and Elem2 already take into account
1662  special cases and can be used as is.
1663  */
1665  {
1667 
1668  struct
1669  {
1672  int index;
1675  } element[2];
1676 
1678  int ncface;
1680 
1681  /** @brief Return true if the face is a local interior face which is NOT
1682  a master nonconforming face. */
1683  bool IsLocal() const
1684  {
1685  return element[1].location == Mesh::ElementLocation::Local;
1686  }
1687 
1688  /** @brief Return true if the face is a shared interior face which is NOT
1689  a master nonconforming face. */
1690  bool IsShared() const
1691  {
1692  return element[1].location == Mesh::ElementLocation::FaceNbr;
1693  }
1694 
1695  /** @brief return true if the face is an interior face to the computation
1696  domain, either a local or shared interior face (not a boundary face)
1697  which is NOT a master nonconforming face.
1698  */
1699  bool IsInterior() const
1700  {
1701  return topology == FaceTopology::Conforming ||
1703  }
1704 
1705  /** @brief Return true if the face is a boundary face. */
1706  bool IsBoundary() const
1707  {
1708  return topology == FaceTopology::Boundary;
1709  }
1710 
1711  /// @brief Return true if the face is of the same type as @a type.
1712  bool IsOfFaceType(FaceType type) const
1713  {
1714  switch (type)
1715  {
1716  case FaceType::Interior:
1717  return IsInterior();
1718  case FaceType::Boundary:
1719  return IsBoundary();
1720  default:
1721  return false;
1722  }
1723  }
1724 
1725  /// @brief Return true if the face is a conforming face.
1726  bool IsConforming() const
1727  {
1729  }
1730 
1731  /// @brief Return true if the face is a nonconforming fine face.
1732  bool IsNonconformingFine() const
1733  {
1735  (element[0].conformity == ElementConformity::Superset ||
1736  element[1].conformity == ElementConformity::Superset);
1737  }
1738 
1739  /// @brief Return true if the face is a nonconforming coarse face.
1740  /** Note that ghost nonconforming master faces cannot be clearly
1741  identified as such with the currently available information, so this
1742  method will return false for such faces. */
1744  {
1746  element[1].conformity == ElementConformity::Subset;
1747  }
1748 
1749  /// @brief cast operator from FaceInformation to FaceInfo.
1750  operator Mesh::FaceInfo() const;
1751  };
1752 
1753  /// @name More advanced entity information access methods
1754  /// @{
1755 
1756  /* Return point matrix of element i of dimension Dim X #v, where for every
1757  vertex we give its coordinates in space of dimension Dim. */
1758  void GetPointMatrix(int i, DenseMatrix &pointmat) const;
1759 
1760  /* Return point matrix of boundary element i of dimension Dim X #v, where for
1761  every vertex we give its coordinates in space of dimension Dim. */
1762  void GetBdrPointMatrix(int i, DenseMatrix &pointmat) const;
1763 
1764  /** This method aims to provide face information in a deciphered format, i.e.
1765  Mesh::FaceInformation, compared to the raw encoded information returned
1766  by Mesh::GetFaceElements() and Mesh::GetFaceInfos(). */
1767  FaceInformation GetFaceInformation(int f) const;
1768 
1769  void GetFaceElements (int Face, int *Elem1, int *Elem2) const;
1770  void GetFaceInfos (int Face, int *Inf1, int *Inf2) const;
1771  void GetFaceInfos (int Face, int *Inf1, int *Inf2, int *NCFace) const;
1772 
1773  /// @}
1774 
1775  /// @name Methods related to mesh partitioning
1776  /// @{
1777 
1778  /// @note The returned array should be deleted by the caller.
1779  int *CartesianPartitioning(int nxyz[]);
1780  /// @note The returned array should be deleted by the caller.
1781  int *GeneratePartitioning(int nparts, int part_method = 1);
1782  /// @todo This method needs a proper description
1783  void CheckPartitioning(int *partitioning_);
1784 
1785  /// @}
1786 
1787  /// @anchor mfem_Mesh_trans
1788  /// @name Methods related to accessing/altering mesh coordinates
1789  ///
1790  /// See also @ref mfem_Mesh_gf_nodes "Coordinates as a GridFunction".
1791  /// @{
1792 
1793  // Vertices are only at the corners of elements, where you would expect them
1794  // in the lowest-order mesh.
1795  void MoveVertices(const Vector &displacements);
1796  void GetVertices(Vector &vert_coord) const;
1797  void SetVertices(const Vector &vert_coord);
1798 
1799  /** @brief Set the internal Vertex array to point to the given @a vertices
1800  array without assuming ownership of the pointer. */
1801  /** If @a zerocopy is `true`, the vertices must be given as an array of 3
1802  doubles per vertex. If @a zerocopy is `false` then the current Vertex
1803  data is first copied to the @a vertices array. */
1804  void ChangeVertexDataOwnership(double *vertices, int len_vertices,
1805  bool zerocopy = false);
1806 
1807  // Nodes are only active for higher order meshes, and share locations with
1808  // the vertices, plus all the higher- order control points within the element
1809  // and along the edges and on the faces.
1810  void GetNode(int i, double *coord) const;
1811  void SetNode(int i, const double *coord);
1812 
1813  // Node operations for curved mesh.
1814  // They call the corresponding '...Vertices' method if the
1815  // mesh is not curved (i.e. Nodes == NULL).
1816  void MoveNodes(const Vector &displacements);
1817  void GetNodes(Vector &node_coord) const;
1818  /// Updates the vertex/node locations. Invokes NodesUpdated().
1819  void SetNodes(const Vector &node_coord);
1820 
1821  void ScaleSubdomains (double sf);
1822  void ScaleElements (double sf);
1823 
1824  void Transform(void (*f)(const Vector&, Vector&));
1825  void Transform(VectorCoefficient &deformation);
1826 
1827  /** @brief This function should be called after the mesh node coordinates
1828  have been updated externally, e.g. by modifying the internal nodal
1829  GridFunction returned by GetNodes(). */
1830  /** It deletes internal quantities derived from the node coordinates,
1831  such as the (Face)GeometricFactors.
1832 
1833  @note Unlike the similarly named protected method UpdateNodes() this
1834  method does not modify the nodes. */
1836 
1837  /// @}
1838 
1839  /// @anchor mfem_Mesh_gf_nodes
1840  /// @name Methods related to nodal coordinates stored as a GridFunction
1841  ///
1842  /// See also @ref mfem_Mesh_trans "Mesh Transformations".
1843  /// @{
1844 
1845  /// @brief Return a pointer to the internal node GridFunction (may be NULL).
1846  ///
1847  /// If the mesh is straight-sided (low-order), it may not have a GridFunction
1848  /// for the nodes, in which case this function returns NULL. To ensure that
1849  /// the nodal GridFunction exists, first call EnsureNodes().
1850  /// @sa SetCurvature().
1851  ///
1852  /// @note The returned object should NOT be deleted by the caller.
1853  GridFunction *GetNodes() { return Nodes; }
1854  const GridFunction *GetNodes() const { return Nodes; }
1855  /// Return the mesh nodes ownership flag.
1856  bool OwnsNodes() const { return own_nodes; }
1857  /// Set the mesh nodes ownership flag.
1858  void SetNodesOwner(bool nodes_owner) { own_nodes = nodes_owner; }
1859  /// Replace the internal node GridFunction with the given GridFunction.
1860  /** Invokes NodesUpdated(). */
1861  void NewNodes(GridFunction &nodes, bool make_owner = false);
1862  /** @brief Swap the internal node GridFunction pointer and ownership flag
1863  members with the given ones. */
1864  /** Invokes NodesUpdated(). */
1865  void SwapNodes(GridFunction *&nodes, int &own_nodes_);
1866 
1867  /// Return the mesh nodes/vertices projected on the given GridFunction.
1868  void GetNodes(GridFunction &nodes) const;
1869  /** Replace the internal node GridFunction with a new GridFunction defined
1870  on the given FiniteElementSpace. The new node coordinates are projected
1871  (derived) from the current nodes/vertices. */
1872  virtual void SetNodalFESpace(FiniteElementSpace *nfes);
1873  /** Replace the internal node GridFunction with the given GridFunction. The
1874  given GridFunction is updated with node coordinates projected (derived)
1875  from the current nodes/vertices. */
1876  void SetNodalGridFunction(GridFunction *nodes, bool make_owner = false);
1877  /** Return the FiniteElementSpace on which the current mesh nodes are
1878  defined or NULL if the mesh does not have nodes. */
1879  const FiniteElementSpace *GetNodalFESpace() const;
1880  /** @brief Make sure that the mesh has valid nodes, i.e. its geometry is
1881  described by a vector finite element grid function (even if it is a
1882  low-order mesh with straight edges).
1883 
1884  @sa GetNodes(). */
1885  void EnsureNodes();
1886 
1887  /// Set the curvature of the mesh nodes using the given polynomial degree.
1888  /** Creates a nodal GridFunction if one doesn't already exist.
1889 
1890  @param[in] order Polynomial degree of the nodal FE space.
1891  @param[in] discont Whether to use a discontinuous or continuous
1892  finite element space (continuous is default).
1893  @param[in] space_dim The space dimension (optional).
1894  @param[in] ordering The Ordering of the finite element space
1895  (Ordering::byVDIM is the default). */
1896  virtual void SetCurvature(int order, bool discont = false, int space_dim = -1,
1897  int ordering = 1);
1898 
1899  /// @}
1900 
1901  /// @name Methods related to mesh refinement
1902  /// @{
1903 
1904  /// Refine all mesh elements.
1905  /** @param[in] ref_algo %Refinement algorithm. Currently used only for pure
1906  tetrahedral meshes. If set to zero (default), a tet mesh will be refined
1907  using algorithm A, that produces elements with better quality compared to
1908  algorithm B used when the parameter is non-zero.
1909 
1910  For tetrahedral meshes, after using algorithm A, the mesh cannot be
1911  refined locally using methods like GeneralRefinement() unless it is
1912  re-finalized using Finalize() with the parameter @a refine set to true.
1913  Note that calling Finalize() in this way will generally invalidate any
1914  FiniteElementSpace%s and GridFunction%s defined on the mesh. */
1915  void UniformRefinement(int ref_algo = 0);
1916 
1917  /** Refine selected mesh elements. Refinement type can be specified for each
1918  element. The function can do conforming refinement of triangles and
1919  tetrahedra and nonconforming refinement (i.e., with hanging-nodes) of
1920  triangles, quadrilaterals and hexahedra. If 'nonconforming' = -1,
1921  suitable refinement method is selected automatically (namely, conforming
1922  refinement for triangles). Use nonconforming = 0/1 to force the method.
1923  For nonconforming refinements, nc_limit optionally specifies the maximum
1924  level of hanging nodes (unlimited by default). */
1925  void GeneralRefinement(const Array<Refinement> &refinements,
1926  int nonconforming = -1, int nc_limit = 0);
1927 
1928  /** Simplified version of GeneralRefinement taking a simple list of elements
1929  to refine, without refinement types. */
1930  void GeneralRefinement(const Array<int> &el_to_refine,
1931  int nonconforming = -1, int nc_limit = 0);
1932 
1933  /// Refine each element with given probability. Uses GeneralRefinement.
1934  void RandomRefinement(double prob, bool aniso = false,
1935  int nonconforming = -1, int nc_limit = 0);
1936 
1937  /// Refine elements sharing the specified vertex. Uses GeneralRefinement.
1938  void RefineAtVertex(const Vertex& vert,
1939  double eps = 0.0, int nonconforming = -1);
1940 
1941  /** Refine element i if elem_error[i] > threshold, for all i.
1942  Returns true if at least one element was refined, false otherwise. */
1943  bool RefineByError(const Array<double> &elem_error, double threshold,
1944  int nonconforming = -1, int nc_limit = 0);
1945 
1946  /** Refine element i if elem_error(i) > threshold, for all i.
1947  Returns true if at least one element was refined, false otherwise. */
1948  bool RefineByError(const Vector &elem_error, double threshold,
1949  int nonconforming = -1, int nc_limit = 0);
1950 
1951  /** Derefine the mesh based on an error measure associated with each
1952  element. A derefinement is performed if the sum of errors of its fine
1953  elements is smaller than 'threshold'. If 'nc_limit' > 0, derefinements
1954  that would increase the maximum level of hanging nodes of the mesh are
1955  skipped. Returns true if the mesh changed, false otherwise. */
1956  bool DerefineByError(Array<double> &elem_error, double threshold,
1957  int nc_limit = 0, int op = 1);
1958 
1959  /// Same as DerefineByError for an error vector.
1960  bool DerefineByError(const Vector &elem_error, double threshold,
1961  int nc_limit = 0, int op = 1);
1962 
1963  /** Make sure that a quad/hex mesh is considered to be nonconforming (i.e.,
1964  has an associated NCMesh object). Simplex meshes can be both conforming
1965  (default) or nonconforming. */
1966  void EnsureNCMesh(bool simplices_nonconforming = false);
1967 
1968  bool Conforming() const { return ncmesh == NULL; }
1969  bool Nonconforming() const { return ncmesh != NULL; }
1970 
1971  /** Return fine element transformations following a mesh refinement.
1972  Space uses this to construct a global interpolation matrix. */
1974 
1975  /// Return type of last modification of the mesh.
1977 
1978  /** Return update counter. The counter starts at zero and is incremented
1979  each time refinement, derefinement, or rebalancing method is called.
1980  It is used for checking proper sequence of Space:: and GridFunction::
1981  Update() calls. */
1982  long GetSequence() const { return sequence; }
1983 
1984  /// @}
1985 
1986  ///@{ @name NURBS mesh refinement methods
1987  /** Refine a NURBS mesh with the knots specified in the file named @a ref_file.
1988  The file has the number of knot vectors on the first line. It is the same
1989  number of knot vectors specified in the NURBS mesh in the section edges. Then
1990  for each knot vector specified in the section edges (with the same ordering),
1991  a line describes (in this order): 1) an integer giving the number of knots
1992  inserted, 2) the knots inserted as a double. The advantage of this method
1993  is that it is possible to specifically refine a coarse NURBS mesh without
1994  changing the mesh file itself. Examples in miniapps/nurbs/meshes. */
1995  void RefineNURBSFromFile(std::string ref_file);
1996  void KnotInsert(Array<KnotVector *> &kv);
1997  void KnotInsert(Array<Vector *> &kv);
1998  /* For each knot vector:
1999  new_degree = max(old_degree, min(old_degree + rel_degree, degree)). */
2000  void DegreeElevate(int rel_degree, int degree = 16);
2001  ///@}
2002 
2003  /// @name Print/Save/Export methods
2004  /// @{
2005 
2006  /// Print the mesh to the given stream using Netgen/Truegrid format.
2007  virtual void PrintXG(std::ostream &os = mfem::out) const;
2008 
2009  /// Print the mesh to the given stream using the default MFEM mesh format.
2010  /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2011  virtual void Print(std::ostream &os = mfem::out) const { Printer(os); }
2012 
2013  /// Save the mesh to a file using Mesh::Print. The given @a precision will be
2014  /// used for ASCII output.
2015  virtual void Save(const std::string &fname, int precision=16) const;
2016 
2017  /// Print the mesh to the given stream using the adios2 bp format
2018 #ifdef MFEM_USE_ADIOS2
2019  virtual void Print(adios2stream &os) const;
2020 #endif
2021  /// Print the mesh in VTK format (linear and quadratic meshes only).
2022  /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2023  void PrintVTK(std::ostream &os);
2024  /** Print the mesh in VTK format. The parameter ref > 0 specifies an element
2025  subdivision number (useful for high order fields and curved meshes).
2026  If the optional field_data is set, we also add a FIELD section in the
2027  beginning of the file with additional dataset information. */
2028  /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2029  void PrintVTK(std::ostream &os, int ref, int field_data=0);
2030  /** Print the mesh in VTU format. The parameter ref > 0 specifies an element
2031  subdivision number (useful for high order fields and curved meshes).
2032  If @a bdr_elements is true, then output (only) the boundary elements,
2033  otherwise output only the non-boundary elements. */
2034  void PrintVTU(std::ostream &os,
2035  int ref=1,
2036  VTKFormat format=VTKFormat::ASCII,
2037  bool high_order_output=false,
2038  int compression_level=0,
2039  bool bdr_elements=false);
2040  /** Print the mesh in VTU format with file name fname. */
2041  virtual void PrintVTU(std::string fname,
2042  VTKFormat format=VTKFormat::ASCII,
2043  bool high_order_output=false,
2044  int compression_level=0,
2045  bool bdr=false);
2046  /** Print the boundary elements of the mesh in VTU format, and output the
2047  boundary attributes as a data array (useful for boundary conditions). */
2048  void PrintBdrVTU(std::string fname,
2049  VTKFormat format=VTKFormat::ASCII,
2050  bool high_order_output=false,
2051  int compression_level=0);
2052 
2053  /** @brief Prints the mesh with boundary elements given by the boundary of
2054  the subdomains, so that the boundary of subdomain i has boundary
2055  attribute i+1. */
2056  /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2057  void PrintWithPartitioning (int *partitioning,
2058  std::ostream &os, int elem_attr = 0) const;
2059 
2060  void PrintElementsWithPartitioning (int *partitioning,
2061  std::ostream &out,
2062  int interior_faces = 0);
2063 
2064  /// Print set of disjoint surfaces:
2065  /*!
2066  * If Aface_face(i,j) != 0, print face j as a boundary
2067  * element with attribute i+1.
2068  */
2069  void PrintSurfaces(const Table &Aface_face, std::ostream &out) const;
2070 
2071  /// Auxiliary method used by PrintCharacteristics().
2072  /** It is also used in the `mesh-explorer` miniapp. */
2073  static void PrintElementsByGeometry(int dim,
2074  const Array<int> &num_elems_by_geom,
2075  std::ostream &out);
2076 
2077  /** @brief Compute and print mesh characteristics such as number of vertices,
2078  number of elements, number of boundary elements, minimal and maximal
2079  element sizes, minimal and maximal element aspect ratios, etc. */
2080  /** If @a Vh or @a Vk are not NULL, return the element sizes and aspect
2081  ratios for all elements in the given Vector%s. */
2082  void PrintCharacteristics(Vector *Vh = NULL, Vector *Vk = NULL,
2083  std::ostream &os = mfem::out);
2084 
2085  /** @brief In serial, this method calls PrintCharacteristics(). In parallel,
2086  additional information about the parallel decomposition is also printed.
2087  */
2088  virtual void PrintInfo(std::ostream &os = mfem::out)
2089  {
2090  PrintCharacteristics(NULL, NULL, os);
2091  }
2092 
2093 #ifdef MFEM_DEBUG
2094  /// Output an NCMesh-compatible debug dump.
2095  void DebugDump(std::ostream &out) const;
2096 #endif
2097 
2098  /// @}
2099 
2100  /// @name Miscellaneous or undocumented methods
2101  /// @{
2102 
2103  /// @brief Creates a mapping @a v2v from the vertex indices of the mesh such
2104  /// that coincident vertices under the given @a translations are identified.
2105  /** Each Vector in @a translations should be of size @a sdim (the spatial
2106  dimension of the mesh). Two vertices are considered coincident if the
2107  translated coordinates of one vertex are within the given tolerance (@a
2108  tol, relative to the mesh diameter) of the coordinates of the other
2109  vertex.
2110  @warning This algorithm does not scale well with the number of boundary
2111  vertices in the mesh, and may run slowly on very large meshes. */
2112  std::vector<int> CreatePeriodicVertexMapping(
2113  const std::vector<Vector> &translations, double tol = 1e-8) const;
2114 
2115  /** @brief Find the ids of the elements that contain the given points, and
2116  their corresponding reference coordinates.
2117 
2118  The DenseMatrix @a point_mat describes the given points - one point for
2119  each column; it should have SpaceDimension() rows.
2120 
2121  The InverseElementTransformation object, @a inv_trans, is used to attempt
2122  the element transformation inversion. If NULL pointer is given, the
2123  method will use a default constructed InverseElementTransformation. Note
2124  that the algorithms in the base class InverseElementTransformation can be
2125  completely overwritten by deriving custom classes that override the
2126  Transform() method.
2127 
2128  If no element is found for the i-th point, elem_ids[i] is set to -1.
2129 
2130  In the ParMesh implementation, the @a point_mat is expected to be the
2131  same on all ranks. If the i-th point is found by multiple ranks, only one
2132  of them will mark that point as found, i.e. set its elem_ids[i] to a
2133  non-negative number; the other ranks will set their elem_ids[i] to -2 to
2134  indicate that the point was found but assigned to another rank.
2135 
2136  @returns The total number of points that were found.
2137 
2138  @note This method is not 100 percent reliable, i.e. it is not guaranteed
2139  to find a point, even if it lies inside a mesh element. */
2140  virtual int FindPoints(DenseMatrix& point_mat, Array<int>& elem_ids,
2141  Array<IntegrationPoint>& ips, bool warn = true,
2142  InverseElementTransformation *inv_trans = NULL);
2143 
2144  /** @brief Computes geometric parameters associated with a Jacobian matrix
2145  in 2D/3D. These parameters are
2146  (1) Area/Volume,
2147  (2) Aspect-ratio (1 in 2D, and 2 non-dimensional and 2 dimensional
2148  parameters in 3D. Dimensional parameters are used
2149  for target construction in TMOP),
2150  (3) skewness (1 in 2D and 3 in 3D), and finally
2151  (4) orientation (1 in 2D and 3 in 3D).
2152  */
2154  double &volume,
2155  Vector &aspr,
2156  Vector &skew,
2157  Vector &ori) const;
2158 
2159  /// Utility function: sum integers from all processors (Allreduce).
2160  virtual long long ReduceInt(int value) const { return value; }
2161 
2162  /// @todo This method needs a proper description
2163  void GetElementColoring(Array<int> &colors, int el0 = 0);
2164 
2165  /// @todo This method needs a proper description
2166  void MesquiteSmooth(const int mesquite_option = 0);
2167 
2168  /// @todo This method needs a proper description
2169  void CheckDisplacements(const Vector &displacements, double &tmax);
2170 
2171  /// @}
2172 };
2173 
2174 /** Overload operator<< for std::ostream and Mesh; valid also for the derived
2175  class ParMesh */
2176 std::ostream &operator<<(std::ostream &out, const Mesh &mesh);
2177 
2178 
2179 /** @brief Structure for storing mesh geometric factors: coordinates, Jacobians,
2180  and determinants of the Jacobians. */
2181 /** Typically objects of this type are constructed and owned by objects of class
2182  Mesh. See Mesh::GetGeometricFactors(). */
2184 {
2185 
2186 private:
2187  void Compute(const GridFunction &nodes,
2189 
2190 public:
2191  const Mesh *mesh;
2194 
2196  {
2197  COORDINATES = 1 << 0,
2198  JACOBIANS = 1 << 1,
2199  DETERMINANTS = 1 << 2,
2200  };
2201 
2202  GeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags,
2204 
2205  GeometricFactors(const GridFunction &nodes, const IntegrationRule &ir,
2206  int flags,
2208 
2209  /// Mapped (physical) coordinates of all quadrature points.
2210  /** This array uses a column-major layout with dimensions (NQ x SDIM x NE)
2211  where
2212  - NQ = number of quadrature points per element,
2213  - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
2214  - NE = number of elements in the mesh. */
2216 
2217  /// Jacobians of the element transformations at all quadrature points.
2218  /** This array uses a column-major layout with dimensions (NQ x SDIM x DIM x
2219  NE) where
2220  - NQ = number of quadrature points per element,
2221  - SDIM = space dimension of the mesh = mesh.SpaceDimension(),
2222  - DIM = dimension of the mesh = mesh.Dimension(), and
2223  - NE = number of elements in the mesh. */
2225 
2226  /// Determinants of the Jacobians at all quadrature points.
2227  /** This array uses a column-major layout with dimensions (NQ x NE) where
2228  - NQ = number of quadrature points per element, and
2229  - NE = number of elements in the mesh. */
2231 };
2232 
2233 /** @brief Structure for storing face geometric factors: coordinates, Jacobians,
2234  determinants of the Jacobians, and normal vectors. */
2235 /** Typically objects of this type are constructed and owned by objects of class
2236  Mesh. See Mesh::GetFaceGeometricFactors(). */
2238 {
2239 public:
2240  const Mesh *mesh;
2244 
2246  {
2247  COORDINATES = 1 << 0,
2248  JACOBIANS = 1 << 1,
2249  DETERMINANTS = 1 << 2,
2250  NORMALS = 1 << 3,
2251  };
2252 
2253  FaceGeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags,
2255 
2256  /// Mapped (physical) coordinates of all quadrature points.
2257  /** This array uses a column-major layout with dimensions (NQ x SDIM x NF)
2258  where
2259  - NQ = number of quadrature points per face,
2260  - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
2261  - NF = number of faces in the mesh. */
2263 
2264  /// Jacobians of the element transformations at all quadrature points.
2265  /** This array uses a column-major layout with dimensions (NQ x SDIM x DIM x
2266  NF) where
2267  - NQ = number of quadrature points per face,
2268  - SDIM = space dimension of the mesh = mesh.SpaceDimension(),
2269  - DIM = dimension of the mesh = mesh.Dimension(), and
2270  - NF = number of faces in the mesh. */
2272 
2273  /// Determinants of the Jacobians at all quadrature points.
2274  /** This array uses a column-major layout with dimensions (NQ x NF) where
2275  - NQ = number of quadrature points per face, and
2276  - NF = number of faces in the mesh. */
2278 
2279  /// Normals at all quadrature points.
2280  /** This array uses a column-major layout with dimensions (NQ x DIM x NF) where
2281  - NQ = number of quadrature points per face,
2282  - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
2283  - NF = number of faces in the mesh. */
2285 };
2286 
2287 /// Class used to extrude the nodes of a mesh
2289 {
2290 private:
2291  int n, layer;
2292  double p[2], s;
2293  Vector tip;
2294 public:
2295  NodeExtrudeCoefficient(const int dim, const int n_, const double s_);
2296  void SetLayer(const int l) { layer = l; }
2298  virtual void Eval(Vector &V, ElementTransformation &T,
2299  const IntegrationPoint &ip);
2301 };
2302 
2303 
2304 /// Extrude a 1D mesh
2305 Mesh *Extrude1D(Mesh *mesh, const int ny, const double sy,
2306  const bool closed = false);
2307 
2308 /// Extrude a 2D mesh
2309 Mesh *Extrude2D(Mesh *mesh, const int nz, const double sz);
2310 
2311 // shift cyclically 3 integers left-to-right
2312 inline void ShiftRight(int &a, int &b, int &c)
2313 {
2314  int t = a;
2315  a = c; c = b; b = t;
2316 }
2317 
2318 /// @brief Print function for Mesh::FaceInformation.
2319 std::ostream& operator<<(std::ostream& os, const Mesh::FaceInformation& info);
2320 
2321 }
2322 
2323 #endif
static Mesh MakePeriodic(const Mesh &orig_mesh, const std::vector< int > &v2v)
Create a periodic mesh by identifying vertices of orig_mesh.
Definition: mesh.cpp:4951
Abstract class for all finite elements.
Definition: fe_base.hpp:233
const IntegrationRule * IntRule
Definition: mesh.hpp:2241
MFEM_DEPRECATED Mesh(int n, double sx=1.0)
Deprecated: see MakeCartesian1D.
Definition: mesh.hpp:1004
void Loader(std::istream &input, int generate_edges=0, std::string parse_tag="")
Definition: mesh.cpp:4026
double GetGeckoElementOrdering(Array< int > &ordering, int iterations=4, int window=4, int period=2, int seed=0, bool verbose=false, double time_limit=0)
Definition: mesh.cpp:2050
Table * GetEdgeVertexTable() const
Definition: mesh.cpp:6419
Geometry::Constants< Geometry::PYRAMID > pyr_t
Definition: mesh.hpp:268
Array< int > GetFaceToBdrElMap() const
Definition: mesh.cpp:1445
static const int vtk_quadratic_hex[27]
Definition: mesh.hpp:251
int * CartesianPartitioning(int nxyz[])
Definition: mesh.cpp:7383
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:96
void SetPatchAttribute(int i, int attr)
Set the attribute of patch i, for a NURBS mesh.
Definition: mesh.cpp:2797
const FiniteElementSpace * GetNodalFESpace() const
Definition: mesh.cpp:5630
const DenseMatrix * PointMatrix
Definition: mesh.hpp:208
void ScaleElements(double sf)
Definition: mesh.cpp:11975
const GridFunction * GetNodes() const
Definition: mesh.hpp:1854
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
void GetElementEdges(int i, Array< int > &edges, Array< int > &cor) const
Return the indices and the orientations of all edges of element i.
Definition: mesh.cpp:6298
void ReadVTKMesh(std::istream &input, int &curved, int &read_gf, bool &finalize_topo)
void FreeElement(Element *E)
Definition: mesh.cpp:12291
int AddQuad(int v1, int v2, int v3, int v4, int attr=1)
Definition: mesh.cpp:1694
int CheckElementOrientation(bool fix_it=true)
Check (and optionally attempt to fix) the orientation of the elements.
Definition: mesh.cpp:5712
static bool remove_unused_vertices
Definition: mesh.hpp:286
void SetVertices(const Vector &vert_coord)
Definition: mesh.cpp:8242
static const int vtk_quadratic_tet[10]
Definition: mesh.hpp:248
void Make2D(int nx, int ny, Element::Type type, double sx, double sy, bool generate_edges, bool sfc_ordering)
Definition: mesh.cpp:3398
Vector J
Jacobians of the element transformations at all quadrature points.
Definition: mesh.hpp:2271
Vector X
Mapped (physical) coordinates of all quadrature points.
Definition: mesh.hpp:2215
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
Definition: mesh.cpp:12692
static Mesh MakeSimplicial(const Mesh &orig_mesh)
Definition: mesh.cpp:4622
Base class for vector Coefficients that optionally depend on time and space.
void UniformRefinement3D_base(Array< int > *f2qf=NULL, DSTable *v_to_v_p=NULL, bool update_nodes=true)
Definition: mesh.cpp:8559
const GeometricFactors * GetGeometricFactors(const IntegrationRule &ir, const int flags, MemoryType d_mt=MemoryType::DEFAULT)
Return the mesh geometric factors corresponding to the given integration rule.
Definition: mesh.cpp:847
int EulerNumber2D() const
Equals 1 - num_holes.
Definition: mesh.hpp:1029
Geometry::Type GetElementBaseGeometry(int i) const
Definition: mesh.hpp:1242
int GetBdrElementEdgeIndex(int i) const
Definition: mesh.cpp:6588
static void PrintElementsByGeometry(int dim, const Array< int > &num_elems_by_geom, std::ostream &out)
Auxiliary method used by PrintCharacteristics().
Definition: mesh.cpp:235
void AddHexAsTets(const int *vi, int attr=1)
Definition: mesh.cpp:1773
static const int NumGeom
Definition: geom.hpp:42
static int ComposeQuadOrientations(int ori_a_b, int ori_b_c)
Definition: mesh.cpp:5999
void AddHexAsWedges(const int *vi, int attr=1)
Definition: mesh.cpp:1792
virtual void PrintInfo(std::ostream &os=mfem::out)
In serial, this method calls PrintCharacteristics(). In parallel, additional information about the pa...
Definition: mesh.hpp:2088
const Table & ElementToFaceTable() const
Definition: mesh.cpp:6825
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
Array< Element * > boundary
Definition: mesh.hpp:91
Geometry::Constants< Geometry::SQUARE > quad_t
Definition: mesh.hpp:264
int Dimension() const
Dimension of the reference space used within the elements.
Definition: mesh.hpp:1020
int * GeneratePartitioning(int nparts, int part_method=1)
Definition: mesh.cpp:7427
CoarseFineTransformations CoarseFineTr
Definition: mesh.hpp:240
int own_nodes
Definition: mesh.hpp:246
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
Definition: mesh.cpp:5668
void MoveVertices(const Vector &displacements)
Definition: mesh.cpp:8222
bool HasGeometry(Geometry::Type geom) const
Return true iff the given geom is encountered in the mesh. Geometries of dimensions lower than Dimens...
Definition: mesh.hpp:1054
static Mesh LoadFromFile(const std::string &filename, int generate_edges=0, int refine=1, bool fix_orientation=true)
Definition: mesh.cpp:3755
IsoparametricTransformation Transformation
Definition: mesh.hpp:234
void GetLocalPtToSegTransformation(IsoparametricTransformation &, int)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:648
void GetCharacteristics(double &h_min, double &h_max, double &kappa_min, double &kappa_max, Vector *Vh=NULL, Vector *Vk=NULL)
Definition: mesh.cpp:200
static FiniteElement * GetTransformationFEforElementType(Element::Type)
Return FiniteElement for reference element of the specified type.
Definition: mesh.cpp:334
FaceGeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags, FaceType type, MemoryType d_mt=MemoryType::DEFAULT)
Definition: mesh.cpp:12625
static Mesh MakeCartesian3D(int nx, int ny, int nz, Element::Type type, double sx=1.0, double sy=1.0, double sz=1.0, bool sfc_ordering=true)
Definition: mesh.cpp:3783
void NewNodes(GridFunction &nodes, bool make_owner=false)
Replace the internal node GridFunction with the given GridFunction.
Definition: mesh.cpp:8329
int NumOfEdges
Definition: mesh.hpp:70
virtual void UniformRefinement2D()
Refine a mixed 2D mesh uniformly.
Definition: mesh.hpp:400
void SwapNodes(GridFunction *&nodes, int &own_nodes_)
Swap the internal node GridFunction pointer and ownership flag members with the given ones...
Definition: mesh.cpp:8351
Element::Type GetBdrElementType(int i) const
Returns the type of boundary element i.
Definition: mesh.cpp:6649
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
Definition: mesh.cpp:136
Geometry::Type GetFaceGeometry(int i) const
Return the Geometry::Type associated with face i.
Definition: mesh.cpp:1421
static int InvertTriOrientation(int ori)
Definition: mesh.cpp:5945
bool FaceIsInterior(int FaceNo) const
Return true if the given face is interior.
Definition: mesh.hpp:1249
void ReadNetgen2DMesh(std::istream &input, int &curved)
void ShiftRight(int &a, int &b, int &c)
Definition: mesh.hpp:2312
void GetVertexToVertexTable(DSTable &) const
Definition: mesh.cpp:6725
static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type)
Create a refined (by any factor) version of orig_mesh.
Definition: mesh.cpp:3793
A specialized ElementTransformation class representing a face and its two neighboring elements...
Definition: eltrans.hpp:480
void CreateVTKMesh(const Vector &points, const Array< int > &cell_data, const Array< int > &cell_offsets, const Array< int > &cell_types, const Array< int > &cell_attributes, int &curved, int &read_gf, bool &finalize_topo)
long GetSequence() const
Definition: mesh.hpp:1982
int AddTriangle(int v1, int v2, int v3, int attr=1)
Definition: mesh.cpp:1680
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition: mesh.hpp:2277
bool Nonconforming() const
Definition: mesh.hpp:1969
int AddBdrPoint(int v, int attr=1)
Definition: mesh.cpp:1900
void DeleteTables()
Definition: mesh.hpp:295
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
GridFunction * Nodes
Definition: mesh.hpp:245
int NumOfElements
Definition: mesh.hpp:69
void GetBdrElementVertices(int i, Array< int > &v) const
Returns the indices of the vertices of boundary element i.
Definition: mesh.hpp:1297
Mesh * Extrude1D(Mesh *mesh, const int ny, const double sy, const bool closed)
Extrude a 1D mesh.
Definition: mesh.cpp:12710
void Transform(void(*f)(const Vector &, Vector &))
Definition: mesh.cpp:12045
bool IsSlaveFace(const FaceInfo &fi) const
Definition: mesh.cpp:1058
void FinalizeCheck()
Definition: mesh.cpp:1945
void ApplyLocalSlaveTransformation(FaceElementTransformations &FT, const FaceInfo &fi, bool is_ghost)
Definition: mesh.cpp:1063
void GetElementJacobian(int i, DenseMatrix &J, const IntegrationPoint *ip=NULL)
Definition: mesh.cpp:60
void AverageVertices(const int *indexes, int n, int result)
Averages the vertices with given indexes and saves the result in vertices[result].
Definition: mesh.cpp:8364
void FinalizeWedgeMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a wedge Mesh.
Definition: mesh.cpp:2873
Element * GetElement(int i)
Return pointer to the i&#39;th element object.
Definition: mesh.hpp:1150
virtual void Save(const std::string &fname, int precision=16) const
Definition: mesh.cpp:10705
void GenerateBoundaryElements()
Definition: mesh.cpp:1907
void GetElementData(const Array< Element *> &elem_array, int geom, Array< int > &elem_vtx, Array< int > &attr) const
Definition: mesh.cpp:9756
int GetNEdges() const
Return the number of edges.
Definition: mesh.hpp:1092
const Element * GetElement(int i) const
Return pointer to the i&#39;th element object.
Definition: mesh.hpp:1143
void PrintCharacteristics(Vector *Vh=NULL, Vector *Vk=NULL, std::ostream &os=mfem::out)
Compute and print mesh characteristics such as number of vertices, number of elements, number of boundary elements, minimal and maximal element sizes, minimal and maximal element aspect ratios, etc.
Definition: mesh.cpp:249
Structure for storing mesh geometric factors: coordinates, Jacobians, and determinants of the Jacobia...
Definition: mesh.hpp:2183
NodeExtrudeCoefficient(const int dim, const int n_, const double s_)
Definition: mesh.cpp:12686
Data type for vertex.
Definition: vertex.hpp:22
void SetMeshGen()
Determine the mesh generator bitmask meshgen, see MeshGenerator().
Definition: mesh.cpp:3973
bool IsNonconformingFine() const
Return true if the face is a nonconforming fine face.
Definition: mesh.hpp:1732
static int GetQuadOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition: mesh.cpp:5951
void ReadNetgen3DMesh(std::istream &input)
Data arrays will be written in ASCII format.
The inverse transformation of a given ElementTransformation.
Definition: eltrans.hpp:185
const Element *const * GetElementsArray() const
Definition: mesh.hpp:1174
void ReadInlineMesh(std::istream &input, bool generate_edges=false)
FaceElementTransformations * GetInteriorFaceTransformations(int FaceNo)
Definition: mesh.hpp:1517
ElementLocation
Definition: mesh.hpp:1610
void RemoveInternalBoundaries()
Definition: mesh.cpp:12203
ElementConformity
Definition: mesh.hpp:1625
Mesh * Extrude2D(Mesh *mesh, const int nz, const double sz)
Extrude a 2D mesh.
Definition: mesh.cpp:12870
virtual FaceElementTransformations * GetFaceElementTransformations(int FaceNo, int mask=31)
Definition: mesh.cpp:968
void SetEmpty()
Definition: mesh.cpp:1481
Array< Element * > faces
Definition: mesh.hpp:92
std::vector< int > CreatePeriodicVertexMapping(const std::vector< Vector > &translations, double tol=1e-8) const
Creates a mapping v2v from the vertex indices of the mesh such that coincident vertices under the giv...
Definition: mesh.cpp:4985
void FinalizeHexMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a hexahedral Mesh.
Definition: mesh.cpp:2908
void GetPointMatrix(int i, DenseMatrix &pointmat) const
Definition: mesh.cpp:6654
int GetNBE() const
Returns number of boundary elements.
Definition: mesh.hpp:1089
void RedRefinement(int i, const DSTable &v_to_v, int *edge1, int *edge2, int *middle)
Definition: mesh.hpp:355
Operation last_operation
Definition: mesh.hpp:289
void MarkTriMeshForRefinement()
Definition: mesh.cpp:2438
void ReadCubit(const char *filename, int &curved, int &read_gf)
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition: mesh.cpp:6274
void InitRefinementTransforms()
Definition: mesh.cpp:10322
IsoparametricTransformation FaceTransformation
Definition: mesh.hpp:236
void UniformRefinement2D_base(bool update_nodes=true)
Definition: mesh.cpp:8400
Array< FaceGeometricFactors * > face_geom_factors
Definition: mesh.hpp:280
Array< NCFaceInfo > nc_faces_info
Definition: mesh.hpp:218
Element * ReadElement(std::istream &)
Definition: mesh.cpp:3955
void GetLocalTriToPyrTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:753
A parallel extension of the NCMesh class.
Definition: pncmesh.hpp:64
Element * NewElement(int geom)
Definition: mesh.cpp:3901
FaceElementTransformations FaceElemTr
Definition: mesh.hpp:237
Table * el_to_face
Definition: mesh.hpp:221
void GetEdgeTransformation(int i, IsoparametricTransformation *EdTr)
Definition: mesh.cpp:581
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
Definition: mesh.cpp:1402
void MarkForRefinement()
Definition: mesh.cpp:2421
void SetVerticesFromNodes(const GridFunction *nodes)
Helper to set vertex coordinates given a high-order curvature function.
Definition: mesh.cpp:5654
Structure for storing face geometric factors: coordinates, Jacobians, determinants of the Jacobians...
Definition: mesh.hpp:2237
ElementTransformation * GetBdrElementTransformation(int i)
Definition: mesh.cpp:438
std::function< double(const Vector &)> f(double mass_coeff)
Definition: lor_mms.hpp:30
void DebugDump(std::ostream &out) const
Output an NCMesh-compatible debug dump.
Definition: mesh.cpp:13097
int AddBdrTriangle(int v1, int v2, int v3, int attr=1)
Definition: mesh.cpp:1857
void SetPatchBdrAttribute(int i, int attr)
Set the attribute of patch boundary element i, for a NURBS mesh.
Definition: mesh.cpp:2814
int GetNV() const
Returns number of vertices. Vertices are only at the corners of elements, where you would expect them...
Definition: mesh.hpp:1083
void MakeRefined_(Mesh &orig_mesh, const Array< int > ref_factors, int ref_type)
Internal function used in Mesh::MakeRefined.
Definition: mesh.cpp:4393
Geometry::Constants< Geometry::SEGMENT > seg_t
Definition: mesh.hpp:262
int GetAttribute(int i) const
Return the attribute of element i.
Definition: mesh.hpp:1190
bool IsLocal() const
Return true if the face is a local interior face which is NOT a master nonconforming face...
Definition: mesh.hpp:1683
void MesquiteSmooth(const int mesquite_option=0)
static int GetTetOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition: mesh.cpp:6030
void GetBdrElementAdjacentElement2(int bdr_el, int &el, int &info) const
For the given boundary element, bdr_el, return its adjacent element and its info, i...
Definition: mesh.cpp:6622
MFEM_DEPRECATED Mesh(int nx, int ny, int nz, Element::Type type, bool generate_edges=false, double sx=1.0, double sy=1.0, double sz=1.0, bool sfc_ordering=true)
Deprecated: see MakeCartesian3D.
Definition: mesh.hpp:985
int AddTri(const int *vi, int attr=1)
Definition: mesh.hpp:798
int AddVertex(double x, double y=0.0, double z=0.0)
Definition: mesh.cpp:1626
void GetBdrElementFace(int i, int *f, int *o) const
Return the index and the orientation of the face of bdr element i. (3D)
Definition: mesh.cpp:6565
Vector J
Jacobians of the element transformations at all quadrature points.
Definition: mesh.hpp:2224
FaceType
Definition: mesh.hpp:45
long long GetGlobalNE() const
Return the total (global) number of elements.
Definition: mesh.hpp:1115
void MoveNodes(const Vector &displacements)
Definition: mesh.cpp:8290
void GetEdgeOrdering(DSTable &v_to_v, Array< int > &order)
Definition: mesh.cpp:2453
void GetElementFaces(int i, Array< int > &faces, Array< int > &ori) const
Return the indices and the orientations of all faces of element i.
Definition: mesh.cpp:6514
NCFaceInfo(bool slave, int master, const DenseMatrix *pm)
Definition: mesh.hpp:213
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a triangular Mesh.
Definition: mesh.cpp:1959
double GetElementSize(ElementTransformation *T, int type=0)
Definition: mesh.cpp:83
void UpdateNURBS()
Definition: mesh.cpp:5221
Symmetric 3D Table stored as an array of rows each of which has a stack of column, floor, number nodes. The number of the node is assigned by counting the nodes from zero as they are pushed into the table. Diagonals of any kind are not allowed so the row, column and floor must all be different for each node. Only one node is stored for all 6 symmetric entries that are indexable by unique triplets of row, column, and floor.
Definition: stable3d.hpp:34
void GetVertices(Vector &vert_coord) const
Definition: mesh.cpp:8231
void PrintVTK(std::ostream &os)
Definition: mesh.cpp:10719
void FinalizeTetMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a tetrahedral Mesh.
Definition: mesh.cpp:2832
void AddBdrQuadAsTriangles(const int *vi, int attr=1)
Definition: mesh.cpp:1885
void Make3D(int nx, int ny, int nz, Element::Type type, double sx, double sy, double sz, bool sfc_ordering)
Definition: mesh.cpp:3117
void AddSegmentFaceElement(int lf, int gf, int el, int v0, int v1)
Definition: mesh.cpp:6875
virtual void SetAttributes()
Determine the sets of unique attribute values in domain and boundary elements.
Definition: mesh.cpp:1572
bool IsInterior() const
return true if the face is an interior face to the computation domain, either a local or shared inter...
Definition: mesh.hpp:1699
void EnsureNCMesh(bool simplices_nonconforming=false)
Definition: mesh.cpp:9888
GeometryList(Mesh &mesh, int dim)
Construct a GeometryList of all geometries of dimension dim in mesh.
Definition: mesh.hpp:1284
void GetNode(int i, double *coord) const
Definition: mesh.cpp:8251
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition: mesh.hpp:2230
void AddHexAsPyramids(const int *vi, int attr=1)
Definition: mesh.cpp:1810
int FindCoarseElement(int i)
Definition: mesh.cpp:10334
GeometryList(Mesh &mesh)
Construct a GeometryList of all element geometries in mesh.
Definition: mesh.hpp:1279
double b
Definition: lissajous.cpp:42
int AddTet(int v1, int v2, int v3, int v4, int attr=1)
Definition: mesh.cpp:1708
void GetFaceTransformation(int i, IsoparametricTransformation *FTr)
Definition: mesh.cpp:504
virtual void PrintXG(std::ostream &os=mfem::out) const
Print the mesh to the given stream using Netgen/Truegrid format.
Definition: mesh.cpp:10407
void GetLocalSegToTriTransformation(IsoparametricTransformation &loc, int i)
Definition: mesh.cpp:663
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition: mesh.cpp:10232
void AddQuadFaceElement(int lf, int gf, int el, int v0, int v1, int v2, int v3)
Definition: mesh.cpp:6940
void CheckPartitioning(int *partitioning_)
Definition: mesh.cpp:7827
void KnotInsert(Array< KnotVector *> &kv)
Definition: mesh.cpp:5147
void LoadPatchTopo(std::istream &input, Array< int > &edge_to_knot)
Read NURBS patch/macro-element mesh.
Definition: mesh.cpp:5282
void ReadGmshMesh(std::istream &input, int &curved, int &read_gf)
STable3D * GetElementToFaceTable(int ret_ftbl=0)
Definition: mesh.cpp:7192
bool Conforming() const
Definition: mesh.hpp:1968
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
Definition: mesh.cpp:5635
void GetEdgeVertices(int i, Array< int > &vert) const
Returns the indices of the vertices of edge i.
Definition: mesh.cpp:6382
int MeshGenerator()
Get the mesh generator/type.
Definition: mesh.hpp:1047
void GetFaceVertices(int i, Array< int > &vert) const
Returns the indices of the vertices of face i.
Definition: mesh.hpp:1311
Type
Constants for the classes derived from Element.
Definition: element.hpp:41
void InitTables()
Definition: mesh.cpp:1474
void CheckDisplacements(const Vector &displacements, double &tmax)
Definition: mesh.cpp:8145
This structure stores the low level information necessary to interpret the configuration of elements ...
Definition: mesh.hpp:153
const double * GetVertex(int i) const
Return pointer to vertex i&#39;s coordinates.
Definition: mesh.hpp:1125
VTKFormat
Data array format for VTK and VTU files.
Definition: vtk.hpp:98
void GetElementData(int geom, Array< int > &elem_vtx, Array< int > &attr) const
Definition: mesh.hpp:1177
int mesh_geoms
Definition: mesh.hpp:78
int AddBdrSegment(int v1, int v2, int attr=1)
Definition: mesh.cpp:1843
Geometry::Constants< Geometry::TETRAHEDRON > tet_t
Definition: mesh.hpp:265
void GetElementVertices(int i, Array< int > &v) const
Returns the indices of the vertices of element i.
Definition: mesh.hpp:1293
int AddElement(Element *elem)
Definition: mesh.cpp:1829
void ReadLineMesh(std::istream &input)
virtual void Load(std::istream &input, int generate_edges=0, int refine=1, bool fix_orientation=true)
Definition: mesh.hpp:666
void SetNodesOwner(bool nodes_owner)
Set the mesh nodes ownership flag.
Definition: mesh.hpp:1858
void GetGeometricParametersFromJacobian(const DenseMatrix &J, double &volume, Vector &aspr, Vector &skew, Vector &ori) const
Computes geometric parameters associated with a Jacobian matrix in 2D/3D. These parameters are (1) Ar...
Definition: mesh.cpp:12430
void SetLayer(const int l)
Definition: mesh.hpp:2296
Table * GetFaceToElementTable() const
Definition: mesh.cpp:6480
Array< int > FindFaceNeighbors(const int elem) const
Returns the sorted, unique indices of elements sharing a face with element elem, including elem...
Definition: mesh.cpp:6537
int GetElementToEdgeTable(Table &, Array< int > &)
Definition: mesh.cpp:6750
void GetHilbertElementOrdering(Array< int > &ordering)
Definition: mesh.cpp:2217
int nbBoundaryFaces
Definition: mesh.hpp:75
void RandomRefinement(double prob, bool aniso=false, int nonconforming=-1, int nc_limit=0)
Refine each element with given probability. Uses GeneralRefinement.
Definition: mesh.cpp:9912
void GetBdrElementEdges(int i, Array< int > &edges, Array< int > &cor) const
Return the indices and the orientations of all edges of bdr element i.
Definition: mesh.cpp:6320
void GetLocalQuadToHexTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:778
void ResetLazyData()
Definition: mesh.cpp:1561
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
Definition: mesh.cpp:1408
static const int vtk_quadratic_pyramid[13]
Definition: mesh.hpp:249
bool OwnsNodes() const
Return the mesh nodes ownership flag.
Definition: mesh.hpp:1856
void GetElementCenter(int i, Vector &center)
Definition: mesh.cpp:75
MFEM_DEPRECATED Geometry::Type GetFaceBaseGeometry(int i) const
Deprecated in favor of Mesh::GetFaceGeometry.
Definition: mesh.hpp:1239
IsoparametricTransformation BdrTransformation
Definition: mesh.hpp:235
void GetLocalFaceTransformation(int face_type, int elem_type, IsoparametricTransformation &Transf, int info)
A helper method that constructs a transformation from the reference space of a face to the reference ...
Definition: mesh.cpp:903
IsoparametricTransformation Transformation2
Definition: mesh.hpp:234
void Init()
Definition: mesh.cpp:1456
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
Definition: mesh.cpp:5577
Element * GetBdrElement(int i)
Return pointer to the i&#39;th boundary element object.
Definition: mesh.hpp:1165
Vector normal
Normals at all quadrature points.
Definition: mesh.hpp:2284
A class for non-conforming AMR. The class is not used directly by the user, rather it is an extension...
Definition: ncmesh.hpp:121
FaceElementTransformations * GetBdrFaceTransformations(int BdrElemNo)
Definition: mesh.cpp:1102
bool IsOfFaceType(FaceType type) const
Return true if the face is of the same type as type.
Definition: mesh.hpp:1712
Geometry::Constants< Geometry::PRISM > pri_t
Definition: mesh.hpp:267
struct mfem::Mesh::FaceInformation::@13 element[2]
virtual MFEM_DEPRECATED void ReorientTetMesh()
Definition: mesh.cpp:7321
prob_type prob
Definition: ex25.cpp:154
int NumOfBdrElements
Definition: mesh.hpp:69
Table * el_to_edge
Definition: mesh.hpp:220
int GetBdrFace(int BdrElemNo) const
Return the local face index for the given boundary face.
Definition: mesh.cpp:1120
void ReadMFEMMesh(std::istream &input, int version, int &curved)
virtual void LocalRefinement(const Array< int > &marked_el, int type=3)
This function is not public anymore. Use GeneralRefinement instead.
Definition: mesh.cpp:9266
Table * GetFaceEdgeTable() const
Definition: mesh.cpp:6391
Data type tetrahedron element.
Definition: tetrahedron.hpp:22
virtual void MarkTetMeshForRefinement(DSTable &v_to_v)
Definition: mesh.cpp:2478
bool IsConforming() const
Return true if the face is a conforming face.
Definition: mesh.hpp:1726
int GetPatchAttribute(int i) const
Return the attribute of patch i, for a NURBS mesh.
Definition: mesh.cpp:2808
Array< Triple< int, int, int > > tmp_vertex_parents
Definition: mesh.hpp:259
MFEM_DEPRECATED Mesh(int nx, int ny, Element::Type type, bool generate_edges=false, double sx=1.0, double sy=1.0, bool sfc_ordering=true)
Deprecated: see MakeCartesian2D.
Definition: mesh.hpp:995
List of mesh geometries stored as Array<Geometry::Type>.
Definition: mesh.hpp:1273
void Destroy()
Definition: mesh.cpp:1532
void PrintVTU(std::ostream &os, int ref=1, VTKFormat format=VTKFormat::ASCII, bool high_order_output=false, int compression_level=0, bool bdr_elements=false)
Definition: mesh.cpp:10919
This structure is used as a human readable output format that decipheres the information contained in...
Definition: mesh.hpp:1664
int CheckBdrElementOrientation(bool fix_it=true)
Check the orientation of the boundary elements.
Definition: mesh.cpp:6163
Geometry::Type GetElementGeometry(int i) const
Definition: mesh.hpp:1228
GeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags, MemoryType d_mt=MemoryType::DEFAULT)
Definition: mesh.cpp:12545
void PrintElementsWithPartitioning(int *partitioning, std::ostream &out, int interior_faces=0)
Definition: mesh.cpp:11465
int GetPatchBdrAttribute(int i) const
Return the attribute of patch boundary element i, for a NURBS mesh.
Definition: mesh.cpp:2826
int GetBdrAttribute(int i) const
Return the attribute of boundary element i.
Definition: mesh.hpp:1196
void GetLocalQuadToWdgTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:800
void AddPointFaceElement(int lf, int gf, int el)
Used in GenerateFaces()
Definition: mesh.cpp:6843
void Make1D(int n, double sx=1.0)
Creates a 1D mesh for the interval [0,sx] divided into n equal intervals.
Definition: mesh.cpp:3576
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition: mesh.hpp:275
virtual void NonconformingRefinement(const Array< Refinement > &refinements, int nc_limit=0)
This function is not public anymore. Use GeneralRefinement instead.
Definition: mesh.cpp:9508
virtual ~Mesh()
Destroys Mesh.
Definition: mesh.hpp:681
void FinalizeMesh(int refine=0, bool fix_orientation=true)
Finalize the construction of any type of Mesh.
Definition: mesh.cpp:2938
const Table & ElementToEdgeTable() const
Definition: mesh.cpp:6834
Table * el_to_el
Definition: mesh.hpp:222
int AddSegment(int v1, int v2, int attr=1)
Definition: mesh.cpp:1666
bool FaceIsTrueInterior(int FaceNo) const
Definition: mesh.hpp:522
Geometry::Constants< Geometry::CUBE > hex_t
Definition: mesh.hpp:266
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:219
Geometry::Type geom_buf[Geometry::NumGeom]
Definition: mesh.hpp:1276
void RemoveUnusedVertices()
Remove unused vertices and rebuild mesh connectivity.
Definition: mesh.cpp:12096
static void PrintElement(const Element *, std::ostream &)
Definition: mesh.cpp:3967
virtual void NURBSUniformRefinement()
Refine NURBS mesh.
Definition: mesh.cpp:5191
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:66
int AddHex(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int attr=1)
Definition: mesh.cpp:1757
const IntegrationRule * IntRule
Definition: mesh.hpp:2192
MemoryType
Memory types supported by MFEM.
Definition: mem_manager.hpp:31
Vector X
Mapped (physical) coordinates of all quadrature points.
Definition: mesh.hpp:2262
void FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
Definition: mesh.cpp:2945
GridFunction * GetNodes()
Return a pointer to the internal node GridFunction (may be NULL).
Definition: mesh.hpp:1853
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:687
void PrepareNodeReorder(DSTable **old_v_to_v, Table **old_elem_vert)
Definition: mesh.cpp:2501
int AddBdrQuad(int v1, int v2, int v3, int v4, int attr=1)
Definition: mesh.cpp:1871
Array< Vertex > vertices
Definition: mesh.hpp:90
void PrintTopo(std::ostream &out, const Array< int > &e_to_k) const
Definition: mesh.cpp:10663
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, double sx=1.0, double sy=1.0, bool sfc_ordering=true)
Definition: mesh.cpp:3773
void InitMesh(int Dim_, int spaceDim_, int NVert, int NElem, int NBdrElem)
Begin construction of a mesh.
Definition: mesh.cpp:1603
void SetBdrAttribute(int i, int attr)
Set the attribute of boundary element i.
Definition: mesh.hpp:1199
void ReadXML_VTKMesh(std::istream &input, int &curved, int &read_gf, bool &finalize_topo, const std::string &xml_prefix="")
void GetBdrElementData(int geom, Array< int > &bdr_elem_vtx, Array< int > &bdr_attr) const
Definition: mesh.hpp:1180
void RefineAtVertex(const Vertex &vert, double eps=0.0, int nonconforming=-1)
Refine elements sharing the specified vertex. Uses GeneralRefinement.
Definition: mesh.cpp:9931
static Mesh MakeCartesian1D(int n, double sx=1.0)
Definition: mesh.cpp:3765
Array< Element * > elements
Definition: mesh.hpp:85
const Table & ElementToElementTable()
Definition: mesh.cpp:6789
int SpaceDimension() const
Dimension of the physical space containing the mesh.
Definition: mesh.hpp:1023
int meshgen
Definition: mesh.hpp:77
const CoarseFineTransformations & GetRefinementTransforms()
Definition: mesh.cpp:10344
void RefineNURBSFromFile(std::string ref_file)
Definition: mesh.cpp:5110
bool RefineByError(const Array< double > &elem_error, double threshold, int nonconforming=-1, int nc_limit=0)
Definition: mesh.cpp:9957
Table * bel_to_edge
Definition: mesh.hpp:224
void GetGeometries(int dim, Array< Geometry::Type > &el_geoms) const
Return all element geometries of the given dimension present in the mesh.
Definition: mesh.cpp:6285
Geometry::Type GetBdrElementGeometry(int i) const
Definition: mesh.hpp:1233
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:1086
void GetLocalTriToTetTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:703
void GetFaceEdges(int i, Array< int > &edges, Array< int > &o) const
Definition: mesh.cpp:6352
double a
Definition: lissajous.cpp:41
NURBSExtension * NURBSext
Optional NURBS mesh extension.
Definition: mesh.hpp:277
int nbInteriorFaces
Definition: mesh.hpp:75
void PrintBdrVTU(std::string fname, VTKFormat format=VTKFormat::ASCII, bool high_order_output=false, int compression_level=0)
Definition: mesh.cpp:10911
int EulerNumber() const
Equals 1 + num_holes - num_loops.
Definition: mesh.hpp:1026
Array< int > be_to_edge
Definition: mesh.hpp:223
Class for integration point with weight.
Definition: intrules.hpp:31
Element::Type GetElementType(int i) const
Returns the type of element i.
Definition: mesh.cpp:6644
void Swap(Mesh &other, bool non_geometry)
Definition: mesh.cpp:9699
Element * ReadElementWithoutAttr(std::istream &)
Definition: mesh.cpp:3925
A standard isoparametric element transformation.
Definition: eltrans.hpp:361
static const int vtk_quadratic_wedge[18]
Definition: mesh.hpp:250
virtual long long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition: mesh.hpp:2160
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: mesh.cpp:355
void GetLocalSegToQuadTransformation(IsoparametricTransformation &loc, int i)
Definition: mesh.cpp:683
virtual int GetNFbyType(FaceType type) const
Returns the number of faces according to the requested type, does not count master nonconforming face...
Definition: mesh.cpp:5684
Table * face_edge
Definition: mesh.hpp:231
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a quadrilateral Mesh.
Definition: mesh.cpp:1988
const Element * GetFace(int i) const
Definition: mesh.hpp:1167
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
Definition: mesh.cpp:3042
bool DerefineByError(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
Definition: mesh.cpp:9626
void ReorderElements(const Array< int > &ordering, bool reorder_vertices=true)
Definition: mesh.cpp:2269
void GetLocalQuadToPyrTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:824
void DegreeElevate(int rel_degree, int degree=16)
Definition: mesh.cpp:5204
int dim
Definition: ex24.cpp:53
Table * edge_vertex
Definition: mesh.hpp:232
virtual bool HasBoundaryElements() const
Checks if the mesh has boundary elements.
Definition: mesh.hpp:1050
Element::Type GetFaceElementType(int Face) const
Definition: mesh.cpp:1440
long sequence
Definition: mesh.hpp:83
virtual ~NodeExtrudeCoefficient()
Definition: mesh.hpp:2300
constexpr int dimension
This example only works in 3D. Kernels for 2D are not implemented.
Definition: hooke.cpp:45
const Mesh * mesh
Definition: mesh.hpp:2191
void MakeSimplicial_(const Mesh &orig_mesh, int *vglobal)
Definition: mesh.cpp:4629
void DestroyPointers()
Definition: mesh.cpp:1506
Array< FaceInfo > faces_info
Definition: mesh.hpp:217
bool IsBoundary() const
Return true if the face is a boundary face.
Definition: mesh.hpp:1706
static int InvertQuadOrientation(int ori)
Definition: mesh.cpp:6024
STable3D * GetFacesTable()
Definition: mesh.cpp:7129
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
Definition: sparsemat.hpp:711
NCMesh * ncmesh
Optional nonconforming mesh extension.
Definition: mesh.hpp:278
virtual void UniformRefinement3D()
Refine a mixed 3D mesh uniformly.
Definition: mesh.hpp:410
int AddBdrElement(Element *elem)
Definition: mesh.cpp:1836
RefCoord t[3]
static void PrintElementWithoutAttr(const Element *, std::ostream &)
Definition: mesh.cpp:3943
Mesh(int Dim_, int NVert, int NElem, int NBdrElem=0, int spaceDim_=-1)
Init constructor: begin the construction of a Mesh object.
Definition: mesh.hpp:637
int AddWedge(int v1, int v2, int v3, int v4, int v5, int v6, int attr=1)
Definition: mesh.cpp:1729
FaceInformation GetFaceInformation(int f) const
Definition: mesh.cpp:1138
virtual bool NonconformingDerefinement(Array< double > &elem_error, double threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition: mesh.cpp:9578
int Dim
Definition: mesh.hpp:66
void Clear()
Clear the contents of the Mesh.
Definition: mesh.hpp:678
ElementConformity conformity
Definition: mesh.hpp:1671
Geometry::Constants< Geometry::TRIANGLE > tri_t
Definition: mesh.hpp:263
double AggregateError(const Array< double > &elem_error, const int *fine, int nfine, int op)
Derefinement helper.
Definition: mesh.cpp:9558
double * GetVertex(int i)
Return pointer to vertex i&#39;s coordinates.
Definition: mesh.hpp:1135
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: mesh.cpp:12316
void SetAttribute(int i, int attr)
Set the attribute of element i.
Definition: mesh.hpp:1193
Mesh & operator=(Mesh &&mesh)
Move assignment operator.
Definition: mesh.cpp:3749
MFEM_DEPRECATED Geometry::Type GetFaceGeometryType(int Face) const
Deprecated in favor of Mesh::GetFaceGeometry.
Definition: mesh.hpp:1220
int GetNFaces() const
Return the number of faces in a 3D mesh.
Definition: mesh.hpp:1095
Vector data type.
Definition: vector.hpp:58
void ReadTrueGridMesh(std::istream &input)
virtual void Print(std::ostream &os=mfem::out) const
Definition: mesh.hpp:2011
const FaceGeometricFactors * GetFaceGeometricFactors(const IntegrationRule &ir, const int flags, FaceType type, MemoryType d_mt=MemoryType::DEFAULT)
Return the mesh geometric factors for the faces corresponding to the given integration rule...
Definition: mesh.cpp:867
static void GetElementArrayEdgeTable(const Array< Element *> &elem_array, const DSTable &v_to_v, Table &el_to_edge)
Definition: mesh.cpp:6703
bool IsShared() const
Return true if the face is a shared interior face which is NOT a master nonconforming face...
Definition: mesh.hpp:1690
bool IsNonconformingCoarse() const
Return true if the face is a nonconforming coarse face.
Definition: mesh.hpp:1743
static int GetTriOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition: mesh.cpp:5862
void SetNode(int i, const double *coord)
Definition: mesh.cpp:8270
Table * face_to_elem
Definition: mesh.hpp:230
void DestroyTables()
Definition: mesh.cpp:1487
void PrintSurfaces(const Table &Aface_face, std::ostream &out) const
Print set of disjoint surfaces:
Definition: mesh.cpp:11838
void GetLocalTriToWdgTransformation(IsoparametricTransformation &loc, int i)
Used in GetFaceElementTransformations (...)
Definition: mesh.cpp:727
void GenerateFaces()
Definition: mesh.cpp:6967
void GetElementColoring(Array< int > &colors, int el0=0)
Definition: mesh.cpp:11271
void ChangeVertexDataOwnership(double *vertices, int len_vertices, bool zerocopy=false)
Set the internal Vertex array to point to the given vertices array without assuming ownership of the ...
Definition: mesh.cpp:3835
void DeleteGeometricFactors()
Destroy all GeometricFactors stored by the Mesh.
Definition: mesh.cpp:889
int GetNumFacesWithGhost() const
Return the number of faces (3D), edges (2D) or vertices (1D) including ghost faces.
Definition: mesh.cpp:5679
int spaceDim
Definition: mesh.hpp:67
IsoparametricTransformation EdgeTransformation
Definition: mesh.hpp:236
Defines the coarse-fine transformations of all fine elements.
Definition: ncmesh.hpp:70
void Printer(std::ostream &out=mfem::out, std::string section_delimiter="") const
Definition: mesh.cpp:10571
MemAlloc< Tetrahedron, 1024 > TetMemory
Definition: mesh.hpp:255
void DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert)
Definition: mesh.cpp:2567
void SetNodes(const Vector &node_coord)
Updates the vertex/node locations. Invokes NodesUpdated().
Definition: mesh.cpp:8314
const Element * GetBdrElement(int i) const
Return pointer to the i&#39;th boundary element object.
Definition: mesh.hpp:1158
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
Definition: mesh.cpp:5624
Operation GetLastOperation() const
Return type of last modification of the mesh.
Definition: mesh.hpp:1976
void ReadNURBSMesh(std::istream &input, int &curved, int &read_gf)
int NumOfVertices
Definition: mesh.hpp:69
void ScaleSubdomains(double sf)
Definition: mesh.cpp:11905
Array< int > be_to_face
Definition: mesh.hpp:225
int AddPyramid(int v1, int v2, int v3, int v4, int v5, int attr=1)
Definition: mesh.cpp:1743
void InitFromNCMesh(const NCMesh &ncmesh)
Initialize vertices/elements/boundary/tables from a nonconforming mesh.
Definition: mesh.cpp:9655
void Bisection(int i, const DSTable &, int *, int *, int *)
Bisect a triangle: element with index i is bisected.
Definition: mesh.cpp:9986
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Definition: mesh.cpp:9820
ElementLocation location
Definition: mesh.hpp:1670
Class for parallel meshes.
Definition: pmesh.hpp:32
Geometry::Type GetBdrElementBaseGeometry(int i) const
Definition: mesh.hpp:1245
Abstract data type element.
Definition: element.hpp:28
void AddTriangleFaceElement(int lf, int gf, int el, int v0, int v1, int v2)
Definition: mesh.cpp:6912
Array< GeometricFactors * > geom_factors
Optional geometric factors.
Definition: mesh.hpp:279
void BdrBisection(int i, const HashTable< Hashed2 > &)
Bisect a boundary triangle: boundary element with index i is bisected.
Definition: mesh.cpp:10195
static int ComposeTriOrientations(int ori_a_b, int ori_b_c)
Definition: mesh.cpp:5922
void GenerateNCFaceInfo()
Definition: mesh.cpp:7068
double GetLength(int i, int j) const
Return the length of the segment from node i to node j.
Definition: mesh.cpp:6688
double GetElementVolume(int i)
Definition: mesh.cpp:119
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Definition: mesh.hpp:273
Table * GetVertexToElementTable()
The returned Table should be deleted by the caller.
Definition: mesh.cpp:6445
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
Definition: mesh.cpp:5583
void PrintWithPartitioning(int *partitioning, std::ostream &os, int elem_attr=0) const
Prints the mesh with boundary elements given by the boundary of the subdomains, so that the boundary ...
Definition: mesh.cpp:11346
const DenseMatrix * point_matrix
Definition: mesh.hpp:1679
void UpdateNodes()
Update the nodes of a curved mesh after the topological part of a Mesh::Operation, such as refinement, has been performed.
Definition: mesh.cpp:8385
void GetBdrPointMatrix(int i, DenseMatrix &pointmat) const
Definition: mesh.cpp:6672
void GetBdrElementAdjacentElement(int bdr_el, int &el, int &info) const
For the given boundary element, bdr_el, return its adjacent element and its info, i...
Definition: mesh.cpp:6600
void GreenRefinement(int i, const DSTable &v_to_v, int *edge1, int *edge2, int *middle)
Definition: mesh.hpp:361
void NodesUpdated()
This function should be called after the mesh node coordinates have been updated externally, e.g. by modifying the internal nodal GridFunction returned by GetNodes().
Definition: mesh.hpp:1835
Class used to extrude the nodes of a mesh.
Definition: mesh.hpp:2288
void AddVertexParents(int i, int p1, int p2)
Mark vertex i as nonconforming, with parent vertices p1 and p2.
Definition: mesh.cpp:1650
int NumOfFaces
Definition: mesh.hpp:70