From b5ecae24dd96e36c4e416b0f054dbd6afe566560 Mon Sep 17 00:00:00 2001 From: iljah Date: Fri, 5 Jun 2020 12:58:30 +0300 Subject: [PATCH] Allow remote cell as argument to get_face_neighbors_of(). --- Makefile | 1 + dccrg.hpp | 4 - tests/get_face_neighbors/Makefile | 10 + tests/get_face_neighbors/project_makefile | 52 +++ tests/get_face_neighbors/test1.cpp | 374 ++++++++++++++++++++++ 5 files changed, 437 insertions(+), 4 deletions(-) create mode 100644 tests/get_face_neighbors/Makefile create mode 100644 tests/get_face_neighbors/project_makefile create mode 100644 tests/get_face_neighbors/test1.cpp diff --git a/Makefile b/Makefile index 0377680..408f6ae 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ include \ tests/get_cell_datatype/project_makefile \ tests/constructors/project_makefile \ tests/get_neighbors_/project_makefile \ + tests/get_face_neighbors/project_makefile \ tests/iterators/project_makefile \ tests/additional_cell_data/project_makefile \ tests/mpi_support/project_makefile \ diff --git a/dccrg.hpp b/dccrg.hpp index 22ab2c7..4be7f18 100644 --- a/dccrg.hpp +++ b/dccrg.hpp @@ -2820,10 +2820,6 @@ template < std::vector > ret_val; - if (this->cell_data.count(cell) == 0) { - return ret_val; - } - if (this->neighbors_.count(cell) == 0) { std::cerr << __FILE__ << ":" << __LINE__ << " Internal error." << std::endl; diff --git a/tests/get_face_neighbors/Makefile b/tests/get_face_neighbors/Makefile new file mode 100644 index 0000000..08b2d50 --- /dev/null +++ b/tests/get_face_neighbors/Makefile @@ -0,0 +1,10 @@ +all: + @$(MAKE) tests/get_face_neighbors/executables -C ../.. + +t: test +test: + @$(MAKE) tests/get_face_neighbors/tests -C ../.. + +c: clean +clean: + @$(MAKE) tests/get_face_neighbors/clean -C ../.. diff --git a/tests/get_face_neighbors/project_makefile b/tests/get_face_neighbors/project_makefile new file mode 100644 index 0000000..e758a48 --- /dev/null +++ b/tests/get_face_neighbors/project_makefile @@ -0,0 +1,52 @@ +TESTS_GET_FACE_NEIGHBORS_EXECUTABLES = \ + tests/get_face_neighbors/test1.exe + +TESTS_GET_FACE_NEIGHBORS_TESTS = \ + tests/get_face_neighbors/test1.tst \ + tests/get_face_neighbors/test1.tstN + +tests/get_face_neighbors/executables: $(TESTS_GET_FACE_NEIGHBORS_EXECUTABLES) + +tests/get_face_neighbors/tests: $(TESTS_GET_FACE_NEIGHBORS_TESTS) + +tests/get_face_neighbors/clean: + @printf "CLEAN tests/get_face_neighbors\n" && rm -f \ + $(TESTS_GET_FACE_NEIGHBORS_EXECUTABLES) \ + $(TESTS_GET_FACE_NEIGHBORS_TESTS) + + +EXECUTABLES += tests/get_face_neighbors/executables +TESTS += tests/get_face_neighbors/tests +CLEAN += tests/get_face_neighbors/clean + + +TESTS_GET_FACE_NEIGHBORS_COMMON_DEPS = \ + $(DCCRG_HEADERS) \ + tests/get_face_neighbors/project_makefile \ + $(ENVIRONMENT_MAKEFILE) \ + Makefile + +TESTS_GET_FACE_NEIGHBORS_COMPILE_COMMAND = \ + @printf "MPICXX $<\n" && $(MPICXX) $< -o $@ \ + $(CPPFLAGS) \ + $(CXXFLAGS) \ + $(LDFLAGS) \ + $(BOOST_CPPFLAGS) \ + $(BOOST_LDFLAGS) \ + $(BOOST_LIBS) \ + $(ZOLTAN_CPPFLAGS) \ + $(ZOLTAN_LDFLAGS) \ + $(ZOLTAN_LIBS) + +tests/get_face_neighbors/test1.exe: \ + tests/get_face_neighbors/test1.cpp \ + $(TESTS_GET_FACE_NEIGHBORS_COMMON_DEPS) + $(TESTS_GET_FACE_NEIGHBORS_COMPILE_COMMAND) + +tests/get_face_neighbors/test1.tst: \ + tests/get_face_neighbors/test1.exe + @printf RUN\ $<...\ \ && $(RUN) ./$< && printf "PASS\n" && touch $@ + +tests/get_face_neighbors/test1.tstN: \ + tests/get_face_neighbors/test1.exe + @printf MPIRUN\ $<...\ \ && $(MPIRUN) ./$< && printf "PASS\n" && touch $@ diff --git a/tests/get_face_neighbors/test1.cpp b/tests/get_face_neighbors/test1.cpp new file mode 100644 index 0000000..ffb1cfd --- /dev/null +++ b/tests/get_face_neighbors/test1.cpp @@ -0,0 +1,374 @@ +/* +Program for testing get_face_neighbors() function of dccrg. + +Copyright 2020 Finnish Meteorological Institute + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License version 3 +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ + +#include "cstdlib" +#include "iostream" + +#include "mpi.h" +#include "zoltan.h" + +#include "dccrg.hpp" + +int main(int argc, char* argv[]) +{ + if (MPI_Init(&argc, &argv) != MPI_SUCCESS) { + std::cerr << "Coudln't initialize MPI." << std::endl; + abort(); + } + MPI_Comm comm = MPI_COMM_WORLD; + +// constexpr auto err = dccrg::error_cell; + + for (int neigh_len: {0, 1, 2, 3}) { + {dccrg::Dccrg grid; grid + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .initialize(comm); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() > 0) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_periodic(true, true, true) + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .initialize(comm); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 6) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_periodic(false, true, true) + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .initialize(comm); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_periodic(true, false, true) + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .initialize(comm); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_periodic(true, true, false) + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .initialize(comm); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + + {dccrg::Dccrg grid; grid + .set_initial_length({2, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 1); + } + grid.balance_load(); + + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + + switch(cell.id) { + case 1: + if (neighs[0].first != 2) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + case 2: + if (neighs[0].first != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + default: + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_initial_length({1, 2, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 1); + } + grid.balance_load(); + + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + + switch(cell.id) { + case 1: + if (neighs[0].first != 2) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + case 2: + if (neighs[0].first != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + default: + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_initial_length({1, 1, 2}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(0) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 1); + } + grid.balance_load(); + + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + + switch(cell.id) { + case 1: + if (neighs[0].first != 2) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + case 2: + if (neighs[0].first != 1) { + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + break; + default: + std::cerr << __FILE__ "(" << __LINE__ << "): " << neigh_len << std::endl; + abort(); + } + }} + + + {dccrg::Dccrg grid; grid + .set_initial_length({1, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(1) + .set_load_balancing_method("RANDOM") + .initialize(comm) + .balance_load(); + grid.refine_completely(1); + grid.stop_refining(); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 3) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } + } + grid.balance_load(); + for (const auto& cell: grid.all_cells()) { + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (neighs.size() != 3) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } + }} + + {dccrg::Dccrg grid; grid + .set_initial_length({3, 1, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(1) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 0); + grid.pin(3, 1); + } + grid.balance_load(); + grid.refine_completely(1); + grid.stop_refining(); + if (grid.get_comm_size() > 1) { + grid.pin(7, 1); + } + grid.balance_load(); + for (const auto& cell: grid.all_cells()) { + if (cell.id != 7) { + continue; + } + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (grid.get_rank() == 0) { + if ( + grid.get_comm_size() > 1 + and neigh_len <= 1 + and neighs.size() != 3 + ) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } else if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } + } + }} + + {dccrg::Dccrg grid; grid + .set_initial_length({1, 3, 1}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(1) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 0); + grid.pin(3, 1); + } + grid.balance_load(); + grid.refine_completely(1); + grid.stop_refining(); + if (grid.get_comm_size() > 1) { + grid.pin(10, 1); + } + grid.balance_load(); + for (const auto& cell: grid.all_cells()) { + if (cell.id != 10) { + continue; + } + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (grid.get_rank() == 0) { + if ( + grid.get_comm_size() > 1 + and neigh_len <= 1 + and neighs.size() != 3 + ) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } else if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } + } + }} + + {dccrg::Dccrg grid; grid + .set_initial_length({1, 1, 3}) + .set_neighborhood_length(neigh_len) + .set_maximum_refinement_level(1) + .set_load_balancing_method("RANDOM") + .initialize(comm); + if (grid.get_comm_size() > 1) { + grid.pin(1, 0); + grid.pin(2, 0); + grid.pin(3, 1); + } + grid.balance_load(); + grid.refine_completely(1); + grid.stop_refining(); + if (grid.get_comm_size() > 1) { + grid.pin(16, 1); + } + grid.balance_load(); + for (const auto& cell: grid.all_cells()) { + if (cell.id != 16) { + continue; + } + const auto& neighs = grid.get_face_neighbors_of(cell.id); + if (grid.get_rank() == 0) { + if ( + grid.get_comm_size() > 1 + and neigh_len <= 1 + and neighs.size() != 3 + ) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } else if (neighs.size() != 4) { + std::cerr << __FILE__ "(" << __LINE__ << "): " + << neigh_len << ", " << cell.id << std::endl; + abort(); + } + } + }} + } + + MPI_Finalize(); + + return EXIT_SUCCESS; +}