From b60c0d61d270c46dc0fac993fd483c3f41652f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 16 May 2022 21:05:07 +0200 Subject: [PATCH] core: Disable pair search for HybridDecomposition --- src/core/HybridDecomposition.cpp | 26 ++---------- src/core/cells.cpp | 5 +++ testsuite/python/CMakeLists.txt | 4 +- ...stem_get_neighbors.py => get_neighbors.py} | 41 ++++--------------- 4 files changed, 20 insertions(+), 56 deletions(-) rename testsuite/python/{cellsystem_get_neighbors.py => get_neighbors.py} (82%) diff --git a/src/core/HybridDecomposition.cpp b/src/core/HybridDecomposition.cpp index 49a647fe857..e5c21e4b8c1 100644 --- a/src/core/HybridDecomposition.cpp +++ b/src/core/HybridDecomposition.cpp @@ -67,36 +67,18 @@ HybridDecomposition::HybridDecomposition(boost::mpi::communicator comm, std::back_inserter(m_collect_ghost_force_comm.communications)); /* coupling between the child decompositions via neighborship relation */ - auto const copy_neighbors = [](Cell *local_cell) { + std::vector additional_reds = m_n_square.get_local_cells(); + std::copy(ghost_cells_n_square.begin(), ghost_cells_n_square.end(), + std::back_inserter(additional_reds)); + for (auto &local_cell : m_regular_decomposition.local_cells()) { std::vector red_neighbors(local_cell->m_neighbors.red().begin(), local_cell->m_neighbors.red().end()); std::vector black_neighbors(local_cell->m_neighbors.black().begin(), local_cell->m_neighbors.black().end()); - return std::make_pair(red_neighbors, black_neighbors); - }; - std::vector red_neighbors; - std::vector black_neighbors; - std::vector additional_reds; - - /* push N-square neighbor cells into regular decomposition neighbor cells */ - additional_reds = m_n_square.get_local_cells(); - std::copy(ghost_cells_n_square.begin(), ghost_cells_n_square.end(), - std::back_inserter(additional_reds)); - for (auto &local_cell : m_regular_decomposition.local_cells()) { - std::tie(red_neighbors, black_neighbors) = copy_neighbors(local_cell); std::copy(additional_reds.begin(), additional_reds.end(), std::back_inserter(red_neighbors)); local_cell->m_neighbors = Neighbors(red_neighbors, black_neighbors); } - - /* push regular decomposition cells into N-square black neighbor cells */ - for (auto &local_cell : m_regular_decomposition.local_cells()) { - for (auto &ns_cell : m_n_square.local_cells()) { - std::tie(red_neighbors, black_neighbors) = copy_neighbors(ns_cell); - black_neighbors.emplace_back(local_cell); - ns_cell->m_neighbors = Neighbors(red_neighbors, black_neighbors); - } - } } void HybridDecomposition::resort(bool global, diff --git a/src/core/cells.cpp b/src/core/cells.cpp index cfa6f17dd95..c6de9c80b7c 100644 --- a/src/core/cells.cpp +++ b/src/core/cells.cpp @@ -135,6 +135,11 @@ mpi_get_short_range_neighbors_local(int const pid, double const distance) { if (not p or p->is_ghost()) { return {}; } + auto const cs_type = cell_structure.decomposition_type(); + if (cs_type == CellStructureType::CELL_STRUCTURE_HYBRID) { + runtimeErrorMsg() << "Cannot search for neighbors in the hybrid " + "decomposition cell system"; + } std::vector ret; auto const cutoff2 = distance * distance; diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt index 4ff8254b6d4..d91bfe3b77a 100644 --- a/testsuite/python/CMakeLists.txt +++ b/testsuite/python/CMakeLists.txt @@ -107,8 +107,8 @@ checkpoint_test(MODES therm_sdm__int_sdm) python_test(FILE bond_breakage.py MAX_NUM_PROC 4) python_test(FILE cellsystem.py MAX_NUM_PROC 4) -python_test(FILE cellsystem_get_neighbors.py MAX_NUM_PROC 4) -python_test(FILE cellsystem_get_neighbors.py MAX_NUM_PROC 3 SUFFIX 3_cores) +python_test(FILE get_neighbors.py MAX_NUM_PROC 4) +python_test(FILE get_neighbors.py MAX_NUM_PROC 3 SUFFIX 3_cores) python_test(FILE tune_skin.py MAX_NUM_PROC 1) python_test(FILE constraint_homogeneous_magnetic_field.py MAX_NUM_PROC 4) python_test(FILE constraint_shape_based.py MAX_NUM_PROC 2) diff --git a/testsuite/python/cellsystem_get_neighbors.py b/testsuite/python/get_neighbors.py similarity index 82% rename from testsuite/python/cellsystem_get_neighbors.py rename to testsuite/python/get_neighbors.py index 5f74d30510c..4a3c4036b2f 100644 --- a/testsuite/python/cellsystem_get_neighbors.py +++ b/testsuite/python/get_neighbors.py @@ -127,45 +127,22 @@ def test_domain_decomposition(self): system.periodicity = [False, True, True] self.assertEqual(get_neighbors(p1, 1.1 * pair_dist), []) - @ut.skipIf(n_nodes != 4, "Only runs if number of MPI cores is 4") def test_hybrid_decomposition(self): """ Set up colloids in a N-square cell system coupled to ions on a - regular decomposition cell system. The ions are set two cells - apart along the x-coordinate, such that they cannot see one - another, even when the neighbor search distance is larger than - the ion-ion distance. + regular decomposition cell system. """ system = self.system system.cell_system.set_hybrid_decomposition( n_square_types={1}, cutoff_regular=0.1) - system.cell_system.node_grid = [self.n_nodes, 1, 1] - - types = {"ion": 0, "colloid": 1} - ions = [] - colloids = [] - for i in range(4): - pos = [0.125 + i * 0.25, 0., 0.] - ions.append(system.part.add(pos=pos, type=types["ion"])) - for i in range(4): - pos = [0.5, 0., 0.] - colloids.append(system.part.add(pos=pos, type=types["colloid"])) - colloid_ids = [p.id for p in colloids] - - # ions can see all colloids - for p_ion in ions: - neighbors = system.cell_system.get_neighbors(p_ion, 0.5) - np.testing.assert_array_equal(np.sort(neighbors), colloid_ids) - - # colloids can see all colloids, but only ions on the same node - for p_colloid in colloids: - neighbors = system.cell_system.get_neighbors(p_colloid, 0.5) - expected = list(colloid_ids) - expected.remove(p_colloid.id) - for p_ion in ions: - if p_ion.node == p_colloid.node: - expected.insert(0, p_ion.id) - np.testing.assert_array_equal(np.sort(neighbors), expected) + p_ion = system.part.add(pos=[0., 0., 0.], type=0) + p_colloid = system.part.add(pos=[0., 0., 0.], type=1) + + msg = "Cannot search for neighbors in the hybrid decomposition cell system" + with np.testing.assert_raises_regex(Exception, rf"Error in get_neighbors\(\): ERROR: {msg}"): + system.cell_system.get_neighbors(p_ion, 0.05) + with np.testing.assert_raises_regex(Exception, rf"Error in get_neighbors\(\): ERROR: {msg}"): + system.cell_system.get_neighbors(p_colloid, 0.05) def test_lees_edwards(self): """