From faea69fdb26464b1570e849119d76f6b1f6205ac Mon Sep 17 00:00:00 2001 From: Antonella Ritorto Date: Fri, 2 May 2025 14:06:21 +0200 Subject: [PATCH 1/2] Update cell depth and thickness in serial simulation for CpGrid with LGRs --- opm/models/utils/simulator.hh | 24 +++++++++++++----------- opm/simulators/flow/CpGridVanguard.hpp | 4 ++++ opm/simulators/flow/FlowBaseVanguard.hpp | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/opm/models/utils/simulator.hh b/opm/models/utils/simulator.hh index 1975500c12..12dc7b63e5 100644 --- a/opm/models/utils/simulator.hh +++ b/opm/models/utils/simulator.hh @@ -129,17 +129,6 @@ public: OPM_END_PARALLEL_TRY_CATCH("Allocating the simulation vanguard failed: ", comm); } - // Only relevant for CpGrid - if (verbose_) { - std::cout << "Adding LGRs, if any\n" << std::flush; - } - - { - OPM_BEGIN_PARALLEL_TRY_CATCH(); - vanguard_->addLgrs(); - OPM_END_PARALLEL_TRY_CATCH("Adding LGRs to the simulation vanguard failed: ", comm); - } - if (verbose_) { std::cout << "Distributing the vanguard's data\n" << std::flush; } @@ -150,6 +139,19 @@ public: OPM_END_PARALLEL_TRY_CATCH("Could not distribute the vanguard data: ", comm); } + // Only relevant for CpGrid + if (verbose_) { + std::cout << "Adding LGRs, if any, in serial run\n" << std::flush; + } + + { + if ( comm.size() == 1 ) { // serial run + OPM_BEGIN_PARALLEL_TRY_CATCH(); + vanguard_->addLgrs(); + OPM_END_PARALLEL_TRY_CATCH("Adding LGRs to the simulation vanguard in serial run failed: ", comm); + } + } + if (verbose_) { std::cout << "Allocating the model\n" << std::flush; } diff --git a/opm/simulators/flow/CpGridVanguard.hpp b/opm/simulators/flow/CpGridVanguard.hpp index 22beeaca18..8769e7b9b1 100644 --- a/opm/simulators/flow/CpGridVanguard.hpp +++ b/opm/simulators/flow/CpGridVanguard.hpp @@ -258,6 +258,10 @@ public: if (const auto& lgrs = this->eclState().getLgrs(); lgrs.size() > 0) { OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view"); this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_); + + this->updateGridView_(); + this->updateCellDepths_(); + this->updateCellThickness_(); } } diff --git a/opm/simulators/flow/FlowBaseVanguard.hpp b/opm/simulators/flow/FlowBaseVanguard.hpp index 2339e19442..7951f2f184 100644 --- a/opm/simulators/flow/FlowBaseVanguard.hpp +++ b/opm/simulators/flow/FlowBaseVanguard.hpp @@ -362,9 +362,9 @@ protected: cellCenterDepth_[elemIdx] = cellCenterDepth(element); if (!num_aqu_cells.empty()) { - const unsigned int global_index = cartesianIndex(elemIdx); - const auto search = num_aqu_cells.find(global_index); - if (search != num_aqu_cells.end()) { + const unsigned int global_index = cartesianIndex(elemIdx); + const auto search = num_aqu_cells.find(global_index); + if (search != num_aqu_cells.end()) { // updating the cell depth using aquifer cell depth cellCenterDepth_[elemIdx] = search->second->depth; } From bdfafbd5cdc15307eee790f3e6a765d68929a365 Mon Sep 17 00:00:00 2001 From: Antonella Ritorto Date: Wed, 7 May 2025 16:50:31 +0200 Subject: [PATCH 2/2] Move the if-serial run into CpGridVanguard::addLgrs(), warn if parallel --- opm/models/utils/simulator.hh | 10 ++++------ opm/simulators/flow/CpGridVanguard.hpp | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/opm/models/utils/simulator.hh b/opm/models/utils/simulator.hh index 12dc7b63e5..c6353c5f51 100644 --- a/opm/models/utils/simulator.hh +++ b/opm/models/utils/simulator.hh @@ -139,17 +139,15 @@ public: OPM_END_PARALLEL_TRY_CATCH("Could not distribute the vanguard data: ", comm); } - // Only relevant for CpGrid + // Only relevant for CpGrid and serial runs. if (verbose_) { std::cout << "Adding LGRs, if any, in serial run\n" << std::flush; } { - if ( comm.size() == 1 ) { // serial run - OPM_BEGIN_PARALLEL_TRY_CATCH(); - vanguard_->addLgrs(); - OPM_END_PARALLEL_TRY_CATCH("Adding LGRs to the simulation vanguard in serial run failed: ", comm); - } + OPM_BEGIN_PARALLEL_TRY_CATCH(); + vanguard_->addLgrs(); + OPM_END_PARALLEL_TRY_CATCH("Adding LGRs to the simulation vanguard in serial run failed: ", comm); } if (verbose_) { diff --git a/opm/simulators/flow/CpGridVanguard.hpp b/opm/simulators/flow/CpGridVanguard.hpp index 8769e7b9b1..daf0e7d118 100644 --- a/opm/simulators/flow/CpGridVanguard.hpp +++ b/opm/simulators/flow/CpGridVanguard.hpp @@ -255,7 +255,7 @@ public: // Check if input file contains Lgrs. // // If there are lgrs, create the grid with them, and update the leaf grid view. - if (const auto& lgrs = this->eclState().getLgrs(); lgrs.size() > 0) { + if (const auto& lgrs = this->eclState().getLgrs(); (lgrs.size() > 0) && (this->grid_->comm().size() == 1)) { OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view"); this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_); @@ -263,6 +263,9 @@ public: this->updateCellDepths_(); this->updateCellThickness_(); } + else { + Opm::OpmLog::warning("Adding LGRs in parallel run is not supported yet.\n"); + } } unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {