MFEM  v3.4
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
geom.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_GEOM
13 #define MFEM_GEOM
14 
15 #include "../config/config.hpp"
16 #include "../linalg/densemat.hpp"
17 #include "intrules.hpp"
18 
19 namespace mfem
20 {
21 
22 /** Types of domains for integration rules and reference finite elements:
23  Geometry::POINT - a point
24  Geometry::SEGMENT - the interval [0,1]
25  Geometry::TRIANGLE - triangle with vertices (0,0), (1,0), (0,1)
26  Geometry::SQUARE - the unit square (0,1)x(0,1)
27  Geometry::TETRAHEDRON - w/ vert. (0,0,0),(1,0,0),(0,1,0),(0,0,1)
28  Geometry::CUBE - the unit cube */
29 class Geometry
30 {
31 public:
33 
34  static const int NumGeom = 6;
35  static const int MaxDim = 3;
36  static const int NumBdrArray[NumGeom];
37  static const char *Name[NumGeom];
38  static const double Volume[NumGeom];
39  static const int Dimension[NumGeom];
40  static const int NumVerts[NumGeom];
41  static const int NumEdges[NumGeom];
42  static const int NumFaces[NumGeom];
43 
44  // Structure that holds constants describing the Geometries.
45  template <Type Geom> struct Constants;
46 
47 private:
48  IntegrationRule *GeomVert[NumGeom];
49  IntegrationPoint GeomCenter[NumGeom];
50  DenseMatrix *GeomToPerfGeomJac[NumGeom];
51  DenseMatrix *PerfGeomToGeomJac[NumGeom];
52 
53 public:
54  Geometry();
55  ~Geometry();
56 
57  /** @brief Return an IntegrationRule consisting of all vertices of the given
58  Geometry::Type, @a GeomType. */
59  const IntegrationRule *GetVertices(int GeomType);
60 
61  /// Return the center of the given Geometry::Type, @a GeomType.
62  const IntegrationPoint &GetCenter(int GeomType)
63  { return GeomCenter[GeomType]; }
64 
65  /// Get a random point in the reference element specified by @a GeomType.
66  /** This method uses the function rand() for random number generation. */
67  static void GetRandomPoint(int GeomType, IntegrationPoint &ip);
68 
69  /// Check if the given point is inside the given reference element.
70  static bool CheckPoint(int GeomType, const IntegrationPoint &ip);
71  /** @brief Check if the given point is inside the given reference element.
72  Overload for fuzzy tolerance. */
73  static bool CheckPoint(int GeomType, const IntegrationPoint &ip, double eps);
74 
75  /// Project a point @a end, onto the given Geometry::Type, @a GeomType.
76  /** Check if the @a end point is inside the reference element, if not
77  overwrite it with the point on the boundary that lies on the line segment
78  between @a beg and @a end (@a beg must be inside the element). Return
79  true if @a end is inside the element, and false otherwise. */
80  static bool ProjectPoint(int GeomType, const IntegrationPoint &beg,
81  IntegrationPoint &end);
82 
83  /// Project a point @a ip, onto the given Geometry::Type, @a GeomType.
84  /** If @a ip is outside the element, replace it with the point on the
85  boundary that is closest to the original @a ip and return false;
86  otherwise, return true without changing @a ip. */
87  static bool ProjectPoint(int GeomType, IntegrationPoint &ip);
88 
89  const DenseMatrix &GetGeomToPerfGeomJac(int GeomType) const
90  { return *GeomToPerfGeomJac[GeomType]; }
92  { return PerfGeomToGeomJac[GeomType]; }
93  void GetPerfPointMat(int GeomType, DenseMatrix &pm);
94  void JacToPerfJac(int GeomType, const DenseMatrix &J,
95  DenseMatrix &PJ) const;
96 
97  /// Return the number of boundary "faces" of a given Geometry::Type.
98  int NumBdr(int GeomType) { return NumBdrArray[GeomType]; }
99 };
100 
101 template <> struct Geometry::Constants<Geometry::POINT>
102 {
103  static const int Dimension = 0;
104  static const int NumVert = 1;
105 
106  static const int NumOrient = 1;
107  static const int Orient[NumOrient][NumVert];
108  static const int InvOrient[NumOrient];
109 };
110 
111 template <> struct Geometry::Constants<Geometry::SEGMENT>
112 {
113  static const int Dimension = 1;
114  static const int NumVert = 2;
115  static const int NumEdges = 1;
116  static const int Edges[NumEdges][2];
117 
118  static const int NumOrient = 2;
119  static const int Orient[NumOrient][NumVert];
120  static const int InvOrient[NumOrient];
121 };
122 
123 template <> struct Geometry::Constants<Geometry::TRIANGLE>
124 {
125  static const int Dimension = 2;
126  static const int NumVert = 3;
127  static const int NumEdges = 3;
128  static const int Edges[NumEdges][2];
129  // Lower-triangular part of the local vertex-to-vertex graph.
130  struct VertToVert
131  {
132  static const int I[NumVert];
133  static const int J[NumEdges][2]; // {end,edge_idx}
134  };
135  static const int NumFaces = 1;
136  static const int FaceVert[NumFaces][NumVert];
137 
138  // For a given base tuple v={v0,v1,v2}, the orientation of a permutation
139  // u={u0,u1,u2} of v, is an index 'j' such that u[i]=v[Orient[j][i]].
140  // The static method Mesh::GetTriOrientation, computes the index 'j' of the
141  // permutation that maps the second argument 'test' to the first argument
142  // 'base': test[Orient[j][i]]=base[i].
143  static const int NumOrient = 6;
144  static const int Orient[NumOrient][NumVert];
145  // The inverse of orientation 'j' is InvOrient[j].
146  static const int InvOrient[NumOrient];
147 };
148 
149 template <> struct Geometry::Constants<Geometry::SQUARE>
150 {
151  static const int Dimension = 2;
152  static const int NumVert = 4;
153  static const int NumEdges = 4;
154  static const int Edges[NumEdges][2];
155  // Lower-triangular part of the local vertex-to-vertex graph.
156  struct VertToVert
157  {
158  static const int I[NumVert];
159  static const int J[NumEdges][2]; // {end,edge_idx}
160  };
161  static const int NumFaces = 1;
162  static const int FaceVert[NumFaces][NumVert];
163 
164  static const int NumOrient = 8;
165  static const int Orient[NumOrient][NumVert];
166  static const int InvOrient[NumOrient];
167 };
168 
169 template <> struct Geometry::Constants<Geometry::TETRAHEDRON>
170 {
171  static const int Dimension = 3;
172  static const int NumVert = 4;
173  static const int NumEdges = 6;
174  static const int Edges[NumEdges][2];
175  static const int NumFaces = 4;
176  static const int FaceTypes[NumFaces];
177  static const int MaxFaceVert = 3;
178  static const int FaceVert[NumFaces][MaxFaceVert];
179  // Lower-triangular part of the local vertex-to-vertex graph.
180  struct VertToVert
181  {
182  static const int I[NumVert];
183  static const int J[NumEdges][2]; // {end,edge_idx}
184  };
185 };
186 
187 template <> struct Geometry::Constants<Geometry::CUBE>
188 {
189  static const int Dimension = 3;
190  static const int NumVert = 8;
191  static const int NumEdges = 12;
192  static const int Edges[NumEdges][2];
193  static const int NumFaces = 6;
194  static const int FaceTypes[NumFaces];
195  static const int MaxFaceVert = 4;
196  static const int FaceVert[NumFaces][MaxFaceVert];
197  // Lower-triangular part of the local vertex-to-vertex graph.
198  struct VertToVert
199  {
200  static const int I[NumVert];
201  static const int J[NumEdges][2]; // {end,edge_idx}
202  };
203 };
204 
205 extern Geometry Geometries;
206 
208 {
209 public:
210  int Times, ETimes;
213  int NumBdrEdges; // at the beginning of RefEdges
214  int Type;
215 
216  RefinedGeometry(int NPts, int NRefG, int NRefE, int NBdrE = 0) :
217  RefPts(NPts), RefGeoms(NRefG), RefEdges(NRefE), NumBdrEdges(NBdrE) { }
218 };
219 
221 {
222 private:
223  int type; // Quadrature1D type (ClosedUniform is default)
226 
227  RefinedGeometry *FindInRGeom(int Geom, int Times, int ETimes, int Type);
228  IntegrationRule *FindInIntPts(int Geom, int NPts);
229 
230 public:
231  GeometryRefiner();
232 
233  /// Set the Quadrature1D type of points to use for subdivision.
234  void SetType(const int t) { type = t; }
235  /// Get the Quadrature1D type of points used for subdivision.
236  int GetType() const { return type; }
237 
238  RefinedGeometry *Refine(int Geom, int Times, int ETimes = 1);
239 
240  /// @note This method always uses Quadrature1D::OpenUniform points.
241  const IntegrationRule *RefineInterior(int Geom, int Times);
242 
244 };
245 
246 extern GeometryRefiner GlobGeometryRefiner;
247 
248 }
249 
250 #endif
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:83
RefinedGeometry(int NPts, int NRefG, int NRefE, int NBdrE=0)
Definition: geom.hpp:216
static const int NumGeom
Definition: geom.hpp:34
void JacToPerfJac(int GeomType, const DenseMatrix &J, DenseMatrix &PJ) const
Definition: geom.cpp:644
static void GetRandomPoint(int GeomType, IntegrationPoint &ip)
Get a random point in the reference element specified by GeomType.
Definition: geom.cpp:206
RefinedGeometry * Refine(int Geom, int Times, int ETimes=1)
Definition: geom.cpp:803
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
static const double Volume[NumGeom]
Definition: geom.hpp:38
static const int NumEdges[NumGeom]
Definition: geom.hpp:41
Array< int > RefEdges
Definition: geom.hpp:212
const IntegrationPoint & GetCenter(int GeomType)
Return the center of the given Geometry::Type, GeomType.
Definition: geom.hpp:62
const IntegrationRule * GetVertices(int GeomType)
Return an IntegrationRule consisting of all vertices of the given Geometry::Type, GeomType...
Definition: geom.cpp:188
const DenseMatrix & GetGeomToPerfGeomJac(int GeomType) const
Definition: geom.hpp:89
static const int NumFaces[NumGeom]
Definition: geom.hpp:42
Geometry Geometries
Definition: geom.cpp:760
static const int Dimension[NumGeom]
Definition: geom.hpp:39
void SetType(const int t)
Set the Quadrature1D type of points to use for subdivision.
Definition: geom.hpp:234
const IntegrationRule * RefineInterior(int Geom, int Times)
Definition: geom.cpp:1124
static const int NumVerts[NumGeom]
Definition: geom.hpp:40
GeometryRefiner GlobGeometryRefiner
Definition: geom.cpp:1202
IntegrationRule RefPts
Definition: geom.hpp:211
static const int NumBdrArray[NumGeom]
Definition: geom.hpp:36
static const char * Name[NumGeom]
Definition: geom.hpp:37
static const int MaxDim
Definition: geom.hpp:35
static bool ProjectPoint(int GeomType, const IntegrationPoint &beg, IntegrationPoint &end)
Project a point end, onto the given Geometry::Type, GeomType.
Definition: geom.cpp:446
void GetPerfPointMat(int GeomType, DenseMatrix &pm)
Definition: geom.cpp:583
int NumBdr(int GeomType)
Return the number of boundary &quot;faces&quot; of a given Geometry::Type.
Definition: geom.hpp:98
DenseMatrix * GetPerfGeomToGeomJac(int GeomType)
Definition: geom.hpp:91
Class for integration point with weight.
Definition: intrules.hpp:25
int GetType() const
Get the Quadrature1D type of points used for subdivision.
Definition: geom.hpp:236
static bool CheckPoint(int GeomType, const IntegrationPoint &ip)
Check if the given point is inside the given reference element.
Definition: geom.cpp:297
Array< int > RefGeoms
Definition: geom.hpp:212