MFEM  v3.3
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 NumBdrArray[];
36  static const char *Name[NumGeom];
37  static const double Volume[NumGeom];
38  static const int Dimension[NumGeom];
39  static const int NumVerts[NumGeom];
40  static const int NumEdges[NumGeom];
41  static const int NumFaces[NumGeom];
42 
43  // Structure that holds constants describing the Geometries.
44  // Currently it contains just the space dimension.
45  template <Type Geom> struct Constants;
46 
47 private:
48  IntegrationRule *GeomVert[NumGeom];
49  IntegrationPoint GeomCenter[NumGeom];
50  DenseMatrix *PerfGeomToGeomJac[NumGeom];
51 
52 public:
53  Geometry();
54  ~Geometry();
55 
56  const IntegrationRule *GetVertices(int GeomType);
57  const IntegrationPoint &GetCenter(int GeomType)
58  { return GeomCenter[GeomType]; }
59  /** Get a random point in the reference element specified by GeomType.
60  This method uses the function rand() for random number generation. */
61  static void GetRandomPoint(int GeomType, IntegrationPoint &ip);
62  /// Check if the given point is inside the given reference element.
63  static bool CheckPoint(int GeomType, const IntegrationPoint &ip);
64  /** Check if the end point is inside the reference element, if not overwrite
65  it with the point on the boundary that lies on the line segment between
66  beg and end (beg must be inside the element). Return true if end is
67  inside the element, and false otherwise. */
68  static bool ProjectPoint(int GeomType, const IntegrationPoint &beg,
69  IntegrationPoint &end);
70 
72  { return PerfGeomToGeomJac[GeomType]; }
73  void GetPerfPointMat(int GeomType, DenseMatrix &pm);
74  void JacToPerfJac(int GeomType, const DenseMatrix &J,
75  DenseMatrix &PJ) const;
76 
77  int NumBdr (int GeomType) { return NumBdrArray[GeomType]; }
78 };
79 
80 template <> struct Geometry::Constants<Geometry::POINT>
81 {
82  static const int Dimension = 0;
83  static const int NumVert = 1;
84 
85  static const int NumOrient = 1;
86  static const int Orient[NumOrient][NumVert];
87  static const int InvOrient[NumOrient];
88 };
89 
90 template <> struct Geometry::Constants<Geometry::SEGMENT>
91 {
92  static const int Dimension = 1;
93  static const int NumVert = 2;
94  static const int NumEdges = 1;
95  static const int Edges[NumEdges][2];
96 
97  static const int NumOrient = 2;
98  static const int Orient[NumOrient][NumVert];
99  static const int InvOrient[NumOrient];
100 };
101 
102 template <> struct Geometry::Constants<Geometry::TRIANGLE>
103 {
104  static const int Dimension = 2;
105  static const int NumVert = 3;
106  static const int NumEdges = 3;
107  static const int Edges[NumEdges][2];
108  // Lower-triangular part of the local vertex-to-vertex graph.
109  struct VertToVert
110  {
111  static const int I[NumVert];
112  static const int J[NumEdges][2]; // {end,edge_idx}
113  };
114  static const int NumFaces = 1;
115  static const int FaceVert[NumFaces][NumVert];
116 
117  // For a given base tuple v={v0,v1,v2}, the orientation of a permutation
118  // u={u0,u1,u2} of v, is an index 'j' such that u[i]=v[Orient[j][i]].
119  // The static method Mesh::GetTriOrientation, computes the index 'j' of the
120  // permutation that maps the second argument 'test' to the first argument
121  // 'base': test[Orient[j][i]]=base[i].
122  static const int NumOrient = 6;
123  static const int Orient[NumOrient][NumVert];
124  // The inverse of orientation 'j' is InvOrient[j].
125  static const int InvOrient[NumOrient];
126 };
127 
128 template <> struct Geometry::Constants<Geometry::SQUARE>
129 {
130  static const int Dimension = 2;
131  static const int NumVert = 4;
132  static const int NumEdges = 4;
133  static const int Edges[NumEdges][2];
134  // Lower-triangular part of the local vertex-to-vertex graph.
135  struct VertToVert
136  {
137  static const int I[NumVert];
138  static const int J[NumEdges][2]; // {end,edge_idx}
139  };
140  static const int NumFaces = 1;
141  static const int FaceVert[NumFaces][NumVert];
142 
143  static const int NumOrient = 8;
144  static const int Orient[NumOrient][NumVert];
145  static const int InvOrient[NumOrient];
146 };
147 
148 template <> struct Geometry::Constants<Geometry::TETRAHEDRON>
149 {
150  static const int Dimension = 3;
151  static const int NumVert = 4;
152  static const int NumEdges = 6;
153  static const int Edges[NumEdges][2];
154  static const int NumFaces = 4;
155  static const int FaceTypes[NumFaces];
156  static const int MaxFaceVert = 3;
157  static const int FaceVert[NumFaces][MaxFaceVert];
158  // Lower-triangular part of the local vertex-to-vertex graph.
159  struct VertToVert
160  {
161  static const int I[NumVert];
162  static const int J[NumEdges][2]; // {end,edge_idx}
163  };
164 };
165 
166 template <> struct Geometry::Constants<Geometry::CUBE>
167 {
168  static const int Dimension = 3;
169  static const int NumVert = 8;
170  static const int NumEdges = 12;
171  static const int Edges[NumEdges][2];
172  static const int NumFaces = 6;
173  static const int FaceTypes[NumFaces];
174  static const int MaxFaceVert = 4;
175  static const int FaceVert[NumFaces][MaxFaceVert];
176  // Lower-triangular part of the local vertex-to-vertex graph.
177  struct VertToVert
178  {
179  static const int I[NumVert];
180  static const int J[NumEdges][2]; // {end,edge_idx}
181  };
182 };
183 
184 extern Geometry Geometries;
185 
187 {
188 public:
189  int Times, ETimes;
192  int NumBdrEdges; // at the begining of RefEdges
193 
194  RefinedGeometry(int NPts, int NRefG, int NRefE, int NBdrE = 0) :
195  RefPts(NPts), RefGeoms(NRefG), RefEdges(NRefE), NumBdrEdges(NBdrE) { }
196 };
197 
199 {
200 private:
201  int type; // 0 - uniform points, otherwise - poly1d.ClosedPoints
204 public:
205  GeometryRefiner();
206 
207  void SetType(const int t) { type = t; }
208  RefinedGeometry *Refine (int Geom, int Times, int ETimes = 1);
209  const IntegrationRule *RefineInterior(int Geom, int Times);
210 
212 };
213 
214 extern GeometryRefiner GlobGeometryRefiner;
215 
216 }
217 
218 #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:194
static const int NumGeom
Definition: geom.hpp:34
void JacToPerfJac(int GeomType, const DenseMatrix &J, DenseMatrix &PJ) const
Definition: geom.cpp:428
static void GetRandomPoint(int GeomType, IntegrationPoint &ip)
Definition: geom.cpp:190
RefinedGeometry * Refine(int Geom, int Times, int ETimes=1)
Definition: geom.cpp:566
Data type dense matrix using column-major storage.
Definition: densemat.hpp:22
static const double Volume[NumGeom]
Definition: geom.hpp:37
static const int NumBdrArray[]
Definition: geom.hpp:35
static const int NumEdges[NumGeom]
Definition: geom.hpp:40
Array< int > RefEdges
Definition: geom.hpp:191
const IntegrationPoint & GetCenter(int GeomType)
Definition: geom.hpp:57
const IntegrationRule * GetVertices(int GeomType)
Definition: geom.cpp:172
static const int NumFaces[NumGeom]
Definition: geom.hpp:41
Geometry Geometries
Definition: geom.cpp:544
static const int Dimension[NumGeom]
Definition: geom.hpp:38
void SetType(const int t)
Definition: geom.hpp:207
const IntegrationRule * RefineInterior(int Geom, int Times)
Definition: geom.cpp:944
static const int NumVerts[NumGeom]
Definition: geom.hpp:39
GeometryRefiner GlobGeometryRefiner
Definition: geom.cpp:1022
IntegrationRule RefPts
Definition: geom.hpp:190
static const char * Name[NumGeom]
Definition: geom.hpp:36
static bool ProjectPoint(int GeomType, const IntegrationPoint &beg, IntegrationPoint &end)
Definition: geom.cpp:317
void GetPerfPointMat(int GeomType, DenseMatrix &pm)
Definition: geom.cpp:367
int NumBdr(int GeomType)
Definition: geom.hpp:77
DenseMatrix * GetPerfGeomToGeomJac(int GeomType)
Definition: geom.hpp:71
Class for integration point with weight.
Definition: intrules.hpp:25
static bool CheckPoint(int GeomType, const IntegrationPoint &ip)
Check if the given point is inside the given reference element.
Definition: geom.cpp:255
Array< int > RefGeoms
Definition: geom.hpp:191