Use dynamic_cast to ParallelEclipseState and do error checking.

This commit is contained in:
Markus Blatt 2020-03-10 11:06:52 +01:00
parent 04311f6337
commit 400ca4230b

View File

@ -40,6 +40,8 @@
#include <dune/common/version.hh> #include <dune/common/version.hh>
#include <sstream>
namespace Opm { namespace Opm {
template <class TypeTag> template <class TypeTag>
class EclCpGridVanguard; class EclCpGridVanguard;
@ -189,17 +191,29 @@ public:
//distribute the grid and switch to the distributed view. //distribute the grid and switch to the distributed view.
{ {
const auto wells = this->schedule().getWellsatEnd(); const auto wells = this->schedule().getWellsatEnd();
auto& eclState = static_cast<ParallelEclipseState&>(this->eclState());
const EclipseGrid* eclGrid = nullptr;
if (grid_->comm().rank() == 0) try
{ {
eclGrid = &this->eclState().getInputGrid(); auto& eclState = dynamic_cast<ParallelEclipseState&>(this->eclState());
} const EclipseGrid* eclGrid = nullptr;
PropsCentroidsDataHandle<Dune::CpGrid> handle(*grid_, eclState, eclGrid, this->centroids_, if (grid_->comm().rank() == 0)
cartesianIndexMapper()); {
defunctWellNames_ = std::get<1>(grid_->loadBalance(handle, edgeWeightsMethod, &wells, faceTrans.data())); eclGrid = &this->eclState().getInputGrid();
}
PropsCentroidsDataHandle<Dune::CpGrid> 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() <<")"<<std::flush;
OpmLog::error(message.str());
std::rethrow_exception(std::current_exception());
}
} }
grid_->switchToDistributedView(); grid_->switchToDistributedView();
@ -218,12 +232,24 @@ public:
#endif #endif
cartesianIndexMapper_.reset(new CartesianIndexMapper(*grid_)); cartesianIndexMapper_.reset(new CartesianIndexMapper(*grid_));
// reset cartesian index mapper for auto creation of field properties
static_cast<ParallelEclipseState&>(this->eclState()).resetCartesianMapper(cartesianIndexMapper_.get());
this->updateGridView_(); this->updateGridView_();
#if HAVE_MPI #if HAVE_MPI
if (mpiSize > 1) { if (mpiSize > 1) {
static_cast<ParallelEclipseState&>(this->eclState()).switchToDistributedProps(); try
{
auto& parallelEclState = dynamic_cast<ParallelEclipseState&>(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() <<")"<<std::flush;
OpmLog::error(message.str());
std::rethrow_exception(std::current_exception());
}
} }
#endif #endif
} }