MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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"
18#include "attribute_sets.hpp"
19#include "triangle.hpp"
20#include "tetrahedron.hpp"
21#include "vertex.hpp"
22#include "vtk.hpp"
23#include "ncmesh.hpp"
24#include "../fem/eltrans.hpp"
26#include "../general/zstr.hpp"
27#ifdef MFEM_USE_ADIOS2
29#endif
30#include <iostream>
31#include <array>
32#include <map>
33#include <vector>
34#include <memory>
35
36namespace mfem
37{
38
39class GeometricFactors;
40class FaceGeometricFactors;
41class KnotVector;
42class NURBSPatch;
43class NURBSExtension;
44class FiniteElementSpace;
45class GridFunction;
46struct Refinement;
47
48/** An enum type to specify if interior or boundary faces are desired. */
49enum class FaceType : bool {Interior, Boundary};
50
51#ifdef MFEM_USE_MPI
52class ParMesh;
53class ParNCMesh;
54#endif
55
56#ifdef MFEM_USE_NETCDF
57namespace cubit
58{
59class CubitBlock;
60}
61#endif
62
63/// Mesh data type
64class Mesh
65{
66 friend class NCMesh;
67 friend class NURBSExtension;
68 friend class NCNURBSExtension;
69#ifdef MFEM_USE_MPI
70 friend class ParMesh;
71 friend class ParNCMesh;
72#endif
73#ifdef MFEM_USE_ADIOS2
74 friend class adios2stream;
75#endif
76
77protected:
78 int Dim;
80
83 /** These variables store the number of Interior and Boundary faces. Calling
84 fes->GetMesh()->GetNBE() doesn't return the expected value in 3D because
85 periodic meshes in 3D have some of their faces marked as boundary for
86 visualization purpose in GLVis. */
88
89 // see MeshGenerator(); global in parallel
91 // sum of (1 << geom) for all geom of all dimensions; local in parallel
93
94 // Counter for Mesh transformations: refinement, derefinement, rebalancing.
95 // Used for checking during Update operations on objects depending on the
96 // Mesh, such as FiniteElementSpace, GridFunction, etc.
98
99 /// Counter for geometric factor invalidation
101
103 // Vertices are only at the corners of elements, where you would expect them
104 // in the lowest-order mesh. In some cases, e.g. in a Mesh that defines the
105 // patch topology for a NURBS mesh (see LoadPatchTopo()) the vertices may be
106 // empty while NumOfVertices is positive.
110
111 /// internal cache for element attributes
113 /// internal cache for boundary element attributes
115
116 /** @brief This structure stores the low level information necessary to
117 interpret the configuration of elements on a specific face. This
118 information can be accessed using methods like GetFaceElements(),
119 GetFaceInfos(), FaceIsInterior(), etc.
120
121 For accessing higher level deciphered information look at
122 Mesh::FaceInformation, and its accessor Mesh::GetFaceInformation().
123
124 Each face contains information on the indices, local reference faces,
125 orientations, and potential nonconformity for the two neighboring
126 elements on a face.
127 Each face can either be an interior, boundary, or shared interior face.
128 Each interior face is shared by two elements referred as Elem1 and Elem2.
129 For boundary faces only the information on Elem1 is relevant.
130 Shared interior faces correspond to faces where Elem1 and Elem2 are
131 distributed on different MPI ranks.
132 Regarding conformity, three cases are distinguished, conforming faces,
133 nonconforming slave faces, and nonconforming master faces. Master and
134 slave referring to the coarse and fine elements respectively on a
135 nonconforming face.
136 Nonconforming slave faces always have the slave element as Elem1 and
137 the master element as Elem2. On the other side, nonconforming master
138 faces always have the master element as Elem1, and one of the slave
139 element as Elem2. Except for ghost nonconforming slave faces, where
140 Elem1 is the master side and Elem2 is the slave side.
141
142 The indices of Elem1 and Elem2 can be indirectly extracted from
143 FaceInfo::Elem1No and FaceInfo::Elem2No, read the note below for special
144 cases on the index of Elem2.
145
146 The local face identifiers are deciphered from FaceInfo::Elem1Inf and
147 FaceInfo::Elem2Inf through the formula: LocalFaceIndex = ElemInf/64,
148 the semantic of the computed local face identifier can be found in
149 fem/geom.cpp. The local face identifier corresponds to an index
150 in the Constants<Geometry>::Edges arrays for 2D element geometries, and
151 to an index in the Constants<Geometry>::FaceVert arrays for 3D element
152 geometries.
153
154 The orientation of each element relative to a face is obtained through
155 the formula: Orientation = ElemInf%64, the semantic of the orientation
156 can also be found in fem/geom.cpp. The orientation corresponds to
157 an index in the Constants<Geometry>::Orient arrays, providing the
158 sequence of vertices identifying the orientation of an edge/face. By
159 convention the orientation of Elem1 is always set to 0, serving as the
160 reference orientation. The orientation of Elem2 relatively to Elem1 is
161 therefore determined just by using the orientation of Elem2. An important
162 special case is the one of nonconforming faces, the orientation should
163 be composed with the PointMatrix, which also contains orientation
164 information. A special treatment should be done for 2D, the orientation
165 in the PointMatrix is not included, therefore when applying the
166 PointMatrix transformation, the PointMatrix should be flipped, except for
167 shared nonconforming slave faces where the transformation can be applied
168 as is.
169
170 Another special case is the case of shared nonconforming faces. Ghost
171 faces use a different design based on so called "ghost" faces.
172 Ghost faces, as their name suggest are very well hidden, and they
173 usually have a separate interface from "standard" faces.
174 */
175 struct FaceInfo
176 {
177 // Inf = 64 * LocalFaceIndex + FaceOrientation
179 int NCFace; /* -1 if this is a regular conforming/boundary face;
180 index into 'nc_faces_info' if >= 0. */
181 };
182 // NOTE: in NC meshes, master faces have Elem2No == -1. Slave faces on the
183 // other hand have Elem2No and Elem2Inf set to the master face's element and
184 // its local face number.
185 //
186 // A local face is one generated from a local element and has index i in
187 // faces_info such that i < GetNumFaces(). Also, Elem1No always refers to the
188 // element (slave or master, in the nonconforming case) that generated the
189 // face.
190 // Classification of a local (non-ghost) face based on its FaceInfo:
191 // - Elem2No >= 0 --> local interior face; can be either:
192 // - NCFace == -1 --> conforming face, or
193 // - NCFace >= 0 --> nonconforming slave face; Elem2No is the index of
194 // the master volume element; Elem2Inf%64 is 0, see the note in
195 // Mesh::GenerateNCFaceInfo().
196 // - Elem2No < 0 --> local "boundary" face; can be one of:
197 // - NCFace == -1 --> conforming face; can be either:
198 // - Elem2Inf < 0 --> true boundary face (no element on side 2)
199 // - Elem2Inf >= 0 --> shared face where element 2 is a face-neighbor
200 // element with index -1-Elem2No. This state is initialized by
201 // ParMesh::ExchangeFaceNbrData().
202 // - NCFace >= 0 --> nonconforming face; can be one of:
203 // - Elem2Inf < 0 --> master nonconforming face, interior or shared;
204 // In this case, Elem2No is -1; see GenerateNCFaceInfo().
205 // - Elem2Inf >= 0 --> shared slave nonconforming face where element 2
206 // is the master face-neighbor element with index -1-Elem2No; see
207 // ParNCMesh::GetFaceNeighbors().
208 //
209 // A ghost face is a nonconforming face that is generated by a non-local,
210 // i.e. ghost, element. A ghost face has index i in faces_info such that
211 // i >= GetNumFaces().
212 // Classification of a ghost (non-local) face based on its FaceInfo:
213 // - Elem1No == -1 --> master ghost face? These ghost faces also have:
214 // Elem2No == -1, Elem1Inf == Elem2Inf == -1, and NCFace == -1.
215 // - Elem1No >= 0 --> slave ghost face; Elem1No is the index of the local
216 // master side element, i.e. side 1 IS NOT the side that generated the
217 // face. Elem2No is < 0 and -1-Elem2No is the index of the ghost
218 // face-neighbor element that generated this slave ghost face. In this
219 // case, Elem2Inf >= 0 and NCFace >= 0.
220 // Relevant methods: GenerateFaces(), GenerateNCFaceInfo(),
221 // ParNCMesh::GetFaceNeighbors(),
222 // ParMesh::ExchangeFaceNbrData()
223
225 {
226 bool Slave; // true if this is a slave face, false if master face
227 int MasterFace; // if Slave, this is the index of the master face
228 // If not Slave, 'MasterFace' is the local face index of this master face
229 // as a face in the unique adjacent element.
230 const DenseMatrix* PointMatrix; // if Slave, position within master face
231 // (NOTE: PointMatrix points to a matrix owned by NCMesh.)
232
233 NCFaceInfo() = default;
234
235 NCFaceInfo(bool slave, int master, const DenseMatrix* pm)
236 : Slave(slave), MasterFace(master), PointMatrix(pm) {}
237 };
238
241
245 Array<int> be_to_face; // faces = vertices (1D), edges (2D), faces (3D)
246
247 Table *bel_to_edge; // for 3D only
248
249 // Note that the following tables are owned by this class and should not be
250 // deleted by the caller. Of these three tables, only face_edge and
251 // edge_vertex are returned by access functions.
252 mutable Table *face_to_elem; // Used by FindFaceNeighbors, not returned.
253 mutable Table *face_edge; // Returned by GetFaceEdgeTable().
254 mutable Table *edge_vertex; // Returned by GetEdgeVertexTable().
255
260
261 // refinement embeddings for forward compatibility with NCMesh
263
264 // Nodes are only active for higher order meshes, and share locations with
265 // the vertices, plus all the higher- order control points within the
266 // element and along the edges and on the faces.
269
270 static const int vtk_quadratic_tet[10];
271 static const int vtk_quadratic_pyramid[13];
272 static const int vtk_quadratic_wedge[18];
273 static const int vtk_quadratic_hex[27];
274
275#ifdef MFEM_USE_MEMALLOC
276 friend class Tetrahedron;
277 MemAlloc <Tetrahedron, 1024> TetMemory;
278#endif
279
280 // used during NC mesh initialization only
282 /// cache for FaceIndices(ftype)
284 /// cache for FaceIndices(ftype)
285 mutable std::unordered_map<int, int> inv_face_indices[2];
286
287 /// compute face_indices[ftype] and inv_face_indices[type]
288 void ComputeFaceInfo(FaceType ftype) const;
289
290public:
298
300
301 /// A list of all unique element attributes used by the Mesh.
303 /// A list of all unique boundary attributes used by the Mesh.
305
306 /// Named sets of element attributes
308
309 /// Named sets of boundary element attributes
311
312 NURBSExtension *NURBSext; ///< Optional NURBS mesh extension.
313 NCMesh *ncmesh; ///< Optional nonconforming mesh extension.
314 Array<GeometricFactors*> geom_factors; ///< Optional geometric factors.
316 factors. */
317
318 // Global parameter that can be used to control the removal of unused
319 // vertices performed when reading a mesh in MFEM format. The default value
320 // (true) is set in mesh_readers.cpp.
322
323 /// Map from boundary or interior face indices to mesh face indices.
324 const Array<int>& GetFaceIndices(FaceType ftype) const;
325 /// Inverse of the map FaceIndices(ftype)
326 const std::unordered_map<int, int>& GetInvFaceIndices(FaceType ftype) const;
327
328protected:
330
331 void Init();
332 void InitTables();
333 void SetEmpty(); // Init all data members with empty values
334 void DestroyTables();
336 void DestroyPointers(); // Delete data specifically allocated by class Mesh.
337 void Destroy(); // Delete all owned data.
338 void ResetLazyData();
339
340 Element *ReadElementWithoutAttr(std::istream &input);
341 static void PrintElementWithoutAttr(const Element *el, std::ostream &os);
342
343 Element *ReadElement(std::istream &input);
344 static void PrintElement(const Element *el, std::ostream &os);
345
346 // Readers for different mesh formats, used in the Load() method.
347 // The implementations of these methods are in mesh_readers.cpp.
348 void ReadMFEMMesh(std::istream &input, int version, int &curved);
349 void ReadLineMesh(std::istream &input);
350 void ReadNetgen2DMesh(std::istream &input, int &curved);
351 void ReadNetgen3DMesh(std::istream &input);
352 void ReadTrueGridMesh(std::istream &input);
353 void CreateVTKMesh(const Vector &points, const Array<int> &cell_data,
354 const Array<int> &cell_offsets,
355 const Array<int> &cell_types,
356 const Array<int> &cell_attributes,
357 int &curved, int &read_gf, bool &finalize_topo);
358 void ReadVTKMesh(std::istream &input, int &curved, int &read_gf,
359 bool &finalize_topo);
360 void ReadXML_VTKMesh(std::istream &input, int &curved, int &read_gf,
361 bool &finalize_topo, const std::string &xml_prefix="");
362 void ReadNURBSMesh(std::istream &input, int &curved, int &read_gf,
363 bool spacing=false, bool nc=false);
364 void ReadInlineMesh(std::istream &input, bool generate_edges = false);
365 void ReadGmshMesh(std::istream &input, int &curved, int &read_gf);
366
367 /* Note NetCDF (optional library) is used for reading cubit files */
368#ifdef MFEM_USE_NETCDF
369 /// @brief Load a mesh from a Genesis file.
370 void ReadCubit(const std::string &filename, int &curved, int &read_gf);
371
372 /// @brief Called internally in ReadCubit. This method creates the vertices.
373 void BuildCubitVertices(const std::vector<int> & unique_vertex_ids,
374 const std::vector<double> & coordx, const std::vector<double> & coordy,
375 const std::vector<double> & coordz);
376
377 /// @brief Called internally in ReadCubit. This method builds the mesh elements.
378 void BuildCubitElements(const int num_elements,
379 const cubit::CubitBlock * blocks,
380 const std::vector<int> & block_ids,
381 const std::map<int, std::vector<int>> & element_ids_for_block_id,
382 const std::map<int, std::vector<int>> & node_ids_for_element_id,
383 const std::map<int, int> & cubit_to_mfem_vertex_map);
384
385 /// @brief Called internally in ReadCubit. This method adds the mesh boundary elements.
387 const cubit::CubitBlock * blocks,
388 const std::vector<int> & boundary_ids,
389 const std::map<int, std::vector<int>> & element_ids_for_boundary_id,
390 const std::map<int, std::vector<std::vector<int>>> & node_ids_for_boundary_id,
391 const std::map<int, std::vector<int>> & side_ids_for_boundary_id,
392 const std::map<int, int> & block_id_for_element_id,
393 const std::map<int, int> & cubit_to_mfem_vertex_map);
394#endif
395
396 /// Determine the mesh generator bitmask #meshgen, see MeshGenerator().
397 /** Also, initializes #mesh_geoms. */
398 void SetMeshGen();
399
400 /// Return the length of the segment from node i to node j.
401 real_t GetLength(int i, int j) const;
402
403 void MarkForRefinement();
405 void GetEdgeOrdering(const DSTable &v_to_v, Array<int> &order);
406 virtual void MarkTetMeshForRefinement(const DSTable &v_to_v);
407
408 // Methods used to prepare and apply permutation of the mesh nodes assuming
409 // that the mesh elements may be rotated (e.g. to mark triangle or tet edges
410 // for refinement) between the two calls - PrepareNodeReorder() and
411 // DoNodeReorder(). The latter method assumes that the 'faces' have not been
412 // updated after the element rotations.
413 void PrepareNodeReorder(DSTable **old_v_to_v, Table **old_elem_vert);
414 void DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert);
415
417 STable3D *GetElementToFaceTable(int ret_ftbl = 0);
418
419 /** Red refinement. Element with index i is refined. The default
420 red refinement for now is Uniform. */
421 void RedRefinement(int i, const DSTable &v_to_v,
422 int *edge1, int *edge2, int *middle)
423 { UniformRefinement(i, v_to_v, edge1, edge2, middle); }
424
425 /** Green refinement. Element with index i is refined. The default
426 refinement for now is Bisection. */
427 void GreenRefinement(int i, const DSTable &v_to_v,
428 int *edge1, int *edge2, int *middle)
429 { Bisection(i, v_to_v, edge1, edge2, middle); }
430
431 /// Bisect a triangle: element with index @a i is bisected.
432 void Bisection(int i, const DSTable &, int *, int *, int *);
433
434 /// Bisect a tetrahedron: element with index @a i is bisected.
435 void Bisection(int i, HashTable<Hashed2> &);
436
437 /// Bisect a boundary triangle: boundary element with index @a i is bisected.
438 void BdrBisection(int i, const HashTable<Hashed2> &);
439
440 /** Uniform Refinement. Element with index i is refined uniformly. */
441 void UniformRefinement(int i, const DSTable &, int *, int *, int *);
442
443 /** @brief Averages the vertices with given @a indexes and saves the result
444 in #vertices[result]. */
445 void AverageVertices(const int *indexes, int n, int result);
446
448 int FindCoarseElement(int i);
449
450 /** @brief Update the nodes of a curved mesh after the topological part of a
451 Mesh::Operation, such as refinement, has been performed. */
452 /** If Nodes GridFunction is defined, i.e. not NULL, this method calls
453 NodesUpdated().
454
455 @note Unlike the similarly named public method NodesUpdated() this
456 method modifies the mesh nodes (if they exist) and calls NodesUpdated().
457 */
458 void UpdateNodes();
459
460 /// Helper to set vertex coordinates given a high-order curvature function.
462
463 void UniformRefinement2D_base(bool update_nodes = true);
464
465 /// Refine a mixed 2D mesh uniformly.
467
468 /* If @a f2qf is not NULL, adds all quadrilateral faces to @a f2qf which
469 represents a "face-to-quad-face" index map. When all faces are quads, the
470 array @a f2qf is kept empty since it is not needed. */
471 void UniformRefinement3D_base(Array<int> *f2qf = NULL,
472 DSTable *v_to_v_p = NULL,
473 bool update_nodes = true);
474
475 /// Refine a mixed 3D mesh uniformly.
477
478 /// This function is not public anymore. Use GeneralRefinement instead.
479 virtual void LocalRefinement(const Array<int> &marked_el, int type = 3);
480
481 /// This function is not public anymore. Use GeneralRefinement instead.
482 virtual void NonconformingRefinement(const Array<Refinement> &refinements,
483 int nc_limit = 0);
484
485 /// NC version of GeneralDerefinement.
486 virtual bool NonconformingDerefinement(Array<real_t> &elem_error,
487 real_t threshold, int nc_limit = 0,
488 int op = 1);
489 /// Derefinement helper.
490 real_t AggregateError(const Array<real_t> &elem_error,
491 const int *fine, int nfine, int op);
492
493 /// Read NURBS patch/macro-element mesh
494 void LoadPatchTopo(std::istream &input, Array<int> &edge_to_ukv);
495
496 /// Read NURBS patch/macro-element mesh (MFEM NURBS NC-patch mesh format)
497 void LoadNonconformingPatchTopo(std::istream &input,
498 Array<int> &edge_to_ukv);
499
500 /// Update this NURBS Mesh and its NURBS data structures after a change, such
501 /// as refinement, derefinement, or degree change.
502 void UpdateNURBS();
503
504 /** @brief Refine the NURBS mesh with default refinement factors in @a rf for
505 each dimension.
506
507 Optionally, if @a usingKVF is true, use refinement factors specified for
508 particular KnotVectors, from the file with name in @a kvf. When
509 coarsening by knot removal is necessary for non-nested spacing formulas,
510 tolerance @a tol is used (see NURBSPatch::KnotRemove()). */
511 void RefineNURBS(bool usingKVF, real_t tol, const Array<int> &rf,
512 const std::string &kvf);
513
514 /** @brief Write the beginning of a NURBS mesh to @a os, specifying the NURBS
515 patch topology. Optional file comments can be provided in @a comments.
516
517 @param[in] os Output stream to which to write.
518 @param[in] e_to_k Map from edge to signed knotvector indices.
519 @param[in] version NURBS mesh version number times 10 (e.g. 11 for v1.1).
520 @param[in] comment Optional comment string, written after version line.
521 */
522 void PrintTopo(std::ostream &os, const Array<int> &e_to_k,
523 const int version,
524 const std::string &comment = "") const;
525
526 /// Write the patch topology edges of a NURBS mesh (see PrintTopo()).
527 void PrintTopoEdges(std::ostream &out, const Array<int> &e_to_k,
528 bool vmap = false) const;
529
530 /// Used in GetFaceElementTransformations (...)
532 int i) const;
534 int i) const;
536 int i) const;
538 int i) const;
540 int i) const;
542 int i) const;
544 int i) const;
546 int i) const;
548 int i) const;
549
550 /** Used in GetFaceElementTransformations to account for the fact that a
551 slave face occupies only a portion of its master face. */
553 const FaceInfo &fi, bool is_ghost) const;
554
555 bool IsSlaveFace(const FaceInfo &fi) const;
556
557 /// Returns the orientation of "test" relative to "base"
558 static int GetTriOrientation(const int *base, const int *test);
559
560 /// Returns the orientation of "base" relative to "test"
561 /// In other words: GetTriOrientation(test, base) should equal
562 /// InvertTriOrientation(GetTriOrientation(base, test))
563 static int InvertTriOrientation(int ori);
564
565 /// Returns the orientation of "c" relative to "a" by composing
566 /// previously computed orientations relative to an intermediate
567 /// set "b".
568 static int ComposeTriOrientations(int ori_a_b, int ori_b_c);
569
570 /// Returns the orientation of "test" relative to "base"
571 static int GetQuadOrientation(const int *base, const int *test);
572
573 /// Returns the orientation of "base" relative to "test"
574 /// In other words: GetQuadOrientation(test, base) should equal
575 /// InvertQuadOrientation(GetQuadOrientation(base, test))
576 static int InvertQuadOrientation(int ori);
577
578 /// Returns the orientation of "c" relative to "a" by composing
579 /// previously computed orientations relative to an intermediate
580 /// set "b".
581 static int ComposeQuadOrientations(int ori_a_b, int ori_b_c);
582
583 /// Returns the orientation of "test" relative to "base"
584 static int GetTetOrientation(const int *base, const int *test);
585
586 static void GetElementArrayEdgeTable(const Array<Element*> &elem_array,
587 const DSTable &v_to_v,
589
590 /** Return element to edge table and the indices for the boundary edges.
591 The entries in the table are ordered according to the order of the
592 nodes in the elements. For example, if T is the element to edge table
593 T(i, 0) gives the index of edge in element i that connects vertex 0
594 to vertex 1, etc. Returns the number of the edges. */
596
597 /// Used in GenerateFaces()
598 void AddPointFaceElement(int lf, int gf, int el);
599
600 void AddSegmentFaceElement (int lf, int gf, int el, int v0, int v1);
601
602 void AddTriangleFaceElement (int lf, int gf, int el,
603 int v0, int v1, int v2);
604
605 void AddQuadFaceElement (int lf, int gf, int el,
606 int v0, int v1, int v2, int v3);
607 /** For a serial Mesh, return true if the face is interior. For a parallel
608 ParMesh return true if the face is interior or shared. In parallel, this
609 method only works if the face neighbor data is exchanged. */
610 bool FaceIsTrueInterior(int FaceNo) const
611 {
612 return FaceIsInterior(FaceNo) || (faces_info[FaceNo].Elem2Inf >= 0);
613 }
614
615 void FreeElement(Element *E);
616
617 void GenerateFaces();
618 void GenerateNCFaceInfo();
619
620 /// Begin construction of a mesh
621 void InitMesh(int Dim_, int spaceDim_, int NVert, int NElem, int NBdrElem);
622
623 // Used in the methods FinalizeXXXMesh() and FinalizeTopology()
624 void FinalizeCheck();
625
626 void Loader(std::istream &input, int generate_edges = 0,
627 std::string parse_tag = "");
628
629 /** @brief If NURBS mesh, write NURBS format. If NCMesh, write mfem v1.1
630 format. If section_delimiter is empty, write mfem v1.0 format. Otherwise,
631 write mfem v1.2 format with the given section_delimiter at the end.
632
633 If @a comments is non-empty, it will be printed after the first line of
634 the file, and each line should begin with '#'. */
635 void Printer(std::ostream &os = mfem::out,
636 std::string section_delimiter = "",
637 const std::string &comments = "") const;
638
639 /// @brief Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz],
640 /// divided into nx*ny*nz hexahedra if @a type = HEXAHEDRON or into
641 /// 6*nx*ny*nz tetrahedrons if @a type = TETRAHEDRON.
642 ///
643 /// The parameter @a sfc_ordering controls how the elements
644 /// (when @a type = HEXAHEDRON) are ordered: true - use space-filling curve
645 /// ordering, or false - use lexicographic ordering.
646 void Make3D(int nx, int ny, int nz, Element::Type type,
647 real_t sx, real_t sy, real_t sz, bool sfc_ordering);
648
649 /// @brief Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz],
650 /// divided into nx*ny*nz*24 tetrahedrons.
651 ///
652 /// The mesh is generated by taking nx*ny*nz hexahedra and splitting each
653 /// hexahedron into 24 tetrahedrons. Each face of the hexahedron is split
654 /// into 4 triangles (face edges are connected to a face-centered point),
655 /// and the triangles are connected to a hex-centered point.
656 void Make3D24TetsFromHex(int nx, int ny, int nz,
657 real_t sx, real_t sy, real_t sz);
658
659 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*4
660 /// triangles.
661 ///
662 /// The mesh is generated by taking nx*ny quadrilaterals and splitting each
663 /// quadrilateral into 4 triangles by connecting the vertices to a
664 /// quad-centered point.
665 void Make2D4TrisFromQuad(int nx, int ny, real_t sx, real_t sy);
666
667 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*5
668 /// quadrilaterals.
669 ///
670 /// The mesh is generated by taking nx*ny quadrilaterals and splitting
671 /// each quadrilateral into 5 quadrilaterals. Each quadrilateral is projected
672 /// inwards and connected to the original quadrilateral.
673 void Make2D5QuadsFromQuad(int nx, int ny, real_t sx, real_t sy);
674
675 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny
676 /// quadrilaterals if @a type = QUADRILATERAL or into 2*nx*ny triangles if
677 /// @a type = TRIANGLE.
678 ///
679 /// If generate_edges = 0 (default) edges are not generated, if 1 edges are
680 /// generated. The parameter @a sfc_ordering controls how the elements (when
681 /// @a type = QUADRILATERAL) are ordered: true - use space-filling curve
682 /// ordering, or false - use lexicographic ordering.
683 void Make2D(int nx, int ny, Element::Type type, real_t sx, real_t sy,
684 bool generate_edges, bool sfc_ordering);
685
686 /// @a brief Creates a 1D mesh for the interval [0,sx] divided into n equal
687 /// intervals.
688 void Make1D(int n, real_t sx = 1.0);
689
690 /// Internal function used in Mesh::MakeRefined
691 void MakeRefined_(Mesh &orig_mesh, const Array<int> &ref_factors,
692 int ref_type);
693
694 /// Initialize vertices/elements/boundary/tables from a nonconforming mesh.
695 void InitFromNCMesh(const NCMesh &ncmesh);
696
697 /// Create from a nonconforming mesh.
698 explicit Mesh(const NCMesh &ncmesh);
699
700 // used in GetElementData() and GetBdrElementData()
701 void GetElementData(const Array<Element*> &elem_array, int geom,
702 Array<int> &elem_vtx, Array<int> &attr) const;
703
704 // Internal helper used in MakeSimplicial (and ParMesh::MakeSimplicial).
705
706 /**
707 * @brief Internal helper user in MakeSimplicial (and
708 * ParMesh::MakeSimplicial). Optional return is used in assembling a higher
709 * order mesh.
710 * @details The construction of the higher order nodes must be separated out
711 * because the
712 *
713 * @param orig_mesh The mesh from to create the simplices
714 * @param vglobal An optional global ordering of vertices. Necessary for
715 * parallel splitting.
716 * @return Array<int> parent elements from the orig_mesh for each split
717 * element
718 */
719 Array<int> MakeSimplicial_(const Mesh &orig_mesh, int *vglobal);
720
721 /**
722 * @brief Helper function for constructing higher order nodes from a mesh
723 * transformed into simplices. Only to be called as part of MakeSimplicial
724 * or ParMesh::MakeSimplicial.
725 *
726 * @param orig_mesh The mesh that was used to transform this mesh into
727 * simplices.
728 * @param parent_elements parent_elements[i] gives the element in orig_mesh
729 * split to give element i.
730 */
731 void MakeHigherOrderSimplicial_(const Mesh &orig_mesh,
732 const Array<int> &parent_elements);
733public:
734
735 /// @anchor mfem_Mesh_ctors
736 /// @name Standard Mesh constructors and related methods
737 ///
738 /// These constructors and assignment operators accept mesh information in
739 /// a variety of common forms. For more specialized constructors see
740 /// @ref mfem_Mesh_named_ctors "Named mesh constructors".
741 /// @{
744
745 /** Copy constructor. Performs a deep copy of (almost) all data, so that the
746 source mesh can be modified (e.g. deleted, refined) without affecting the
747 new mesh. If 'copy_nodes' is false, use a shallow (pointer) copy for the
748 nodes, if present. */
749 explicit Mesh(const Mesh &mesh, bool copy_nodes = true);
750
751 /// Move constructor, useful for using a Mesh as a function return value.
752 Mesh(Mesh &&mesh);
753
754 /// Move assignment operator.
755 Mesh& operator=(Mesh &&mesh);
756
757 /// Explicitly delete the copy assignment operator.
758 Mesh& operator=(const Mesh &mesh) = delete;
759
760 /// Construct a Mesh from the given primary data.
761 /** The array @a vertices is used as external data, i.e. the Mesh does not
762 copy the data and will not delete the pointer.
763
764 The data from the other arrays is copied into the internal Mesh data
765 structures.
766
767 This method calls the method FinalizeTopology(). The method Finalize()
768 may be called after this constructor and after optionally setting the
769 Mesh nodes. */
770 Mesh(real_t *vertices, int num_vertices,
771 int *element_indices, Geometry::Type element_type,
772 int *element_attributes, int num_elements,
773 int *boundary_indices, Geometry::Type boundary_type,
774 int *boundary_attributes, int num_boundary_elements,
775 int dimension, int space_dimension = -1);
776
777 /** @anchor mfem_Mesh_init_ctor
778 @brief _Init_ constructor: begin the construction of a Mesh object.
779
780 Construct a shell of a mesh object allocating space to store pointers to
781 the vertices, elements, and boundary elements. The vertices and elements
782 themselves can later be added using methods from the
783 @ref mfem_Mesh_construction "Mesh construction" group. */
784 Mesh(int Dim_, int NVert, int NElem, int NBdrElem = 0, int spaceDim_ = -1)
786 {
787 if (spaceDim_ == -1) { spaceDim_ = Dim_; }
788 InitMesh(Dim_, spaceDim_, NVert, NElem, NBdrElem);
789 }
790
791 /** Creates mesh by reading a file in MFEM, Netgen, or VTK format. If
792 generate_edges = 0 (default) edges are not generated, if 1 edges are
793 generated. See also @a Mesh::LoadFromFile. See @a Mesh::Finalize for the
794 meaning of @a refine. */
795 explicit Mesh(const std::string &filename, int generate_edges = 0,
796 int refine = 1, bool fix_orientation = true);
797
798 /** Creates mesh by reading data stream in MFEM, Netgen, or VTK format. If
799 generate_edges = 0 (default) edges are not generated, if 1 edges are
800 generated. */
801 explicit Mesh(std::istream &input, int generate_edges = 0, int refine = 1,
802 bool fix_orientation = true);
803
804 /// Create a disjoint mesh from the given mesh array
805 ///
806 /// @note Data is copied from the meshes in @a mesh_array.
807 Mesh(Mesh *mesh_array[], int num_pieces);
808
809 /** This is similar to the mesh constructor with the same arguments, but here
810 the current mesh is destroyed and another one created based on the data
811 stream again given in MFEM, Netgen, or VTK format. If generate_edges = 0
812 (default) edges are not generated, if 1 edges are generated. */
813 /// \see mfem::ifgzstream() for on-the-fly decompression of compressed ascii
814 /// inputs.
815 virtual void Load(std::istream &input, int generate_edges = 0,
816 int refine = 1, bool fix_orientation = true)
817 {
818 Loader(input, generate_edges);
819 Finalize(refine, fix_orientation);
820 }
821
822 /// Swaps internal data with another mesh. By default, non-geometry members
823 /// like 'ncmesh' and 'NURBSExt' are only swapped when 'non_geometry' is set.
824 void Swap(Mesh& other, bool non_geometry);
825
826 /// Clear the contents of the Mesh.
827 void Clear() { Destroy(); SetEmpty(); }
828
829 /// Destroys Mesh.
830 virtual ~Mesh() { DestroyPointers(); }
831
832 /** Get the edge to unique knotvector map used by NURBS patch topology meshes
833 Various index maps are defined using the following indices:
834
835 edge: Edge index in the patch topology mesh
836 pkv: Patch knotvector index, equivalent to (p * dim + d) where
837 p is the patch index, dim is the topological dimension of
838 the patch, and d is the local dimension
839 rpkv: Root patch knotvector index; the lowest index pkv for all
840 equivalent pkv.
841 ukv: (signed) Unique knotvector index. Equivalent to rpkv reordered
842 from 0 to N-1, where N is the number of unique knotvectors +
843 sign, which indicates the orientation of the edge.
844 @param[in,out] edge_to_ukv Array<int> Map from edge index to (signed)
845 unique knotvector index. Will be resized
846 to the number of edges.
847 @param[in,out] ukv_to_rpkv Array<int> Map from (unsigned) unique
848 knotvector index to the (unsigned) root
849 patch knotvector index. Will be resized
850 to the number of unique knotvectors.
851 */
852 void GetEdgeToUniqueKnotvector(Array<int> &edge_to_ukv,
853 Array<int> &ukv_to_rpkv) const;
854
855 /// @}
856
857 /** @anchor mfem_Mesh_named_ctors @name Named mesh constructors.
858
859 Each of these constructors uses the move constructor, and can be used as
860 the right-hand side of an assignment when creating new meshes. For more
861 general mesh constructors see
862 @ref mfem_Mesh_ctors "Standard mesh constructors".*/
863 ///@{
864
865 /** Creates mesh by reading a file in MFEM, Netgen, or VTK format. If
866 generate_edges = 0 (default) edges are not generated, if 1 edges are
867 generated.
868
869 @note @a filename is not cached by the Mesh object and can be
870 safely deleted following this function call.
871 */
872 static Mesh LoadFromFile(const std::string &filename,
873 int generate_edges = 0, int refine = 1,
874 bool fix_orientation = true);
875
876 /// Creates 1D mesh, divided into n equal intervals.
877 static Mesh MakeCartesian1D(int n, real_t sx = 1.0);
878
879 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny
880 /// quadrilaterals if @a type = QUADRILATERAL or into 2*nx*ny triangles if
881 /// @a type = TRIANGLE.
882 ///
883 /// If generate_edges = 0 (default) edges are not generated, if 1 edges are
884 /// generated. The parameter @a sfc_ordering controls how the elements (when
885 /// @a type = QUADRILATERAL) are ordered: true - use space-filling curve
886 /// ordering, or false - use lexicographic ordering.
887 static Mesh MakeCartesian2D(
888 int nx, int ny, Element::Type type, bool generate_edges = false,
889 real_t sx = 1.0, real_t sy = 1.0, bool sfc_ordering = true);
890
891 /// @brief Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz],
892 /// divided into nx*ny*nz hexahedra if @a type = HEXAHEDRON or into
893 /// 6*nx*ny*nz tetrahedrons if @a type = TETRAHEDRON.
894 ///
895 /// The parameter @a sfc_ordering controls how the elements
896 /// (when @a type = HEXAHEDRON) are ordered: true - use space-filling curve
897 /// ordering, or false - use lexicographic ordering.
898 static Mesh MakeCartesian3D(
899 int nx, int ny, int nz, Element::Type type,
900 real_t sx = 1.0, real_t sy = 1.0, real_t sz = 1.0,
901 bool sfc_ordering = true);
902
903 /// @brief Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz],
904 /// divided into nx*ny*nz*24 tetrahedrons.
905 ///
906 /// The mesh is generated by taking nx*ny*nz hexahedra and splitting each
907 /// hexahedron into 24 tetrahedrons. Each face of the hexahedron is split
908 /// into 4 triangles (face edges are connected to a face-centered point),
909 /// and the triangles are connected to a hex-centered point.
910 static Mesh MakeCartesian3DWith24TetsPerHex(int nx, int ny, int nz,
911 real_t sx = 1.0, real_t sy = 1.0,
912 real_t sz = 1.0);
913
914 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*4
915 /// triangles.
916 ///
917 /// The mesh is generated by taking nx*ny quadrilaterals and splitting each
918 /// quadrilateral into 4 triangles by connecting the vertices to a
919 /// quad-centered point.
920 static Mesh MakeCartesian2DWith4TrisPerQuad(int nx, int ny, real_t sx = 1.0,
921 real_t sy = 1.0);
922
923 /// @brief Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*5
924 /// quadrilaterals.
925 ///
926 /// The mesh is generated by taking nx*ny quadrilaterals and splitting
927 /// each quadrilateral into 5 quadrilaterals. Each quadrilateral is projected
928 /// inwards and connected to the original quadrilateral.
929 static Mesh MakeCartesian2DWith5QuadsPerQuad(int nx, int ny, real_t sx = 1.0,
930 real_t sy = 1.0);
931
932
933 /// Create a refined (by any factor) version of @a orig_mesh.
934 /** @param[in] orig_mesh The starting coarse mesh.
935 @param[in] ref_factor The refinement factor, an integer > 1.
936 @param[in] ref_type Specify the positions of the new vertices. The
937 options are BasisType::ClosedUniform or
938 BasisType::GaussLobatto.
939
940 The refinement data which can be accessed with GetRefinementTransforms()
941 is set to reflect the performed refinements.
942
943 @note The constructed Mesh is straight-sided. */
944 static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type);
945
946 /// Create a refined mesh, where each element of the original mesh may be
947 /// refined by a different factor.
948 /** @param[in] orig_mesh The starting coarse mesh.
949 @param[in] ref_factors An array of integers whose size is the number of
950 elements of @a orig_mesh. The @a ith element of
951 @a orig_mesh is refined by refinement factor
952 @a ref_factors[i].
953 @param[in] ref_type Specify the positions of the new vertices. The
954 options are BasisType::ClosedUniform or
955 BasisType::GaussLobatto.
956
957 The refinement data which can be accessed with GetRefinementTransforms()
958 is set to reflect the performed refinements.
959
960 @note The constructed Mesh is straight-sided. */
961 /// refined @a ref_factors[i] times in each dimension.
962 static Mesh MakeRefined(Mesh &orig_mesh, const Array<int> &ref_factors,
963 int ref_type);
964
965 /** Create a mesh by splitting each element of @a orig_mesh into simplices.
966 Quadrilaterals are split into two triangles, prisms are split into
967 3 tetrahedra, and hexahedra are split into either 5 or 6 tetrahedra
968 depending on the configuration.
969 @warning The curvature of the original mesh is not carried over to the
970 new mesh. Periodic meshes are not supported. */
971 static Mesh MakeSimplicial(const Mesh &orig_mesh);
972
973 /// Create a periodic mesh by identifying vertices of @a orig_mesh.
974 /** Each vertex @a i will be mapped to vertex @a v2v[i], such that all
975 vertices that are coincident under the periodic mapping get mapped to
976 the same index. The mapping @a v2v can be generated from translation
977 vectors using Mesh::CreatePeriodicVertexMapping.
978 @note MFEM requires that each edge of the resulting mesh be uniquely
979 identifiable by a pair of distinct vertices. As a consequence, periodic
980 boundaries must be separated by at least two interior vertices.
981 @note The resulting mesh uses a discontinuous nodal function, see
982 SetCurvature() for further details. */
983 static Mesh MakePeriodic(const Mesh &orig_mesh, const std::vector<int> &v2v);
984
985 ///@}
986
987 /// Construct a Mesh from a NURBSExtension
988 explicit Mesh( const NURBSExtension& ext );
989
990 /** @anchor mfem_Mesh_construction
991 @name Methods for piecewise Mesh construction.
992
993 These methods are intended to be used with the @ref mfem_Mesh_init_ctor
994 "init constructor". */
995 ///@{
996
997 /// @note The returned object should be deleted by the caller.
998 Element *NewElement(int geom);
999
1000 int AddVertex(real_t x, real_t y = 0.0, real_t z = 0.0);
1001 int AddVertex(const real_t *coords);
1002 int AddVertex(const Vector &coords);
1003 /// Mark vertex @a i as nonconforming, with parent vertices @a p1 and @a p2.
1004 void AddVertexParents(int i, int p1, int p2);
1005 /// Adds a vertex at the mean center of the @a nverts vertex indices given
1006 /// by @a vi.
1007 int AddVertexAtMeanCenter(const int *vi, const int nverts, int dim = 3);
1008
1009 /// Adds a segment to the mesh given by 2 vertices @a v1 and @a v2.
1010 int AddSegment(int v1, int v2, int attr = 1);
1011 /// Adds a segment to the mesh given by 2 vertices @a vi.
1012 int AddSegment(const int *vi, int attr = 1);
1013
1014 /// Adds a triangle to the mesh given by 3 vertices @a v1 through @a v3.
1015 int AddTriangle(int v1, int v2, int v3, int attr = 1);
1016 /// Adds a triangle to the mesh given by 3 vertices @a vi.
1017 int AddTriangle(const int *vi, int attr = 1);
1018 /// Adds a triangle to the mesh given by 3 vertices @a vi.
1019 int AddTri(const int *vi, int attr = 1) { return AddTriangle(vi, attr); }
1020
1021 /// Adds a quadrilateral to the mesh given by 4 vertices @a v1 through @a v4.
1022 int AddQuad(int v1, int v2, int v3, int v4, int attr = 1);
1023 /// Adds a quadrilateral to the mesh given by 4 vertices @a vi.
1024 int AddQuad(const int *vi, int attr = 1);
1025
1026 /// Adds a tetrahedron to the mesh given by 4 vertices @a v1 through @a v4.
1027 int AddTet(int v1, int v2, int v3, int v4, int attr = 1);
1028 /// Adds a tetrahedron to the mesh given by 4 vertices @a vi.
1029 int AddTet(const int *vi, int attr = 1);
1030
1031 /// Adds a wedge to the mesh given by 6 vertices @a v1 through @a v6.
1032 int AddWedge(int v1, int v2, int v3, int v4, int v5, int v6, int attr = 1);
1033 /// Adds a wedge to the mesh given by 6 vertices @a vi.
1034 int AddWedge(const int *vi, int attr = 1);
1035
1036 /// Adds a pyramid to the mesh given by 5 vertices @a v1 through @a v5.
1037 int AddPyramid(int v1, int v2, int v3, int v4, int v5, int attr = 1);
1038 /// Adds a pyramid to the mesh given by 5 vertices @a vi.
1039 int AddPyramid(const int *vi, int attr = 1);
1040
1041 /// Adds a hexahedron to the mesh given by 8 vertices @a v1 through @a v8.
1042 int AddHex(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8,
1043 int attr = 1);
1044 /// Adds a hexahedron to the mesh given by 8 vertices @a vi.
1045 int AddHex(const int *vi, int attr = 1);
1046 /// @brief Adds 6 tetrahedrons to the mesh by splitting a hexahedron given by
1047 /// 8 vertices @a vi.
1048 void AddHexAsTets(const int *vi, int attr = 1);
1049 /// @brief Adds 2 wedges to the mesh by splitting a hexahedron given by
1050 /// 8 vertices @a vi.
1051 void AddHexAsWedges(const int *vi, int attr = 1);
1052 /// @brief Adds 6 pyramids to the mesh by splitting a hexahedron given by
1053 /// 8 vertices @a vi.
1054 void AddHexAsPyramids(const int *vi, int attr = 1);
1055
1056 /// @brief Adds 24 tetrahedrons to the mesh by splitting a hexahedron.
1057 ///
1058 /// @a vi are the 8 vertices of the hexahedron, @a hex_face_verts has the
1059 /// map from the 4 vertices of each face of the hexahedron to the index
1060 /// of the point created at the center of the face, and @a attr is the
1061 /// attribute of the new elements. See @a Make3D24TetsFromHex for usage.
1062 void AddHexAs24TetsWithPoints(int *vi,
1063 std::map<std::array<int, 4>, int>
1064 &hex_face_verts,
1065 int attr = 1);
1066
1067 /// @brief Adds 4 triangles to the mesh by splitting a quadrilateral given by
1068 /// 4 vertices @a vi.
1069 ///
1070 /// @a attr is the attribute of the new elements. See @a Make2D4TrisFromQuad
1071 /// for usage.
1072 void AddQuadAs4TrisWithPoints(int *vi, int attr = 1);
1073
1074 /// @brief Adds 5 quadrilaterals to the mesh by splitting a quadrilateral
1075 /// given by 4 vertices @a vi.
1076 ///
1077 /// @a attr is the attribute of the new elements. See @a Make2D5QuadsFromQuad
1078 /// for usage.
1079 void AddQuadAs5QuadsWithPoints(int *vi, int attr = 1);
1080
1081 /// The parameter @a elem should be allocated using the NewElement() method
1082 /// @note Ownership of @a elem will pass to the Mesh object
1083 int AddElement(Element *elem);
1084 /// The parameter @a elem should be allocated using the NewElement() method
1085 /// @note Ownership of @a elem will pass to the Mesh object
1086 int AddBdrElement(Element *elem);
1087
1088 /**
1089 * @brief Add an array of boundary elements to the mesh, along with map from
1090 * the elements to their faces
1091 * @param[in] bdr_elems The set of boundary element pointers, ownership of
1092 * the pointers will be transferred to the Mesh object
1093 * @param[in] be_to_face The map from the boundary element index to the face
1094 * index
1095 */
1096 void AddBdrElements(Array<Element *> &bdr_elems,
1097 const Array<int> &be_to_face);
1098
1099 int AddBdrSegment(int v1, int v2, int attr = 1);
1100 int AddBdrSegment(const int *vi, int attr = 1);
1101
1102 int AddBdrTriangle(int v1, int v2, int v3, int attr = 1);
1103 int AddBdrTriangle(const int *vi, int attr = 1);
1104
1105 int AddBdrQuad(int v1, int v2, int v3, int v4, int attr = 1);
1106 int AddBdrQuad(const int *vi, int attr = 1);
1107 void AddBdrQuadAsTriangles(const int *vi, int attr = 1);
1108
1109 int AddBdrPoint(int v, int attr = 1);
1110
1111 virtual void GenerateBoundaryElements();
1112 /// Finalize the construction of a triangular Mesh.
1113 void FinalizeTriMesh(int generate_edges = 0, int refine = 0,
1114 bool fix_orientation = true);
1115 /// Finalize the construction of a quadrilateral Mesh.
1116 void FinalizeQuadMesh(int generate_edges = 0, int refine = 0,
1117 bool fix_orientation = true);
1118 /// Finalize the construction of a tetrahedral Mesh.
1119 void FinalizeTetMesh(int generate_edges = 0, int refine = 0,
1120 bool fix_orientation = true);
1121 /// Finalize the construction of a wedge Mesh.
1122 void FinalizeWedgeMesh(int generate_edges = 0, int refine = 0,
1123 bool fix_orientation = true);
1124 /// Finalize the construction of a hexahedral Mesh.
1125 void FinalizeHexMesh(int generate_edges = 0, int refine = 0,
1126 bool fix_orientation = true);
1127 /// Finalize the construction of any type of Mesh.
1128 /** This method calls FinalizeTopology() and Finalize(). */
1129 void FinalizeMesh(int refine = 0, bool fix_orientation = true);
1130
1131 ///@}
1132
1133 /// @name Mesh consistency methods
1134 /// @{
1135
1136 /** @brief Finalize the construction of the secondary topology (connectivity)
1137 data of a Mesh. */
1138 /** This method does not require any actual coordinate data (either vertex
1139 coordinates for linear meshes or node coordinates for meshes with nodes)
1140 to be available. However, the data generated by this method is generally
1141 required by the FiniteElementSpace class.
1142
1143 After calling this method, setting the Mesh vertices or nodes, it may be
1144 appropriate to call the method Finalize(). */
1145 void FinalizeTopology(bool generate_bdr = true);
1146
1147 /// Finalize the construction of a general Mesh.
1148 /** This method will:
1149 - check and optionally fix the orientation of regular elements
1150 - check and fix the orientation of boundary elements
1151 - assume that #vertices are defined, if #Nodes == NULL
1152 - assume that #Nodes are defined, if #Nodes != NULL.
1153 @param[in] refine If true, prepare the Mesh for conforming refinement of
1154 triangular or tetrahedral meshes.
1155 @param[in] fix_orientation
1156 If true, fix the orientation of inverted mesh elements
1157 by permuting their vertices.
1158
1159 Before calling this method, call FinalizeTopology() and ensure that the
1160 Mesh vertices or nodes are set. */
1161 virtual void Finalize(bool refine = false, bool fix_orientation = false);
1162
1163 /// @brief Determine the sets of unique attribute values in domain if @a
1164 /// elem_attrs_changed and boundary elements if @a bdr_face_attrs_changed.
1165 ///
1166 /// Separately scan the domain and boundary elements to generate unique,
1167 /// sorted sets of the element attribute values present in the mesh and
1168 /// store these in the Mesh::attributes and Mesh::bdr_attributes arrays.
1169 virtual void SetAttributes(bool elem_attrs_changed = true,
1170 bool bdr_face_attrs_changed = true);
1171
1172 /// Check (and optionally attempt to fix) the orientation of the elements
1173 /** @param[in] fix_it If `true`, attempt to fix the orientations of some
1174 elements: triangles, quads, and tets.
1175 @return The number of elements with wrong orientation.
1176
1177 @note For meshes with nodes (e.g. high-order or periodic meshes), fixing
1178 the element orientations may require additional permutation of the nodal
1179 GridFunction of the mesh which is not performed by this method. Instead,
1180 the method Finalize() should be used with the parameter
1181 @a fix_orientation set to `true`.
1182
1183 @note This method performs a simple check if an element is inverted, e.g.
1184 for most elements types, it checks if the Jacobian of the mapping from
1185 the reference element is non-negative at the center of the element. */
1186 int CheckElementOrientation(bool fix_it = true);
1187
1188 /// Check the orientation of the boundary elements
1189 /** @return The number of boundary elements with wrong orientation. */
1190 int CheckBdrElementOrientation(bool fix_it = true);
1191
1192 /** This method modifies a tetrahedral mesh so that Nedelec spaces of order
1193 greater than 1 can be defined on the mesh. Specifically, we
1194 1) rotate all tets in the mesh so that the vertices {v0, v1, v2, v3}
1195 satisfy: v0 < v1 < min(v2, v3).
1196 2) rotate all boundary triangles so that the vertices {v0, v1, v2}
1197 satisfy: v0 < min(v1, v2).
1198
1199 @note Refinement does not work after a call to this method! */
1200 MFEM_DEPRECATED virtual void ReorientTetMesh();
1201
1202 /// Remove unused vertices and rebuild mesh connectivity.
1203 void RemoveUnusedVertices();
1204
1205 /** Remove boundary elements that lie in the interior of the mesh, i.e. that
1206 have two adjacent faces in 3D, or edges in 2D. */
1208
1209 /**
1210 * @brief Clear the boundary element to edge map.
1211 */
1213 {
1214 delete bel_to_edge;
1215 bel_to_edge = nullptr;
1216 }
1217
1218 /// @}
1219
1220 /// @name Element ordering methods
1221 /// @{
1222
1223 /** This is our integration with the Gecko library. The method finds an
1224 element ordering that will increase memory coherency by putting elements
1225 that are in physical proximity closer in memory. It can also be used to
1226 obtain a space-filling curve ordering for ParNCMesh partitioning.
1227 @param[out] ordering Output element ordering.
1228 @param iterations Total number of V cycles. The ordering may improve with
1229 more iterations. The best iteration is returned at the end.
1230 @param window Initial window size. This determines the number of
1231 permutations tested at each multigrid level and strongly influences the
1232 quality of the result, but the cost of increasing 'window' is exponential.
1233 @param period The window size is incremented every 'period' iterations.
1234 @param seed Seed for initial random ordering (0 = skip random reorder).
1235 @param verbose Print the progress of the optimization to mfem::out.
1236 @param time_limit Optional time limit for the optimization, in seconds.
1237 When reached, ordering from the best iteration so far is returned
1238 (0 = no limit).
1239 @return The final edge product cost of the ordering. The function may be
1240 called in an external loop with different seeds, and the best ordering can
1241 then be retained. */
1243 int iterations = 4, int window = 4,
1244 int period = 2, int seed = 0,
1245 bool verbose = false, real_t time_limit = 0);
1246
1247 /** Return an ordering of the elements that approximately follows the Hilbert
1248 curve. The method performs a spatial (Hilbert) sort on the centers of all
1249 elements and returns the resulting sequence, which can then be passed to
1250 ReorderElements. This is a cheap alternative to GetGeckoElementOrdering.*/
1251 void GetHilbertElementOrdering(Array<int> &ordering);
1252
1253 /** Rebuilds the mesh with a different order of elements. For each element i,
1254 the array ordering[i] contains its desired new index. Note that the method
1255 reorders vertices, edges and faces along with the elements. */
1256 void ReorderElements(const Array<int> &ordering, bool reorder_vertices = true);
1257
1258 /// @}
1259
1260 /// @anchor mfem_Mesh_deprecated_ctors @name Deprecated mesh constructors
1261 ///
1262 /// These constructors have been deprecated in favor of
1263 /// @ref mfem_Mesh_named_ctors "Named mesh constructors".
1264 /// @{
1265
1266 /// Deprecated: see @a MakeCartesian3D.
1267 MFEM_DEPRECATED
1268 Mesh(int nx, int ny, int nz, Element::Type type, bool generate_edges = false,
1269 real_t sx = 1.0, real_t sy = 1.0, real_t sz = 1.0,
1270 bool sfc_ordering = true)
1272 {
1273 Make3D(nx, ny, nz, type, sx, sy, sz, sfc_ordering);
1274 Finalize(true); // refine = true
1275 }
1276
1277 /// Deprecated: see @a MakeCartesian2D.
1278 MFEM_DEPRECATED
1279 Mesh(int nx, int ny, Element::Type type, bool generate_edges = false,
1280 real_t sx = 1.0, real_t sy = 1.0, bool sfc_ordering = true)
1282 {
1283 Make2D(nx, ny, type, sx, sy, generate_edges, sfc_ordering);
1284 Finalize(true); // refine = true
1285 }
1286
1287 /// Deprecated: see @a MakeCartesian1D.
1288 MFEM_DEPRECATED
1289 explicit Mesh(int n, real_t sx = 1.0)
1291 {
1292 Make1D(n, sx);
1293 // Finalize(); // reminder: not needed
1294 }
1295
1296 /// Deprecated: see @a MakeRefined.
1297 MFEM_DEPRECATED
1298 Mesh(Mesh *orig_mesh, int ref_factor, int ref_type);
1299
1300 /// @}
1301
1302 /// @name Information about the mesh as a whole
1303 /// @{
1304
1305 /// @brief Dimension of the reference space used within the elements
1306 int Dimension() const { return Dim; }
1307
1308 /// @brief Dimension of the physical space containing the mesh
1309 int SpaceDimension() const { return spaceDim; }
1310
1311 /// Equals 1 + num_holes - num_loops
1312 inline int EulerNumber() const
1314 /// Equals 1 - num_holes
1315 inline int EulerNumber2D() const
1316 { return NumOfVertices - NumOfEdges + NumOfElements; }
1317
1318 /** @brief Get the mesh generator/type.
1319
1320 The purpose of this is to be able to quickly tell what type of elements
1321 one has in the mesh. Examination of this bitmask along with knowledge
1322 of the mesh dimension can be used to identify which element types are
1323 present.
1324
1325 @return A bitmask:
1326 - bit 0 - simplices are present in the mesh (segments, triangles, tets),
1327 - bit 1 - tensor product elements are present in the mesh (quads, hexes),
1328 - bit 2 - the mesh has wedge elements.
1329 - bit 3 - the mesh has pyramid elements.
1330
1331 In parallel, the result takes into account elements on all processors.
1332 */
1333 inline int MeshGenerator() const { return meshgen; }
1334
1335 /// Checks if the mesh has boundary elements
1336 virtual bool HasBoundaryElements() const { return (NumOfBdrElements > 0); }
1337
1338 /** @brief Return true iff the given @a geom is encountered in the mesh.
1339 Geometries of dimensions lower than Dimension() are counted as well. */
1341 { return mesh_geoms & (1 << geom); }
1342
1343 /** @brief Return the number of geometries of the given dimension present in
1344 the mesh. */
1345 /** For a parallel mesh only the local geometries are counted. */
1346 int GetNumGeometries(int dim) const;
1347
1348 /// Return all element geometries of the given dimension present in the mesh.
1349 /** For a parallel mesh only the local geometries are returned.
1350
1351 The returned geometries are sorted. */
1352 void GetGeometries(int dim, Array<Geometry::Type> &el_geoms) const;
1353
1354 /// @brief Returns true if the mesh is a mixed mesh, false otherwise.
1355 ///
1356 /// A mixed mesh is one where there are multiple types of element geometries.
1357 bool IsMixedMesh() const;
1358
1359 /// Returns the minimum and maximum corners of the mesh bounding box.
1360 /** For high-order meshes, the geometry is first refined @a ref times. */
1361 void GetBoundingBox(Vector &min, Vector &max, int ref = 2);
1362
1363 void GetCharacteristics(real_t &h_min, real_t &h_max,
1364 real_t &kappa_min, real_t &kappa_max,
1365 Vector *Vh = NULL, Vector *Vk = NULL);
1366
1367 /// @}
1368
1369 /// @name Information concerning numbers of mesh entities
1370 /// @{
1371
1372 /** @brief Returns number of vertices. Vertices are only at the corners of
1373 elements, where you would expect them in the lowest-order mesh. */
1374 inline int GetNV() const { return NumOfVertices; }
1375
1376 /// Returns number of elements.
1377 inline int GetNE() const { return NumOfElements; }
1378
1379 /// Returns number of boundary elements.
1380 inline int GetNBE() const { return NumOfBdrElements; }
1381
1382 /// Return the number of edges.
1383 inline int GetNEdges() const { return NumOfEdges; }
1384
1385 /// Return the number of faces in a 3D mesh.
1386 inline int GetNFaces() const { return NumOfFaces; }
1387
1388 /// Return the number of faces (3D), edges (2D) or vertices (1D).
1389 int GetNumFaces() const;
1390
1391 /** @brief Return the number of faces (3D), edges (2D) or vertices (1D)
1392 including ghost faces. */
1393 int GetNumFacesWithGhost() const;
1394
1395 /** @brief Returns the number of faces according to the requested type, does
1396 not count master nonconforming faces.
1397
1398 If type==Boundary returns only the number of true boundary faces
1399 contrary to GetNBE() that returns all "boundary" elements which may
1400 include actual interior faces.
1401 Similarly, if type==Interior, only the true interior faces are counted
1402 excluding all master nonconforming faces. */
1403 virtual int GetNFbyType(FaceType type) const;
1404
1405 /// Return the total (global) number of elements.
1406 long long GetGlobalNE() const { return ReduceInt(NumOfElements); }
1407
1408 /// @}
1409
1410 /// @name Access to individual mesh entities
1411 /// @{
1412
1413 /// @brief Return pointer to vertex i's coordinates.
1414 /// @warning For high-order meshes (when #Nodes != NULL) vertices may not be
1415 /// updated and should not be used!
1416 const real_t *GetVertex(int i) const { return vertices[i](); }
1417
1418 /// @brief Return pointer to vertex i's coordinates.
1419 ///
1420 /// @warning For high-order meshes (when Nodes != NULL) vertices may not
1421 /// being updated and should not be used!
1422 ///
1423 /// @note The pointer returned by this function can be used to
1424 /// alter vertex locations but the pointer itself should not be
1425 /// changed by the caller.
1426 real_t *GetVertex(int i) { return vertices[i](); }
1427
1428 /// @brief Return pointer to the i'th element object
1429 ///
1430 /// The index @a i should be in the range [0, Mesh::GetNE())
1431 ///
1432 /// In parallel, @a i is the local element index which is in the
1433 /// same range mentioned above.
1434 const Element *GetElement(int i) const { return elements[i]; }
1435
1436 /// @brief Return pointer to the i'th element object
1437 ///
1438 /// @note Provides read/write access to the i'th element object so
1439 /// that element attributes or connectivity can be adjusted. However,
1440 /// the Element object itself should not be deleted by the caller.
1441 Element *GetElement(int i) { return elements[i]; }
1442
1443 /// @brief Return pointer to the i'th boundary element object
1444 ///
1445 /// The index @a i should be in the range [0, Mesh::GetNBE())
1446 ///
1447 /// In parallel, @a i is the local boundary element index which is
1448 /// in the same range mentioned above.
1449 const Element *GetBdrElement(int i) const { return boundary[i]; }
1450
1451 /// @brief Return pointer to the i'th boundary element object
1452 ///
1453 /// @note Provides read/write access to the i'th boundary element object so
1454 /// that boundary attributes or connectivity can be adjusted. However,
1455 /// the Element object itself should not be deleted by the caller.
1456 Element *GetBdrElement(int i) { return boundary[i]; }
1457
1458 /// @brief Return pointer to the i'th face element object
1459 ///
1460 /// The index @a i should be in the range [0, Mesh::GetNFaces())
1461 const Element *GetFace(int i) const { return faces[i]; }
1462
1463 /// @}
1464
1465 /// @name Access to groups of mesh entities
1466 /// @{
1467
1468 const Element* const *GetElementsArray() const
1469 { return elements.GetData(); }
1470
1471 void GetElementData(int geom, Array<int> &elem_vtx, Array<int> &attr) const
1472 { GetElementData(elements, geom, elem_vtx, attr); }
1473
1474 void GetBdrElementData(int geom, Array<int> &bdr_elem_vtx,
1475 Array<int> &bdr_attr) const
1476 { GetElementData(boundary, geom, bdr_elem_vtx, bdr_attr); }
1477
1478 /// @}
1479
1480 /// @name Access information concerning individual mesh entites
1481 /// @{
1482
1483 /// Return the attribute of element i.
1484 int GetAttribute(int i) const { return elements[i]->GetAttribute(); }
1485
1486 /// Set the attribute of element i.
1487 void SetAttribute(int i, int attr);
1488
1489 /// Return the attribute of boundary element i.
1490 int GetBdrAttribute(int i) const { return boundary[i]->GetAttribute(); }
1491
1492 /// Set the attribute of boundary element i.
1493 void SetBdrAttribute(int i, int attr) { boundary[i]->SetAttribute(attr); }
1494
1495 /// Return the attribute of patch i, for a NURBS mesh.
1496 int GetPatchAttribute(int i) const;
1497
1498 /// Set the attribute of patch i, for a NURBS mesh.
1499 void SetPatchAttribute(int i, int attr);
1500
1501 /// Return the attribute of patch boundary element i, for a NURBS mesh.
1502 int GetPatchBdrAttribute(int i) const;
1503
1504 /// Set the attribute of patch boundary element i, for a NURBS mesh.
1505 void SetPatchBdrAttribute(int i, int attr);
1506
1507 /** Returns a deep copy of all patches. This method is not const
1508 as it first sets the patches in NURBSext using control points
1509 defined by Nodes. Caller gets ownership of the returned object,
1510 and is responsible for deletion.*/
1511 void GetNURBSPatches(Array<NURBSPatch*> &patches);
1512
1513 /// Returns the type of element i.
1514 Element::Type GetElementType(int i) const;
1515
1516 /// Returns the type of boundary element i.
1517 Element::Type GetBdrElementType(int i) const;
1518
1519 /// Deprecated in favor of Mesh::GetFaceGeometry
1520 MFEM_DEPRECATED Geometry::Type GetFaceGeometryType(int Face) const
1521 { return GetFaceGeometry(Face); }
1522
1523 Element::Type GetFaceElementType(int Face) const;
1524
1525 /// Return the Geometry::Type associated with face @a i.
1526 Geometry::Type GetFaceGeometry(int i) const;
1527
1528 /// @brief If the local mesh is not empty, return GetFaceGeometry(0);
1529 /// otherwise return a typical face geometry present in the global mesh.
1530 ///
1531 /// Note that in mixed meshes or meshes with prism or pyramid elements, there
1532 /// will be more than one face geometry.
1534
1536 {
1537 return elements[i]->GetGeometryType();
1538 }
1539
1540 /** @brief If the local mesh is not empty, return GetElementGeometry(0);
1541 otherwise, return a typical Geometry present in the global mesh.
1542
1543 This method can be used to replace calls like GetElementGeometry(0) in
1544 order to handle empty local meshes better. */
1546
1548 {
1549 return boundary[i]->GetGeometryType();
1550 }
1551
1552 /// Deprecated in favor of Mesh::GetFaceGeometry
1553 MFEM_DEPRECATED Geometry::Type GetFaceBaseGeometry(int i) const
1554 { return GetFaceGeometry(i); }
1555
1558
1561
1562 /// Return true if the given face is interior. @sa FaceIsTrueInterior().
1563 bool FaceIsInterior(int FaceNo) const
1564 {
1565 return (faces_info[FaceNo].Elem2No >= 0);
1566 }
1567
1568 /** @brief Get the size of the i-th element relative to the perfect
1569 reference element. */
1570 real_t GetElementSize(int i, int type = 0);
1571
1572 real_t GetElementSize(int i, const Vector &dir);
1573
1574 real_t GetElementSize(ElementTransformation *T, int type = 0) const;
1575
1576 real_t GetElementVolume(int i);
1577
1578 void GetElementCenter(int i, Vector &center);
1579
1580 /** Compute the Jacobian of the transformation from the perfect
1581 reference element at the given integration point (defaults to the
1582 center of the element if no integration point is specified) */
1583 void GetElementJacobian(int i, DenseMatrix &J,
1584 const IntegrationPoint *ip = NULL);
1585
1586 /// @}
1587
1588 /// List of mesh geometries stored as Array<Geometry::Type>.
1589 class GeometryList : public Array<Geometry::Type>
1590 {
1591 protected:
1593 public:
1594 /// Construct a GeometryList of all element geometries in @a mesh.
1595 GeometryList(const Mesh &mesh)
1596 : Array<Geometry::Type>(geom_buf, Geometry::NumGeom)
1597 { mesh.GetGeometries(mesh.Dimension(), *this); }
1598 /** @brief Construct a GeometryList of all geometries of dimension @a dim
1599 in @a mesh. */
1600 GeometryList(const Mesh &mesh, int dim)
1601 : Array<Geometry::Type>(geom_buf, Geometry::NumGeom)
1602 { mesh.GetGeometries(dim, *this); }
1603 };
1604
1605 /// @name Access connectivity for individual mesh entites
1606 /// @{
1607
1608 /// Returns the indices of the vertices of element i.
1609 void GetElementVertices(int i, Array<int> &v) const
1610 { elements[i]->GetVertices(v); }
1611
1612 /// Returns the indices of the vertices of boundary element i.
1613 void GetBdrElementVertices(int i, Array<int> &v) const
1614 { boundary[i]->GetVertices(v); }
1615
1616 /// Return the indices and the orientations of all edges of element i.
1617 void GetElementEdges(int i, Array<int> &edges, Array<int> &cor) const;
1618
1619 /// Return the indices and the orientations of all edges of bdr element i.
1620 void GetBdrElementEdges(int i, Array<int> &edges, Array<int> &cor) const;
1621
1622 /** Return the indices and the orientations of all edges of face i.
1623 Works for both 2D (face=edge) and 3D faces. */
1624 void GetFaceEdges(int i, Array<int> &edges, Array<int> &o) const;
1625
1626 /// Returns the indices of the vertices of face i.
1627 void GetFaceVertices(int i, Array<int> &vert) const
1628 {
1629 if (Dim == 1)
1630 {
1631 vert.SetSize(1); vert[0] = i;
1632 }
1633 else
1634 {
1635 faces[i]->GetVertices(vert);
1636 }
1637 }
1638
1639 /// Returns the indices of the vertices of edge i.
1640 void GetEdgeVertices(int i, Array<int> &vert) const;
1641
1642 /// Return the indices and the orientations of all faces of element i.
1643 void GetElementFaces(int i, Array<int> &faces, Array<int> &ori) const;
1644
1645 /** @brief Returns the sorted, unique indices of elements sharing a face with
1646 element @a elem, including @a elem. */
1647 Array<int> FindFaceNeighbors(const int elem) const;
1648
1649 /** Return the index and the orientation of the vertex of bdr element i. (1D)
1650 Return the index and the orientation of the edge of bdr element i. (2D)
1651 Return the index and the orientation of the face of bdr element i. (3D)
1652
1653 In 2D, the returned edge orientation is 0 or 1, not +/-1 as returned by
1654 GetElementEdges/GetBdrElementEdges. */
1655 void GetBdrElementFace(int i, int *f, int *o) const;
1656
1657 /** @brief For the given boundary element, bdr_el, return its adjacent
1658 element and its info, i.e. 64*local_bdr_index+bdr_orientation.
1659
1660 The returned bdr_orientation is that of the boundary element relative to
1661 the respective face element.
1662
1663 @sa GetBdrElementAdjacentElement2() */
1664 void GetBdrElementAdjacentElement(int bdr_el, int &el, int &info) const;
1665
1666 /** @brief Deprecated.
1667
1668 For the given boundary element, bdr_el, return its adjacent element and
1669 its info, i.e. 64*local_bdr_index+inverse_bdr_orientation.
1670
1671 The returned inverse_bdr_orientation is the inverse of the orientation of
1672 the boundary element relative to the respective face element. In other
1673 words this is the orientation of the face element relative to the
1674 boundary element.
1675
1676 @warning This only differs from GetBdrElementAdjacentElement by returning
1677 the face info with inverted orientation. It does @b not return
1678 information corresponding to a second adjacent face. This function is
1679 deprecated, use Geometry::GetInverseOrientation, Mesh::EncodeFaceInfo,
1680 Mesh::DecodeFaceInfoOrientation, and Mesh::DecodeFaceInfoLocalIndex
1681 instead.
1682
1683 @sa GetBdrElementAdjacentElement() */
1684 MFEM_DEPRECATED
1685 void GetBdrElementAdjacentElement2(int bdr_el, int &el, int &info) const;
1686
1687 /// @brief Return the local face (codimension-1) index for the given boundary
1688 /// element index.
1689 int GetBdrElementFaceIndex(int be_idx) const { return be_to_face[be_idx]; }
1690
1691 /// Deprecated in favor of GetBdrElementFaceIndex().
1692 MFEM_DEPRECATED int GetBdrFace(int i) const { return GetBdrElementFaceIndex(i); }
1693
1694 /** Return the vertex index of boundary element i. (1D)
1695 Return the edge index of boundary element i. (2D)
1696 Return the face index of boundary element i. (3D)
1697
1698 Deprecated in favor of GetBdrElementFaceIndex(). */
1699 MFEM_DEPRECATED int GetBdrElementEdgeIndex(int i) const { return GetBdrElementFaceIndex(i); }
1700
1701 /// @}
1702
1703 /// @name Access connectivity data
1704 /// @{
1705
1706 /// @note The returned Table should be deleted by the caller
1708
1709 /// @note The returned Table should be deleted by the caller
1711
1712 /// Return the "face"-element Table. Here "face" refers to face (3D),
1713 /// edge (2D), or vertex (1D).
1714 ///
1715 /// @note The returned Table should be deleted by the caller.
1717
1718 /// Returns the face-to-edge Table (3D)
1719 ///
1720 /// @note The returned object should NOT be deleted by the caller.
1721 Table *GetFaceEdgeTable() const;
1722
1723 /// Returns the edge-to-vertex Table (3D)
1724 ///
1725 /// @note The returned object should NOT be deleted by the caller.
1726 Table *GetEdgeVertexTable() const;
1727
1728 /** Return vertex to vertex table. The connections stored in the table
1729 are from smaller to bigger vertex index, i.e. if i<j and (i, j) is
1730 in the table, then (j, i) is not stored.
1731
1732 @note This data is not stored internally as a Table. The Table passed as
1733 an argument is populated using the EdgeVertex Table (see GetEdgeVertexTable)
1734 if available or the element connectivity.
1735 */
1736 void GetVertexToVertexTable(DSTable &) const;
1737
1739
1740 const Table &ElementToFaceTable() const;
1741
1742 const Table &ElementToEdgeTable() const;
1743
1745
1746 ///@}
1747
1748 /// @brief Return FiniteElement for reference element of the specified type
1749 ///
1750 /// @note The returned object is a pointer to a global object and should not
1751 /// be deleted by the caller.
1753
1754 /** @brief For the vertex (1D), edge (2D), or face (3D) of a boundary element
1755 with the orientation @a o, return the transformation of the boundary
1756 element integration point @ ip to the face element. In 2D, the
1757 the orientation is 0 or 1 as returned by GetBdrElementFace, not +/-1.
1758 Supports both internal and external boundaries. */
1760 const IntegrationPoint &ip);
1761
1762 /// @anchor mfem_Mesh_elem_trans
1763 /// @name Access the coordinate transformation for individual elements
1764 ///
1765 /// See also the methods related to
1766 /// @ref mfem_Mesh_geom_factors "Geometric Factors" for accessing
1767 /// information cached at quadrature points.
1768 /// @{
1769
1770 /// @brief Builds the transformation defining the i-th element in @a ElTr.
1771 /// @a ElTr must be allocated in advance and will be owned by the caller.
1772 ///
1773 /// @note The provided pointer must not be NULL. In the future this should be
1774 /// changed to a reference parameter consistent with
1775 /// GetFaceElementTransformations.
1776 void GetElementTransformation(int i,
1777 IsoparametricTransformation *ElTr) const;
1778
1779 /// @brief Returns a pointer to the transformation defining the i-th element.
1780 ///
1781 /// @note The returned object is owned by the class and is shared, i.e.,
1782 /// calling this function resets pointers obtained from previous calls.
1783 /// Also, this pointer should @b not be deleted by the caller.
1785
1786 /// @brief If the local mesh is not empty return GetElementTransformation(0);
1787 /// otherwise, return the identity transformation for a typical geometry in
1788 /// the mesh and a typical finite element in the nodal finite element space
1789 /// (if present).
1790 ///
1791 /// This method can be used to replace calls like GetElementTransformation(0)
1792 /// in order to handle empty local meshes better.
1793 ///
1794 /// @note The returned object is owned by the class and is shared, i.e.,
1795 /// calling this function resets pointers obtained from previous calls. Also,
1796 /// this pointer should @b not be deleted by the caller.
1798
1799 /// @brief Builds the transformation defining the i-th element in @a ElTr
1800 /// assuming position of the vertices/nodes are given by @a nodes.
1801 /// @a ElTr must be allocated in advance and will be owned by the caller.
1802 ///
1803 /// @note The provided pointer must not be NULL. In the future this should be
1804 /// changed to a reference parameter consistent with
1805 /// GetFaceElementTransformations.
1806 void GetElementTransformation(int i, const Vector &nodes,
1807 IsoparametricTransformation *ElTr) const;
1808
1809 /// @brief Returns a pointer to the transformation defining the i-th boundary
1810 /// element.
1811 ///
1812 /// @note The returned object is owned by the class and is shared, i.e.,
1813 /// calling this function resets pointers obtained from previous calls.
1814 /// Also, the returned object should NOT be deleted by the caller.
1816
1817 /// @brief Builds the transformation defining the i-th boundary element in
1818 /// @a ElTr. @a ElTr must be allocated in advance and will be owned by the
1819 /// caller.
1820 ///
1821 /// @note The provided pointer must not be NULL. In the future this should be
1822 /// changed to a reference parameter consistent with
1823 /// GetFaceElementTransformations.
1824 void GetBdrElementTransformation(int i,
1825 IsoparametricTransformation *ElTr) const;
1826
1827 /// @brief Returns a pointer to the transformation defining the given face
1828 /// element.
1829 ///
1830 /// @note The returned object is owned by the class and is shared, i.e.,
1831 /// calling this function resets pointers obtained from previous calls. Also,
1832 /// the returned object should NOT be deleted by the caller.
1834
1835 /// @brief Builds the transformation defining the i-th face element in
1836 /// @a FTr. @a FTr must be allocated in advance and will be owned by the
1837 /// caller.
1838 ///
1839 /// @note The provided pointer must not be NULL. In the future this should be
1840 /// changed to a reference parameter consistent with
1841 /// GetFaceElementTransformations.
1842 void GetFaceTransformation(int i, IsoparametricTransformation *FTr) const;
1843
1844 /** @brief A helper method that constructs a transformation from the
1845 reference space of a face to the reference space of an element. */
1846 /** The local index of the face as a face in the element and its orientation
1847 are given by the input parameter @a info, as @a info = 64*loc_face_idx +
1848 loc_face_orientation. */
1849 void GetLocalFaceTransformation(int face_type, int elem_type,
1851 int info) const;
1852
1853 /// @brief Builds the transformation defining the i-th edge element in
1854 /// @a EdTr. @a EdTr must be allocated in advance and will be owned by the
1855 /// caller.
1856 ///
1857 /// @note The provided pointer must not be NULL. In the future this should be
1858 /// changed to a reference parameter consistent with
1859 /// GetFaceElementTransformations.
1860 void GetEdgeTransformation(int i, IsoparametricTransformation *EdTr) const;
1861
1862 /// @brief Returns a pointer to the transformation defining the given edge
1863 /// element.
1864 ///
1865 /// @note The returned object is owned by the class and is shared, i.e.,
1866 /// calling this function resets pointers obtained from previous calls.
1867 /// Also, the returned object should NOT be deleted by the caller.
1869
1870 /// Returns (a pointer to an object containing) the following data:
1871 ///
1872 /// 1) Elem1No - the index of the first element that contains this face this
1873 /// is the element that has the same outward unit normal vector as the
1874 /// face;
1875 ///
1876 /// 2) Elem2No - the index of the second element that contains this face this
1877 /// element has outward unit normal vector as the face multiplied with -1;
1878 ///
1879 /// 3) Elem1, Elem2 - pointers to the ElementTransformation's of the first
1880 /// and the second element respectively;
1881 ///
1882 /// 4) Face - pointer to the ElementTransformation of the face;
1883 ///
1884 /// 5) Loc1, Loc2 - IntegrationPointTransformation's mapping the face
1885 /// coordinate system to the element coordinate system (both in their
1886 /// reference elements). Used to transform IntegrationPoints from face to
1887 /// element. More formally, let:
1888 /// TL1, TL2 be the transformations represented by Loc1, Loc2,
1889 /// TE1, TE2 - the transformations represented by Elem1, Elem2,
1890 /// TF - the transformation represented by Face, then
1891 /// TF(x) = TE1(TL1(x)) = TE2(TL2(x)) for all x in the reference face.
1892 ///
1893 /// 6) FaceGeom - the base geometry for the face.
1894 ///
1895 /// The mask specifies which fields in the structure to return:
1896 /// mask & 1 - Elem1, mask & 2 - Elem2
1897 /// mask & 4 - Loc1, mask & 8 - Loc2, mask & 16 - Face.
1898 /// These mask values are defined in the ConfigMasks enum type as part of the
1899 /// FaceElementTransformations class in fem/eltrans.hpp.
1900 ///
1901 /// @note The returned object is owned by the class and is shared, i.e.,
1902 /// calling this function resets pointers obtained from previous calls.
1903 /// Also, this pointer should NOT be deleted by the caller.
1905 GetFaceElementTransformations(int FaceNo, int mask = 31);
1906
1907 /// @brief Variant of GetFaceElementTransformations using a user allocated
1908 /// FaceElementTransformations object.
1909 virtual void GetFaceElementTransformations(int FaceNo,
1913 int mask = 31) const;
1914
1915 /// @brief See GetFaceElementTransformations().
1916 ///
1917 /// @note The returned object is owned by the class and is shared, i.e.,
1918 /// calling this function resets pointers obtained from previous calls.
1919 /// Also, this pointer should NOT be deleted by the caller.
1921
1922 /// @brief Variant of GetInteriorFaceTransformations using a user allocated
1923 /// FaceElementTransformations object.
1924 void GetInteriorFaceTransformations(int FaceNo,
1927 IsoparametricTransformation &ElTr2) const;
1928
1929 /// @brief Builds the transformation defining the given boundary face.
1930 ///
1931 /// @note The returned object is owned by the class and is shared, i.e.,
1932 /// calling this function resets pointers obtained from previous calls.
1933 /// Also, this pointer should NOT be deleted by the caller.
1935
1936 /// @brief Variant of GetBdrFaceTransformations using a user allocated
1937 /// FaceElementTransformations object.
1938 void GetBdrFaceTransformations(int BdrElemNo,
1941 IsoparametricTransformation &ElTr2) const;
1942
1943 /// @}
1944
1945 /// @anchor mfem_Mesh_geom_factors
1946 /// @name Access the coordinate transformation at quadrature points
1947 ///
1948 /// See also methods related to
1949 /// @ref mfem_Mesh_elem_trans "Element-wise coordinate transformation".
1950 /// @{
1951
1952 /** @brief Return the mesh geometric factors corresponding to the given
1953 integration rule.
1954
1955 The IntegrationRule used with GetGeometricFactors needs to remain valid
1956 until the internally stored GeometricFactors objects are destroyed (by
1957 calling Mesh::DeleteGeometricFactors(), Mesh::NodesUpdated(), or the Mesh
1958 destructor).
1959
1960 If the device MemoryType parameter @a d_mt is specified, then the
1961 returned object will use that type unless it was previously allocated
1962 with a different type.
1963
1964 The returned pointer points to an internal object that may be invalidated
1965 by mesh operations such as refinement, vertex/node movement, etc. Since
1966 not all such modifications can be tracked by the Mesh class (e.g. when
1967 using the pointer returned by GetNodes() to change the nodes) one needs
1968 to account for such changes by calling the method NodesUpdated() which,
1969 in particular, will call DeleteGeometricFactors(). */
1971 const IntegrationRule& ir,
1972 const int flags,
1974
1975 /** @brief Return the mesh geometric factors for the faces corresponding
1976 to the given integration rule.
1977
1978 The IntegrationRule used with GetFaceGeometricFactors needs to remain
1979 valid until the internally stored FaceGeometricFactors objects are
1980 destroyed (by either calling Mesh::DeleteGeometricFactors(),
1981 Mesh::NodesUpdated(), or the Mesh destructor).
1982
1983 If the device MemoryType parameter @a d_mt is specified, then the
1984 returned object will use that type unless it was previously allocated
1985 with a different type.
1986
1987 The returned pointer points to an internal object that may be invalidated
1988 by mesh operations such as refinement, vertex/node movement, etc. Since
1989 not all such modifications can be tracked by the Mesh class (e.g. when
1990 using the pointer returned by GetNodes() to change the nodes) one needs
1991 to account for such changes by calling the method NodesUpdated() which,
1992 in particular, will call DeleteGeometricFactors(). */
1994 const IntegrationRule& ir,
1995 const int flags,
1996 FaceType type,
1998
1999 /// Destroy all GeometricFactors stored by the Mesh.
2000 /** This method can be used to force recomputation of the GeometricFactors,
2001 for example, after the mesh nodes are modified externally.
2002
2003 @note In general, the preferred method for resetting the GeometricFactors
2004 should be to call NodesUpdated(). */
2006
2007 /// @}
2008
2009 /** This enumerated type describes the three main face topologies:
2010 - Boundary, for faces on the boundary of the computational domain,
2011 - Conforming, for conforming faces interior to the computational domain,
2012 - Nonconforming, for nonconforming faces interior to the computational
2013 domain. */
2015 Conforming,
2017 NA
2018 };
2019
2020 /** This enumerated type describes the location of the two elements sharing a
2021 face, Local meaning that the element is local to the MPI rank, FaceNbr
2022 meaning that the element is distributed on a different MPI rank, this
2023 typically means that methods with FaceNbr should be used to access the
2024 relevant information, e.g., ParFiniteElementSpace::GetFaceNbrElementVDofs.
2025 */
2027
2028 /** This enumerated type describes the topological relation of an element to
2029 a face:
2030 - Coincident meaning that the element's face is topologically equal to
2031 the mesh face.
2032 - Superset meaning that the element's face is topologically coarser than
2033 the mesh face, i.e., the element's face contains the mesh face.
2034 - Subset meaning that the element's face is topologically finer than the
2035 mesh face, i.e., the element's face is contained in the mesh face.
2036 Superset and Subset are only relevant for nonconforming faces.
2037 Master nonconforming faces have a conforming element on one side, and a
2038 fine element on the other side. Slave nonconforming faces have a
2039 conforming element on one side, and a coarse element on the other side.
2040 */
2042
2043 /** This enumerated type describes the corresponding FaceInfo internal
2044 representation (encoded cases), c.f. FaceInfo's documentation:
2045 Classification of a local (non-ghost) face based on its FaceInfo:
2046 - Elem2No >= 0 --> local interior face; can be either:
2047 - NCFace == -1 --> LocalConforming,
2048 - NCFace >= 0 --> LocalSlaveNonconforming,
2049 - Elem2No < 0 --> local "boundary" face; can be one of:
2050 - NCFace == -1 --> conforming face; can be either:
2051 - Elem2Inf < 0 --> Boundary,
2052 - Elem2Inf >= 0 --> SharedConforming,
2053 - NCFace >= 0 --> nonconforming face; can be one of:
2054 - Elem2Inf < 0 --> MasterNonconforming (shared or not shared),
2055 - Elem2Inf >= 0 --> SharedSlaveNonconforming.
2056 Classification of a ghost (non-local) face based on its FaceInfo:
2057 - Elem1No == -1 --> GhostMaster (includes other unused ghost faces),
2058 - Elem1No >= 0 --> GhostSlave.
2059 */
2069
2070 /** @brief This structure is used as a human readable output format that
2071 deciphers the information contained in Mesh::FaceInfo when using the
2072 Mesh::GetFaceInformation() method.
2073
2074 The element indices in this structure don't need further processing,
2075 contrary to the ones obtained through Mesh::GetFacesElements and can
2076 directly be used, e.g., Elem1 and Elem2 indices.
2077 Likewise the orientations for Elem1 and Elem2 already take into account
2078 special cases and can be used as is.
2079 */
2081 {
2083
2084 struct
2085 {
2092
2096
2097 /** @brief Return true if the face is a local interior face which is NOT
2098 a master nonconforming face. */
2099 bool IsLocal() const
2100 {
2101 return element[1].location == Mesh::ElementLocation::Local;
2102 }
2103
2104 /** @brief Return true if the face is a shared interior face which is NOT
2105 a master nonconforming face. */
2106 bool IsShared() const
2107 {
2108 return element[1].location == Mesh::ElementLocation::FaceNbr;
2109 }
2110
2111 /** @brief return true if the face is an interior face to the computation
2112 domain, either a local or shared interior face (not a boundary face)
2113 which is NOT a master nonconforming face.
2114 */
2115 bool IsInterior() const
2116 {
2119 }
2120
2121 /** @brief Return true if the face is a boundary face. */
2122 bool IsBoundary() const
2123 {
2125 }
2126
2127 /// @brief Return true if the face is of the same type as @a type.
2128 bool IsOfFaceType(FaceType type) const
2129 {
2130 switch (type)
2131 {
2132 case FaceType::Interior:
2133 return IsInterior();
2134 case FaceType::Boundary:
2135 return IsBoundary();
2136 default:
2137 return false;
2138 }
2139 }
2140
2141 /// @brief Return true if the face is a conforming face.
2142 bool IsConforming() const
2143 {
2145 }
2146
2147 /// @brief Return true if the face is a nonconforming fine face.
2149 {
2151 (element[0].conformity == ElementConformity::Superset ||
2152 element[1].conformity == ElementConformity::Superset);
2153 }
2154
2155 /// @brief Return true if the face is a nonconforming coarse face.
2156 /** Note that ghost nonconforming master faces cannot be clearly
2157 identified as such with the currently available information, so this
2158 method will return false for such faces. */
2160 {
2162 element[1].conformity == ElementConformity::Subset;
2163 }
2164
2165 /// @brief cast operator from FaceInformation to FaceInfo.
2166 operator Mesh::FaceInfo() const;
2167 };
2168
2169 /// Given a "face info int", return the face orientation. @sa FaceInfo.
2170 static int DecodeFaceInfoOrientation(int info) { return info%64; }
2171
2172 /// Given a "face info int", return the local face index. @sa FaceInfo.
2173 static int DecodeFaceInfoLocalIndex(int info) { return info/64; }
2174
2175 /// @brief Given @a local_face_index and @a orientation, return the
2176 /// corresponding encoded "face info int". @sa FaceInfo.
2177 static int EncodeFaceInfo(int local_face_index, int orientation)
2178 { return orientation + local_face_index*64; }
2179
2180 /// @name More advanced entity information access methods
2181 /// @{
2182
2183 /* Return point matrix of element i of dimension Dim X #v, where for every
2184 vertex we give its coordinates in space of dimension Dim. */
2185 void GetPointMatrix(int i, DenseMatrix &pointmat) const;
2186
2187 /* Return point matrix of boundary element i of dimension Dim X #v, where for
2188 every vertex we give its coordinates in space of dimension Dim. */
2189 void GetBdrPointMatrix(int i, DenseMatrix &pointmat) const;
2190
2191 /** This method aims to provide face information in a deciphered format, i.e.
2192 Mesh::FaceInformation, compared to the raw encoded information returned
2193 by Mesh::GetFaceElements() and Mesh::GetFaceInfos(). */
2194 FaceInformation GetFaceInformation(int f) const;
2195
2196 void GetFaceElements (int Face, int *Elem1, int *Elem2) const;
2197 void GetFaceInfos (int Face, int *Inf1, int *Inf2) const;
2198 void GetFaceInfos (int Face, int *Inf1, int *Inf2, int *NCFace) const;
2199
2200 /// @brief Populate a marker array identifying exterior faces
2201 ///
2202 /// @param[in,out] face_marker Resized if necessary to the number of
2203 /// local faces. The array entries will be
2204 /// zero for interior faces and 1 for exterior
2205 /// faces.
2206 virtual void GetExteriorFaceMarker(Array<int> &face_marker) const;
2207
2208 /// @brief Unmark boundary attributes of internal boundaries
2209 ///
2210 /// @param[in,out] bdr_marker Array of length bdr_attributes.Max().
2211 /// Entries associated with internal boundaries
2212 /// will be set to zero. Other entries will remain
2213 /// unchanged.
2214 /// @param[in] excl Only unmark entries which exclusively contain
2215 /// internal faces [default: true].
2216 virtual void UnmarkInternalBoundaries(Array<int> &bdr_marker,
2217 bool excl = true) const;
2218
2219 /// @brief Unmark boundary attributes in the named set
2220 ///
2221 /// @param[in] set_name Name of a named boundary attribute set.
2222 /// @param[in,out] bdr_marker Array of length bdr_attributes.Max().
2223 /// Entries associated with the named set will be
2224 /// set to zero. Other entries will remain
2225 /// unchanged.
2226 virtual void UnmarkNamedBoundaries(const std::string &set_name,
2227 Array<int> &bdr_marker) const;
2228
2229 /// @brief Mark boundary attributes of external boundaries
2230 ///
2231 /// @param[in,out] bdr_marker Array of length bdr_attributes.Max().
2232 /// Entries associated with external boundaries
2233 /// will be set to one. Other entries will remain
2234 /// unchanged.
2235 /// @param[in] excl Only mark entries which exclusively contain
2236 /// external faces [default: true].
2237 virtual void MarkExternalBoundaries(Array<int> &bdr_marker,
2238 bool excl = true) const;
2239
2240 /// @brief Mark boundary attributes in the named set
2241 ///
2242 /// @param[in] set_name Name of a named boundary attribute set.
2243 /// @param[in,out] bdr_marker Array of length bdr_attributes.Max().
2244 /// Entries associated with the named set will be
2245 /// set to one. Other entries will remain
2246 /// unchanged.
2247 virtual void MarkNamedBoundaries(const std::string &set_name,
2248 Array<int> &bdr_marker) const;
2249
2250 /// @}
2251
2252 /// @name Methods related to mesh partitioning
2253 /// @{
2254
2255 /// @note The returned array should be deleted by the caller.
2256 int *CartesianPartitioning(int nxyz[]);
2257 /// @note The returned array should be deleted by the caller.
2258 int *GeneratePartitioning(int nparts, int part_method = 1);
2259 /// @todo This method needs a proper description
2260 void CheckPartitioning(int *partitioning_);
2261
2262 /// @}
2263
2264 /// @anchor mfem_Mesh_trans
2265 /// @name Methods related to accessing/altering mesh coordinates
2266 ///
2267 /// See also @ref mfem_Mesh_gf_nodes "Coordinates as a GridFunction".
2268 /// @{
2269
2270 // Vertices are only at the corners of elements, where you would expect them
2271 // in the lowest-order mesh.
2272 void MoveVertices(const Vector &displacements);
2273 void GetVertices(Vector &vert_coord) const;
2274 void SetVertices(const Vector &vert_coord);
2275
2276 /** @brief Set the internal Vertex array to point to the given @a vertices
2277 array without assuming ownership of the pointer. */
2278 /** If @a zerocopy is `true`, the vertices must be given as an array of 3
2279 doubles per vertex. If @a zerocopy is `false` then the current Vertex
2280 data is first copied to the @a vertices array. */
2281 void ChangeVertexDataOwnership(real_t *vertices, int len_vertices,
2282 bool zerocopy = false);
2283
2284 // Nodes are only active for higher order meshes, and share locations with
2285 // the vertices, plus all the higher- order control points within the element
2286 // and along the edges and on the faces.
2287 void GetNode(int i, real_t *coord) const;
2288 void SetNode(int i, const real_t *coord);
2289
2290 // Node operations for curved mesh.
2291 // They call the corresponding '...Vertices' method if the
2292 // mesh is not curved (i.e. Nodes == NULL).
2293 void MoveNodes(const Vector &displacements);
2294 void GetNodes(Vector &node_coord) const;
2295 /// Updates the vertex/node locations. Invokes NodesUpdated().
2296 void SetNodes(const Vector &node_coord);
2297
2298 void ScaleSubdomains (real_t sf);
2299 void ScaleElements (real_t sf);
2300
2301 void Transform(std::function<void(const Vector &, Vector&)> f);
2302 void Transform(VectorCoefficient &deformation);
2303
2304 /** @brief This function should be called after the mesh node coordinates
2305 have been updated externally, e.g. by modifying the internal nodal
2306 GridFunction returned by GetNodes(). */
2307 /** It deletes internal quantities derived from the node coordinates,
2308 such as the (Face)GeometricFactors.
2309
2310 @note Unlike the similarly named protected method UpdateNodes() this
2311 method does not modify the nodes. */
2313
2314 /// @brief Returns the attributes for all elements in this mesh. The i'th
2315 /// entry of the array is the attribute of the i'th element of the mesh.
2316 ///
2317 /// The returned array points to an internal object that may be invalidated
2318 /// by mesh operations such as refinement or any element attributes are
2319 /// modified. Since not all such modifications can be tracked by the Mesh
2320 /// class (e.g. if a user calls GetElement() then changes the element
2321 /// attribute directly), one needs to account for such changes by calling the
2322 /// method SetAttributes().
2323 const Array<int>& GetElementAttributes() const;
2324
2325 /// @brief Returns the attributes for all boundary elements in this mesh.
2326 ///
2327 /// The face restriction will give "face E-vectors" on the boundary that
2328 /// are numbered in the order of the faces of mesh. This numbering will be
2329 /// different than the numbering of the boundary elements. We compute
2330 /// mappings so that the array `bdr_attributes[i]` gives the boundary
2331 /// attribute of the `i`th boundary face in the mesh face order.
2332 /// Attributes <= 0 indicate there is no boundary element and should be
2333 /// skipped.
2334 ///
2335 /// The returned array points to an internal object that may be invalidated
2336 /// by mesh operations such as refinement or any element attributes are
2337 /// modified. Since not all such modifications can be tracked by the Mesh
2338 /// class (e.g. if a user calls GetElement() then changes the element
2339 /// attribute directly), one needs to account for such changes by calling the
2340 /// method SetAttributes().
2341 const Array<int>& GetBdrFaceAttributes() const;
2342
2343 /// @}
2344
2345 /// @anchor mfem_Mesh_gf_nodes
2346 /// @name Methods related to nodal coordinates stored as a GridFunction
2347 ///
2348 /// See also @ref mfem_Mesh_trans "Mesh Transformations".
2349 /// @{
2350
2351 /// @brief Return a pointer to the internal node GridFunction (may be NULL).
2352 ///
2353 /// If the mesh is straight-sided (low-order), it may not have a GridFunction
2354 /// for the nodes, in which case this function returns NULL. To ensure that
2355 /// the nodal GridFunction exists, first call EnsureNodes().
2356 /// @sa SetCurvature().
2357 ///
2358 /// @note The returned object should NOT be deleted by the caller.
2360 const GridFunction *GetNodes() const { return Nodes; }
2361 /// Return the mesh nodes ownership flag.
2362 bool OwnsNodes() const { return own_nodes; }
2363 /// Set the mesh nodes ownership flag.
2364 void SetNodesOwner(bool nodes_owner) { own_nodes = nodes_owner; }
2365 /// Replace the internal node GridFunction with the given GridFunction.
2366 /** Invokes NodesUpdated(). */
2367 void NewNodes(GridFunction &nodes, bool make_owner = false);
2368 /** @brief Swap the internal node GridFunction pointer and ownership flag
2369 members with the given ones. */
2370 /** Invokes NodesUpdated(). */
2371 void SwapNodes(GridFunction *&nodes, int &own_nodes_);
2372
2373 /// Return the mesh nodes/vertices projected on the given GridFunction.
2374 void GetNodes(GridFunction &nodes) const;
2375 /** Replace the internal node GridFunction with a new GridFunction defined
2376 on the given FiniteElementSpace. The new node coordinates are projected
2377 (derived) from the current nodes/vertices. */
2378 virtual void SetNodalFESpace(FiniteElementSpace *nfes);
2379 /** Replace the internal node GridFunction with the given GridFunction. The
2380 given GridFunction is updated with node coordinates projected (derived)
2381 from the current nodes/vertices. */
2382 void SetNodalGridFunction(GridFunction *nodes, bool make_owner = false);
2383 /** Return the FiniteElementSpace on which the current mesh nodes are
2384 defined or NULL if the mesh does not have nodes. */
2385 const FiniteElementSpace *GetNodalFESpace() const;
2386 /** @brief Make sure that the mesh has valid nodes, i.e. its geometry is
2387 described by a vector finite element grid function (even if it is a
2388 low-order mesh with straight edges).
2389
2390 @sa GetNodes(). */
2391 void EnsureNodes();
2392
2393 /// Set the curvature of the mesh nodes using the given polynomial degree.
2394 /** Creates a nodal GridFunction if one doesn't already exist.
2395
2396 @param[in] order Polynomial degree of the nodal FE space. If this
2397 value is <= 0 then the method will remove the
2398 nodal GridFunction and the Mesh will use the
2399 vertices array instead; the other arguments are
2400 ignored in this case.
2401 @param[in] discont Whether to use a discontinuous or continuous
2402 finite element space (continuous is default).
2403 @param[in] space_dim The space dimension (optional).
2404 @param[in] ordering The Ordering of the finite element space
2405 (Ordering::byVDIM is the default). */
2406 virtual void SetCurvature(int order, bool discont = false, int space_dim = -1,
2407 int ordering = 1);
2408
2409 /// @}
2410
2411 /// @name Methods related to mesh refinement
2412 /// @{
2413
2414 /// Refine all mesh elements.
2415 /** @param[in] ref_algo %Refinement algorithm. Currently used only for pure
2416 tetrahedral meshes. If set to zero (default), a tet mesh will be refined
2417 using algorithm A, that produces elements with better quality compared to
2418 algorithm B used when the parameter is non-zero.
2419
2420 For tetrahedral meshes, after using algorithm A, the mesh cannot be
2421 refined locally using methods like GeneralRefinement() unless it is
2422 re-finalized using Finalize() with the parameter @a refine set to true.
2423 Note that calling Finalize() in this way will generally invalidate any
2424 FiniteElementSpace%s and GridFunction%s defined on the mesh. */
2425 void UniformRefinement(int ref_algo = 0);
2426
2427 /** @brief Refine NURBS mesh, with an optional refinement factor, generally
2428 anisotropic.
2429
2430 @param[in] rf Optional refinement factor. If scalar, the factor is used
2431 for all dimensions. If an array, factors can be specified
2432 for each dimension. The factor multiplies the number of
2433 elements in each dimension. Some factors can be 1.
2434 @param[in] tol NURBS geometry deviation tolerance, cf. Algorithm A5.8 of
2435 "The NURBS Book", 2nd ed, Piegl and Tiller. */
2436 virtual void NURBSUniformRefinement(int rf = 2, real_t tol = 1.0e-12);
2437 virtual void NURBSUniformRefinement(const Array<int> &rf, real_t tol=1.e-12);
2438
2439 /** @a brief Use knotvector refinement factors loaded from the file with name
2440 in @a kvf. Everywhere else, use the default refinement factor @a rf. */
2441 virtual void RefineNURBSWithKVFactors(int rf, const std::string &kvf);
2442
2443 /// Coarsening for a NURBS mesh, with an optional coarsening factor @a cf > 1
2444 /// which divides the number of elements in each dimension.
2445 void NURBSCoarsening(int cf = 2, real_t tol = 1.0e-12);
2446
2447 /** Refine selected mesh elements. Refinement type can be specified for each
2448 element. The function can do conforming refinement of triangles and
2449 tetrahedra and nonconforming refinement (i.e., with hanging-nodes) of
2450 triangles, quadrilaterals and hexahedra. If 'nonconforming' = -1,
2451 suitable refinement method is selected automatically (namely, conforming
2452 refinement for triangles). Use nonconforming = 0/1 to force the method.
2453 For nonconforming refinements, nc_limit optionally specifies the maximum
2454 level of hanging nodes (unlimited by default). */
2455 void GeneralRefinement(const Array<Refinement> &refinements,
2456 int nonconforming = -1, int nc_limit = 0);
2457
2458 /** Simplified version of GeneralRefinement taking a simple list of elements
2459 to refine, without refinement types. */
2460 void GeneralRefinement(const Array<int> &el_to_refine,
2461 int nonconforming = -1, int nc_limit = 0);
2462
2463 /// Refine each element with given probability. Uses GeneralRefinement.
2464 void RandomRefinement(real_t prob, bool aniso = false,
2465 int nonconforming = -1, int nc_limit = 0);
2466
2467 /// Refine elements sharing the specified vertex. Uses GeneralRefinement.
2468 void RefineAtVertex(const Vertex& vert,
2469 real_t eps = 0.0, int nonconforming = -1);
2470
2471 /** Refine element i if elem_error[i] > threshold, for all i.
2472 Returns true if at least one element was refined, false otherwise. */
2473 bool RefineByError(const Array<real_t> &elem_error, real_t threshold,
2474 int nonconforming = -1, int nc_limit = 0);
2475
2476 /** Refine element i if elem_error(i) > threshold, for all i.
2477 Returns true if at least one element was refined, false otherwise. */
2478 bool RefineByError(const Vector &elem_error, real_t threshold,
2479 int nonconforming = -1, int nc_limit = 0);
2480
2481 /** Derefine the mesh based on an error measure associated with each
2482 element. A derefinement is performed if the sum of errors of its fine
2483 elements is smaller than 'threshold'. If 'nc_limit' > 0, derefinements
2484 that would increase the maximum level of hanging nodes of the mesh are
2485 skipped. Returns true if the mesh changed, false otherwise. */
2486 bool DerefineByError(Array<real_t> &elem_error, real_t threshold,
2487 int nc_limit = 0, int op = 1);
2488
2489 /// Same as DerefineByError for an error vector.
2490 bool DerefineByError(const Vector &elem_error, real_t threshold,
2491 int nc_limit = 0, int op = 1);
2492
2493 /** Make sure that a quad/hex mesh is considered to be nonconforming (i.e.,
2494 has an associated NCMesh object). Simplex meshes can be both conforming
2495 (default) or nonconforming. */
2496 void EnsureNCMesh(bool simplices_nonconforming = false);
2497
2498 bool Conforming() const;
2499 bool Nonconforming() const { return !Conforming(); }
2500
2501 /** Designate this mesh for output as "NC mesh v1.1", meaning it is
2502 nonconforming with nonuniform refinement spacings. */
2504 {
2505 ncmesh->using_scaling = true;
2506 }
2507
2508 /** Return fine element transformations following a mesh refinement.
2509 Space uses this to construct a global interpolation matrix. */
2511
2512 /// Return type of last modification of the mesh.
2514
2515 /** Return update counter. The counter starts at zero and is incremented
2516 each time refinement, derefinement, or rebalancing method is called.
2517 It is used for checking proper sequence of Space:: and GridFunction::
2518 Update() calls. */
2519 long GetSequence() const { return sequence; }
2520
2521 /// @brief Return the nodes update counter.
2522 ///
2523 /// This counter starts at zero, and is incremented every time the geometric
2524 /// factors must be recomputed (e.g. on calls to Mesh::Transform,
2525 /// Mesh::NodesUpdated, etc.)
2526 long GetNodesSequence() const { return nodes_sequence; }
2527
2528 /// @}
2529
2530 ///@{ @name NURBS mesh refinement methods
2531 /** Refine a NURBS mesh with the knots specified in the file named @a ref_file.
2532 The file has the number of knot vectors on the first line. It is the same
2533 number of knot vectors specified in the NURBS mesh in the section edges. Then
2534 for each knot vector specified in the section edges (with the same ordering),
2535 a line describes (in this order): 1) an integer giving the number of knots
2536 inserted, 2) the knots inserted as a double. The advantage of this method
2537 is that it is possible to specifically refine a coarse NURBS mesh without
2538 changing the mesh file itself. Examples in miniapps/nurbs/meshes. */
2539 void RefineNURBSFromFile(std::string ref_file);
2540
2541 /// For NURBS meshes, insert the new knots in @a kv, for each direction.
2543
2544 /// For NURBS meshes, insert the knots in @a kv, for each direction.
2545 void KnotInsert(Array<Vector*> &kv);
2546
2547 /// For NURBS meshes, remove the knots in @a kv, for each direction.
2548 void KnotRemove(Array<Vector*> &kv);
2549
2550 /* For each knot vector:
2551 new_degree = max(old_degree, min(old_degree + rel_degree, degree)). */
2552 void DegreeElevate(int rel_degree, int degree = 16);
2553 ///@}
2554
2555 /// @name Print/Save/Export methods
2556 /// @{
2557
2558 /// Print the mesh to the given stream using Netgen/Truegrid format.
2559 virtual void PrintXG(std::ostream &os = mfem::out) const;
2560
2561 /** @brief Print the mesh to the given stream using the default MFEM mesh
2562 format.
2563
2564 \see mfem::ofgzstream() for on-the-fly compression of ascii outputs. If
2565 @a comments is non-empty, it will be printed after the first line of the
2566 file, and each line should begin with '#'. */
2567 virtual void Print(std::ostream &os = mfem::out,
2568 const std::string &comments = "") const
2569 { Printer(os, "", comments); }
2570
2571 /// Save the mesh to a file using Mesh::Print. The given @a precision will be
2572 /// used for ASCII output.
2573 virtual void Save(const std::string &fname, int precision=16) const;
2574
2575 /// Print the mesh to the given stream using the adios2 bp format
2576#ifdef MFEM_USE_ADIOS2
2577 virtual void Print(adios2stream &os) const;
2578#endif
2579 /// Print the mesh in VTK format (linear and quadratic meshes only).
2580 /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2581 void PrintVTK(std::ostream &os);
2582 /** Print the mesh in VTK format. The parameter ref > 0 specifies an element
2583 subdivision number (useful for high order fields and curved meshes).
2584 If the optional field_data is set, we also add a FIELD section in the
2585 beginning of the file with additional dataset information. */
2586 /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2587 void PrintVTK(std::ostream &os, int ref, int field_data=0);
2588 /** Print the mesh in VTU format. The parameter ref > 0 specifies an element
2589 subdivision number (useful for high order fields and curved meshes).
2590 If @a bdr_elements is true, then output (only) the boundary elements,
2591 otherwise output only the non-boundary elements. */
2592 void PrintVTU(std::ostream &os,
2593 int ref=1,
2595 bool high_order_output=false,
2596 int compression_level=0,
2597 bool bdr_elements=false);
2598 /** Print the mesh in VTU format with file name fname. */
2599 virtual void PrintVTU(std::string fname,
2601 bool high_order_output=false,
2602 int compression_level=0,
2603 bool bdr_elements=false);
2604 /** Print the boundary elements of the mesh in VTU format, and output the
2605 boundary attributes as a data array (useful for boundary conditions). */
2606 void PrintBdrVTU(std::string fname,
2608 bool high_order_output=false,
2609 int compression_level=0);
2610
2611#ifdef MFEM_USE_HDF5
2612 /// @brief Save the Mesh in %VTKHDF format.
2613 void SaveVTKHDF(const std::string &fname, bool high_order=true);
2614#endif
2615
2616#ifdef MFEM_USE_NETCDF
2617 /// @brief Export a mesh to an Exodus II file.
2618 void PrintExodusII(const std::string &fpath);
2619#endif
2620
2621 /** @brief Prints the mesh with boundary elements given by the boundary of
2622 the subdomains, so that the boundary of subdomain i has boundary
2623 attribute i+1. */
2624 /// \see mfem::ofgzstream() for on-the-fly compression of ascii outputs
2625 void PrintWithPartitioning (int *partitioning,
2626 std::ostream &os, int elem_attr = 0) const;
2627
2628 void PrintElementsWithPartitioning (int *partitioning,
2629 std::ostream &os,
2630 int interior_faces = 0);
2631
2632 /// Print set of disjoint surfaces:
2633 /*!
2634 * If Aface_face(i,j) != 0, print face j as a boundary
2635 * element with attribute i+1.
2636 */
2637 void PrintSurfaces(const Table &Aface_face, std::ostream &os) const;
2638
2639 /// Auxiliary method used by PrintCharacteristics().
2640 /** It is also used in the `mesh-explorer` miniapp. */
2641 static void PrintElementsByGeometry(int dim,
2642 const Array<int> &num_elems_by_geom,
2643 std::ostream &os);
2644
2645 /** @brief Compute and print mesh characteristics such as number of vertices,
2646 number of elements, number of boundary elements, minimal and maximal
2647 element sizes, minimal and maximal element aspect ratios, etc. */
2648 /** If @a Vh or @a Vk are not NULL, return the element sizes and aspect
2649 ratios for all elements in the given Vector%s. */
2650 void PrintCharacteristics(Vector *Vh = NULL, Vector *Vk = NULL,
2651 std::ostream &os = mfem::out);
2652
2653 /** @brief In serial, this method calls PrintCharacteristics(). In parallel,
2654 additional information about the parallel decomposition is also printed.
2655 */
2656 virtual void PrintInfo(std::ostream &os = mfem::out)
2657 {
2658 PrintCharacteristics(NULL, NULL, os);
2659 }
2660
2661#ifdef MFEM_DEBUG
2662 /// Output an NCMesh-compatible debug dump.
2663 void DebugDump(std::ostream &os) const;
2664#endif
2665
2666 /// @}
2667
2668 /// @name Miscellaneous or undocumented methods
2669 /// @{
2670
2671 /// @brief Creates a mapping @a v2v from the vertex indices of the mesh such
2672 /// that coincident vertices under the given @a translations are identified.
2673 /** Each Vector in @a translations should be of size @a sdim (the spatial
2674 dimension of the mesh). Two vertices are considered coincident if the
2675 translated coordinates of one vertex are within the given tolerance (@a
2676 tol, relative to the mesh diameter) of the coordinates of the other
2677 vertex.
2678 @warning This algorithm does not scale well with the number of boundary
2679 vertices in the mesh, and may run slowly on very large meshes. */
2680 std::vector<int> CreatePeriodicVertexMapping(
2681 const std::vector<Vector> &translations, real_t tol = 1e-8) const;
2682
2683 /** @brief Find the ids of the elements that contain the given points, and
2684 their corresponding reference coordinates.
2685
2686 The DenseMatrix @a point_mat describes the given points - one point for
2687 each column; it should have SpaceDimension() rows.
2688
2689 The InverseElementTransformation object, @a inv_trans, is used to attempt
2690 the element transformation inversion. If NULL pointer is given, the
2691 method will use a default constructed InverseElementTransformation. Note
2692 that the algorithms in the base class InverseElementTransformation can be
2693 completely overwritten by deriving custom classes that override the
2694 Transform() method.
2695
2696 If no element is found for the i-th point, elem_ids[i] is set to -1.
2697
2698 In the ParMesh implementation, the @a point_mat is expected to be the
2699 same on all ranks. If the i-th point is found by multiple ranks, only one
2700 of them will mark that point as found, i.e. set its elem_ids[i] to a
2701 non-negative number; the other ranks will set their elem_ids[i] to -2 to
2702 indicate that the point was found but assigned to another rank.
2703
2704 @returns The total number of points that were found.
2705
2706 @note This method is not 100 percent reliable, i.e. it is not guaranteed
2707 to find a point, even if it lies inside a mesh element. */
2708 virtual int FindPoints(DenseMatrix& point_mat, Array<int>& elem_ids,
2709 Array<IntegrationPoint>& ips, bool warn = true,
2710 InverseElementTransformation *inv_trans = NULL);
2711
2712 /** @brief Computes geometric parameters associated with a Jacobian matrix
2713 in 2D/3D. These parameters are
2714 (1) Area/Volume,
2715 (2) Aspect-ratio (1 in 2D, and 2 non-dimensional and 2 dimensional
2716 parameters in 3D. Dimensional parameters are used
2717 for target construction in TMOP),
2718 (3) skewness (1 in 2D and 3 in 3D), and finally
2719 (4) orientation (1 in 2D and 3 in 3D).
2720 */
2722 real_t &volume,
2723 Vector &aspr,
2724 Vector &skew,
2725 Vector &ori) const;
2726
2727 /// Utility function: sum integers from all processors (Allreduce).
2728 virtual long long ReduceInt(int value) const { return value; }
2729
2730 /// @todo This method needs a proper description
2731 void GetElementColoring(Array<int> &colors, int el0 = 0);
2732
2733 /// @todo This method needs a proper description
2734 void CheckDisplacements(const Vector &displacements, real_t &tmax);
2735
2736 /// @}
2737};
2738
2739/** Overload operator<< for std::ostream and Mesh; valid also for the derived
2740 class ParMesh */
2741std::ostream &operator<<(std::ostream &os, const Mesh &mesh);
2742
2743/// @brief Print function for Mesh::FaceInformation.
2744std::ostream& operator<<(std::ostream &os, const Mesh::FaceInformation& info);
2745
2746
2747/** @brief Class containing a minimal description of a part (a subset of the
2748 elements) of a Mesh and its connectivity to other parts.
2749
2750 The main purpose of this class is to facilitate the partitioning of serial
2751 meshes (in serial, i.e. on one processor) and save the parts in parallel
2752 MFEM mesh format.
2753
2754 Another potential futrure purpose of this class could be to facilitate
2755 exchange of MeshParts between MPI ranks for repartitioning purposes. It can
2756 also potentially be used to implement parallel mesh I/O functions with
2757 partitionings that have number of parts different from the number of MPI
2758 tasks.
2759
2760 @note Parts of NURBS or non-conforming meshes cannot be fully described by
2761 this class alone with its current data members. Such extensions may be added
2762 in the future.
2763*/
2765{
2766protected:
2767 struct Entity { int geom; int num_verts; const int *verts; };
2769 {
2774
2775 EntityHelper(int dim_,
2776 const Array<int> (&entity_to_vertex_)[Geometry::NumGeom]);
2777 Entity FindEntity(int bytype_entity_id);
2778 };
2779
2780public:
2781 /// Reference space dimension of the elements
2783
2784 /// Dimension of the physical space into which the MeshPart is embedded.
2786
2787 /// Number of vertices
2789
2790 /// Number of elements with reference space dimension equal to 'dimension'.
2792
2793 /** @brief Number of boundary elements with reference space dimension equal
2794 to 'dimension'-1. */
2796
2797 /**
2798 Each 'entity_to_vertex[geom]' describes the entities of Geometry::Type
2799 'geom' in terms of their vertices. The number of entities of type 'geom'
2800 is:
2801
2802 num_entities[geom] = size('entity_to_vertex[geom]')/num_vertices[geom]
2803
2804 The number of all elements, 'num_elements', is:
2805
2806 'num_elements' = sum_{dim[geom]=='dimension'} num_entities[geom]
2807
2808 and the number of all boundary elements, 'num_bdr_elements' is:
2809
2810 'num_bdr_elements' = sum_{dim[geom]=='dimension'-1} num_entities[geom]
2811
2812 Note that 'entity_to_vertex' does NOT describe all "faces" in the mesh
2813 part (i.e. all 'dimension'-1 entities) but only the boundary elements.
2814 Also, note that lower dimesional entities ('dimension'-2 and lower) are
2815 NOT described by the respective array, i.e. the array will be empty.
2816 */
2818
2819 /** @brief Store the refinement flags for tetraheral elements. If all tets
2820 have zero refinement flags then this array is empty, i.e. has size 0. */
2822
2823 /**
2824 Terminology: "by-type" element/boundary ordering: ordered by
2825 Geometry::Type and within each Geometry::Type 'geom' ordered as in
2826 'entity_to_vertex[geom]'.
2827
2828 Optional re-ordering of the elements that will be used by (Par)Mesh
2829 objects constructed from this MeshPart. This array maps "natural" element
2830 ids (used by the Mesh/ParMesh objects) to "by-type" element ids (see
2831 above):
2832
2833 "by-type" element id = element_map["natural" element id]
2834
2835 The size of the array is either 'num_elements' or 0 when no re-ordering is
2836 needed (then "by-type" id == "natural" id).
2837 */
2839
2840 /// Optional re-ordering for the boundary elements, similar to 'element_map'.
2842
2843 /**
2844 Element attributes. Ordered using the "natural" element ordering defined
2845 by the array 'element_map'. The size of this array is 'num_elements'.
2846 */
2848
2849 /**
2850 Boundary element attributes. Ordered using the "natural" boundary element
2851 ordering defined by the array 'boundary_map'. The size of this array is
2852 'num_bdr_elements'.
2853 */
2855
2856 /**
2857 Optional vertex coordinates. The size of the array is either
2858
2859 size = 'space_dimension' * 'num_vertices'
2860
2861 or 0 when the vertex coordinates are not used, i.e. when the MeshPart uses
2862 a nodal GridFunction to describe its location in physical space. This
2863 array uses Ordering::byVDIM: "X0,Y0,Z0, X1,Y1,Z1, ...".
2864 */
2866
2867 /**
2868 Optional serial Mesh object constructed on demand using the method
2869 GetMesh(). One use case for it is when one wants to construct FE spaces
2870 and GridFunction%s on the MeshPart for saving or MPI communication.
2871 */
2872 std::unique_ptr<Mesh> mesh;
2873
2874 /**
2875 Nodal FE space defined on 'mesh' used by the GridFunction 'nodes'. Uses
2876 the FE collection from the global nodal FE space.
2877 */
2878 std::unique_ptr<FiniteElementSpace> nodal_fes;
2879
2880 /**
2881 'nodes': pointer to a GridFunction describing the physical location of the
2882 MeshPart. Used for describing high-order and periodic meshes. This
2883 GridFunction is defined on the FE space 'nodal_fes' which, in turn, is
2884 defined on the Mesh 'mesh'.
2885 */
2886 std::unique_ptr<GridFunction> nodes;
2887
2888 /** @name Connectivity to other MeshPart objects */
2889 ///@{
2890
2891 /// Total number of MeshParts
2893
2894 /** @brief Index of the part described by this MeshPart:
2895 0 <= 'my_part_id' < 'num_parts' */
2897
2898 /**
2899 A group G is a subset of the set { 0, 1, ..., 'num_parts'-1 } for which
2900 there is a mesh entity E (of any dimension) in the global mesh such that
2901 G is the set of the parts assigned (by the partitioning array) to the
2902 elements adjacent to E. The MeshPart describes only the "neighbor" groups,
2903 i.e. the groups that contain 'my_part_id'. The Table 'my_groups' defines
2904 the "neighbor" groups in terms of their part ids. In other words, it maps
2905 "neighbor" group ids to a (sorted) list of part ids. In particular, the
2906 number of "neighbor" groups is given by 'my_groups.Size()'. The "local"
2907 group { 'my_part_id' } has index 0 in 'my_groups'.
2908 */
2910
2911 /**
2912 Shared entities for this MeshPart are mesh entities of all dimensions less
2913 than 'dimension' that are generated by the elements of this MeshPart and
2914 at least one other MeshPart.
2915
2916 The Table 'group_shared_entity_to_vertex[geom]' defines, for each group,
2917 the shared entities of Geometry::Type 'geom'. Each row (corresponding to a
2918 "neighbor" group, as defined by 'my_groups') in the Table defines the
2919 shared entities in a way similar to the arrays 'entity_to_vertex[geom]'.
2920 The "local" group (with index 0) does not have any shared entities, so the
2921 0-th row in the Table is always empty.
2922
2923 IMPORTANT: the descriptions of the groups in this MeshPart must match
2924 their descriptions in all neighboring MeshParts. This includes the
2925 ordering of the shared entities within the group, as well as the vertex
2926 ordering of each shared entity.
2927 */
2929
2930 ///@}
2931
2932 /** @brief Write the MeshPart to a stream using the parallel format
2933 "MFEM mesh v1.2". */
2934 void Print(std::ostream &os) const;
2935
2936 /** @brief Construct a serial Mesh object from the MeshPart.
2937
2938 The nodes of 'mesh' are NOT initialized by this method, however, the
2939 nodal FE space and nodal GridFunction can be created and then attached to
2940 the 'mesh'. The Mesh is constructed only if 'mesh' is empty, otherwise
2941 the method simply returns the object held by 'mesh'.
2942 */
2943 Mesh &GetMesh();
2944};
2945
2946
2947/** @brief Class that allows serial meshes to be partitioned into MeshPart
2948 objects, typically one MeshPart at a time, which can then be used to write
2949 the local mesh in parallel MFEM mesh format.
2950
2951 Sample usage of this class: partition a serial mesh and save it in parallel
2952 MFEM format:
2953 \code
2954 // The array 'partitioning' can be obtained e.g. from
2955 // mesh->GeneratePartitioning():
2956 void usage1(Mesh *mesh, int num_parts, int *partitioning)
2957 {
2958 MeshPartitioner partitioner(*mesh, num_parts, partitioning);
2959 MeshPart mesh_part;
2960 for (int i = 0; i < num_parts; i++)
2961 {
2962 partitioner.ExtractPart(i, mesh_part);
2963 ofstream omesh(MakeParFilename("my-mesh.", i));
2964 mesh_part.Print(omesh);
2965 }
2966 }
2967 \endcode
2968
2969 This class can also be used to partition a mesh and GridFunction(s) and save
2970 them in parallel:
2971 \code
2972 // The array 'partitioning' can be obtained e.g. from
2973 // mesh->GeneratePartitioning():
2974 void usage2(Mesh *mesh, int num_parts, int *partitioning,
2975 GridFunction *gf)
2976 {
2977 MeshPartitioner partitioner(*mesh, num_parts, partitioning);
2978 MeshPart mesh_part;
2979 for (int i = 0; i < num_parts; i++)
2980 {
2981 partitioner.ExtractPart(i, mesh_part);
2982 ofstream omesh(MakeParFilename("my-mesh.", i));
2983 mesh_part.Print(omesh);
2984 auto lfes = partitioner.ExtractFESpace(mesh_part, *gf->FESpace());
2985 auto lgf = partitioner.ExtractGridFunction(mesh_part, *gf, *lfes);
2986 ofstream ofield(MakeParFilename("my-field.", i));
2987 lgf->Save(ofield);
2988 }
2989 }
2990 \endcode
2991*/
2993{
2994protected:
3001
3002public:
3003 /** @brief Construct a MeshPartitioner.
3004
3005 @param[in] mesh_ Mesh to be partitioned into MeshPart%s.
3006 @param[in] num_parts_ Number of parts to partition the mesh into.
3007 @param[in] partitioning_ Partitioning array: for every element in the
3008 mesh gives the partition it belongs to; if NULL,
3009 partitioning will be generated internally by
3010 calling Mesh::GeneratePartitioning().
3011 @param[in] part_method Partitioning method to be used in the call to
3012 Mesh::GeneratePartitioning() when the provided
3013 input partitioning is NULL.
3014 */
3015 MeshPartitioner(Mesh &mesh_, int num_parts_,
3016 const int *partitioning_ = nullptr, int part_method = 1);
3017
3018 /** @brief Construct a MeshPart corresponding to the given @a part_id.
3019
3020 @param[in] part_id Partition index to extract; valid values are in
3021 the range [0, num_parts).
3022 @param[out] mesh_part Output MeshPart object; its contents is
3023 overwritten, while potentially reusing existing
3024 dynamic memory allocations.
3025 */
3026 void ExtractPart(int part_id, MeshPart &mesh_part) const;
3027
3028 /** @brief Construct a local version of the given FiniteElementSpace
3029 @a global_fespace corresponding to the given @a mesh_part.
3030
3031 @param[in,out] mesh_part MeshPart on which to construct the local
3032 FiniteElementSpace; this object is
3033 generally modified by this call since it
3034 calls mesh_part.GetMesh() to ensure the
3035 local mesh is constructed.
3036 @param[in] global_fespace The global FiniteElementSpace that should
3037 be restricted to the @a mesh_part.
3038
3039 @returns A FiniteElementSpace pointer stored in a unique_ptr. The
3040 returned local FiniteElementSpace is built on the Mesh object
3041 contained in @a mesh_part (MeshPart::mesh) and it reuses the
3042 FiniteElementCollection of the @a global_fespace.
3043 */
3044 std::unique_ptr<FiniteElementSpace>
3045 ExtractFESpace(MeshPart &mesh_part,
3046 const FiniteElementSpace &global_fespace) const;
3047
3048 /** @brief Construct a local version of the given GridFunction, @a global_gf,
3049 corresponding to the given @a mesh_part. The respective data is copied
3050 from @a global_gf to the returned local GridFunction.
3051
3052 @param[in] mesh_part MeshPart on which to construct the local
3053 GridFunction.
3054 @param[in] global_gf The global GridFunction that should be
3055 restricted to the @a mesh_part.
3056 @param[in,out] local_fespace The local FiniteElementSpace corresponding
3057 to @a mesh_part, e.g. constructed by the
3058 method ExtractFESpace().
3059
3060 @returns A GridFunction pointer stored in a unique_ptr. The returned
3061 local GridFunction is initialized with data appropriately copied
3062 from @a global_gf.
3063 */
3064 std::unique_ptr<GridFunction>
3065 ExtractGridFunction(const MeshPart &mesh_part,
3066 const GridFunction &global_gf,
3067 FiniteElementSpace &local_fespace) const;
3068};
3069
3070
3071/** @brief Structure for storing mesh geometric factors: coordinates, Jacobians,
3072 and determinants of the Jacobians. */
3073/** Typically objects of this type are constructed and owned by objects of class
3074 Mesh. See Mesh::GetGeometricFactors(). */
3076{
3077private:
3078 void Compute(const GridFunction &nodes,
3080
3081public:
3082 const Mesh *mesh;
3085
3087 {
3088 COORDINATES = 1 << 0,
3089 JACOBIANS = 1 << 1,
3091 };
3092
3093 GeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags,
3095
3097 int flags,
3099
3100 /// Mapped (physical) coordinates of all quadrature points.
3101 /** This array uses a column-major layout with dimensions (NQ x SDIM x NE)
3102 where
3103 - NQ = number of quadrature points per element,
3104 - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
3105 - NE = number of elements in the mesh. */
3107
3108 /// Jacobians of the element transformations at all quadrature points.
3109 /** This array uses a column-major layout with dimensions (NQ x SDIM x DIM x
3110 NE) where
3111 - NQ = number of quadrature points per element,
3112 - SDIM = space dimension of the mesh = mesh.SpaceDimension(),
3113 - DIM = dimension of the mesh = mesh.Dimension(), and
3114 - NE = number of elements in the mesh. */
3116
3117 /// Determinants of the Jacobians at all quadrature points.
3118 /** This array uses a column-major layout with dimensions (NQ x NE) where
3119 - NQ = number of quadrature points per element, and
3120 - NE = number of elements in the mesh. */
3122};
3123
3124
3125/** @brief Structure for storing face geometric factors: coordinates, Jacobians,
3126 determinants of the Jacobians, and normal vectors. */
3127/** Typically objects of this type are constructed and owned by objects of class
3128 Mesh. See Mesh::GetFaceGeometricFactors(). */
3130{
3131public:
3132 const Mesh *mesh;
3136
3138 {
3139 COORDINATES = 1 << 0,
3140 JACOBIANS = 1 << 1,
3142 NORMALS = 1 << 3,
3143 };
3144
3145 FaceGeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags,
3147
3148 /// Mapped (physical) coordinates of all quadrature points.
3149 /** This array uses a column-major layout with dimensions (NQ x SDIM x NF)
3150 where
3151 - NQ = number of quadrature points per face,
3152 - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
3153 - NF = number of faces in the mesh. */
3155
3156 /// Jacobians of the element transformations at all quadrature points.
3157 /** This array uses a column-major layout with dimensions (NQ x SDIM x
3158 (DIM-1) x NF) where
3159 - NQ = number of quadrature points per face,
3160 - SDIM = space dimension of the mesh = mesh.SpaceDimension(),
3161 - DIM = dimension of the mesh = mesh.Dimension(), and
3162 - NF = number of faces in the mesh. */
3164
3165 /// Determinants of the Jacobians at all quadrature points.
3166 /** This array uses a column-major layout with dimensions (NQ x NF) where
3167 - NQ = number of quadrature points per face, and
3168 - NF = number of faces in the mesh. */
3170
3171 /// Normals at all quadrature points.
3172 /** This array uses a column-major layout with dimensions (NQ x DIM x NF) where
3173 - NQ = number of quadrature points per face,
3174 - SDIM = space dimension of the mesh = mesh.SpaceDimension(), and
3175 - NF = number of faces in the mesh. */
3177};
3178
3179
3180/// Class used to extrude the nodes of a mesh
3182{
3183private:
3184 int n, layer;
3185 real_t p[2], s;
3186 Vector tip;
3187public:
3188 NodeExtrudeCoefficient(const int dim, const int n_, const real_t s_);
3189 void SetLayer(const int l) { layer = l; }
3191 void Eval(Vector &V, ElementTransformation &T,
3192 const IntegrationPoint &ip) override;
3194};
3195
3196
3197/// Extrude a 1D mesh
3198Mesh *Extrude1D(Mesh *mesh, const int ny, const real_t sy,
3199 const bool closed = false);
3200
3201/// Extrude a 2D mesh
3202Mesh *Extrude2D(Mesh *mesh, const int nz, const real_t sz);
3203
3204// shift cyclically 3 integers left-to-right
3205inline void ShiftRight(int &a, int &b, int &c)
3206{
3207 int t = a;
3208 a = c; c = b; b = t;
3209}
3210
3211}
3212
3213#endif
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition array.hpp:840
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
Abstract data type element.
Definition element.hpp:29
Type
Constants for the classes derived from Element.
Definition element.hpp:41
A specialized ElementTransformation class representing a face and its two neighboring elements.
Definition eltrans.hpp:750
Structure for storing face geometric factors: coordinates, Jacobians, determinants of the Jacobians,...
Definition mesh.hpp:3130
Vector normal
Normals at all quadrature points.
Definition mesh.hpp:3176
Vector J
Jacobians of the element transformations at all quadrature points.
Definition mesh.hpp:3163
const IntegrationRule * IntRule
Definition mesh.hpp:3133
Vector X
Mapped (physical) coordinates of all quadrature points.
Definition mesh.hpp:3154
FaceGeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags, FaceType type, MemoryType d_mt=MemoryType::DEFAULT)
Definition mesh.cpp:14984
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition mesh.hpp:3169
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
Abstract class for all finite elements.
Definition fe_base.hpp:247
Structure for storing mesh geometric factors: coordinates, Jacobians, and determinants of the Jacobia...
Definition mesh.hpp:3076
Vector X
Mapped (physical) coordinates of all quadrature points.
Definition mesh.hpp:3106
const Mesh * mesh
Definition mesh.hpp:3082
const IntegrationRule * IntRule
Definition mesh.hpp:3083
Vector detJ
Determinants of the Jacobians at all quadrature points.
Definition mesh.hpp:3121
Vector J
Jacobians of the element transformations at all quadrature points.
Definition mesh.hpp:3115
GeometricFactors(const Mesh *mesh, const IntegrationRule &ir, int flags, MemoryType d_mt=MemoryType::DEFAULT)
Definition mesh.cpp:14904
static const int NumGeom
Definition geom.hpp:46
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:32
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
The inverse transformation of a given ElementTransformation.
Definition eltrans.hpp:200
A standard isoparametric element transformation.
Definition eltrans.hpp:629
Class containing a minimal description of a part (a subset of the elements) of a Mesh and its connect...
Definition mesh.hpp:2765
Array< real_t > vertex_coordinates
Definition mesh.hpp:2865
int dimension
Reference space dimension of the elements.
Definition mesh.hpp:2782
int num_vertices
Number of vertices.
Definition mesh.hpp:2788
Table group_shared_entity_to_vertex[Geometry::NumGeom]
Definition mesh.hpp:2928
Array< int > entity_to_vertex[Geometry::NumGeom]
Definition mesh.hpp:2817
std::unique_ptr< Mesh > mesh
Definition mesh.hpp:2872
Array< int > boundary_map
Optional re-ordering for the boundary elements, similar to 'element_map'.
Definition mesh.hpp:2841
std::unique_ptr< FiniteElementSpace > nodal_fes
Definition mesh.hpp:2878
int num_parts
Total number of MeshParts.
Definition mesh.hpp:2892
Array< int > tet_refine_flags
Store the refinement flags for tetraheral elements. If all tets have zero refinement flags then this ...
Definition mesh.hpp:2821
int space_dimension
Dimension of the physical space into which the MeshPart is embedded.
Definition mesh.hpp:2785
int num_bdr_elements
Number of boundary elements with reference space dimension equal to 'dimension'-1.
Definition mesh.hpp:2795
int num_elements
Number of elements with reference space dimension equal to 'dimension'.
Definition mesh.hpp:2791
Mesh & GetMesh()
Construct a serial Mesh object from the MeshPart.
Definition mesh.cpp:14237
int my_part_id
Index of the part described by this MeshPart: 0 <= 'my_part_id' < 'num_parts'.
Definition mesh.hpp:2896
Array< int > element_map
Definition mesh.hpp:2838
Array< int > attributes
Definition mesh.hpp:2847
Table my_groups
Definition mesh.hpp:2909
std::unique_ptr< GridFunction > nodes
Definition mesh.hpp:2886
void Print(std::ostream &os) const
Write the MeshPart to a stream using the parallel format "MFEM mesh v1.2".
Definition mesh.cpp:14057
Array< int > bdr_attributes
Definition mesh.hpp:2854
Class that allows serial meshes to be partitioned into MeshPart objects, typically one MeshPart at a ...
Definition mesh.hpp:2993
Array< int > partitioning
Definition mesh.hpp:2996
std::unique_ptr< FiniteElementSpace > ExtractFESpace(MeshPart &mesh_part, const FiniteElementSpace &global_fespace) const
Construct a local version of the given FiniteElementSpace global_fespace corresponding to the given m...
Definition mesh.cpp:14862
MeshPartitioner(Mesh &mesh_, int num_parts_, const int *partitioning_=nullptr, int part_method=1)
Construct a MeshPartitioner.
Definition mesh.cpp:14320
std::unique_ptr< GridFunction > ExtractGridFunction(const MeshPart &mesh_part, const GridFunction &global_gf, FiniteElementSpace &local_fespace) const
Construct a local version of the given GridFunction, global_gf, corresponding to the given mesh_part....
Definition mesh.cpp:14877
void ExtractPart(int part_id, MeshPart &mesh_part) const
Construct a MeshPart corresponding to the given part_id.
Definition mesh.cpp:14392
List of mesh geometries stored as Array<Geometry::Type>.
Definition mesh.hpp:1590
Geometry::Type geom_buf[Geometry::NumGeom]
Definition mesh.hpp:1592
GeometryList(const Mesh &mesh)
Construct a GeometryList of all element geometries in mesh.
Definition mesh.hpp:1595
GeometryList(const Mesh &mesh, int dim)
Construct a GeometryList of all geometries of dimension dim in mesh.
Definition mesh.hpp:1600
Mesh data type.
Definition mesh.hpp:65
int CheckElementOrientation(bool fix_it=true)
Check (and optionally attempt to fix) the orientation of the elements.
Definition mesh.cpp:6890
Array< Vertex > vertices
Definition mesh.hpp:107
void GetFaceEdges(int i, Array< int > &edges, Array< int > &o) const
Definition mesh.cpp:7642
void GetEdgeOrdering(const DSTable &v_to_v, Array< int > &order)
Definition mesh.cpp:2996
Geometry::Constants< Geometry::TETRAHEDRON > tet_t
Definition mesh.hpp:294
void GetLocalFaceTransformation(int face_type, int elem_type, IsoparametricTransformation &Transf, int info) const
A helper method that constructs a transformation from the reference space of a face to the reference ...
Definition mesh.cpp:1038
void NURBSCoarsening(int cf=2, real_t tol=1.0e-12)
Definition mesh.cpp:11169
void SetVerticesFromNodes(const GridFunction *nodes)
Helper to set vertex coordinates given a high-order curvature function.
Definition mesh.cpp:6832
void ReadGmshMesh(std::istream &input, int &curved, int &read_gf)
int GetPatchBdrAttribute(int i) const
Return the attribute of patch boundary element i, for a NURBS mesh.
Definition mesh.cpp:3371
int GetElementToEdgeTable(Table &)
Definition mesh.cpp:8068
int meshgen
Definition mesh.hpp:90
void LoadNonconformingPatchTopo(std::istream &input, Array< int > &edge_to_ukv)
Read NURBS patch/macro-element mesh (MFEM NURBS NC-patch mesh format)
Definition mesh.cpp:6658
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:7569
void SetVertices(const Vector &vert_coord)
Definition mesh.cpp:9564
Element * NewElement(int geom)
Definition mesh.cpp:4818
Operation GetLastOperation() const
Return type of last modification of the mesh.
Definition mesh.hpp:2513
IsoparametricTransformation Transformation2
Definition mesh.hpp:256
int GetNEdges() const
Return the number of edges.
Definition mesh.hpp:1383
void MarkForRefinement()
Definition mesh.cpp:2964
void GetBdrElementFace(int i, int *f, int *o) const
Definition mesh.cpp:7886
void InitMesh(int Dim_, int spaceDim_, int NVert, int NElem, int NBdrElem)
Begin construction of a mesh.
Definition mesh.cpp:1977
Table * GetVertexToBdrElementTable()
Definition mesh.cpp:7768
static void PrintElement(const Element *el, std::ostream &os)
Definition mesh.cpp:4884
Array< FaceInfo > faces_info
Definition mesh.hpp:239
int EulerNumber() const
Equals 1 + num_holes - num_loops.
Definition mesh.hpp:1312
CoarseFineTransformations CoarseFineTr
Definition mesh.hpp:262
void GetElementJacobian(int i, DenseMatrix &J, const IntegrationPoint *ip=NULL)
Definition mesh.cpp:65
int AddSegment(int v1, int v2, int attr=1)
Adds a segment to the mesh given by 2 vertices v1 and v2.
Definition mesh.cpp:2057
int AddBdrElement(Element *elem)
Definition mesh.cpp:2370
void GetElementColoring(Array< int > &colors, int el0=0)
Definition mesh.cpp:12766
void BuildCubitElements(const int num_elements, const cubit::CubitBlock *blocks, const std::vector< int > &block_ids, const std::map< int, std::vector< int > > &element_ids_for_block_id, const std::map< int, std::vector< int > > &node_ids_for_element_id, const std::map< int, int > &cubit_to_mfem_vertex_map)
Called internally in ReadCubit. This method builds the mesh elements.
virtual FaceElementTransformations * GetFaceElementTransformations(int FaceNo, int mask=31)
Definition mesh.cpp:1104
void FinalizeMesh(int refine=0, bool fix_orientation=true)
Finalize the construction of any type of Mesh.
Definition mesh.cpp:3496
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition mesh.hpp:304
static void PrintElementWithoutAttr(const Element *el, std::ostream &os)
Definition mesh.cpp:4860
Element * GetElement(int i)
Return pointer to the i'th element object.
Definition mesh.hpp:1441
MemAlloc< Tetrahedron, 1024 > TetMemory
Definition mesh.hpp:277
void RedRefinement(int i, const DSTable &v_to_v, int *edge1, int *edge2, int *middle)
Definition mesh.hpp:421
NURBSExtension * NURBSext
Optional NURBS mesh extension.
Definition mesh.hpp:312
void ReadTrueGridMesh(std::istream &input)
static const int vtk_quadratic_tet[10]
Definition mesh.hpp:270
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
Definition mesh.cpp:1563
const GridFunction * GetNodes() const
Definition mesh.hpp:2360
virtual void GetExteriorFaceMarker(Array< int > &face_marker) const
Populate a marker array identifying exterior faces.
Definition mesh.cpp:1656
IsoparametricTransformation EdgeTransformation
Definition mesh.hpp:258
static FiniteElement * GetTransformationFEforElementType(Element::Type)
Return FiniteElement for reference element of the specified type.
Definition mesh.cpp:339
int AddBdrQuad(int v1, int v2, int v3, int v4, int attr=1)
Definition mesh.cpp:2417
int * CartesianPartitioning(int nxyz[])
Definition mesh.cpp:8705
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:7858
static int GetQuadOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition mesh.cpp:7130
Element::Type GetElementType(int i) const
Returns the type of element i.
Definition mesh.cpp:7962
void GetLocalSegToQuadTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:719
virtual long long ReduceInt(int value) const
Utility function: sum integers from all processors (Allreduce).
Definition mesh.hpp:2728
const Array< int > & GetFaceIndices(FaceType ftype) const
Map from boundary or interior face indices to mesh face indices.
Definition mesh.cpp:1003
int NumOfBdrElements
Definition mesh.hpp:81
void BdrBisection(int i, const HashTable< Hashed2 > &)
Bisect a boundary triangle: boundary element with index i is bisected.
Definition mesh.cpp:11600
Element::Type GetBdrElementType(int i) const
Returns the type of boundary element i.
Definition mesh.cpp:7967
std::unordered_map< int, int > inv_face_indices[2]
cache for FaceIndices(ftype)
Definition mesh.hpp:285
const Table & ElementToEdgeTable() const
Definition mesh.cpp:8152
bool Conforming() const
Definition mesh.cpp:15455
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
Definition mesh.cpp:6846
virtual void UnmarkNamedBoundaries(const std::string &set_name, Array< int > &bdr_marker) const
Unmark boundary attributes in the named set.
Definition mesh.cpp:1720
void ReadNetgen3DMesh(std::istream &input)
void GetBdrElementVertices(int i, Array< int > &v) const
Returns the indices of the vertices of boundary element i.
Definition mesh.hpp:1613
Array< int > face_indices[2]
cache for FaceIndices(ftype)
Definition mesh.hpp:283
Geometry::Type GetFaceGeometry(int i) const
Return the Geometry::Type associated with face i.
Definition mesh.cpp:1576
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Definition mesh.cpp:11225
Array< int > bdr_face_attrs_cache
internal cache for boundary element attributes
Definition mesh.hpp:114
Geometry::Type GetElementGeometry(int i) const
Definition mesh.hpp:1535
Geometry::Type GetBdrElementGeometry(int i) const
Definition mesh.hpp:1547
void MakeHigherOrderSimplicial_(const Mesh &orig_mesh, const Array< int > &parent_elements)
Helper function for constructing higher order nodes from a mesh transformed into simplices....
Definition mesh.cpp:5912
int AddTri(const int *vi, int attr=1)
Adds a triangle to the mesh given by 3 vertices vi.
Definition mesh.hpp:1019
static Mesh MakeCartesian1D(int n, real_t sx=1.0)
Creates 1D mesh, divided into n equal intervals.
Definition mesh.cpp:4609
int GetAttribute(int i) const
Return the attribute of element i.
Definition mesh.hpp:1484
void NodesUpdated()
This function should be called after the mesh node coordinates have been updated externally,...
Definition mesh.hpp:2312
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:6747
void GetElementVertices(int i, Array< int > &v) const
Returns the indices of the vertices of element i.
Definition mesh.hpp:1609
void UniformRefinement3D_base(Array< int > *f2qf=NULL, DSTable *v_to_v_p=NULL, bool update_nodes=true)
Definition mesh.cpp:9892
int AddQuad(int v1, int v2, int v3, int v4, int attr=1)
Adds a quadrilateral to the mesh given by 4 vertices v1 through v4.
Definition mesh.cpp:2085
long nodes_sequence
Counter for geometric factor invalidation.
Definition mesh.hpp:100
virtual void Load(std::istream &input, int generate_edges=0, int refine=1, bool fix_orientation=true)
Definition mesh.hpp:815
void ComputeFaceInfo(FaceType ftype) const
compute face_indices[ftype] and inv_face_indices[type]
Definition mesh.cpp:982
IsoparametricTransformation FaceTransformation
Definition mesh.hpp:258
Array< NCFaceInfo > nc_faces_info
Definition mesh.hpp:240
@ REBALANCE
Definition mesh.hpp:299
Array< int > MakeSimplicial_(const Mesh &orig_mesh, int *vglobal)
Internal helper user in MakeSimplicial (and ParMesh::MakeSimplicial). Optional return is used in asse...
Definition mesh.cpp:5575
void MakeRefined_(Mesh &orig_mesh, const Array< int > &ref_factors, int ref_type)
Internal function used in Mesh::MakeRefined.
Definition mesh.cpp:5335
int AddWedge(int v1, int v2, int v3, int v4, int v5, int v6, int attr=1)
Adds a wedge to the mesh given by 6 vertices v1 through v6.
Definition mesh.cpp:2120
Array< int > GetFaceToBdrElMap() const
Definition mesh.cpp:1617
static Mesh MakeCartesian2DWith4TrisPerQuad(int nx, int ny, real_t sx=1.0, real_t sy=1.0)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*4 triangles.
Definition mesh.cpp:4646
void ReadInlineMesh(std::istream &input, bool generate_edges=false)
void SetPatchAttribute(int i, int attr)
Set the attribute of patch i, for a NURBS mesh.
Definition mesh.cpp:3342
void FinalizeTetMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a tetrahedral Mesh.
Definition mesh.cpp:3390
real_t GetLength(int i, int j) const
Return the length of the segment from node i to node j.
Definition mesh.cpp:8006
const FiniteElementSpace * GetNodalFESpace() const
Definition mesh.cpp:6794
void AddBdrQuadAsTriangles(const int *vi, int attr=1)
Definition mesh.cpp:2431
int AddPyramid(int v1, int v2, int v3, int v4, int v5, int attr=1)
Adds a pyramid to the mesh given by 5 vertices v1 through v5.
Definition mesh.cpp:2134
void Loader(std::istream &input, int generate_edges=0, std::string parse_tag="")
Definition mesh.cpp:4943
const Table & ElementToElementTable()
Definition mesh.cpp:8107
void ScaleElements(real_t sf)
Definition mesh.cpp:13470
void GenerateNCFaceInfo()
Definition mesh.cpp:8392
void ReadLineMesh(std::istream &input)
void ApplyLocalSlaveTransformation(FaceElementTransformations &FT, const FaceInfo &fi, bool is_ghost) const
Definition mesh.cpp:1254
Array< Element * > faces
Definition mesh.hpp:109
int Dim
Definition mesh.hpp:78
real_t AggregateError(const Array< real_t > &elem_error, const int *fine, int nfine, int op)
Derefinement helper.
Definition mesh.cpp:10891
void CheckPartitioning(int *partitioning_)
Definition mesh.cpp:9149
void DoNodeReorder(DSTable *old_v_to_v, Table *old_elem_vert)
Definition mesh.cpp:3110
Geometry::Type GetTypicalElementGeometry() const
If the local mesh is not empty, return GetElementGeometry(0); otherwise, return a typical Geometry pr...
Definition mesh.cpp:1628
void GetLocalPtToSegTransformation(IsoparametricTransformation &, int i) const
Used in GetFaceElementTransformations (...)
Definition mesh.cpp:684
const Element *const * GetElementsArray() const
Definition mesh.hpp:1468
bool Nonconforming() const
Definition mesh.hpp:2499
int GetBdrAttribute(int i) const
Return the attribute of boundary element i.
Definition mesh.hpp:1490
virtual void MarkExternalBoundaries(Array< int > &bdr_marker, bool excl=true) const
Mark boundary attributes of external boundaries.
Definition mesh.cpp:1741
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,...
Definition mesh.cpp:254
void UpdateNURBS()
Definition mesh.cpp:6405
static int ComposeQuadOrientations(int ori_a_b, int ori_b_c)
Definition mesh.cpp:7178
int AddTriangle(int v1, int v2, int v3, int attr=1)
Adds a triangle to the mesh given by 3 vertices v1 through v3.
Definition mesh.cpp:2071
void GenerateFaces()
Definition mesh.cpp:8285
static const int vtk_quadratic_wedge[18]
Definition mesh.hpp:272
int EulerNumber2D() const
Equals 1 - num_holes.
Definition mesh.hpp:1315
AttributeSets bdr_attribute_sets
Named sets of boundary element attributes.
Definition mesh.hpp:310
void AddBdrElements(Array< Element * > &bdr_elems, const Array< int > &be_to_face)
Add an array of boundary elements to the mesh, along with map from the elements to their faces.
Definition mesh.cpp:2377
void Destroy()
Definition mesh.cpp:1881
int GetBdrElementFaceIndex(int be_idx) const
Return the local face (codimension-1) index for the given boundary element index.
Definition mesh.hpp:1689
void GetVertices(Vector &vert_coord) const
Definition mesh.cpp:9553
void InitFromNCMesh(const NCMesh &ncmesh)
Initialize vertices/elements/boundary/tables from a nonconforming mesh.
Definition mesh.cpp:10991
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:6862
void Make1D(int n, real_t sx=1.0)
Definition mesh.cpp:4408
void DeleteTables()
Definition mesh.hpp:335
void RefineNURBSFromFile(std::string ref_file)
Definition mesh.cpp:6212
const Element * GetElement(int i) const
Return pointer to the i'th element object.
Definition mesh.hpp:1434
int AddBdrPoint(int v, int attr=1)
Definition mesh.cpp:2446
void FinalizeWedgeMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a wedge Mesh.
Definition mesh.cpp:3431
static int GetTriOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition mesh.cpp:7041
void PrintTopo(std::ostream &os, const Array< int > &e_to_k, const int version, const std::string &comment="") const
Write the beginning of a NURBS mesh to os, specifying the NURBS patch topology. Optional file comment...
Definition mesh.cpp:12102
Geometry::Constants< Geometry::SEGMENT > seg_t
Definition mesh.hpp:291
void GetElementData(int geom, Array< int > &elem_vtx, Array< int > &attr) const
Definition mesh.hpp:1471
static Mesh MakeSimplicial(const Mesh &orig_mesh)
Definition mesh.cpp:5564
void SetPatchBdrAttribute(int i, int attr)
Set the attribute of patch boundary element i, for a NURBS mesh.
Definition mesh.cpp:3359
int GetNFaces() const
Return the number of faces in a 3D mesh.
Definition mesh.hpp:1386
int AddVertexAtMeanCenter(const int *vi, const int nverts, int dim=3)
Definition mesh.cpp:2040
static int GetTetOrientation(const int *base, const int *test)
Returns the orientation of "test" relative to "base".
Definition mesh.cpp:7209
Geometry::Constants< Geometry::PRISM > pri_t
Definition mesh.hpp:296
real_t GetGeckoElementOrdering(Array< int > &ordering, int iterations=4, int window=4, int period=2, int seed=0, bool verbose=false, real_t time_limit=0)
Definition mesh.cpp:2593
static int EncodeFaceInfo(int local_face_index, int orientation)
Given local_face_index and orientation, return the corresponding encoded "face info int".
Definition mesh.hpp:2177
bool FaceIsTrueInterior(int FaceNo) const
Definition mesh.hpp:610
long GetSequence() const
Definition mesh.hpp:2519
const CoarseFineTransformations & GetRefinementTransforms() const
Definition mesh.cpp:11749
void Make2D5QuadsFromQuad(int nx, int ny, real_t sx, real_t sy)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*5 quadrilaterals.
Definition mesh.cpp:4039
void SetScaledNCMesh()
Definition mesh.hpp:2503
bool IsMixedMesh() const
Returns true if the mesh is a mixed mesh, false otherwise.
Definition mesh.cpp:7582
const Array< int > & GetElementAttributes() const
Returns the attributes for all elements in this mesh. The i'th entry of the array is the attribute of...
Definition mesh.cpp:965
Geometry::Constants< Geometry::SQUARE > quad_t
Definition mesh.hpp:293
void GetLocalQuadToWdgTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:836
ElementTransformation * GetFaceTransformation(int FaceNo)
Returns a pointer to the transformation defining the given face element.
Definition mesh.cpp:610
void SetAttribute(int i, int attr)
Set the attribute of element i.
Definition mesh.cpp:7950
Element * GetBdrElement(int i)
Return pointer to the i'th boundary element object.
Definition mesh.hpp:1456
void FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
Definition mesh.cpp:3502
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
Definition mesh.hpp:2567
void DestroyTables()
Definition mesh.cpp:1836
void RefineNURBS(bool usingKVF, real_t tol, const Array< int > &rf, const std::string &kvf)
Refine the NURBS mesh with default refinement factors in rf for each dimension.
Definition mesh.cpp:6335
static Mesh MakeCartesian2DWith5QuadsPerQuad(int nx, int ny, real_t sx=1.0, real_t sy=1.0)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*5 quadrilaterals.
Definition mesh.cpp:4655
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:903
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:12841
void Clear()
Clear the contents of the Mesh.
Definition mesh.hpp:827
void PrepareNodeReorder(DSTable **old_v_to_v, Table **old_elem_vert)
Definition mesh.cpp:3044
void ReadXML_VTKMesh(std::istream &input, int &curved, int &read_gf, bool &finalize_topo, const std::string &xml_prefix="")
int AddVertex(real_t x, real_t y=0.0, real_t z=0.0)
Definition mesh.cpp:2000
virtual void LocalRefinement(const Array< int > &marked_el, int type=3)
This function is not public anymore. Use GeneralRefinement instead.
Definition mesh.cpp:10603
int GetNE() const
Returns number of elements.
Definition mesh.hpp:1377
const Element * GetFace(int i) const
Return pointer to the i'th face element object.
Definition mesh.hpp:1461
void Make3D(int nx, int ny, int nz, Element::Type type, real_t sx, real_t sy, real_t sz, bool sfc_ordering)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz hexahedra if type =...
Definition mesh.cpp:3683
virtual void Save(const std::string &fname, int precision=16) const
Definition mesh.cpp:12178
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:784
int AddTet(int v1, int v2, int v3, int v4, int attr=1)
Adds a tetrahedron to the mesh given by 4 vertices v1 through v4.
Definition mesh.cpp:2099
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
Definition mesh.cpp:141
void GetBdrPointMatrix(int i, DenseMatrix &pointmat) const
Definition mesh.cpp:7990
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1306
ElementTransformation * GetTypicalElementTransformation()
If the local mesh is not empty return GetElementTransformation(0); otherwise, return the identity tra...
Definition mesh.cpp:393
Table * el_to_face
Definition mesh.hpp:243
void RandomRefinement(real_t prob, bool aniso=false, int nonconforming=-1, int nc_limit=0)
Refine each element with given probability. Uses GeneralRefinement.
Definition mesh.cpp:11317
const Element * GetBdrElement(int i) const
Return pointer to the i'th boundary element object.
Definition mesh.hpp:1449
void CheckDisplacements(const Vector &displacements, real_t &tmax)
Definition mesh.cpp:9467
void AddTriangleFaceElement(int lf, int gf, int el, int v0, int v1, int v2)
Definition mesh.cpp:8230
void AddHexAs24TetsWithPoints(int *vi, std::map< std::array< int, 4 >, int > &hex_face_verts, int attr=1)
Adds 24 tetrahedrons to the mesh by splitting a hexahedron.
Definition mesh.cpp:2302
void GetNode(int i, real_t *coord) const
Definition mesh.cpp:9573
bool OwnsNodes() const
Return the mesh nodes ownership flag.
Definition mesh.hpp:2362
void ReorderElements(const Array< int > &ordering, bool reorder_vertices=true)
Definition mesh.cpp:2812
void GreenRefinement(int i, const DSTable &v_to_v, int *edge1, int *edge2, int *middle)
Definition mesh.hpp:427
void UpdateNodes()
Update the nodes of a curved mesh after the topological part of a Mesh::Operation,...
Definition mesh.cpp:9718
void PrintElementsWithPartitioning(int *partitioning, std::ostream &os, int interior_faces=0)
Definition mesh.cpp:12960
Mesh & operator=(Mesh &&mesh)
Move assignment operator.
Definition mesh.cpp:4593
Geometry::Constants< Geometry::CUBE > hex_t
Definition mesh.hpp:295
void Transform(std::function< void(const Vector &, Vector &)> f)
Definition mesh.cpp:13540
long sequence
Definition mesh.hpp:97
static int InvertQuadOrientation(int ori)
Definition mesh.cpp:7203
Array< FaceGeometricFactors * > face_geom_factors
Definition mesh.hpp:315
void GetLocalTriToPyrTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:789
ElementConformity
Definition mesh.hpp:2041
Table * bel_to_edge
Definition mesh.hpp:247
Geometry::Constants< Geometry::TRIANGLE > tri_t
Definition mesh.hpp:292
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:4664
real_t GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
Definition mesh.cpp:110
Element * ReadElementWithoutAttr(std::istream &input)
Definition mesh.cpp:4842
void SetNodesOwner(bool nodes_owner)
Set the mesh nodes ownership flag.
Definition mesh.hpp:2364
int AddBdrSegment(int v1, int v2, int attr=1)
Definition mesh.cpp:2389
bool DerefineByError(Array< real_t > &elem_error, real_t threshold, int nc_limit=0, int op=1)
Definition mesh.cpp:10962
void FinalizeHexMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a hexahedral Mesh.
Definition mesh.cpp:3466
int AddElement(Element *elem)
Definition mesh.cpp:2363
static int DecodeFaceInfoLocalIndex(int info)
Given a "face info int", return the local face index.
Definition mesh.hpp:2173
Table * el_to_edge
Definition mesh.hpp:242
void DeleteBoundaryElementToEdge()
Clear the boundary element to edge map.
Definition mesh.hpp:1212
FaceInformation GetFaceInformation(int f) const
Definition mesh.cpp:1293
int GetNumFacesWithGhost() const
Return the number of faces (3D), edges (2D) or vertices (1D) including ghost faces.
Definition mesh.cpp:6857
void GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
Definition mesh.cpp:360
void RefineAtVertex(const Vertex &vert, real_t eps=0.0, int nonconforming=-1)
Refine elements sharing the specified vertex. Uses GeneralRefinement.
Definition mesh.cpp:11336
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:7610
static int InvertTriOrientation(int ori)
Definition mesh.cpp:7124
STable3D * GetElementToFaceTable(int ret_ftbl=0)
Definition mesh.cpp:8513
void FinalizeQuadMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a quadrilateral Mesh.
Definition mesh.cpp:2531
void SaveVTKHDF(const std::string &fname, bool high_order=true)
Save the Mesh in VTKHDF format.
Definition mesh.cpp:12746
void Make3D24TetsFromHex(int nx, int ny, int nz, real_t sx, real_t sy, real_t sz)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz*24 tetrahedrons.
Definition mesh.cpp:4113
virtual bool NonconformingDerefinement(Array< real_t > &elem_error, real_t threshold, int nc_limit=0, int op=1)
NC version of GeneralDerefinement.
Definition mesh.cpp:10914
void AddVertexParents(int i, int p1, int p2)
Mark vertex i as nonconforming, with parent vertices p1 and p2.
Definition mesh.cpp:2024
void PrintExodusII(const std::string &fpath)
Export a mesh to an Exodus II file.
MFEM_DEPRECATED void GetBdrElementAdjacentElement2(int bdr_el, int &el, int &info) const
Deprecated.
Definition mesh.cpp:7927
int GetPatchAttribute(int i) const
Return the attribute of patch i, for a NURBS mesh.
Definition mesh.cpp:3353
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
Definition mesh.cpp:1557
void Printer(std::ostream &os=mfem::out, std::string section_delimiter="", const std::string &comments="") const
If NURBS mesh, write NURBS format. If NCMesh, write mfem v1.1 format. If section_delimiter is empty,...
Definition mesh.cpp:11976
bool FaceIsInterior(int FaceNo) const
Return true if the given face is interior.
Definition mesh.hpp:1563
ElementTransformation * GetBdrElementTransformation(int i)
Returns a pointer to the transformation defining the i-th boundary element.
Definition mesh.cpp:533
static bool remove_unused_vertices
Definition mesh.hpp:321
IsoparametricTransformation Transformation
Definition mesh.hpp:256
void Init()
Definition mesh.cpp:1804
void Make2D4TrisFromQuad(int nx, int ny, real_t sx, real_t sy)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny*4 triangles.
Definition mesh.cpp:3966
MFEM_DEPRECATED Geometry::Type GetFaceGeometryType(int Face) const
Deprecated in favor of Mesh::GetFaceGeometry.
Definition mesh.hpp:1520
void GetLocalTriToWdgTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:763
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:7835
int SpaceDimension() const
Dimension of the physical space containing the mesh.
Definition mesh.hpp:1309
void GetNURBSPatches(Array< NURBSPatch * > &patches)
Definition mesh.cpp:3377
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:883
static Mesh MakeCartesian3D(int nx, int ny, int nz, Element::Type type, real_t sx=1.0, real_t sy=1.0, real_t sz=1.0, bool sfc_ordering=true)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz hexahedra if type =...
Definition mesh.cpp:4627
Table * edge_vertex
Definition mesh.hpp:254
void GetCharacteristics(real_t &h_min, real_t &h_max, real_t &kappa_min, real_t &kappa_max, Vector *Vh=NULL, Vector *Vk=NULL)
Definition mesh.cpp:205
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
Definition mesh.cpp:6788
void ReadCubit(const std::string &filename, int &curved, int &read_gf)
Load a mesh from a Genesis file.
static const int vtk_quadratic_pyramid[13]
Definition mesh.hpp:271
virtual void SetAttributes(bool elem_attrs_changed=true, bool bdr_face_attrs_changed=true)
Determine the sets of unique attribute values in domain if elem_attrs_changed and boundary elements i...
Definition mesh.cpp:1937
void SetNode(int i, const real_t *coord)
Definition mesh.cpp:9592
int NumOfVertices
Definition mesh.hpp:81
const Array< int > & GetBdrFaceAttributes() const
Returns the attributes for all boundary elements in this mesh.
Definition mesh.cpp:925
AttributeSets attribute_sets
Named sets of element attributes.
Definition mesh.hpp:307
virtual void UniformRefinement3D()
Refine a mixed 3D mesh uniformly.
Definition mesh.hpp:476
static int ComposeTriOrientations(int ori_a_b, int ori_b_c)
Definition mesh.cpp:7101
Array< int > be_to_face
Definition mesh.hpp:245
Mesh & operator=(const Mesh &mesh)=delete
Explicitly delete the copy assignment operator.
void PrintBdrVTU(std::string fname, VTKFormat format=VTKFormat::ASCII, bool high_order_output=false, int compression_level=0)
Definition mesh.cpp:12384
const std::unordered_map< int, int > & GetInvFaceIndices(FaceType ftype) const
Inverse of the map FaceIndices(ftype)
Definition mesh.cpp:1013
void AddSegmentFaceElement(int lf, int gf, int el, int v0, int v1)
Definition mesh.cpp:8193
FaceElementTransformations * GetBdrFaceTransformations(int BdrElemNo)
Builds the transformation defining the given boundary face.
Definition mesh.cpp:1223
int AddBdrTriangle(int v1, int v2, int v3, int attr=1)
Definition mesh.cpp:2403
void GetGeometricParametersFromJacobian(const DenseMatrix &J, real_t &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:13914
int MeshGenerator() const
Get the mesh generator/type.
Definition mesh.hpp:1333
int GetNV() const
Returns number of vertices. Vertices are only at the corners of elements, where you would expect them...
Definition mesh.hpp:1374
static int DecodeFaceInfoOrientation(int info)
Given a "face info int", return the face orientation.
Definition mesh.hpp:2170
void GetHilbertElementOrdering(Array< int > &ordering)
Definition mesh.cpp:2760
void GetEdgeToUniqueKnotvector(Array< int > &edge_to_ukv, Array< int > &ukv_to_rpkv) const
Definition mesh.cpp:6542
void GetEdgeVertices(int i, Array< int > &vert) const
Returns the indices of the vertices of edge i.
Definition mesh.cpp:7672
void AddQuadAs5QuadsWithPoints(int *vi, int attr=1)
Adds 5 quadrilaterals to the mesh by splitting a quadrilateral given by 4 vertices vi.
Definition mesh.cpp:2242
void ReadVTKMesh(std::istream &input, int &curved, int &read_gf, bool &finalize_topo)
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:12392
virtual void UniformRefinement2D()
Refine a mixed 2D mesh uniformly.
Definition mesh.hpp:466
GridFunction * Nodes
Definition mesh.hpp:267
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:6042
Element::Type GetFaceElementType(int Face) const
Definition mesh.cpp:1612
int CheckBdrElementOrientation(bool fix_it=true)
Check the orientation of the boundary elements.
Definition mesh.cpp:7342
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:7905
Array< int > elem_attrs_cache
internal cache for element attributes
Definition mesh.hpp:112
Table * el_to_el
Definition mesh.hpp:244
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:9697
Table * face_edge
Definition mesh.hpp:253
real_t GetElementVolume(int i)
Definition mesh.cpp:124
static Mesh LoadFromFile(const std::string &filename, int generate_edges=0, int refine=1, bool fix_orientation=true)
Definition mesh.cpp:4599
int NumOfElements
Definition mesh.hpp:81
static const int vtk_quadratic_hex[27]
Definition mesh.hpp:273
void Swap(Mesh &other, bool non_geometry)
Definition mesh.cpp:11036
Array< Triple< int, int, int > > tmp_vertex_parents
Definition mesh.hpp:281
virtual void GenerateBoundaryElements()
Definition mesh.cpp:2453
static void GetElementArrayEdgeTable(const Array< Element * > &elem_array, const DSTable &v_to_v, Table &el_to_edge)
Definition mesh.cpp:8021
std::vector< int > CreatePeriodicVertexMapping(const std::vector< Vector > &translations, real_t 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:6076
void Bisection(int i, const DSTable &, int *, int *, int *)
Bisect a triangle: element with index i is bisected.
Definition mesh.cpp:11391
void GetFaceVertices(int i, Array< int > &vert) const
Returns the indices of the vertices of face i.
Definition mesh.hpp:1627
void ResetLazyData()
Definition mesh.cpp:1918
void UniformRefinement2D_base(bool update_nodes=true)
Definition mesh.cpp:9733
IsoparametricTransformation BdrTransformation
Definition mesh.hpp:257
void PrintTopoEdges(std::ostream &out, const Array< int > &e_to_k, bool vmap=false) const
Write the patch topology edges of a NURBS mesh (see PrintTopo()).
Definition mesh.cpp:12138
void GetLocalSegToTriTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:699
void DestroyPointers()
Definition mesh.cpp:1855
void InitTables()
Definition mesh.cpp:1823
void DegreeElevate(int rel_degree, int degree=16)
Definition mesh.cpp:6388
Table * face_to_elem
Definition mesh.hpp:252
int NumOfFaces
Definition mesh.hpp:82
void GetBdrElementData(int geom, Array< int > &bdr_elem_vtx, Array< int > &bdr_attr) const
Definition mesh.hpp:1474
int spaceDim
Definition mesh.hpp:79
int FindCoarseElement(int i)
Definition mesh.cpp:11739
void FinalizeTriMesh(int generate_edges=0, int refine=0, bool fix_orientation=true)
Finalize the construction of a triangular Mesh.
Definition mesh.cpp:2502
void GetElementCenter(int i, Vector &center)
Definition mesh.cpp:80
void AddHexAsPyramids(const int *vi, int attr=1)
Adds 6 pyramids to the mesh by splitting a hexahedron given by 8 vertices vi.
Definition mesh.cpp:2201
static void PrintElementsByGeometry(int dim, const Array< int > &num_elems_by_geom, std::ostream &os)
Auxiliary method used by PrintCharacteristics().
Definition mesh.cpp:240
int AddHex(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int attr=1)
Adds a hexahedron to the mesh given by 8 vertices v1 through v8.
Definition mesh.cpp:2148
static IntegrationPoint TransformBdrElementToFace(Geometry::Type geom, int o, const IntegrationPoint &ip)
For the vertex (1D), edge (2D), or face (3D) of a boundary element with the orientation o,...
Definition mesh.cpp:7453
MFEM_DEPRECATED int GetBdrFace(int i) const
Deprecated in favor of GetBdrElementFaceIndex().
Definition mesh.hpp:1692
void SetEmpty()
Definition mesh.cpp:1830
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
Definition mesh.cpp:6741
int GetNBE() const
Returns number of boundary elements.
Definition mesh.hpp:1380
long long GetGlobalNE() const
Return the total (global) number of elements.
Definition mesh.hpp:1406
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
Definition mesh.cpp:3608
MFEM_DEPRECATED Mesh(int n, real_t sx=1.0)
Deprecated: see MakeCartesian1D.
Definition mesh.hpp:1289
void AddQuadFaceElement(int lf, int gf, int el, int v0, int v1, int v2, int v3)
Definition mesh.cpp:8258
void ReadMFEMMesh(std::istream &input, int version, int &curved)
Geometry::Constants< Geometry::PYRAMID > pyr_t
Definition mesh.hpp:297
void KnotRemove(Array< Vector * > &kv)
For NURBS meshes, remove the knots in kv, for each direction.
Definition mesh.cpp:6293
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:13800
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)
void GetEdgeTransformation(int i, IsoparametricTransformation *EdTr) const
Builds the transformation defining the i-th edge element in EdTr. EdTr must be allocated in advance a...
Definition mesh.cpp:616
int own_nodes
Definition mesh.hpp:268
void GetElementData(const Array< Element * > &elem_array, int geom, Array< int > &elem_vtx, Array< int > &attr) const
Definition mesh.cpp:11105
void PrintSurfaces(const Table &Aface_face, std::ostream &os) const
Print set of disjoint surfaces:
Definition mesh.cpp:13333
bool IsSlaveFace(const FaceInfo &fi) const
Definition mesh.cpp:1249
void FreeElement(Element *E)
Definition mesh.cpp:13775
void BuildCubitBoundaries(const cubit::CubitBlock *blocks, const std::vector< int > &boundary_ids, const std::map< int, std::vector< int > > &element_ids_for_boundary_id, const std::map< int, std::vector< std::vector< int > > > &node_ids_for_boundary_id, const std::map< int, std::vector< int > > &side_ids_for_boundary_id, const std::map< int, int > &block_id_for_element_id, const std::map< int, int > &cubit_to_mfem_vertex_map)
Called internally in ReadCubit. This method adds the mesh boundary elements.
Array< Element * > boundary
Definition mesh.hpp:108
virtual void MarkTetMeshForRefinement(const DSTable &v_to_v)
Definition mesh.cpp:3021
void GetPointMatrix(int i, DenseMatrix &pointmat) const
Definition mesh.cpp:7972
FaceElementTransformations * GetInteriorFaceTransformations(int FaceNo)
See GetFaceElementTransformations().
Definition mesh.cpp:1203
void GetLocalTriToTetTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:739
virtual void PrintInfo(std::ostream &os=mfem::out)
In serial, this method calls PrintCharacteristics(). In parallel, additional information about the pa...
Definition mesh.hpp:2656
virtual void PrintXG(std::ostream &os=mfem::out) const
Print the mesh to the given stream using Netgen/Truegrid format.
Definition mesh.cpp:11812
MFEM_DEPRECATED Geometry::Type GetFaceBaseGeometry(int i) const
Deprecated in favor of Mesh::GetFaceGeometry.
Definition mesh.hpp:1553
NCMesh * ncmesh
Optional nonconforming mesh extension.
Definition mesh.hpp:313
void NewNodes(GridFunction &nodes, bool make_owner=false)
Replace the internal node GridFunction with the given GridFunction.
Definition mesh.cpp:9654
virtual void NURBSUniformRefinement(int rf=2, real_t tol=1.0e-12)
Refine NURBS mesh, with an optional refinement factor, generally anisotropic.
Definition mesh.cpp:6320
MFEM_DEPRECATED Mesh(int nx, int ny, int nz, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, real_t sz=1.0, bool sfc_ordering=true)
Deprecated: see MakeCartesian3D.
Definition mesh.hpp:1268
int mesh_geoms
Definition mesh.hpp:92
void DebugDump(std::ostream &os) const
Output an NCMesh-compatible debug dump.
Definition mesh.cpp:15470
real_t * GetVertex(int i)
Return pointer to vertex i's coordinates.
Definition mesh.hpp:1426
MFEM_DEPRECATED int GetBdrElementEdgeIndex(int i) const
Definition mesh.hpp:1699
GridFunction * GetNodes()
Return a pointer to the internal node GridFunction (may be NULL).
Definition mesh.hpp:2359
bool RefineByError(const Array< real_t > &elem_error, real_t threshold, int nonconforming=-1, int nc_limit=0)
Definition mesh.cpp:11362
static Mesh MakeCartesian3DWith24TetsPerHex(int nx, int ny, int nz, real_t sx=1.0, real_t sy=1.0, real_t sz=1.0)
Creates a mesh for the parallelepiped [0,sx]x[0,sy]x[0,sz], divided into nx*ny*nz*24 tetrahedrons.
Definition mesh.cpp:4637
virtual ~Mesh()
Destroys Mesh.
Definition mesh.hpp:830
STable3D * GetFacesTable()
Definition mesh.cpp:8450
Table * GetFaceEdgeTable() const
Definition mesh.cpp:7681
void EnsureNCMesh(bool simplices_nonconforming=false)
Definition mesh.cpp:11293
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:1340
virtual MFEM_DEPRECATED void ReorientTetMesh()
Definition mesh.cpp:8643
void PrintVTK(std::ostream &os)
Definition mesh.cpp:12192
virtual void MarkNamedBoundaries(const std::string &set_name, Array< int > &bdr_marker) const
Mark boundary attributes in the named set.
Definition mesh.cpp:1783
void ReadNURBSMesh(std::istream &input, int &curved, int &read_gf, bool spacing=false, bool nc=false)
void MoveNodes(const Vector &displacements)
Definition mesh.cpp:9612
Array< GeometricFactors * > geom_factors
Optional geometric factors.
Definition mesh.hpp:314
void SetMeshGen()
Determine the mesh generator bitmask meshgen, see MeshGenerator().
Definition mesh.cpp:4890
int nbBoundaryFaces
Definition mesh.hpp:87
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
Definition mesh.cpp:4617
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:7588
void Make2D(int nx, int ny, Element::Type type, real_t sx, real_t sy, bool generate_edges, bool sfc_ordering)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
Definition mesh.cpp:4230
void AddHexAsTets(const int *vi, int attr=1)
Adds 6 tetrahedrons to the mesh by splitting a hexahedron given by 8 vertices vi.
Definition mesh.cpp:2164
FaceElementTransformations FaceElemTr
Definition mesh.hpp:259
void SetNodes(const Vector &node_coord)
Updates the vertex/node locations. Invokes NodesUpdated().
Definition mesh.cpp:9639
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
Definition mesh.cpp:7558
void FinalizeCheck()
Definition mesh.cpp:2488
void GetLocalQuadToPyrTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:860
void AddHexAsWedges(const int *vi, int attr=1)
Adds 2 wedges to the mesh by splitting a hexahedron given by 8 vertices vi.
Definition mesh.cpp:2183
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:6799
Element * ReadElement(std::istream &input)
Definition mesh.cpp:4872
virtual bool HasBoundaryElements() const
Checks if the mesh has boundary elements.
Definition mesh.hpp:1336
void ScaleSubdomains(real_t sf)
Definition mesh.cpp:13400
void GetVertexToVertexTable(DSTable &) const
Definition mesh.cpp:8043
void GetLocalQuadToHexTransformation(IsoparametricTransformation &loc, int i) const
Definition mesh.cpp:814
int NumOfEdges
Definition mesh.hpp:82
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:11637
Geometry::Type GetTypicalFaceGeometry() const
If the local mesh is not empty, return GetFaceGeometry(0); otherwise return a typical face geometry p...
Definition mesh.cpp:1596
Geometry::Type GetElementBaseGeometry(int i) const
Definition mesh.hpp:1556
virtual void UnmarkInternalBoundaries(Array< int > &bdr_marker, bool excl=true) const
Unmark boundary attributes of internal boundaries.
Definition mesh.cpp:1675
Operation last_operation
Definition mesh.hpp:329
void SwapNodes(GridFunction *&nodes, int &own_nodes_)
Swap the internal node GridFunction pointer and ownership flag members with the given ones.
Definition mesh.cpp:9676
virtual void RefineNURBSWithKVFactors(int rf, const std::string &kvf)
Definition mesh.cpp:6315
void LoadPatchTopo(std::istream &input, Array< int > &edge_to_ukv)
Read NURBS patch/macro-element mesh.
Definition mesh.cpp:6467
void SetBdrAttribute(int i, int attr)
Set the attribute of boundary element i.
Definition mesh.hpp:1493
void ChangeVertexDataOwnership(real_t *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:4708
MFEM_DEPRECATED Mesh(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Deprecated: see MakeCartesian2D.
Definition mesh.hpp:1279
int nbInteriorFaces
Definition mesh.hpp:87
Table * GetVertexToElementTable()
Definition mesh.cpp:7735
void InitRefinementTransforms()
Definition mesh.cpp:11727
void BuildCubitVertices(const std::vector< int > &unique_vertex_ids, const std::vector< double > &coordx, const std::vector< double > &coordy, const std::vector< double > &coordz)
Called internally in ReadCubit. This method creates the vertices.
Geometry::Type GetBdrElementBaseGeometry(int i) const
Definition mesh.hpp:1559
Table * GetEdgeVertexTable() const
Definition mesh.cpp:7709
int * GeneratePartitioning(int nparts, int part_method=1)
Definition mesh.cpp:8749
Table * GetFaceToElementTable() const
Definition mesh.cpp:7801
void MarkTriMeshForRefinement()
Definition mesh.cpp:2981
void ReadNetgen2DMesh(std::istream &input, int &curved)
Array< Element * > elements
Definition mesh.hpp:102
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Definition mesh.hpp:302
void AddPointFaceElement(int lf, int gf, int el)
Used in GenerateFaces()
Definition mesh.cpp:8161
void RemoveInternalBoundaries()
Definition mesh.cpp:13698
virtual void NonconformingRefinement(const Array< Refinement > &refinements, int nc_limit=0)
This function is not public anymore. Use GeneralRefinement instead.
Definition mesh.cpp:10845
void MoveVertices(const Vector &displacements)
Definition mesh.cpp:9544
const real_t * GetVertex(int i) const
Return pointer to vertex i's coordinates.
Definition mesh.hpp:1416
void DeleteGeometricFactors()
Destroy all GeometricFactors stored by the Mesh.
Definition mesh.cpp:1022
const Table & ElementToFaceTable() const
Definition mesh.cpp:8143
long GetNodesSequence() const
Return the nodes update counter.
Definition mesh.hpp:2526
void AddQuadAs4TrisWithPoints(int *vi, int attr=1)
Adds 4 triangles to the mesh by splitting a quadrilateral given by 4 vertices vi.
Definition mesh.cpp:2220
void RemoveUnusedVertices()
Remove unused vertices and rebuild mesh connectivity.
Definition mesh.cpp:13591
void KnotInsert(Array< KnotVector * > &kv)
For NURBS meshes, insert the new knots in kv, for each direction.
Definition mesh.cpp:6249
A class for non-conforming AMR. The class is not used directly by the user, rather it is an extension...
Definition ncmesh.hpp:190
bool using_scaling
Definition ncmesh.hpp:686
NCNURBSExtension extends NURBSExtension to support NC-patch NURBS meshes.
Definition ncnurbs.hpp:23
NURBSExtension generally contains multiple NURBSPatch objects spanning an entire Mesh....
Definition nurbs.hpp:474
Class used to extrude the nodes of a mesh.
Definition mesh.hpp:3182
void SetLayer(const int l)
Definition mesh.hpp:3189
NodeExtrudeCoefficient(const int dim, const int n_, const real_t s_)
Definition mesh.cpp:15045
virtual ~NodeExtrudeCoefficient()
Definition mesh.hpp:3193
void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
Definition mesh.cpp:15051
Class for parallel meshes.
Definition pmesh.hpp:34
A parallel extension of the NCMesh class.
Definition pncmesh.hpp:63
Symmetric 3D Table stored as an array of rows each of which has a stack of column,...
Definition stable3d.hpp:35
Table stores the connectivity of elements of TYPE I to elements of TYPE II. For example,...
Definition table.hpp:43
Data type tetrahedron element.
Base class for vector Coefficients that optionally depend on time and space.
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 ...
Vector data type.
Definition vector.hpp:82
Data type for vertex.
Definition vertex.hpp:23
int dim
Definition ex24.cpp:53
prob_type prob
Definition ex25.cpp:156
constexpr int dimension
This example only works in 3D. Kernels for 2D are not implemented.
Definition hooke.cpp:45
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
mfem::real_t real_t
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
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
void ShiftRight(int &a, int &b, int &c)
Definition mesh.hpp:3205
Mesh * Extrude1D(Mesh *mesh, const int ny, const real_t sy, const bool closed)
Extrude a 1D mesh.
Definition mesh.cpp:15069
Mesh * Extrude2D(Mesh *mesh, const int nz, const real_t sz)
Extrude a 2D mesh.
Definition mesh.cpp:15229
VTKFormat
Data array format for VTK and VTU files.
Definition vtk.hpp:100
@ ASCII
Data arrays will be written in ASCII format.
float real_t
Definition config.hpp:46
MemoryType
Memory types supported by MFEM.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
FaceType
Definition mesh.hpp:49
Defines the coarse-fine transformations of all fine elements.
Definition ncmesh.hpp:90
EntityHelper(int dim_, const Array< int >(&entity_to_vertex_)[Geometry::NumGeom])
Definition mesh.cpp:14029
Entity FindEntity(int bytype_entity_id)
Definition mesh.cpp:14044
entity_to_vertex_type & entity_to_vertex
Definition mesh.hpp:2773
const Array< int > entity_to_vertex_type[Geometry::NumGeom]
Definition mesh.hpp:2772
int geom_offsets[Geometry::NumGeom+1]
Definition mesh.hpp:2771
const int * verts
Definition mesh.hpp:2767
This structure stores the low level information necessary to interpret the configuration of elements ...
Definition mesh.hpp:176
This structure is used as a human readable output format that deciphers the information contained in ...
Definition mesh.hpp:2081
ElementLocation location
Definition mesh.hpp:2086
bool IsNonconformingFine() const
Return true if the face is a nonconforming fine face.
Definition mesh.hpp:2148
bool IsBoundary() const
Return true if the face is a boundary face.
Definition mesh.hpp:2122
bool IsNonconformingCoarse() const
Return true if the face is a nonconforming coarse face.
Definition mesh.hpp:2159
bool IsOfFaceType(FaceType type) const
Return true if the face is of the same type as type.
Definition mesh.hpp:2128
struct mfem::Mesh::FaceInformation::@15 element[2]
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:2115
bool IsLocal() const
Return true if the face is a local interior face which is NOT a master nonconforming face.
Definition mesh.hpp:2099
bool IsConforming() const
Return true if the face is a conforming face.
Definition mesh.hpp:2142
ElementConformity conformity
Definition mesh.hpp:2087
bool IsShared() const
Return true if the face is a shared interior face which is NOT a master nonconforming face.
Definition mesh.hpp:2106
const DenseMatrix * point_matrix
Definition mesh.hpp:2095
const DenseMatrix * PointMatrix
Definition mesh.hpp:230
NCFaceInfo(bool slave, int master, const DenseMatrix *pm)
Definition mesh.hpp:235
std::array< int, NCMesh::MaxFaceNodes > nodes