libMesh
mixed_order_test.C
Go to the documentation of this file.
1 #include <libmesh/libmesh.h>
2 
3 #include <libmesh/elem.h>
4 #include <libmesh/mesh.h>
5 #include <libmesh/mesh_generation.h>
6 
8 
9 #include "test_comm.h"
10 #include "libmesh_cppunit.h"
11 
12 
13 using namespace libMesh;
14 
15 class MixedOrderTest : public CppUnit::TestCase
16 {
21 public:
22  LIBMESH_CPPUNIT_TEST_SUITE( MixedOrderTest );
23 
24  CPPUNIT_TEST( testFindNeighbors );
25  CPPUNIT_TEST( testStitch );
26 
27  CPPUNIT_TEST_SUITE_END();
28 
29 public:
30  void setUp() {}
31 
32  void tearDown() {}
33 
34  static int n_neighbor_links (const MeshBase & mesh)
35  {
36  int n_neighbors = 0;
37  for (const auto & elem : mesh.local_element_ptr_range())
38  for (const auto & neigh : elem->neighbor_ptr_range())
39  if (neigh)
40  ++n_neighbors;
41  mesh.comm().sum(n_neighbors);
42  return n_neighbors;
43  }
44 
45 
47  {
48  LOG_UNIT_TEST;
49 
51 
52  // Construct a multi-element Tri3 mesh
54  /*nx=*/3, /*ny=*/3,
55  /*xmin=*/0., /*xmax=*/1.,
56  /*ymin=*/0., /*ymax=*/1.,
57  /*elem_type=*/TRI3);
58 
59  // Make some of them into Tri6
60  auto range_start = mesh.elements_begin();
61  const auto range_end = mesh.elements_end();
62  while (range_start != range_end && (*range_start)->id() < 5)
63  ++range_start;
64 
65  const int old_n_neighbors = n_neighbor_links(mesh);
66 
67  mesh.all_second_order_range({range_start,range_end},
68  /*full_ordered=*/true);
69  const int new_n_neighbors = n_neighbor_links(mesh);
70  CPPUNIT_ASSERT_EQUAL(old_n_neighbors, new_n_neighbors);
71 
73  const int newer_n_neighbors = n_neighbor_links(mesh);
74  CPPUNIT_ASSERT_EQUAL(old_n_neighbors, newer_n_neighbors);
75  }
76 
77  void testStitch()
78  {
79  LOG_UNIT_TEST;
80 
81  Mesh mesh0(*TestCommWorld),
82  mesh1(*TestCommWorld);
83 
84  // Quad4 mesh and Quad9 mesh
86  /*nx=*/3, /*ny=*/3,
87  /*xmin=*/0., /*xmax=*/1.,
88  /*ymin=*/0., /*ymax=*/1.,
89  /*elem_type=*/QUAD4);
90  CPPUNIT_ASSERT_EQUAL(mesh0.n_nodes(), dof_id_type(16));
91 
93  /*nx=*/3, /*ny=*/3,
94  /*xmin=*/-1., /*xmax=*/0.,
95  /*ymin=*/0., /*ymax=*/1.,
96  /*elem_type=*/QUAD9);
97  CPPUNIT_ASSERT_EQUAL(mesh1.n_nodes(), dof_id_type(49));
98 
99  // Stitch them together
100  mesh0.stitch_meshes(mesh1, 3, 1, TOLERANCE, /*clear_bcids*/ true,
101  /*verbose*/ false, /*binary_search*/ false,
102  /*enforce_all_nodes_match*/ false,
103  /*merge_all_or_nothing*/ false);
104  CPPUNIT_ASSERT_EQUAL(mesh0.n_nodes(), dof_id_type(61));
105 
106  const int stitched_n_neighbors = n_neighbor_links(mesh0);
107  CPPUNIT_ASSERT_EQUAL(stitched_n_neighbors, 54);
108 
109  mesh0.all_second_order_range(mesh0.element_ptr_range(),
110  /*full_ordered=*/true);
111  const int new_n_neighbors = n_neighbor_links(mesh0);
112  CPPUNIT_ASSERT_EQUAL(new_n_neighbors, 54);
113  }
114 };
115 
116 
virtual void all_second_order_range(const SimpleRange< element_iterator > &range, const bool full_ordered=true)=0
Converts a set of this Mesh&#39;s elements defined by range from FIRST order to SECOND order...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
virtual dof_id_type n_nodes() const override final
void sum(T &r) const
MeshBase & mesh
const Parallel::Communicator & comm() const
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:75
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true)=0
Locate element face (edge in 2D) neighbors.
void testFindNeighbors()
static int n_neighbor_links(const MeshBase &mesh)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
uint8_t dof_id_type
Definition: id_types.h:67
CPPUNIT_TEST_SUITE_REGISTRATION(MixedOrderTest)