20#ifndef OPM_NLDD_REPORTING_HEADER_INCLUDED
21#define OPM_NLDD_REPORTING_HEADER_INCLUDED
23#include <dune/grid/common/gridenums.hh>
24#include <dune/grid/common/partitionset.hh>
38#include <fmt/format.h>
75 std::string_view header,
76 const std::vector<int>& data);
90 const bool output_cout,
103template <
class Gr
id,
class Domain,
class ElementMapper,
class CartMapper>
105 const std::filesystem::path& odir,
106 const std::vector<Domain>& domains,
107 const std::vector<SimulatorReport>& domain_reports,
109 const ElementMapper& elementMapper,
110 const CartMapper& cartMapper)
112 const auto& dims = cartMapper.cartesianDimensions();
113 const auto total_size = dims[0] * dims[1] * dims[2];
114 const auto& comm = grid.comm();
115 const int rank = comm.rank();
118 std::vector<int> cell_iterations(grid.size(0), 0);
121 const auto ds = domains.size();
122 for (
auto domain_idx = 0*ds; domain_idx < ds; ++domain_idx) {
123 const auto& domain = domains[domain_idx];
124 const auto& report = domain_reports[domain_idx];
125 const int iterations = report.success.total_newton_iterations +
126 report.failure.total_newton_iterations;
128 for (
const int cell_idx : domain.cells) {
129 cell_iterations[cell_idx] = iterations;
134 auto full_iterations = std::vector<int>(total_size, 0);
137 const auto& gridView = grid.leafGridView();
138 for (
const auto& cell : elements(gridView, Dune::Partitions::interior)) {
139 const int cell_idx = elementMapper.index(cell);
140 const int cart_idx = cartMapper.cartesianIndex(cell_idx);
141 full_iterations[cart_idx] = cell_iterations[cell_idx];
145 comm.max(full_iterations.data(), full_iterations.size());
150 "NLDD_ITER", full_iterations);
163template <
class Gr
id,
class Domain,
class ElementMapper,
class CartMapper>
165 const std::filesystem::path& odir,
166 const std::vector<Domain>& domains,
168 const ElementMapper& elementMapper,
169 const CartMapper& cartMapper)
171 const auto& dims = cartMapper.cartesianDimensions();
172 const auto total_size = dims[0] * dims[1] * dims[2];
173 const auto& comm = grid.comm();
174 const int rank = comm.rank();
179 auto full_partition = std::vector<int>(total_size, -1);
183 for (
const auto& cell : elements(grid.leafGridView(), Dune::Partitions::interior)) {
184 full_partition[cartMapper.cartesianIndex(elementMapper.index(cell))] = partition_vector[i++];
188 comm.max(full_partition.data(), full_partition.size());
193 "NLDD_DOM", full_partition);
196 const auto nDigit = 1 +
static_cast<int>(std::floor(std::log10(comm.size())));
197 auto partition_fname = odir / fmt::format(
"{1:0>{0}}", nDigit, rank);
198 std::ofstream pfile { partition_fname };
201 for (
const auto& cell : elements(grid.leafGridView(), Dune::Partitions::interior)) {
203 << cartMapper.cartesianIndex(elementMapper.index(cell)) <<
' '
204 << partition_vector[cell_index++] <<
'\n';
218template <
class Gr
id,
class Domain>
220 const std::vector<int>& partition_vector,
221 const std::vector<Domain>& domains,
223 std::vector<SimulatorReport>& domain_reports_accumulated,
227 const auto& gridView = grid.leafGridView();
228 const auto& comm = grid.comm();
229 const int rank = comm.rank();
231 const int num_domains = domains.size();
232 const int owned_cells = partition_vector.size();
235 int overlap_cells = std::count_if(elements(gridView).begin(), elements(gridView).end(),
236 [](
const auto& cell) {
return cell.partitionType() == Dune::OverlapEntity; });
245 const auto dr_size = domain_reports_accumulated.size();
246 for (
auto i = 0*dr_size; i < dr_size; ++i) {
247 auto& domain_report = domain_reports_accumulated[i];
248 domain_report.success.num_domains = 1;
249 domain_report.success.num_overlap_cells = 0;
250 domain_report.success.num_owned_cells = domains[i].cells.size();
256 comm.gather(&owned_cells, info.
all_owned.data(), 1, 0);
257 comm.gather(&overlap_cells, info.
all_overlap.data(), 1, 0);
258 comm.gather(&num_wells, info.
all_wells.data(), 1, 0);
259 comm.gather(&num_domains, info.
all_domains.data(), 1, 0);
274template <
class Gr
id,
class Domain>
276 const std::vector<Domain>& domains,
279 const auto& comm = grid.comm();
280 const int rank = comm.rank();
282 auto numD = std::vector<int>(comm.size() + 1, 0);
283 numD[rank + 1] =
static_cast<int>(domains.size());
284 comm.sum(numD.data(), numD.size());
285 std::partial_sum(numD.begin(), numD.end(), numD.begin());
287 auto p = std::vector<int>(grid.size(0));
288 auto maxCellIdx = std::numeric_limits<int>::min();
291 for (
const auto& domain : domains) {
292 for (
const auto& cell : domain.cells) {
294 if (cell > maxCellIdx) {
302 p.erase(p.begin() + maxCellIdx + 1, p.end());
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
void printDistributionSummary(const DomainInfo &info)
void writeNlddFile(const std::string &file, std::string_view header, const std::vector< int > &data)
Definition: blackoilboundaryratevector.hh:39
void printDomainDistributionSummary(const std::vector< int > &partition_vector, const std::vector< Domain > &domains, SimulatorReport &local_reports_accumulated, std::vector< SimulatorReport > &domain_reports_accumulated, const Grid &grid, int num_wells)
Definition: NlddReporting.hpp:219
void reportNlddStatistics(const std::vector< SimulatorReport > &domain_reports, const SimulatorReport &local_report, const bool output_cout, const Parallel::Communication &comm)
std::vector< int > reconstitutePartitionVector(const std::vector< Domain > &domains, const Grid &grid)
Definition: NlddReporting.hpp:275
void writePartitions(const std::filesystem::path &odir, const std::vector< Domain > &domains, const Grid &grid, const ElementMapper &elementMapper, const CartMapper &cartMapper)
Definition: NlddReporting.hpp:164
void writeNonlinearIterationsPerCell(const std::filesystem::path &odir, const std::vector< Domain > &domains, const std::vector< SimulatorReport > &domain_reports, const Grid &grid, const ElementMapper &elementMapper, const CartMapper &cartMapper)
Definition: NlddReporting.hpp:104
Definition: SimulatorReport.hpp:122
SimulatorReportSingle success
Definition: SimulatorReport.hpp:123
int num_wells
Definition: SimulatorReport.hpp:65
int num_owned_cells
Definition: SimulatorReport.hpp:67
int num_overlap_cells
Definition: SimulatorReport.hpp:66
int num_domains
Definition: SimulatorReport.hpp:64
Definition: NlddReporting.hpp:48
std::vector< int > all_owned
All owned cells.
Definition: NlddReporting.hpp:49
DomainInfo(std::size_t size)
Definition: NlddReporting.hpp:54
std::vector< int > all_domains
All domains.
Definition: NlddReporting.hpp:52
std::vector< int > all_wells
All wells.
Definition: NlddReporting.hpp:51
std::vector< int > all_overlap
All overlap cells.
Definition: NlddReporting.hpp:50