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