| 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_TETRAHEDRON |
| 13 | #define MFEM_TETRAHEDRON |
| 14 | |
| 15 | #include "../config/config.hpp" |
| 16 | #include "element.hpp" |
| 17 | |
| 18 | namespace mfem |
| 19 | { |
| 20 | |
| 21 | /// Data type tetrahedron element |
| 22 | class Tetrahedron : public Element |
| 23 | { |
| 24 | protected: |
| 25 | int indices[4]; |
| 26 | |
| 27 | /** The refinement flag keeps (in order) : |
| 28 | 1. Two marked edges given with local index (0..5) for the two faces |
| 29 | that don't have the refinement edge as edge. The refinement edge |
| 30 | is determined by the first two nodes of the tetrahedron. Each |
| 31 | marked edge is stored in 3 bits (or as implemented in the functions |
| 32 | CreateRefinementFlag and ParseRefinementFlag. |
| 33 | 2. Type of the element, stored in the next 3 bits. |
| 34 | 3. The rest is free for now. **/ |
| 35 | int refinement_flag; |
| 36 | |
| 37 | unsigned transform; |
| 38 | |
| 39 | public: |
| 40 | typedef Geometry::Constants<Geometry::TETRAHEDRON> geom_t; |
| 41 | |
| 42 | /// Constants for different types of tetrahedrons. |
| 43 | enum { TYPE_PU=0, TYPE_A=1, TYPE_PF=2, TYPE_O=3, TYPE_M=4 }; |
| 44 | |
| 45 | Tetrahedron() : Element(Geometry::TETRAHEDRON) |
| 46 | { refinement_flag = 0; transform = 0; } |
| 47 | |
| 48 | /// Constructs tetrahedron by specifying the indices and the attribute. |
| 49 | Tetrahedron(const int *ind, int attr = 1); |
| 50 | |
| 51 | /// Constructs tetrahedron by specifying the indices and the attribute. |
| 52 | Tetrahedron(int ind1, int ind2, int ind3, int ind4, int attr = 1); |
| 53 | |
| 54 | /// Initialize the vertex indices and the attribute of a Tetrahedron. |
| 55 | void Init(int ind1, int ind2, int ind3, int ind4, int attr = 1, |
| 56 | int ref_flag = 0); |
| 57 | |
| 58 | /// Return element's type. |
| 59 | Type GetType() const override { return Element::TETRAHEDRON; } |
| 60 | |
| 61 | void ParseRefinementFlag(int refinement_edges[2], int &type, |
| 62 | int &flag) const; |
| 63 | void CreateRefinementFlag(int refinement_edges[2], int type, int flag = 0); |
| 64 | |
| 65 | void GetMarkedFace(const int face, int *fv) const; |
| 66 | |
| 67 | int GetRefinementFlag() const { return refinement_flag; } |
| 68 | |
| 69 | void SetRefinementFlag(int rf) { refinement_flag = rf; } |
| 70 | |
| 71 | /// Return 1 if the element needs refinement in order to get conforming mesh. |
| 72 | int NeedRefinement(HashTable<Hashed2> &v_to_v) const override; |
| 73 | |
| 74 | /** Reorder the vertices so that the longest edge is from vertex 0 |
| 75 | to vertex 1. If called it should be once from the mesh constructor, |
| 76 | because the order may be used later for setting the edges. **/ |
| 77 | void MarkEdge(const DSTable &v_to_v, const int *length) override; |
| 78 | |
| 79 | void ResetTransform(int tr) override { transform = tr; } |
| 80 | unsigned GetTransform() const override { return transform; } |
| 81 | |
| 82 | /// Add 'tr' to the current chain of coarse-fine transformations. |
| 83 | void PushTransform(int tr) override |
| 84 | { transform = (transform << 3) | (tr + 1); } |
| 85 | |
| 86 | /// Calculate point matrix corresponding to a chain of transformations. |
| 87 | static void GetPointMatrix(unsigned transform, DenseMatrix &pm); |
| 88 | |
| 89 | /// Get the indices defining the vertices. |
| 90 | void GetVertices(Array<int> &v) const override; |
| 91 | |
| 92 | /// Set the indices defining the vertices. |
| 93 | void SetVertices(const Array<int> &v) override; |
| 94 | |
| 95 | /// @note The returned array should NOT be deleted by the caller. |
| 96 | int * GetVertices () override { return indices; } |
| 97 | |
| 98 | /// Set the indices defining the vertices. |
| 99 | void SetVertices(const int *ind) override; |
| 100 | |
| 101 | int GetNVertices() const override { return 4; } |
| 102 | |
| 103 | int GetNEdges() const override { return (6); } |
| 104 | |
| 105 | const int *GetEdgeVertices(int ei) const override |
| 106 | { return geom_t::Edges[ei]; } |
| 107 | |
| 108 | /// @deprecated Use GetNFaces(void) and GetNFaceVertices(int) instead. |
| 109 | MFEM_DEPRECATED int GetNFaces(int &nFaceVertices) const override |
| 110 | { nFaceVertices = 3; return 4; } |
| 111 | |
| 112 | int GetNFaces() const override { return 4; } |
| 113 | |
| 114 | int GetNFaceVertices(int) const override { return 3; } |
| 115 | |
| 116 | const int *GetFaceVertices(int fi) const override |
| 117 | { return geom_t::FaceVert[fi]; } |
| 118 | |
| 119 | Element *Duplicate(Mesh *m) const override; |
| 120 | |
| 121 | virtual ~Tetrahedron() = default; |
| 122 | }; |
| 123 | |
| 124 | // Defined in fe.cpp to ensure construction before 'mfem::Geometries'. |
| 125 | extern MFEM_EXPORT class Linear3DFiniteElement TetrahedronFE; |
| 126 | |
| 127 | } |
| 128 | |
| 129 | #endif |