BlackoilModelNldd.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
3 Copyright 2014, 2015 Dr. Blatt - HPC-Simulation-Software & Services
4 Copyright 2014, 2015 Statoil ASA.
5 Copyright 2015 NTNU
6 Copyright 2015, 2016, 2017 IRIS AS
7
8 This file is part of the Open Porous Media project (OPM).
9
10 OPM is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 OPM is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with OPM. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#ifndef OPM_BLACKOILMODEL_NLDD_HEADER_INCLUDED
25#define OPM_BLACKOILMODEL_NLDD_HEADER_INCLUDED
26
27#include <dune/common/timer.hh>
28
29#include <opm/grid/common/SubGridPart.hpp>
30
32
39
41
42#if COMPILE_GPU_BRIDGE
44#else
46#endif
48
52
54
56
57#include <fmt/format.h>
58
59#include <algorithm>
60#include <array>
61#include <cassert>
62#include <cmath>
63#include <cstddef>
64#include <filesystem>
65#include <memory>
66#include <numeric>
67#include <set>
68#include <sstream>
69#include <string>
70#include <type_traits>
71#include <utility>
72#include <vector>
73
74namespace Opm {
75
76template<class TypeTag> class BlackoilModel;
77
79template <class TypeTag>
81{
82public:
90
95
96 static constexpr int numEq = Indices::numEq;
97
103 : model_(model)
104 , wellModel_(model.wellModel())
105 , rank_(model_.simulator().vanguard().grid().comm().rank())
106 {
107 // Create partitions.
108 const auto& [partition_vector_initial, num_domains_initial] = this->partitionCells();
109
110 int num_domains = num_domains_initial;
111 std::vector<int> partition_vector = partition_vector_initial;
112
113 // Fix-up for an extreme case: Interior cells who do not have any on-rank
114 // neighbours. Move all such cells into a single domain on this rank,
115 // and mark the domain for skipping. For what it's worth, we've seen this
116 // case occur in practice when testing on field cases.
117 bool isolated_cells = false;
118 for (auto& domainId : partition_vector) {
119 if (domainId < 0) {
120 domainId = num_domains;
121 isolated_cells = true;
122 }
123 }
124 if (isolated_cells) {
125 num_domains++;
126 }
127
128 // Set nldd handler in main well model
129 model.wellModel().setNlddAdapter(&wellModel_);
130
131 // Scan through partitioning to get correct size for each.
132 std::vector<int> sizes(num_domains, 0);
133 for (const auto& p : partition_vector) {
134 ++sizes[p];
135 }
136
137 // Set up correctly sized vectors of entity seeds and of indices for each partition.
138 using EntitySeed = typename Grid::template Codim<0>::EntitySeed;
139 std::vector<std::vector<EntitySeed>> seeds(num_domains);
140 std::vector<std::vector<int>> partitions(num_domains);
141 for (int domain = 0; domain < num_domains; ++domain) {
142 seeds[domain].resize(sizes[domain]);
143 partitions[domain].resize(sizes[domain]);
144 }
145
146 // Iterate through grid once, setting the seeds of all partitions.
147 // Note: owned cells only!
148 const auto& grid = model_.simulator().vanguard().grid();
149
150 std::vector<int> count(num_domains, 0);
151 const auto& gridView = grid.leafGridView();
152 const auto beg = gridView.template begin<0, Dune::Interior_Partition>();
153 const auto end = gridView.template end<0, Dune::Interior_Partition>();
154 int cell = 0;
155 for (auto it = beg; it != end; ++it, ++cell) {
156 const int p = partition_vector[cell];
157 seeds[p][count[p]] = it->seed();
158 partitions[p][count[p]] = cell;
159 ++count[p];
160 }
161 assert(count == sizes);
162
163 // Create the domains.
164 for (int index = 0; index < num_domains; ++index) {
165 std::vector<bool> interior(partition_vector.size(), false);
166 for (int ix : partitions[index]) {
167 interior[ix] = true;
168 }
169
170 Dune::SubGridPart<Grid> view{grid, std::move(seeds[index])};
171
172 // Mark the last domain for skipping if it contains isolated cells
173 const bool skip = isolated_cells && (index == num_domains - 1);
174 this->domains_.emplace_back(index,
175 std::move(partitions[index]),
176 std::move(interior),
177 std::move(view),
178 skip);
179 }
180
181 // Initialize storage for previous mobilities in a single flat vector
182 const auto numCells = grid.size(0);
183 previousMobilities_.resize(numCells * FluidSystem::numActivePhases(), 0.0);
184 for (const auto& domain : domains_) {
185 updateMobilities(domain);
186 }
187
188 // Initialize domain_needs_solving_ to true for all domains
189 domain_needs_solving_.resize(num_domains, true);
190
191 // Set up container for the local system matrices.
192 domain_matrices_.resize(num_domains);
193
194 // Set up container for the local linear solvers.
195 for (int index = 0; index < num_domains; ++index) {
196 // TODO: The ISTLSolver constructor will make
197 // parallel structures appropriate for the full grid
198 // only. This must be addressed before going parallel.
199 const auto& eclState = model_.simulator().vanguard().eclState();
201 loc_param.is_nldd_local_solver_ = true;
202 loc_param.init(eclState.getSimulationConfig().useCPR());
203 // Override solver type with umfpack if small domain.
204 if (domains_[index].cells.size() < 200) {
205 loc_param.linsolver_ = "umfpack";
206 }
207 loc_param.linear_solver_print_json_definition_ = false;
208 const bool force_serial = true;
209 domain_linsolvers_.emplace_back(model_.simulator(), loc_param, force_serial);
210 domain_linsolvers_.back().setDomainIndex(index);
211 }
212
213 assert(int(domains_.size()) == num_domains);
214
215 domain_reports_accumulated_.resize(num_domains);
216
217 // Print domain distribution summary
219 partition_vector,
220 domains_,
221 local_reports_accumulated_,
222 domain_reports_accumulated_,
223 grid,
224 wellModel_.numLocalWellsEnd());
225 }
226
229 {
230 // Setup domain->well mapping.
231 wellModel_.setupDomains(domains_);
232 }
233
235 template <class NonlinearSolverType>
237 const SimulatorTimerInterface& timer,
238 NonlinearSolverType& nonlinear_solver)
239 {
240 // ----------- Set up reports and timer -----------
242
243 if (iteration < model_.param().nldd_num_initial_newton_iter_) {
244 report = model_.nonlinearIterationNewton(iteration,
245 timer,
246 nonlinear_solver);
247 return report;
248 }
249
250 model_.initialLinearization(report, iteration, nonlinear_solver.minIter(), nonlinear_solver.maxIter(), timer);
251
252 if (report.converged) {
253 return report;
254 }
255
256 // ----------- If not converged, do an NLDD iteration -----------
257 Dune::Timer localSolveTimer;
258 Dune::Timer detailTimer;
259 localSolveTimer.start();
260 detailTimer.start();
261 auto& solution = model_.simulator().model().solution(0);
262 auto initial_solution = solution;
263 auto locally_solved = initial_solution;
264
265 // ----------- Decide on an ordering for the domains -----------
266 const auto domain_order = this->getSubdomainOrder();
267 local_reports_accumulated_.success.pre_post_time += detailTimer.stop();
268
269 // ----------- Solve each domain separately -----------
270 DeferredLogger logger;
271 std::vector<SimulatorReportSingle> domain_reports(domains_.size());
272 for (const int domain_index : domain_order) {
273 const auto& domain = domains_[domain_index];
274 SimulatorReportSingle local_report;
275 detailTimer.reset();
276 detailTimer.start();
277
278 domain_needs_solving_[domain_index] = checkIfSubdomainNeedsSolving(domain, iteration);
279
280 updateMobilities(domain);
281
282 if (domain.skip || !domain_needs_solving_[domain_index]) {
283 local_report.skipped_domains = true;
284 local_report.converged = true;
285 domain_reports[domain.index] = local_report;
286 continue;
287 }
288 try {
289 switch (model_.param().local_solve_approach_) {
291 solveDomainJacobi(solution, locally_solved, local_report, logger,
292 iteration, timer, domain);
293 break;
294 default:
296 solveDomainGaussSeidel(solution, locally_solved, local_report, logger,
297 iteration, timer, domain);
298 break;
299 }
300 }
301 catch (...) {
302 // Something went wrong during local solves.
303 local_report.converged = false;
304 }
305 // This should have updated the global matrix to be
306 // dR_i/du_j evaluated at new local solutions for
307 // i == j, at old solution for i != j.
308 if (!local_report.converged) {
309 // TODO: more proper treatment, including in parallel.
310 logger.debug(fmt::format("Convergence failure in domain {} on rank {}." , domain.index, rank_));
311 }
312 local_report.solver_time += detailTimer.stop();
313 domain_reports[domain.index] = local_report;
314 }
315 detailTimer.reset();
316 detailTimer.start();
317 // Communicate and log all messages.
318 auto global_logger = gatherDeferredLogger(logger, model_.simulator().vanguard().grid().comm());
319 global_logger.logMessages();
320
321 // Accumulate local solve data.
322 // Putting the counts in a single array to avoid multiple
323 // comm.sum() calls. Keeping the named vars for readability.
324 std::array<int, 5> counts{ 0, 0, 0, static_cast<int>(domain_reports.size()), 0 };
325 int& num_converged = counts[0];
326 int& num_converged_already = counts[1];
327 int& num_local_newtons = counts[2];
328 int& num_domains = counts[3];
329 int& num_skipped = counts[4];
330 {
331 auto step_newtons = 0;
332 const auto dr_size = domain_reports.size();
333 for (auto i = 0*dr_size; i < dr_size; ++i) {
334 // Reset the needsSolving flag for the next iteration
335 domain_needs_solving_[i] = false;
336 const auto& dr = domain_reports[i];
337 if (dr.converged) {
338 ++num_converged;
339 if (dr.total_newton_iterations == 0) {
340 ++num_converged_already;
341 }
342 else {
343 // If we needed to solve the domain, we also solve in next iteration
344 domain_needs_solving_[i] = true;
345 }
346 }
347 if (dr.skipped_domains) {
348 ++num_skipped;
349 }
350 step_newtons += dr.total_newton_iterations;
351 // Accumulate local reports per domain
352 domain_reports_accumulated_[i] += dr;
353 // Accumulate local reports per rank
354 local_reports_accumulated_ += dr;
355 }
356 num_local_newtons = step_newtons;
357 }
358
359 if (model_.param().local_solve_approach_ == DomainSolveApproach::Jacobi) {
360 solution = locally_solved;
361 model_.simulator().model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
362 }
363
364#if HAVE_MPI
365 // Communicate solutions:
366 // With multiple processes, this process' overlap (i.e. not
367 // owned) cells' solution values have been modified by local
368 // solves in the owning processes, and remain unchanged
369 // here. We must therefore receive the updated solution on the
370 // overlap cells and update their intensive quantities before
371 // we move on.
372 const auto& comm = model_.simulator().vanguard().grid().comm();
373 if (comm.size() > 1) {
374 const auto* ccomm = model_.simulator().model().newtonMethod().linearSolver().comm();
375
376 // Copy numerical values from primary vars.
377 ccomm->copyOwnerToAll(solution, solution);
378
379 // Copy flags from primary vars.
380 const std::size_t num = solution.size();
381 Dune::BlockVector<std::size_t> allmeanings(num);
382 for (std::size_t ii = 0; ii < num; ++ii) {
383 allmeanings[ii] = PVUtil::pack(solution[ii]);
384 }
385 ccomm->copyOwnerToAll(allmeanings, allmeanings);
386 for (std::size_t ii = 0; ii < num; ++ii) {
387 PVUtil::unPack(solution[ii], allmeanings[ii]);
388 }
389
390 // Update intensive quantities for our overlap values.
391 model_.simulator().model().invalidateAndUpdateIntensiveQuantitiesOverlap(/*timeIdx=*/0);
392
393 // Make total counts of domains converged.
394 comm.sum(counts.data(), counts.size());
395 }
396#endif // HAVE_MPI
397
398 const bool is_iorank = this->rank_ == 0;
399 if (is_iorank) {
400 OpmLog::debug(fmt::format("Local solves finished. Converged for {}/{} domains. {} domains were skipped. {} domains did no work. {} total local Newton iterations.\n",
401 num_converged, num_domains, num_skipped, num_converged_already, num_local_newtons));
402 }
403 auto total_local_solve_time = localSolveTimer.stop();
404 report.local_solve_time += total_local_solve_time;
405 local_reports_accumulated_.success.total_time += total_local_solve_time;
406 local_reports_accumulated_.success.pre_post_time += detailTimer.stop();
407
408 // Finish with a Newton step.
409 // Note that the "iteration + 100" is a simple way to avoid entering
410 // "if (iteration == 0)" and similar blocks, and also makes it a little
411 // easier to spot the iteration residuals in the DBG file. A more sophisticated
412 // approach can be done later.
413 auto rep = model_.nonlinearIterationNewton(iteration + 100, timer, nonlinear_solver);
414 report += rep;
415 if (rep.converged) {
416 report.converged = true;
417 }
418 return report;
419 }
420
423 {
424 return local_reports_accumulated_;
425 }
426
428 const std::vector<SimulatorReport>& domainAccumulatedReports() const
429 {
430 // Update the number of wells for each domain that has been added to the well model at this point
431 // this is a mutable operation that updates the well counts in the domain reports.
432 const auto dr_size = domain_reports_accumulated_.size();
433 // Reset well counts before updating
434 for (auto i = 0*dr_size; i < dr_size; ++i) {
435 domain_reports_accumulated_[i].success.num_wells = 0;
436 }
437 // Update the number of wells for each domain
438 for (const auto& [wname, domain] : wellModel_.well_domain()) {
439 domain_reports_accumulated_[domain].success.num_wells++;
440 }
441 return domain_reports_accumulated_;
442 }
443
446 void writePartitions(const std::filesystem::path& odir) const
447 {
448 const auto& grid = this->model_.simulator().vanguard().grid();
449 const auto& elementMapper = this->model_.simulator().model().elementMapper();
450 const auto& cartMapper = this->model_.simulator().vanguard().cartesianIndexMapper();
451
453 odir,
454 domains_,
455 grid,
456 elementMapper,
457 cartMapper);
458 }
459
461 void writeNonlinearIterationsPerCell(const std::filesystem::path& odir) const
462 {
463 const auto& grid = this->model_.simulator().vanguard().grid();
464 const auto& elementMapper = this->model_.simulator().model().elementMapper();
465 const auto& cartMapper = this->model_.simulator().vanguard().cartesianIndexMapper();
466
468 odir,
469 domains_,
470 domain_reports_accumulated_,
471 grid,
472 elementMapper,
473 cartMapper);
474 }
475
476private:
479 solveDomain(const Domain& domain,
480 const SimulatorTimerInterface& timer,
481 SimulatorReportSingle& local_report,
482 DeferredLogger& logger,
483 [[maybe_unused]] const int global_iteration,
484 const bool initial_assembly_required)
485 {
486 auto& modelSimulator = model_.simulator();
487 Dune::Timer detailTimer;
488
489 modelSimulator.model().newtonMethod().setIterationIndex(0);
490
491 // When called, if assembly has already been performed
492 // with the initial values, we only need to check
493 // for local convergence. Otherwise, we must do a local
494 // assembly.
495 int iter = 0;
496 if (initial_assembly_required) {
497 detailTimer.start();
498 modelSimulator.model().newtonMethod().setIterationIndex(iter);
499 // TODO: we should have a beginIterationLocal function()
500 // only handling the well model for now
501 wellModel_.assemble(modelSimulator.model().newtonMethod().numIterations(),
502 modelSimulator.timeStepSize(),
503 domain);
504 const double tt0 = detailTimer.stop();
505 local_report.assemble_time += tt0;
506 local_report.assemble_time_well += tt0;
507 detailTimer.reset();
508 detailTimer.start();
509 // Assemble reservoir locally.
510 this->assembleReservoirDomain(domain);
511 local_report.assemble_time += detailTimer.stop();
512 local_report.total_linearizations += 1;
513 }
514 detailTimer.reset();
515 detailTimer.start();
516 std::vector<Scalar> resnorms;
517 auto convreport = this->getDomainConvergence(domain, timer, 0, logger, resnorms);
518 local_report.update_time += detailTimer.stop();
519 if (convreport.converged()) {
520 // TODO: set more info, timing etc.
521 local_report.converged = true;
522 return convreport;
523 }
524
525 // We have already assembled for the first iteration,
526 // but not done the Schur complement for the wells yet.
527 detailTimer.reset();
528 detailTimer.start();
529 model_.wellModel().linearizeDomain(domain,
530 modelSimulator.model().linearizer().jacobian(),
531 modelSimulator.model().linearizer().residual());
532 const double tt1 = detailTimer.stop();
533 local_report.assemble_time += tt1;
534 local_report.assemble_time_well += tt1;
535
536 // Local Newton loop.
537 const int max_iter = model_.param().max_local_solve_iterations_;
538 const auto& grid = modelSimulator.vanguard().grid();
539 double damping_factor = 1.0;
540 std::vector<std::vector<Scalar>> convergence_history;
541 convergence_history.reserve(20);
542 convergence_history.push_back(resnorms);
543 do {
544 // Solve local linear system.
545 // Note that x has full size, we expect it to be nonzero only for in-domain cells.
546 const int nc = grid.size(0);
547 BVector x(nc);
548 detailTimer.reset();
549 detailTimer.start();
550 this->solveJacobianSystemDomain(domain, x);
551 model_.wellModel().postSolveDomain(x, domain);
552 if (damping_factor != 1.0) {
553 x *= damping_factor;
554 }
555 local_report.linear_solve_time += detailTimer.stop();
556 local_report.linear_solve_setup_time += model_.linearSolveSetupTime();
557 local_report.total_linear_iterations = model_.linearIterationsLastSolve();
558
559 // Update local solution. // TODO: x is still full size, should we optimize it?
560 detailTimer.reset();
561 detailTimer.start();
562 this->updateDomainSolution(domain, x);
563 local_report.update_time += detailTimer.stop();
564
565 // Assemble well and reservoir.
566 detailTimer.reset();
567 detailTimer.start();
568 ++iter;
569 modelSimulator.model().newtonMethod().setIterationIndex(iter);
570 // TODO: we should have a beginIterationLocal function()
571 // only handling the well model for now
572 // Assemble reservoir locally.
573 wellModel_.assemble(modelSimulator.model().newtonMethod().numIterations(),
574 modelSimulator.timeStepSize(),
575 domain);
576 const double tt3 = detailTimer.stop();
577 local_report.assemble_time += tt3;
578 local_report.assemble_time_well += tt3;
579 detailTimer.reset();
580 detailTimer.start();
581 this->assembleReservoirDomain(domain);
582 local_report.assemble_time += detailTimer.stop();
583
584 // Check for local convergence.
585 detailTimer.reset();
586 detailTimer.start();
587 resnorms.clear();
588 convreport = this->getDomainConvergence(domain, timer, iter, logger, resnorms);
589 convergence_history.push_back(resnorms);
590 local_report.update_time += detailTimer.stop();
591
592 // apply the Schur complement of the well model to the
593 // reservoir linearized equations
594 detailTimer.reset();
595 detailTimer.start();
596 model_.wellModel().linearizeDomain(domain,
597 modelSimulator.model().linearizer().jacobian(),
598 modelSimulator.model().linearizer().residual());
599 const double tt2 = detailTimer.stop();
600 local_report.assemble_time += tt2;
601 local_report.assemble_time_well += tt2;
602
603 // Check if we should dampen. Only do so if wells are converged.
604 if (!convreport.converged() && !convreport.wellFailed()) {
605 bool oscillate = false;
606 bool stagnate = false;
607 const auto num_residuals = convergence_history.front().size();
608 detail::detectOscillations(convergence_history, iter, num_residuals,
609 Scalar{0.2}, 1, oscillate, stagnate);
610 if (oscillate) {
611 damping_factor *= 0.85;
612 logger.debug(fmt::format("| Damping factor is now {}", damping_factor));
613 }
614 }
615 } while (!convreport.converged() && iter <= max_iter);
616
617 modelSimulator.problem().endIteration();
618
619 local_report.converged = convreport.converged();
620 local_report.total_newton_iterations = iter;
621 local_report.total_linearizations += iter;
622 // TODO: set more info, timing etc.
623 return convreport;
624 }
625
627 void assembleReservoirDomain(const Domain& domain)
628 {
629 OPM_TIMEBLOCK(assembleReservoirDomain);
630 // -------- Mass balance equations --------
631 model_.simulator().model().linearizer().linearizeDomain(domain);
632 }
633
635 void solveJacobianSystemDomain(const Domain& domain, BVector& global_x)
636 {
637 const auto& modelSimulator = model_.simulator();
638
639 Dune::Timer perfTimer;
640 perfTimer.start();
641
642 const Mat& main_matrix = modelSimulator.model().linearizer().jacobian().istlMatrix();
643 if (domain_matrices_[domain.index]) {
644 Details::copySubMatrix(main_matrix, domain.cells, *domain_matrices_[domain.index]);
645 } else {
646 domain_matrices_[domain.index] = std::make_unique<Mat>(Details::extractMatrix(main_matrix, domain.cells));
647 }
648 auto& jac = *domain_matrices_[domain.index];
649 auto res = Details::extractVector(modelSimulator.model().linearizer().residual(),
650 domain.cells);
651 auto x = res;
652
653 // set initial guess
654 global_x = 0.0;
655 x = 0.0;
656
657 auto& linsolver = domain_linsolvers_[domain.index];
658
659 linsolver.prepare(jac, res);
660 model_.linearSolveSetupTime() = perfTimer.stop();
661 linsolver.setResidual(res);
662 linsolver.solve(x);
663
664 Details::setGlobal(x, domain.cells, global_x);
665 }
666
668 void updateDomainSolution(const Domain& domain, const BVector& dx)
669 {
670 OPM_TIMEBLOCK(updateDomainSolution);
671 auto& simulator = model_.simulator();
672 auto& newtonMethod = simulator.model().newtonMethod();
673 SolutionVector& solution = simulator.model().solution(/*timeIdx=*/0);
674
675 newtonMethod.update_(/*nextSolution=*/solution,
676 /*curSolution=*/solution,
677 /*update=*/dx,
678 /*resid=*/dx,
679 domain.cells); // the update routines of the black
680 // oil model do not care about the
681 // residual
682
683 // if the solution is updated, the intensive quantities need to be recalculated
684 simulator.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain);
685 }
686
688 std::pair<Scalar, Scalar> localDomainConvergenceData(const Domain& domain,
689 std::vector<Scalar>& R_sum,
690 std::vector<Scalar>& maxCoeff,
691 std::vector<Scalar>& B_avg,
692 std::vector<int>& maxCoeffCell)
693 {
694 const auto& modelSimulator = model_.simulator();
695
696 Scalar pvSumLocal = 0.0;
697 Scalar numAquiferPvSumLocal = 0.0;
698 const auto& model = modelSimulator.model();
699 const auto& problem = modelSimulator.problem();
700
701 const auto& modelResid = modelSimulator.model().linearizer().residual();
702
703 ElementContext elemCtx(modelSimulator);
704 const auto& gridView = domain.view;
705 const auto& elemEndIt = gridView.template end</*codim=*/0>();
706 IsNumericalAquiferCell isNumericalAquiferCell(gridView.grid());
707
708 for (auto elemIt = gridView.template begin</*codim=*/0>();
709 elemIt != elemEndIt;
710 ++elemIt)
711 {
712 if (elemIt->partitionType() != Dune::InteriorEntity) {
713 continue;
714 }
715 const auto& elem = *elemIt;
716 elemCtx.updatePrimaryStencil(elem);
717 elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
718
719 const unsigned cell_idx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
720 const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
721 const auto& fs = intQuants.fluidState();
722
723 const auto pvValue = problem.referencePorosity(cell_idx, /*timeIdx=*/0) *
724 model.dofTotalVolume(cell_idx);
725 pvSumLocal += pvValue;
726
727 if (isNumericalAquiferCell(elem))
728 {
729 numAquiferPvSumLocal += pvValue;
730 }
731
732 model_.getMaxCoeff(cell_idx, intQuants, fs, modelResid, pvValue,
733 B_avg, R_sum, maxCoeff, maxCoeffCell);
734 }
735
736 // compute local average in terms of global number of elements
737 const int bSize = B_avg.size();
738 for ( int i = 0; i<bSize; ++i )
739 {
740 B_avg[ i ] /= Scalar(domain.cells.size());
741 }
742
743 return {pvSumLocal, numAquiferPvSumLocal};
744 }
745
746 ConvergenceReport getDomainReservoirConvergence(const double reportTime,
747 const double dt,
748 const int iteration,
749 const Domain& domain,
750 DeferredLogger& logger,
751 std::vector<Scalar>& B_avg,
752 std::vector<Scalar>& residual_norms)
753 {
754 using Vector = std::vector<Scalar>;
755
756 const int numComp = numEq;
757 Vector R_sum(numComp, 0.0 );
758 Vector maxCoeff(numComp, std::numeric_limits<Scalar>::lowest() );
759 std::vector<int> maxCoeffCell(numComp, -1);
760 const auto [ pvSum, numAquiferPvSum]
761 = this->localDomainConvergenceData(domain, R_sum, maxCoeff, B_avg, maxCoeffCell);
762
763 auto cnvErrorPvFraction = computeCnvErrorPvLocal(domain, B_avg, dt);
764 cnvErrorPvFraction /= (pvSum - numAquiferPvSum);
765
766 // Default value of relaxed_max_pv_fraction_ is 0.03 and min_strict_cnv_iter_ is 0.
767 // For each iteration, we need to determine whether to use the relaxed CNV tolerance.
768 // To disable the usage of relaxed CNV tolerance, you can set the relaxed_max_pv_fraction_ to be 0.
769 const bool use_relaxed_cnv = cnvErrorPvFraction < model_.param().relaxed_max_pv_fraction_ &&
770 iteration >= model_.param().min_strict_cnv_iter_;
771 // Tighter bound for local convergence should increase the
772 // likelyhood of: local convergence => global convergence
773 const Scalar tol_cnv = model_.param().local_tolerance_scaling_cnv_
774 * (use_relaxed_cnv ? model_.param().tolerance_cnv_relaxed_
775 : model_.param().tolerance_cnv_);
776
777 const bool use_relaxed_mb = iteration >= model_.param().min_strict_mb_iter_;
778 const Scalar tol_mb = model_.param().local_tolerance_scaling_mb_
779 * (use_relaxed_mb ? model_.param().tolerance_mb_relaxed_ : model_.param().tolerance_mb_);
780
781 // Finish computation
782 std::vector<Scalar> CNV(numComp);
783 std::vector<Scalar> mass_balance_residual(numComp);
784 for (int compIdx = 0; compIdx < numComp; ++compIdx )
785 {
786 CNV[compIdx] = B_avg[compIdx] * dt * maxCoeff[compIdx];
787 mass_balance_residual[compIdx] = std::abs(B_avg[compIdx]*R_sum[compIdx]) * dt / pvSum;
788 residual_norms.push_back(CNV[compIdx]);
789 }
790
791 // Create convergence report.
792 ConvergenceReport report{reportTime};
793 using CR = ConvergenceReport;
794 for (int compIdx = 0; compIdx < numComp; ++compIdx) {
795 Scalar res[2] = { mass_balance_residual[compIdx], CNV[compIdx] };
796 CR::ReservoirFailure::Type types[2] = { CR::ReservoirFailure::Type::MassBalance,
797 CR::ReservoirFailure::Type::Cnv };
798 Scalar tol[2] = { tol_mb, tol_cnv };
799 for (int ii : {0, 1}) {
800 if (std::isnan(res[ii])) {
801 report.setReservoirFailed({types[ii], CR::Severity::NotANumber, compIdx});
802 logger.debug("NaN residual for " + model_.compNames().name(compIdx) + " equation.");
803 } else if (res[ii] > model_.param().max_residual_allowed_) {
804 report.setReservoirFailed({types[ii], CR::Severity::TooLarge, compIdx});
805 logger.debug("Too large residual for " + model_.compNames().name(compIdx) + " equation.");
806 } else if (res[ii] < 0.0) {
807 report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
808 logger.debug("Negative residual for " + model_.compNames().name(compIdx) + " equation.");
809 } else if (res[ii] > tol[ii]) {
810 report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
811 }
812
813 report.setReservoirConvergenceMetric(types[ii], compIdx, res[ii], tol[ii]);
814 }
815 }
816
817 // Output of residuals. If converged at initial state, log nothing.
818 const bool converged_at_initial_state = (report.converged() && iteration == 0);
819 if (!converged_at_initial_state) {
820 if (iteration == 0) {
821 // Log header.
822 std::string msg = fmt::format("Domain {} on rank {}, size {}, containing cell {}\n| Iter",
823 domain.index, this->rank_, domain.cells.size(), domain.cells[0]);
824 for (int compIdx = 0; compIdx < numComp; ++compIdx) {
825 msg += " MB(";
826 msg += model_.compNames().name(compIdx)[0];
827 msg += ") ";
828 }
829 for (int compIdx = 0; compIdx < numComp; ++compIdx) {
830 msg += " CNV(";
831 msg += model_.compNames().name(compIdx)[0];
832 msg += ") ";
833 }
834 logger.debug(msg);
835 }
836 // Log convergence data.
837 std::ostringstream ss;
838 ss << "| ";
839 const std::streamsize oprec = ss.precision(3);
840 const std::ios::fmtflags oflags = ss.setf(std::ios::scientific);
841 ss << std::setw(4) << iteration;
842 for (int compIdx = 0; compIdx < numComp; ++compIdx) {
843 ss << std::setw(11) << mass_balance_residual[compIdx];
844 }
845 for (int compIdx = 0; compIdx < numComp; ++compIdx) {
846 ss << std::setw(11) << CNV[compIdx];
847 }
848 ss.precision(oprec);
849 ss.flags(oflags);
850 logger.debug(ss.str());
851 }
852
853 return report;
854 }
855
856 ConvergenceReport getDomainConvergence(const Domain& domain,
857 const SimulatorTimerInterface& timer,
858 const int iteration,
859 DeferredLogger& logger,
860 std::vector<Scalar>& residual_norms)
861 {
862 OPM_TIMEBLOCK(getDomainConvergence);
863 std::vector<Scalar> B_avg(numEq, 0.0);
864 auto report = this->getDomainReservoirConvergence(timer.simulationTimeElapsed(),
865 timer.currentStepLength(),
866 iteration,
867 domain,
868 logger,
869 B_avg,
870 residual_norms);
871 report += wellModel_.getWellConvergence(domain, B_avg, logger);
872 return report;
873 }
874
876 std::vector<int> getSubdomainOrder()
877 {
878 const auto& modelSimulator = model_.simulator();
879 const auto& solution = modelSimulator.model().solution(0);
880
881 std::vector<int> domain_order(domains_.size());
882 std::iota(domain_order.begin(), domain_order.end(), 0);
883
884 if (model_.param().local_solve_approach_ == DomainSolveApproach::Jacobi) {
885 // Do nothing, 0..n-1 order is fine.
886 return domain_order;
887 } else if (model_.param().local_solve_approach_ == DomainSolveApproach::GaussSeidel) {
888 // Calculate the measure used to order the domains.
889 std::vector<Scalar> measure_per_domain(domains_.size());
890 switch (model_.param().local_domains_ordering_) {
892 // Use average pressures to order domains.
893 for (const auto& domain : domains_) {
894 const Scalar press_sum =
895 std::accumulate(domain.cells.begin(), domain.cells.end(), Scalar{0},
896 [&solution](const auto acc, const auto c)
897 { return acc + solution[c][Indices::pressureSwitchIdx]; });
898 const Scalar avgpress = press_sum / domain.cells.size();
899 measure_per_domain[domain.index] = avgpress;
900 }
901 break;
902 }
904 // Use max pressures to order domains.
905 for (const auto& domain : domains_) {
906 measure_per_domain[domain.index] =
907 std::accumulate(domain.cells.begin(), domain.cells.end(), Scalar{0},
908 [&solution](const auto acc, const auto c)
909 { return std::max(acc, solution[c][Indices::pressureSwitchIdx]); });
910 }
911 break;
912 }
914 // Use maximum residual to order domains.
915 const auto& residual = modelSimulator.model().linearizer().residual();
916 const int num_vars = residual[0].size();
917 for (const auto& domain : domains_) {
918 Scalar maxres = 0.0;
919 for (const int c : domain.cells) {
920 for (int ii = 0; ii < num_vars; ++ii) {
921 maxres = std::max(maxres, std::fabs(residual[c][ii]));
922 }
923 }
924 measure_per_domain[domain.index] = maxres;
925 }
926 break;
927 }
928 } // end of switch (model_.param().local_domains_ordering_)
929
930 // Sort by largest measure, keeping index order if equal.
931 const auto& m = measure_per_domain;
932 std::stable_sort(domain_order.begin(), domain_order.end(),
933 [&m](const int i1, const int i2){ return m[i1] > m[i2]; });
934 return domain_order;
935 } else {
936 throw std::logic_error("Domain solve approach must be Jacobi or Gauss-Seidel");
937 }
938 }
939
940 template<class GlobalEqVector>
941 void solveDomainJacobi(GlobalEqVector& solution,
942 GlobalEqVector& locally_solved,
943 SimulatorReportSingle& local_report,
944 DeferredLogger& logger,
945 const int iteration,
946 const SimulatorTimerInterface& timer,
947 const Domain& domain)
948 {
949 auto initial_local_well_primary_vars = wellModel_.getPrimaryVarsDomain(domain.index);
950 auto initial_local_solution = Details::extractVector(solution, domain.cells);
951 auto convrep = solveDomain(domain, timer, local_report, logger, iteration, false);
952 if (local_report.converged) {
953 auto local_solution = Details::extractVector(solution, domain.cells);
954 Details::setGlobal(local_solution, domain.cells, locally_solved);
955 Details::setGlobal(initial_local_solution, domain.cells, solution);
956 model_.simulator().model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain);
957 } else {
958 wellModel_.setPrimaryVarsDomain(domain.index, initial_local_well_primary_vars);
959 Details::setGlobal(initial_local_solution, domain.cells, solution);
960 model_.simulator().model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain);
961 }
962 }
963
964 template<class GlobalEqVector>
965 void solveDomainGaussSeidel(GlobalEqVector& solution,
966 GlobalEqVector& locally_solved,
967 SimulatorReportSingle& local_report,
968 DeferredLogger& logger,
969 const int iteration,
970 const SimulatorTimerInterface& timer,
971 const Domain& domain)
972 {
973 auto initial_local_well_primary_vars = wellModel_.getPrimaryVarsDomain(domain.index);
974 auto initial_local_solution = Details::extractVector(solution, domain.cells);
975 auto convrep = solveDomain(domain, timer, local_report, logger, iteration, true);
976 if (!local_report.converged) {
977 // We look at the detailed convergence report to evaluate
978 // if we should accept the unconverged solution.
979 // We do not accept a solution if the wells are unconverged.
980 if (!convrep.wellFailed()) {
981 // Calculare the sums of the mb and cnv failures.
982 Scalar mb_sum = 0.0;
983 Scalar cnv_sum = 0.0;
984 for (const auto& rc : convrep.reservoirConvergence()) {
986 mb_sum += rc.value();
987 } else if (rc.type() == ConvergenceReport::ReservoirFailure::Type::Cnv) {
988 cnv_sum += rc.value();
989 }
990 }
991 // If not too high, we overrule the convergence failure.
992 const Scalar acceptable_local_mb_sum = 1e-3;
993 const Scalar acceptable_local_cnv_sum = 1.0;
994 if (mb_sum < acceptable_local_mb_sum && cnv_sum < acceptable_local_cnv_sum) {
995 local_report.converged = true;
996 local_report.accepted_unconverged_domains += 1;
997 logger.debug(fmt::format("Accepting solution in unconverged domain {} on rank {}.", domain.index, rank_));
998 logger.debug(fmt::format("Value of mb_sum: {} cnv_sum: {}", mb_sum, cnv_sum));
999 } else {
1000 logger.debug("Unconverged local solution.");
1001 }
1002 } else {
1003 logger.debug("Unconverged local solution with well convergence failures:");
1004 for (const auto& wf : convrep.wellFailures()) {
1005 logger.debug(to_string(wf));
1006 }
1007 }
1008 }
1009 if (local_report.converged) {
1010 local_report.converged_domains += 1;
1011 auto local_solution = Details::extractVector(solution, domain.cells);
1012 Details::setGlobal(local_solution, domain.cells, locally_solved);
1013 } else {
1014 local_report.unconverged_domains += 1;
1015 wellModel_.setPrimaryVarsDomain(domain.index, initial_local_well_primary_vars);
1016 Details::setGlobal(initial_local_solution, domain.cells, solution);
1017 model_.simulator().model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain);
1018 }
1019 }
1020
1021 Scalar computeCnvErrorPvLocal(const Domain& domain,
1022 const std::vector<Scalar>& B_avg, double dt) const
1023 {
1024 Scalar errorPV{};
1025 const auto& simulator = model_.simulator();
1026 const auto& model = simulator.model();
1027 const auto& problem = simulator.problem();
1028 const auto& residual = simulator.model().linearizer().residual();
1029
1030 for (const int cell_idx : domain.cells) {
1031 const Scalar pvValue = problem.referencePorosity(cell_idx, /*timeIdx=*/0) *
1032 model.dofTotalVolume(cell_idx);
1033 const auto& cellResidual = residual[cell_idx];
1034 bool cnvViolated = false;
1035
1036 for (unsigned eqIdx = 0; eqIdx < cellResidual.size(); ++eqIdx) {
1037 using std::fabs;
1038 Scalar CNV = cellResidual[eqIdx] * dt * B_avg[eqIdx] / pvValue;
1039 cnvViolated = cnvViolated || (fabs(CNV) > model_.param().tolerance_cnv_);
1040 }
1041
1042 if (cnvViolated) {
1043 errorPV += pvValue;
1044 }
1045 }
1046 return errorPV;
1047 }
1048
1049 decltype(auto) partitionCells() const
1050 {
1051 const auto& grid = this->model_.simulator().vanguard().grid();
1052
1053 using GridView = std::remove_cv_t<std::remove_reference_t<
1054 decltype(grid.leafGridView())>>;
1055
1056 using Element = std::remove_cv_t<std::remove_reference_t<
1057 typename GridView::template Codim<0>::Entity>>;
1058
1059 const auto& param = this->model_.param();
1060
1061 auto zoltan_ctrl = ZoltanPartitioningControl<Element>{};
1062
1063 zoltan_ctrl.domain_imbalance = param.local_domains_partition_imbalance_;
1064
1065 zoltan_ctrl.index =
1066 [elementMapper = &this->model_.simulator().model().elementMapper()]
1067 (const Element& element)
1068 {
1069 return elementMapper->index(element);
1070 };
1071
1072 zoltan_ctrl.local_to_global =
1073 [cartMapper = &this->model_.simulator().vanguard().cartesianIndexMapper()]
1074 (const int elemIdx)
1075 {
1076 return cartMapper->cartesianIndex(elemIdx);
1077 };
1078
1079 // Forming the list of wells is expensive, so do this only if needed.
1080 const auto need_wells = param.local_domains_partition_method_ == "zoltan";
1081
1082 const auto wells = need_wells
1083 ? this->model_.simulator().vanguard().schedule().getWellsatEnd()
1084 : std::vector<Well>{};
1085
1086 const auto& possibleFutureConnectionSet = need_wells
1087 ? this->model_.simulator().vanguard().schedule().getPossibleFutureConnections()
1088 : std::unordered_map<std::string, std::set<int>> {};
1089
1090 // If defaulted parameter for number of domains, choose a reasonable default.
1091 constexpr int default_cells_per_domain = 1000;
1092 const int num_domains = (param.num_local_domains_ > 0)
1093 ? param.num_local_domains_
1094 : detail::countGlobalCells(grid) / default_cells_per_domain;
1095 return ::Opm::partitionCells(param.local_domains_partition_method_,
1096 num_domains, grid.leafGridView(), wells,
1097 possibleFutureConnectionSet, zoltan_ctrl,
1098 param.local_domains_partition_well_neighbor_levels_);
1099 }
1100
1101 void updateMobilities(const Domain& domain)
1102 {
1103 if (domain.skip || model_.param().nldd_relative_mobility_change_tol_ == 0.0) {
1104 return;
1105 }
1106 const auto numActivePhases = FluidSystem::numActivePhases();
1107 for (const auto globalDofIdx : domain.cells) {
1108 const auto& intQuants = model_.simulator().model().intensiveQuantities(globalDofIdx, /* time_idx = */ 0);
1109
1110 for (unsigned activePhaseIdx = 0; activePhaseIdx < numActivePhases; ++activePhaseIdx) {
1111 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
1112 const auto mobIdx = globalDofIdx * numActivePhases + activePhaseIdx;
1113 previousMobilities_[mobIdx] = getValue(intQuants.mobility(phaseIdx));
1114 }
1115 }
1116 }
1117
1118 bool checkIfSubdomainNeedsSolving(const Domain& domain, const int iteration)
1119 {
1120 if (domain.skip) {
1121 return false;
1122 }
1123
1124 // If we domain was marked as needing solving in previous iterations,
1125 // we do not need to check again
1126 if (domain_needs_solving_[domain.index]) {
1127 return true;
1128 }
1129
1130 // If we do not check for mobility changes, we need to solve the domain
1131 if (model_.param().nldd_relative_mobility_change_tol_ == 0.0) {
1132 return true;
1133 }
1134
1135 // Skip mobility check on first iteration
1136 if (iteration == 0) {
1137 return true;
1138 }
1139
1140 return checkSubdomainChangeRelative(domain);
1141 }
1142
1143 bool checkSubdomainChangeRelative(const Domain& domain)
1144 {
1145 const auto numActivePhases = FluidSystem::numActivePhases();
1146
1147 // Check mobility changes for all cells in the domain
1148 for (const auto globalDofIdx : domain.cells) {
1149 const auto& intQuants = model_.simulator().model().intensiveQuantities(globalDofIdx, /* time_idx = */ 0);
1150
1151 // Calculate average previous mobility for normalization
1152 Scalar cellMob = 0.0;
1153 for (unsigned activePhaseIdx = 0; activePhaseIdx < numActivePhases; ++activePhaseIdx) {
1154 const auto mobIdx = globalDofIdx * numActivePhases + activePhaseIdx;
1155 cellMob += previousMobilities_[mobIdx] / numActivePhases;
1156 }
1157
1158 // Check relative changes for each phase
1159 for (unsigned activePhaseIdx = 0; activePhaseIdx < numActivePhases; ++activePhaseIdx) {
1160 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
1161 const auto mobIdx = globalDofIdx * numActivePhases + activePhaseIdx;
1162 const auto mobility = getValue(intQuants.mobility(phaseIdx));
1163 const auto relDiff = std::abs(mobility - previousMobilities_[mobIdx]) / cellMob;
1164 if (relDiff > model_.param().nldd_relative_mobility_change_tol_) {
1165 return true;
1166 }
1167 }
1168 }
1169 return false;
1170 }
1171
1172 BlackoilModel<TypeTag>& model_;
1173 BlackoilWellModelNldd<TypeTag> wellModel_;
1174 std::vector<Domain> domains_;
1175 std::vector<std::unique_ptr<Mat>> domain_matrices_;
1176 std::vector<ISTLSolverType> domain_linsolvers_;
1177 SimulatorReport local_reports_accumulated_;
1178 // mutable because we need to update the number of wells for each domain in getDomainAccumulatedReports()
1179 mutable std::vector<SimulatorReport> domain_reports_accumulated_;
1180 int rank_ = 0;
1181 // Store previous mobilities to check for changes - single flat vector indexed by (globalCellIdx * numActivePhases + activePhaseIdx)
1182 std::vector<Scalar> previousMobilities_;
1183 // Flag indicating if this domain should be solved in the next iteration
1184 std::vector<bool> domain_needs_solving_;
1185};
1186
1187} // namespace Opm
1188
1189#endif // OPM_BLACKOILMODEL_NLDD_HEADER_INCLUDED
A NLDD implementation for three-phase black oil.
Definition: BlackoilModelNldd.hpp:81
GetPropType< TypeTag, Properties::SolutionVector > SolutionVector
Definition: BlackoilModelNldd.hpp:89
GetPropType< TypeTag, Properties::Indices > Indices
Definition: BlackoilModelNldd.hpp:86
const std::vector< SimulatorReport > & domainAccumulatedReports() const
return the statistics of local solves accumulated for each domain on this rank
Definition: BlackoilModelNldd.hpp:428
void writePartitions(const std::filesystem::path &odir) const
Definition: BlackoilModelNldd.hpp:446
BlackoilModelNldd(BlackoilModel< TypeTag > &model)
The constructor sets up the subdomains.
Definition: BlackoilModelNldd.hpp:102
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilModelNldd.hpp:87
typename BlackoilModel< TypeTag >::Mat Mat
Definition: BlackoilModelNldd.hpp:94
const SimulatorReport & localAccumulatedReports() const
return the statistics of local solves accumulated for this rank
Definition: BlackoilModelNldd.hpp:422
SimulatorReportSingle nonlinearIterationNldd(const int iteration, const SimulatorTimerInterface &timer, NonlinearSolverType &nonlinear_solver)
Do one non-linear NLDD iteration.
Definition: BlackoilModelNldd.hpp:236
SubDomain< Grid > Domain
Definition: BlackoilModelNldd.hpp:92
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilModelNldd.hpp:83
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: BlackoilModelNldd.hpp:84
void prepareStep()
Called before starting a time step.
Definition: BlackoilModelNldd.hpp:228
void writeNonlinearIterationsPerCell(const std::filesystem::path &odir) const
Write the number of nonlinear iterations per cell to a file in ResInsight compatible format.
Definition: BlackoilModelNldd.hpp:461
static constexpr int numEq
Definition: BlackoilModelNldd.hpp:96
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilModelNldd.hpp:85
typename BlackoilModel< TypeTag >::BVector BVector
Definition: BlackoilModelNldd.hpp:91
Definition: BlackoilModel.hpp:62
BlackoilWellModel< TypeTag > & wellModel()
return the StandardWells object
Definition: BlackoilModel.hpp:278
typename SparseMatrixAdapter::IstlMatrix Mat
Definition: BlackoilModel.hpp:107
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilModel.hpp:108
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
void debug(const std::string &tag, const std::string &message)
Definition: ISTLSolver.hpp:147
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:34
Vector extractVector(const Vector &x, const std::vector< int > &indices)
Definition: extractMatrix.hpp:104
void copySubMatrix(const Matrix &A, const std::vector< int > &indices, Matrix &B)
Definition: extractMatrix.hpp:35
void setGlobal(const Vector &x, const std::vector< int > &indices, Vector &global_x)
Definition: extractMatrix.hpp:115
Matrix extractMatrix(const Matrix &m, const std::vector< int > &indices)
Definition: extractMatrix.hpp:47
void unPack(PV &privar, const std::size_t meanings)
Definition: priVarsPacking.hpp:41
std::size_t pack(const PV &privar)
Definition: priVarsPacking.hpp:31
std::size_t countGlobalCells(const Grid &grid)
Get the number of cells of a global grid.
Definition: countGlobalCells.hpp:82
void detectOscillations(const std::vector< std::vector< Scalar > > &residualHistory, const int it, const int numPhases, const Scalar relaxRelTol, const int minimumOscillatingPhases, bool &oscillate, bool &stagnate)
Detect oscillation or stagnation in a given residual history.
Definition: blackoilboundaryratevector.hh:39
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Parallel::Communication communicator)
Create a global log combining local logs.
std::pair< std::vector< int >, int > partitionCells(const std::string &method, const int num_local_domains, const GridView &grid_view, const std::vector< Well > &wells, const std::unordered_map< std::string, std::set< int > > &possibleFutureConnections, const ZoltanPartitioningControl< Element > &zoltan_ctrl, const int num_neighbor_levels)
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
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
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
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
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
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParameters.hpp:177
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition: FlowLinearSolverParameters.hpp:95
bool is_nldd_local_solver_
Definition: FlowLinearSolverParameters.hpp:109
void init(bool cprRequestedInDataFile)
bool linear_solver_print_json_definition_
Definition: FlowLinearSolverParameters.hpp:111
std::string linsolver_
Definition: FlowLinearSolverParameters.hpp:110
Definition: SimulatorReport.hpp:122
SimulatorReportSingle success
Definition: SimulatorReport.hpp:123
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34
double linear_solve_time
Definition: SimulatorReport.hpp:43
int skipped_domains
Definition: SimulatorReport.hpp:71
double assemble_time
Definition: SimulatorReport.hpp:39
double assemble_time_well
Definition: SimulatorReport.hpp:41
double solver_time
Definition: SimulatorReport.hpp:38
bool converged
Definition: SimulatorReport.hpp:55
double pre_post_time
Definition: SimulatorReport.hpp:40
double total_time
Definition: SimulatorReport.hpp:37
double linear_solve_setup_time
Definition: SimulatorReport.hpp:42
unsigned int total_newton_iterations
Definition: SimulatorReport.hpp:50
double update_time
Definition: SimulatorReport.hpp:45
double local_solve_time
Definition: SimulatorReport.hpp:44
unsigned int total_linearizations
Definition: SimulatorReport.hpp:49
unsigned int total_linear_iterations
Definition: SimulatorReport.hpp:51
Definition: SubDomain.hpp:85