From 400ca4230b792bdcbf74fab2355e220873539504 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Tue, 10 Mar 2020 11:06:52 +0100 Subject: [PATCH] Use dynamic_cast to ParallelEclipseState and do error checking. --- ebos/eclcpgridvanguard.hh | 48 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/ebos/eclcpgridvanguard.hh b/ebos/eclcpgridvanguard.hh index f23b7c981..80abf8176 100644 --- a/ebos/eclcpgridvanguard.hh +++ b/ebos/eclcpgridvanguard.hh @@ -40,6 +40,8 @@ #include +#include + namespace Opm { template class EclCpGridVanguard; @@ -189,17 +191,29 @@ public: //distribute the grid and switch to the distributed view. { const auto wells = this->schedule().getWellsatEnd(); - auto& eclState = static_cast(this->eclState()); - const EclipseGrid* eclGrid = nullptr; - if (grid_->comm().rank() == 0) + try { - eclGrid = &this->eclState().getInputGrid(); - } + auto& eclState = dynamic_cast(this->eclState()); + const EclipseGrid* eclGrid = nullptr; - PropsCentroidsDataHandle handle(*grid_, eclState, eclGrid, this->centroids_, - cartesianIndexMapper()); - defunctWellNames_ = std::get<1>(grid_->loadBalance(handle, edgeWeightsMethod, &wells, faceTrans.data())); + if (grid_->comm().rank() == 0) + { + eclGrid = &this->eclState().getInputGrid(); + } + + PropsCentroidsDataHandle handle(*grid_, eclState, eclGrid, this->centroids_, + cartesianIndexMapper()); + defunctWellNames_ = std::get<1>(grid_->loadBalance(handle, edgeWeightsMethod, &wells, faceTrans.data())); + } + catch(const std::bad_cast& e) + { + std::ostringstream message; + message << "Parallel simulator setup is incorrect as it does not use ParallelEclipseState (" + << e.what() <<")"<switchToDistributedView(); @@ -218,12 +232,24 @@ public: #endif cartesianIndexMapper_.reset(new CartesianIndexMapper(*grid_)); - // reset cartesian index mapper for auto creation of field properties - static_cast(this->eclState()).resetCartesianMapper(cartesianIndexMapper_.get()); this->updateGridView_(); #if HAVE_MPI if (mpiSize > 1) { - static_cast(this->eclState()).switchToDistributedProps(); + try + { + auto& parallelEclState = dynamic_cast(this->eclState()); + // reset cartesian index mapper for auto creation of field properties + parallelEclState.resetCartesianMapper(cartesianIndexMapper_.get()); + parallelEclState.switchToDistributedProps(); + } + catch(const std::bad_cast& e) + { + std::ostringstream message; + message << "Parallel simulator setup is incorrect as it does not use ParallelEclipseState (" + << e.what() <<")"<