libMesh
Loading...
Searching...
No Matches
parallel_ghost_sync_test.C
Go to the documentation of this file.
1
2// libMesh includes
3#include <libmesh/parallel_ghost_sync.h>
4#include <libmesh/mesh.h>
5#include <libmesh/mesh_generation.h>
6
7#include "test_comm.h"
8#include "libmesh_cppunit.h"
9
10
11namespace {
12
13 using namespace libMesh;
14
15 struct SyncAndTest {
16 typedef std::vector<Real> datum;
17
18 const MeshBase & mesh;
19
20 std::unordered_set<dof_id_type> answered_ids;
21
22 SyncAndTest(MeshBase & _mesh) :
23 mesh(_mesh) {}
24
25 ~SyncAndTest() {
26 for (const Node * node : mesh.node_ptr_range())
27 if (node->processor_id() != mesh.processor_id())
28 CPPUNIT_ASSERT(answered_ids.count(node->id()));
29 }
30
31 void gather_data (const std::vector<dof_id_type> & ids,
32 std::vector<datum> & data)
33 {
34 data.resize(ids.size());
35
36 for (auto i : index_range(ids))
37 {
38 const Node * node = mesh.query_node_ptr(ids[i]);
39
40 // We should only be asked about nodes we own
41 CPPUNIT_ASSERT(node);
42 CPPUNIT_ASSERT_EQUAL(mesh.processor_id(), node->processor_id());
43
44 data[i] = {(*node)(2), (*node)(1), (*node)(0)};
45 }
46 }
47
48 void act_on_data (const std::vector<dof_id_type> & ids,
49 const std::vector<datum> & data)
50 {
51 CPPUNIT_ASSERT_EQUAL(ids.size(), data.size());
52
53 for (auto i : index_range(ids))
54 {
55 answered_ids.insert(ids[i]);
56
57 // We should have every node we asked about
58 const Node * node = mesh.query_node_ptr(ids[i]);
59 CPPUNIT_ASSERT(node);
60 CPPUNIT_ASSERT(mesh.processor_id() != node->processor_id());
61
62 CPPUNIT_ASSERT_EQUAL(data[i].size(), std::size_t(3));
63 CPPUNIT_ASSERT_EQUAL(data[i][0], (*node)(2));
64 CPPUNIT_ASSERT_EQUAL(data[i][1], (*node)(1));
65 CPPUNIT_ASSERT_EQUAL(data[i][2], (*node)(0));
66 }
67 }
68 };
69}
70
71
72using namespace libMesh;
73
74class ParallelGhostSyncTest : public CppUnit::TestCase {
75public:
77
79
81
82private:
83 std::unique_ptr<Mesh> _mesh;
84
85public:
86 void setUp()
87 {
88 _mesh = std::make_unique<Mesh>(*TestCommWorld);
89 constexpr unsigned int n = 3;
90 MeshTools::Generation::build_cube (*_mesh, n, n, n, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, HEX27);
91 }
92
93 void tearDown()
94 {}
95
96 void testByXYZ()
97 {
98 LOG_UNIT_TEST;
99
100 SyncAndTest sync(*_mesh);
101 LocationMap<Node> loc_map;
102 loc_map.init(*_mesh);
104 (*TestCommWorld, _mesh->nodes_begin(), _mesh->nodes_end(),
105 loc_map, sync);
106 }
107
108};
109
std::unique_ptr< Mesh > _mesh
LIBMESH_CPPUNIT_TEST_SUITE(ParallelGhostSyncTest)
processor_id_type processor_id() const
Definition dof_object.h:881
Data structures that enable location-based lookups The key is a hash of the Point location.
void init(MeshBase &)
This is the MeshBase class.
Definition mesh_base.h:81
virtual const Node * query_node_ptr(const dof_id_type i) const =0
A Node is like a Point, but with more information.
Definition node.h:55
processor_id_type processor_id() const
Communicator * TestCommWorld
MeshBase & mesh
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
void sync_dofobject_data_by_xyz(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, LocationMap< DofObjType > &location_map, SyncFunctor &sync)
Request data about a range of ghost nodes uniquely identified by their xyz location or a range of act...
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
CPPUNIT_TEST_SUITE_REGISTRATION(ParallelGhostSyncTest)