Skip to content

Commit 7726ab0

Browse files
authored
Merge pull request #4164 from roystgnr/more_static_maps
More static maps
2 parents 744b363 + 06e8786 commit 7726ab0

File tree

7 files changed

+159
-19
lines changed

7 files changed

+159
-19
lines changed

include/geom/elem.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ class Elem : public ReferenceCountedObject<Elem>,
625625
*/
626626
virtual ElemType type () const = 0;
627627

628+
/**
629+
* This array maps the integer representation of the \p ElemType enum
630+
* to the geometric dimension of the element.
631+
*
632+
* This is currently usable even for complicated subclasses with
633+
* runtime-varying topology.
634+
*/
635+
static const unsigned int type_to_dim_map[INVALID_ELEM];
636+
628637
/**
629638
* \returns The dimensionality of the object.
630639
*/
@@ -964,8 +973,17 @@ class Elem : public ReferenceCountedObject<Elem>,
964973
void build_edge_ptr (std::unique_ptr<const Elem> & edge, const unsigned int i) const;
965974

966975
/**
967-
* \returns The default approximation order for this element type.
968-
* This is the order that will be used to compute the map to the
976+
* This array maps the integer representation of the \p ElemType enum
977+
* to the default approximation order of elements of that type.
978+
*
979+
* This is currently usable even for complicated subclasses with
980+
* runtime-varying topology.
981+
*/
982+
static const Order type_to_default_order_map[INVALID_ELEM];
983+
984+
/**
985+
* \returns The default approximation order for this element. This
986+
* is the order that will be used to compute the map to the
969987
* reference element.
970988
*/
971989
virtual Order default_order () const = 0;

src/geom/elem.C

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,66 @@ Threads::spin_mutex parent_bracketing_nodes_mutex;
100100
const subdomain_id_type Elem::invalid_subdomain_id = std::numeric_limits<subdomain_id_type>::max();
101101

102102
// Initialize static member variables
103+
const unsigned int Elem::type_to_dim_map [] =
104+
{
105+
1, // EDGE2
106+
1, // EDGE3
107+
1, // EDGE4
108+
109+
2, // TRI3
110+
2, // TRI6
111+
112+
2, // QUAD4
113+
2, // QUAD8
114+
2, // QUAD9
115+
116+
3, // TET4
117+
3, // TET10
118+
119+
3, // HEX8
120+
3, // HEX20
121+
3, // HEX27
122+
123+
3, // PRISM6
124+
3, // PRISM15
125+
3, // PRISM18
126+
127+
3, // PYRAMID5
128+
3, // PYRAMID13
129+
3, // PYRAMID14
130+
131+
1, // INFEDGE2
132+
133+
2, // INFQUAD4
134+
2, // INFQUAD6
135+
136+
3, // INFHEX8
137+
3, // INFHEX16
138+
3, // INFHEX18
139+
140+
3, // INFPRISM6
141+
3, // INFPRISM12
142+
143+
0, // NODEELEM
144+
145+
0, // REMOTEELEM
146+
147+
2, // TRI3SUBDIVISION
148+
2, // TRISHELL3
149+
2, // QUADSHELL4
150+
2, // QUADSHELL8
151+
152+
2, // TRI7
153+
3, // TET14
154+
3, // PRISM20
155+
3, // PRISM21
156+
3, // PYRAMID18
157+
158+
2, // QUADSHELL9
159+
160+
2, // C0POLYGON
161+
};
162+
103163
const unsigned int Elem::max_n_nodes;
104164

105165
const unsigned int Elem::type_to_n_nodes_map [] =
@@ -282,6 +342,66 @@ const unsigned int Elem::type_to_n_edges_map [] =
282342
invalid_uint, // C0POLYGON
283343
};
284344

345+
const Order Elem::type_to_default_order_map [] =
346+
{
347+
FIRST, // EDGE2
348+
SECOND, // EDGE3
349+
THIRD, // EDGE4
350+
351+
FIRST, // TRI3
352+
SECOND, // TRI6
353+
354+
FIRST, // QUAD4
355+
SECOND, // QUAD8
356+
SECOND, // QUAD9
357+
358+
FIRST, // TET4
359+
SECOND, // TET10
360+
361+
FIRST, // HEX8
362+
SECOND, // HEX20
363+
SECOND, // HEX27
364+
365+
FIRST, // PRISM6
366+
SECOND, // PRISM15
367+
SECOND, // PRISM18
368+
369+
FIRST, // PYRAMID5
370+
SECOND, // PYRAMID13
371+
SECOND, // PYRAMID14
372+
373+
FIRST, // INFEDGE2
374+
375+
FIRST, // INFQUAD4
376+
SECOND, // INFQUAD6
377+
378+
FIRST, // INFHEX8
379+
SECOND, // INFHEX16
380+
SECOND, // INFHEX18
381+
382+
FIRST, // INFPRISM6
383+
SECOND, // INFPRISM12
384+
385+
CONSTANT, // NODEELEM
386+
387+
INVALID_ORDER, // REMOTEELEM
388+
389+
FIRST, // TRI3SUBDIVISION
390+
FIRST, // TRISHELL3
391+
FIRST, // QUADSHELL4
392+
SECOND, // QUADSHELL8
393+
394+
THIRD, // TRI7
395+
THIRD, // TET14
396+
THIRD, // PRISM20
397+
THIRD, // PRISM21
398+
THIRD, // PYRAMID18
399+
400+
SECOND, // QUADSHELL9
401+
402+
FIRST, // C0POLYGON
403+
};
404+
285405
// ------------------------------------------------------------
286406
// Elem class member functions
287407
std::unique_ptr<Elem> Elem::disconnected_clone() const

tests/fe/fe_test.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ class FETestBase : public CppUnit::TestCase {
349349
void setUp()
350350
{
351351
_mesh = std::make_unique<Mesh>(*TestCommWorld);
352-
const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
353-
_dim = test_elem->dim();
352+
_dim = Elem::type_to_dim_map[elem_type];
354353
const unsigned int build_ny = (_dim > 1) * build_nx;
355354
const unsigned int build_nz = (_dim > 2) * build_nx;
356355

tests/geom/elem_test.C

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,16 @@ public:
198198
{
199199
CPPUNIT_ASSERT(elem->n_nodes() <= Elem::max_n_nodes);
200200

201+
const ElemType etype = elem->type();
202+
203+
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(elem->dim()),
204+
Elem::type_to_dim_map[etype]);
205+
CPPUNIT_ASSERT_EQUAL(elem->default_order(),
206+
Elem::type_to_default_order_map[etype]);
207+
201208
// If we have an element type with topology defined solely by
202209
// the type, then that should match the runtime topology. If
203210
// not, then we should be aware of it.
204-
const ElemType etype = elem->type();
205211
if (!elem->runtime_topology())
206212
{
207213
CPPUNIT_ASSERT_EQUAL(elem->n_nodes(), Elem::type_to_n_nodes_map[etype]);

tests/mesh/mesh_input.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ public:
954954
ny = added_sides_nxyz[1],
955955
nz = added_sides_nxyz[2];
956956

957-
const unsigned int dim = Elem::build(elem_type)->dim();
957+
const unsigned int dim = Elem::type_to_dim_map[elem_type];
958958
const bool is_tensor = (Elem::build(elem_type)->n_sides() == dim * 2);
959959

960960
// Figure out how many fake and true elements to expect

tests/systems/systems_test.C

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,7 @@ public:
777777
TransientExplicitSystem &sys =
778778
es.add_system<TransientExplicitSystem> ("SimpleSystem");
779779

780-
auto generic_elem = Elem::build(elem_type);
781-
782-
auto u_var = sys.add_variable("u", generic_elem->default_order(), LAGRANGE_VEC);
780+
auto u_var = sys.add_variable("u", Elem::type_to_default_order_map[elem_type], LAGRANGE_VEC);
783781

784782
MeshTools::Generation::build_square (mesh,
785783
1, 1,
@@ -792,7 +790,7 @@ public:
792790
// function projection code right now
793791
for (const auto & node : mesh.local_node_ptr_range())
794792
{
795-
for (unsigned int i = 0; i < generic_elem->dim(); ++i)
793+
for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
796794
{
797795
auto dof_index = node->dof_number(sys.number(), u_var, i);
798796
sys.solution->set(dof_index, (*node)(i));
@@ -812,7 +810,7 @@ public:
812810
for (const auto & node : mesh.local_node_ptr_range())
813811
{
814812
// 2D element here
815-
for (unsigned int i = 0; i < generic_elem->dim(); ++i)
813+
for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
816814
{
817815
auto dof_index = node->dof_number(sys.number(), u_var, i);
818816
auto value = (*sys.solution)(dof_index);
@@ -829,9 +827,8 @@ public:
829827
TransientExplicitSystem &sys =
830828
es.add_system<TransientExplicitSystem> ("SimpleSystem");
831829

832-
auto generic_elem = Elem::build(elem_type);
833-
834-
auto u_var = sys.add_variable("u", generic_elem->default_order(), LAGRANGE_VEC);
830+
auto u_var = sys.add_variable
831+
("u", Elem::type_to_default_order_map[elem_type], LAGRANGE_VEC);
835832

836833
MeshTools::Generation::build_cube (mesh,
837834
1, 1, 1,
@@ -844,7 +841,7 @@ public:
844841
// function projection code right now
845842
for (const auto & node : mesh.local_node_ptr_range())
846843
{
847-
for (unsigned int i = 0; i < generic_elem->dim(); ++i)
844+
for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
848845
{
849846
auto dof_index = node->dof_number(sys.number(), u_var, i);
850847
sys.solution->set(dof_index, (*node)(i));
@@ -863,7 +860,7 @@ public:
863860

864861
for (const auto & node : mesh.local_node_ptr_range())
865862
{
866-
for (unsigned int i = 0; i < generic_elem->dim(); ++i)
863+
for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
867864
{
868865
auto dof_index = node->dof_number(sys.number(), u_var, i);
869866
auto value = (*sys.solution)(dof_index);

tests/utils/point_locator_test.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public:
4242
Mesh mesh(*TestCommWorld);
4343

4444
const unsigned int n_elem_per_side = 5;
45-
const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
46-
const unsigned int ymax = test_elem->dim() > 1;
47-
const unsigned int zmax = test_elem->dim() > 2;
45+
const unsigned int dim = Elem::type_to_dim_map[elem_type];
46+
const unsigned int ymax = dim > 1;
47+
const unsigned int zmax = dim > 2;
4848
const unsigned int ny = ymax * n_elem_per_side;
4949
const unsigned int nz = zmax * n_elem_per_side;
5050

0 commit comments

Comments
 (0)