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 <sstream>
namespace Opm {
template <class TypeTag>
class EclCpGridVanguard;
@ -189,7 +191,10 @@ public:
//distribute the grid and switch to the distributed view.
{
const auto wells = this->schedule().getWellsatEnd();
auto& eclState = static_cast<ParallelEclipseState&>(this->eclState());
try
{
auto& eclState = dynamic_cast<ParallelEclipseState&>(this->eclState());
const EclipseGrid* eclGrid = nullptr;
if (grid_->comm().rank() == 0)
@ -201,6 +206,15 @@ public:
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();
cartesianIndexMapper_.reset();
@ -218,12 +232,24 @@ public:
#endif
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_();
#if HAVE_MPI
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
}