From b95b342517263dd43f49545db6ae5936d0f9a784 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 29 Jun 2023 12:41:56 +0200 Subject: [PATCH] partitionCells: drop indent for namespace --- opm/simulators/flow/partitionCells.cpp | 211 ++++++++++++------------- opm/simulators/flow/partitionCells.hpp | 49 +++--- 2 files changed, 129 insertions(+), 131 deletions(-) diff --git a/opm/simulators/flow/partitionCells.cpp b/opm/simulators/flow/partitionCells.cpp index e4f5f1ea5..f3e2d71aa 100644 --- a/opm/simulators/flow/partitionCells.cpp +++ b/opm/simulators/flow/partitionCells.cpp @@ -44,140 +44,139 @@ namespace { - std::pair, int> - countDomains(std::vector partition_vector) - { - auto maxPos = std::max_element(partition_vector.begin(), - partition_vector.end()); +std::pair, int> +countDomains(std::vector partition_vector) +{ + auto maxPos = std::max_element(partition_vector.begin(), + partition_vector.end()); - const auto num_domains = (maxPos == partition_vector.end()) - ? 0 : *maxPos + 1; + const auto num_domains = (maxPos == partition_vector.end()) + ? 0 : *maxPos + 1; - return { std::move(partition_vector), num_domains }; - } + return { std::move(partition_vector), num_domains }; +} - template - struct HasZoltanPartitioning : public std::false_type {}; +template +struct HasZoltanPartitioning : public std::false_type {}; - template - struct HasZoltanPartitioning< - GridType, - std::void_t().zoltanPartitionWithoutScatter - (std::declval*>(), - std::declval(), - std::declval(), - std::declval()))> - > : public std::true_type {}; +template +struct HasZoltanPartitioning< + GridType, + std::void_t().zoltanPartitionWithoutScatter + (std::declval*>(), + std::declval(), + std::declval(), + std::declval()))> + > : public std::true_type {}; } // anonymous namespace namespace Opm { - template - std::pair, int> partitionCells(const Grid& grid, - const std::vector& wells, - const std::string& method, - const int num_local_domains, - const double partition_imbalance) - { - if (method == "zoltan") { - if constexpr (HasZoltanPartitioning::value) { - return partitionCellsZoltan(grid, wells, num_local_domains, partition_imbalance); - } else { - OPM_THROW(std::runtime_error, "Zoltan requested for local domain partitioning, " - "but is not available for the current grid type."); - } - } else if (method == "simple") { - const int num_cells = detail::countLocalInteriorCells(grid); - return partitionCellsSimple(num_cells, num_local_domains); - } else if (method.size() > 10 && method.substr(method.size() - 10, 10) == ".partition") { - // Method string ends with ".partition", interpret as filename for partitioning. - const int num_cells = detail::countLocalInteriorCells(grid); - return partitionCellsFromFile(method, num_cells); +template +std::pair, int> partitionCells(const Grid& grid, + const std::vector& wells, + const std::string& method, + const int num_local_domains, + const double partition_imbalance) +{ + if (method == "zoltan") { + if constexpr (HasZoltanPartitioning::value) { + return partitionCellsZoltan(grid, wells, num_local_domains, partition_imbalance); } else { - OPM_THROW(std::runtime_error, "Unknown local domain partitioning method requested: " + method); + OPM_THROW(std::runtime_error, "Zoltan requested for local domain partitioning, " + "but is not available for the current grid type."); } + } else if (method == "simple") { + const int num_cells = detail::countLocalInteriorCells(grid); + return partitionCellsSimple(num_cells, num_local_domains); + } else if (method.size() > 10 && method.substr(method.size() - 10, 10) == ".partition") { + // Method string ends with ".partition", interpret as filename for partitioning. + const int num_cells = detail::countLocalInteriorCells(grid); + return partitionCellsFromFile(method, num_cells); + } else { + OPM_THROW(std::runtime_error, "Unknown local domain partitioning method requested: " + method); + } +} + + +// Read from file, containing one number per cell. +std::pair, int> partitionCellsFromFile(const std::string& filename, const int num_cells) +{ + // Read file into single vector. + std::ifstream is(filename); + const std::vector cellpart{std::istream_iterator(is), std::istream_iterator()}; + if (cellpart.size() != size_t(num_cells)) { + auto msg = fmt::format("Partition file contains {} entries, but there are {} cells.", + cellpart.size(), num_cells); + throw std::runtime_error(msg); } + // Create and return the output domain vector. + const int num_domains = (*std::max_element(cellpart.begin(), cellpart.end())) + 1; + return { cellpart, num_domains }; +} - // Read from file, containing one number per cell. - std::pair, int> partitionCellsFromFile(const std::string& filename, const int num_cells) - { - // Read file into single vector. - std::ifstream is(filename); - const std::vector cellpart{std::istream_iterator(is), std::istream_iterator()}; - if (cellpart.size() != size_t(num_cells)) { - auto msg = fmt::format("Partition file contains {} entries, but there are {} cells.", - cellpart.size(), num_cells); - throw std::runtime_error(msg); - } - // Create and return the output domain vector. - const int num_domains = (*std::max_element(cellpart.begin(), cellpart.end())) + 1; - return { cellpart, num_domains }; +// Trivially simple partitioner +std::pair, int> partitionCellsSimple(const int num_cells, const int num_domains) +{ + // Build the partitions. + const int dom_sz = num_cells / num_domains; + std::vector bounds(num_domains + 1, dom_sz); + bounds[0] = 0; + for (int i = 0; i < num_cells % num_domains; ++i) { + ++bounds[i + 1]; } - - - // Trivially simple partitioner - std::pair, int> partitionCellsSimple(const int num_cells, const int num_domains) - { - // Build the partitions. - const int dom_sz = num_cells / num_domains; - std::vector bounds(num_domains + 1, dom_sz); - bounds[0] = 0; - for (int i = 0; i < num_cells % num_domains; ++i) { - ++bounds[i + 1]; - } - std::partial_sum(bounds.begin(), bounds.end(), bounds.begin()); - assert(bounds[num_domains] == num_cells); - std::vector part(num_cells); - for (int i = 0; i < num_domains; ++i) { - std::fill(part.begin() + bounds[i], part.begin() + bounds[i + 1], i); - } - return { part, num_domains }; + std::partial_sum(bounds.begin(), bounds.end(), bounds.begin()); + assert(bounds[num_domains] == num_cells); + std::vector part(num_cells); + for (int i = 0; i < num_domains; ++i) { + std::fill(part.begin() + bounds[i], part.begin() + bounds[i + 1], i); } + return { part, num_domains }; +} - template - std::pair, int> partitionCellsZoltan(const Grid& grid, - const std::vector& wells, - const int num_domains, - const double domain_imbalance) - { - auto partition_vector = grid.zoltanPartitionWithoutScatter - (&wells, nullptr, num_domains, domain_imbalance); +template +std::pair, int> partitionCellsZoltan(const Grid& grid, + const std::vector& wells, + const int num_domains, + const double domain_imbalance) +{ + auto partition_vector = grid.zoltanPartitionWithoutScatter + (&wells, nullptr, num_domains, domain_imbalance); - return countDomains(std::move(partition_vector)); - } + return countDomains(std::move(partition_vector)); +} - template std::pair,int> - partitionCells(const Dune::CpGrid&, - const std::vector&, - const std::string&, - const int, - const double); +template std::pair,int> +partitionCells(const Dune::CpGrid&, + const std::vector&, + const std::string&, + const int, + const double); - template std::pair,int> - partitionCells>(const Dune::PolyhedralGrid<3,3,double>&, - const std::vector&, - const std::string&, - const int, - const double); +template std::pair,int> +partitionCells>(const Dune::PolyhedralGrid<3,3,double>&, + const std::vector&, + const std::string&, + const int, + const double); #if HAVE_DUNE_ALUGRID #if HAVE_MPI - using ALUGrid3CN = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridMPIComm>; +using ALUGrid3CN = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridMPIComm>; #else - using ALUGrid3CN = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridNoComm>; +using ALUGrid3CN = Dune::ALUGrid<3, 3, Dune::cube, Dune::nonconforming, Dune::ALUGridNoComm>; #endif //HAVE_MPI - template std::pair,int> - partitionCells(const ALUGrid3CN&, - const std::vector&, - const std::string&, - const int, - const double); +template std::pair,int> +partitionCells(const ALUGrid3CN&, + const std::vector&, + const std::string&, + const int, + const double); #endif - } // namespace Opm diff --git a/opm/simulators/flow/partitionCells.hpp b/opm/simulators/flow/partitionCells.hpp index fd2e62880..5dfd9b84a 100644 --- a/opm/simulators/flow/partitionCells.hpp +++ b/opm/simulators/flow/partitionCells.hpp @@ -24,35 +24,34 @@ #include #include -namespace Opm -{ - class Well; +namespace Opm { - /// Partitions the grid using the specified method. - /// \return pair containing a partition vector (partition number for each cell), and the number of partitions. - template - std::pair, int> partitionCells(const Grid& grid, - const std::vector& wells, - const std::string& method, - const int num_local_domains, - const double partition_imbalance); +class Well; - /// Read a partitioning from file, assumed to contain one number per cell, its partition number. - /// \return pair containing a partition vector (partition number for each cell), and the number of partitions. - std::pair, int> partitionCellsFromFile(const std::string& filename, const int num_cells); +/// Partitions the grid using the specified method. +/// \return pair containing a partition vector (partition number for each cell), and the number of partitions. +template +std::pair, int> partitionCells(const Grid& grid, + const std::vector& wells, + const std::string& method, + const int num_local_domains, + const double partition_imbalance); - /// Trivially simple partitioner assigning partitions en bloc, consecutively by cell index. - /// \return pair containing a partition vector (partition number for each cell), and the number of partitions. - std::pair, int> partitionCellsSimple(const int num_cells, const int num_domains); +/// Read a partitioning from file, assumed to contain one number per cell, its partition number. +/// \return pair containing a partition vector (partition number for each cell), and the number of partitions. +std::pair, int> partitionCellsFromFile(const std::string& filename, const int num_cells); - /// Partitions the grid using the Zoltan graph partitioner. - /// \return pair containing a partition vector (partition number for each cell), and the number of partitions. - template - std::pair, int> partitionCellsZoltan(const Grid& grid, - const std::vector& wells, - const int num_domains, - const double domain_imbalance); +/// Trivially simple partitioner assigning partitions en bloc, consecutively by cell index. +/// \return pair containing a partition vector (partition number for each cell), and the number of partitions. +std::pair, int> partitionCellsSimple(const int num_cells, const int num_domains); + +/// Partitions the grid using the Zoltan graph partitioner. +/// \return pair containing a partition vector (partition number for each cell), and the number of partitions. +template +std::pair, int> partitionCellsZoltan(const Grid& grid, + const std::vector& wells, + const int num_domains, + const double domain_imbalance); } // namespace Opm - #endif // OPM_ASPINPARTITION_HEADER_INCLUDED