From c6d3994722681f19f438989f36553069ce1321c5 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 15 Jul 2014 13:15:34 +0200 Subject: [PATCH] EclipseWriter: make it not crash if no wells are present --- opm/core/io/eclipse/EclipseWriter.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index a51b8eef..de5ea6e8 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -682,16 +682,24 @@ protected: { // convert m^3/s of injected fluid to m^3/d of produced fluid const double convFactor = Opm::unit::convert::to(1., Opm::unit::day); - const double value = sign_ * wellState.wellRates()[index_] * convFactor; + double value = 0; + if (wellState.wellRates().size() > 0) { + assert(int(wellState.wellRates().size()) > index_); + value = sign_ * wellState.wellRates()[index_] * convFactor; + } return value; } double bhp(const WellState& wellstate) { - // Note that 'index_' is used here even though it is meant - // to give a (well,phase) pair. - const int num_phases = wellstate.wellRates().size() / wellstate.bhp().size(); - return wellstate.bhp()[index_/num_phases]; + if (wellstate.bhp().size() > 0) { + // Note that 'index_' is used here even though it is meant + // to give a (well,phase) pair. + const int num_phases = wellstate.wellRates().size() / wellstate.bhp().size(); + + return wellstate.bhp()[index_/num_phases]; + } + return 0.0; } };