-
Notifications
You must be signed in to change notification settings - Fork 155
LGR: rebuild Cartesian->compressed map after refinement, enable serial summary output, fix rank-asymmetric throw #7245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hnil
wants to merge
3
commits into
OPM:master
Choose a base branch
from
hnil:pr/lgr-serial-output-and-robustness
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−26
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| #ifndef OPM_CPGRID_VANGUARD_HPP | ||
| #define OPM_CPGRID_VANGUARD_HPP | ||
|
|
||
| #include <opm/common/ErrorMacros.hpp> | ||
| #include <opm/common/TimingMacros.hpp> | ||
|
|
||
| #include <opm/models/common/multiphasebaseproperties.hh> | ||
|
|
@@ -43,6 +44,8 @@ | |
| #include <tuple> | ||
| #include <vector> | ||
|
|
||
| #include <fmt/format.h> | ||
|
|
||
| namespace Opm { | ||
| template <class TypeTag> | ||
| class CpGridVanguard; | ||
|
|
@@ -118,14 +121,57 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag> | |
|
|
||
| int compressedIndexForInteriorLGR(const std::string& lgr_tag, const Connection& conn) const override | ||
| { | ||
| const std::array<int,3> lgr_ijk = {conn.getI(), conn.getJ(), conn.getK()}; | ||
| const auto& lgr_level = this->grid().getLgrNameToLevel().at(lgr_tag); | ||
| // Every rank registers every requested LGR name, with an empty level | ||
| // grid on ranks that hold no cell of the box (interior or overlap) -- | ||
| // the level structure is identical on all ranks. A name that fails to | ||
| // resolve is therefore a programming error, not a distribution effect, | ||
| // and must be fatal rather than silently skipped. | ||
| const auto& nameToLevel = this->grid().getLgrNameToLevel(); | ||
| const auto levelIt = nameToLevel.find(lgr_tag); | ||
| if (levelIt == nameToLevel.end()) { | ||
| OPM_THROW(std::logic_error, | ||
| fmt::format("Internal error: LGR '{}' is not known to the grid. " | ||
| "The level structure must be identical on all ranks.", | ||
| lgr_tag)); | ||
| } | ||
| const int lgr_level = levelIt->second; | ||
|
|
||
| if (ParentType::lgrMappers_.has_value() == false) { | ||
| ParentType::lgrMappers_.emplace(this->grid().mapLocalCartesianIndexSetsToLeafIndexSet()); | ||
| } | ||
|
|
||
| // An out-of-range Cartesian position within the level is likewise a | ||
| // bug (a COMPDATL record addressing outside its LGR box has already | ||
| // been validated at parse time), so it is fatal too. | ||
| const auto& lgr_dim = this->grid().currentData()[lgr_level]->logicalCartesianSize(); | ||
| const std::array<int,3> lgr_ijk = {conn.getI(), conn.getJ(), conn.getK()}; | ||
| if (lgr_ijk[0] < 0 || lgr_ijk[0] >= lgr_dim[0] || | ||
| lgr_ijk[1] < 0 || lgr_ijk[1] >= lgr_dim[1] || | ||
| lgr_ijk[2] < 0 || lgr_ijk[2] >= lgr_dim[2]) | ||
| { | ||
| OPM_THROW(std::logic_error, | ||
| fmt::format("Internal error: connection ({},{},{}) is outside " | ||
| "LGR '{}' with dimensions {}x{}x{}.", | ||
| lgr_ijk[0], lgr_ijk[1], lgr_ijk[2], lgr_tag, | ||
| lgr_dim[0], lgr_dim[1], lgr_dim[2])); | ||
| } | ||
|
Comment on lines
+147
to
+157
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See source code comment above. If something is supposed to be checked in opm-common during parsing, then should it really be checked here, again? Skip or make it an assertion. |
||
| const auto lgr_cartesian_index = (lgr_ijk[2]*lgr_dim[0]*lgr_dim[1]) + (lgr_ijk[1]*lgr_dim[0]) + (lgr_ijk[0]); | ||
| return ParentType::lgrMappers_.value()[lgr_level].at(lgr_cartesian_index); | ||
|
|
||
| // A cell that is absent from this rank's level mapper is the one | ||
| // legitimate miss: the box lives elsewhere and this rank's level grid | ||
| // is empty (or holds another part of it). Mirror | ||
| // compressedIndexForInterior and return -1; the global existence of | ||
| // every connection cell is checked collectively afterwards | ||
| // (checkAllConnectionsFound). Using .at() here threw | ||
| // std::out_of_range on such ranks -- asymmetrically, which deadlocked | ||
| // runs at higher rank counts where more ranks hold no part of the box. | ||
|
Comment on lines
+163
to
+167
|
||
| const auto& mapper = ParentType::lgrMappers_.value()[lgr_level]; | ||
| const auto it = mapper.find(lgr_cartesian_index); | ||
| if (it == mapper.end()) { | ||
| return -1; | ||
| } | ||
|
|
||
| return static_cast<int>(it->second); | ||
| } | ||
| /*! | ||
| * Checking consistency of simulator | ||
|
|
@@ -253,9 +299,7 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag> | |
| this->numJacobiBlocks(), this->enableEclOutput()); | ||
| #endif | ||
|
|
||
| this->updateGridView_(); | ||
| this->updateCartesianToCompressedMapping_(); | ||
| this->updateCellThickness_(); | ||
| this->updateDerivedGridState_(); | ||
|
|
||
| #if HAVE_MPI | ||
| this->distributeFieldProps_(this->eclState()); | ||
|
|
@@ -266,6 +310,22 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag> | |
| this->updateCellDepths_(); | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Recompute everything the vanguard derives from the grid. | ||
| * | ||
| * Needed after every change to the leaf grid -- load balancing and local | ||
| * refinement both renumber the leaf cells. Kept in one method so a | ||
| * future grid-changing step cannot miss one of the updates. Cell depths | ||
| * are not included: they need the distributed field properties, so each | ||
| * caller updates them once those are available. | ||
| */ | ||
| void updateDerivedGridState_() | ||
| { | ||
| this->updateGridView_(); | ||
| this->updateCartesianToCompressedMapping_(); | ||
| this->updateCellThickness_(); | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Add LGRs and update Leaf Grid View in the simulation grid. | ||
| */ | ||
|
|
@@ -277,9 +337,13 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag> | |
| OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view"); | ||
| this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_); | ||
|
|
||
| this->updateGridView_(); | ||
| // Refinement changed the leaf cell count and ordering, so the | ||
| // state derived at load-balance time -- in particular the | ||
| // (level-zero-only) Cartesian->compressed map used to resolve | ||
| // coarse well connections -- is stale and must be rebuilt before | ||
| // well connections are resolved. | ||
| this->updateDerivedGridState_(); | ||
| this->updateCellDepths_(); | ||
| this->updateCellThickness_(); | ||
|
|
||
| if (this->grid_->comm().size()>1) { | ||
| // Add LGRs and update the leaf grid view in the global (undistributed) simulation grid. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.