Merge pull request #931 from atgeirr/fix-deck-error

Do not assign to dereferenced null pointers.
This commit is contained in:
Atgeirr Flø Rasmussen 2016-11-18 11:59:40 +01:00 committed by GitHub
commit 54ad92ff40
7 changed files with 48 additions and 50 deletions

View File

@ -94,7 +94,6 @@ try
Parser parser; Parser parser;
std::shared_ptr< Deck > deck;
// bool check_well_controls = false; // bool check_well_controls = false;
// int max_well_control_iterations = 0; // int max_well_control_iterations = 0;
@ -102,8 +101,8 @@ try
if (use_deck) { if (use_deck) {
ParseContext parseContext; ParseContext parseContext;
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
*deck = parser.parseFile(deck_filename , parseContext); auto deck = parser.parseFile(deck_filename , parseContext);
eclipseState.reset(new EclipseState(*deck, parseContext)); eclipseState.reset(new EclipseState(deck, parseContext));
// Grid init // Grid init
grid.reset(new GridManager(eclipseState->getInputGrid())); grid.reset(new GridManager(eclipseState->getInputGrid()));
@ -111,18 +110,18 @@ try
const UnstructuredGrid& ug_grid = *(grid->c_grid()); const UnstructuredGrid& ug_grid = *(grid->c_grid());
state.reset( new BlackoilState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ) ,2)); state.reset( new BlackoilState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ) ,2));
// Rock and fluid init // Rock and fluid init
props.reset(new BlackoilPropertiesFromDeck(*deck, *eclipseState, ug_grid, param)); props.reset(new BlackoilPropertiesFromDeck(deck, *eclipseState, ug_grid, param));
// check_well_controls = param.getDefault("check_well_controls", false); // check_well_controls = param.getDefault("check_well_controls", false);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10); // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
// Rock compressibility. // Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState)); rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// Gravity. // Gravity.
gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity; gravity[2] = deck.hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
// Init state variables (saturation and pressure). // Init state variables (saturation and pressure).
if (param.has("init_saturation")) { if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state); initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else { } else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state); initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
} }
initBlackoilSurfvol(ug_grid, *props, *state); initBlackoilSurfvol(ug_grid, *props, *state);
} }
@ -240,7 +239,7 @@ try
int step = 0; int step = 0;
SimulatorTimer simtimer; SimulatorTimer simtimer;
// Use timer for last epoch to obtain total time. // Use timer for last epoch to obtain total time.
Opm::TimeMap timeMap(*deck); const auto& timeMap = eclipseState->getSchedule().getTimeMap();
simtimer.init(timeMap); simtimer.init(timeMap);
const double total_time = simtimer.totalTime(); const double total_time = simtimer.totalTime();
for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) { for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) {

View File

@ -101,7 +101,6 @@ try
bool use_deck = param.has("deck_filename"); bool use_deck = param.has("deck_filename");
std::shared_ptr< EclipseState > eclipseState; std::shared_ptr< EclipseState > eclipseState;
std::shared_ptr< Deck > deck;
std::unique_ptr<GridManager> grid; std::unique_ptr<GridManager> grid;
std::unique_ptr<IncompPropertiesInterface> props; std::unique_ptr<IncompPropertiesInterface> props;
std::unique_ptr<RockCompressibility> rock_comp; std::unique_ptr<RockCompressibility> rock_comp;
@ -112,28 +111,29 @@ try
if (use_deck) { if (use_deck) {
Parser parser; Parser parser;
ParseContext parseContext; ParseContext parseContext;
parseContext.update(ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN);
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
*deck = parser.parseFile(deck_filename , parseContext); auto deck = parser.parseFile(deck_filename , parseContext);
eclipseState.reset( new EclipseState(*deck, parseContext)); eclipseState.reset( new EclipseState(deck, parseContext));
// Grid init // Grid init
grid.reset(new GridManager(eclipseState->getInputGrid())); grid.reset(new GridManager(eclipseState->getInputGrid()));
{ {
const UnstructuredGrid& ug_grid = *(grid->c_grid()); const UnstructuredGrid& ug_grid = *(grid->c_grid());
// Rock and fluid init // Rock and fluid init
props.reset(new IncompPropertiesFromDeck(*deck, *eclipseState, ug_grid)); props.reset(new IncompPropertiesFromDeck(deck, *eclipseState, ug_grid));
state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ))); state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid )));
// Rock compressibility. // Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState)); rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// Gravity. // Gravity.
gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity; gravity[2] = deck.hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
// Init state variables (saturation and pressure). // Init state variables (saturation and pressure).
if (param.has("init_saturation")) { if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state); initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else { } else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state); initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
} }
} }
} else { } else {

View File

@ -101,7 +101,6 @@ try
// If we have a "deck_filename", grid and props will be read from that. // If we have a "deck_filename", grid and props will be read from that.
bool use_deck = param.has("deck_filename"); bool use_deck = param.has("deck_filename");
Opm::Parser parser; Opm::Parser parser;
std::shared_ptr< Opm::Deck > deck;
std::unique_ptr<GridManager> grid; std::unique_ptr<GridManager> grid;
std::unique_ptr<IncompPropertiesInterface> props; std::unique_ptr<IncompPropertiesInterface> props;
std::unique_ptr<RockCompressibility> rock_comp; std::unique_ptr<RockCompressibility> rock_comp;
@ -114,8 +113,8 @@ try
if (use_deck) { if (use_deck) {
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
Opm::ParseContext parseContext; Opm::ParseContext parseContext;
*deck = parser.parseFile(deck_filename, parseContext); auto deck = parser.parseFile(deck_filename, parseContext);
eclipseState.reset(new EclipseState(*deck , parseContext)); eclipseState.reset(new EclipseState(deck , parseContext));
// Grid init // Grid init
grid.reset(new GridManager(eclipseState->getInputGrid())); grid.reset(new GridManager(eclipseState->getInputGrid()));
@ -123,20 +122,20 @@ try
const UnstructuredGrid& ug_grid = *(grid->c_grid()); const UnstructuredGrid& ug_grid = *(grid->c_grid());
// Rock and fluid init // Rock and fluid init
props.reset(new IncompPropertiesFromDeck(*deck, *eclipseState, ug_grid)); props.reset(new IncompPropertiesFromDeck(deck, *eclipseState, ug_grid));
// check_well_controls = param.getDefault("check_well_controls", false); // check_well_controls = param.getDefault("check_well_controls", false);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10); // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ))); state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid )));
// Rock compressibility. // Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState)); rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// Gravity. // Gravity.
gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity; gravity[2] = deck.hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
// Init state variables (saturation and pressure). // Init state variables (saturation and pressure).
if (param.has("init_saturation")) { if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state); initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else { } else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state); initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
} }
} }
} else { } else {
@ -254,7 +253,7 @@ try
} else { } else {
// With a deck, we may have more report steps etc. // With a deck, we may have more report steps etc.
WellState well_state; WellState well_state;
Opm::TimeMap timeMap(*deck); const auto& timeMap = eclipseState->getSchedule().getTimeMap();
SimulatorTimer simtimer; SimulatorTimer simtimer;
for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) { for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) {
// Report on start of report step. // Report on start of report step.

View File

@ -87,7 +87,7 @@ try
// If we have a "deck_filename", grid and props will be read from that. // If we have a "deck_filename", grid and props will be read from that.
bool use_deck = param.has("deck_filename"); bool use_deck = param.has("deck_filename");
std::shared_ptr< Deck > deck; Deck deck;
boost::scoped_ptr<GridManager> grid; boost::scoped_ptr<GridManager> grid;
boost::scoped_ptr<IncompPropertiesInterface> props; boost::scoped_ptr<IncompPropertiesInterface> props;
boost::scoped_ptr<RockCompressibility> rock_comp; boost::scoped_ptr<RockCompressibility> rock_comp;
@ -101,32 +101,32 @@ try
std::string deck_filename = param.get<std::string>("deck_filename"); std::string deck_filename = param.get<std::string>("deck_filename");
Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }}); Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
Parser parser; Parser parser;
*deck = parser.parseFile(deck_filename , parseContext); deck = parser.parseFile(deck_filename , parseContext);
eclipseState.reset(new Opm::EclipseState(*deck , parseContext)); eclipseState.reset(new Opm::EclipseState(deck , parseContext));
// Grid init // Grid init
grid.reset(new GridManager(eclipseState->getInputGrid())); grid.reset(new GridManager(eclipseState->getInputGrid()));
{ {
const UnstructuredGrid& ug_grid = *(grid->c_grid()); const UnstructuredGrid& ug_grid = *(grid->c_grid());
// Rock and fluid init // Rock and fluid init
props.reset(new IncompPropertiesFromDeck(*deck, *eclipseState, ug_grid )); props.reset(new IncompPropertiesFromDeck(deck, *eclipseState, ug_grid ));
// check_well_controls = param.getDefault("check_well_controls", false); // check_well_controls = param.getDefault("check_well_controls", false);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10); // max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
state.reset( new PolymerState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 2)); state.reset( new PolymerState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 2));
// Rock compressibility. // Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState)); rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// Gravity. // Gravity.
gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity; gravity[2] = deck.hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
// Init state variables (saturation and pressure). // Init state variables (saturation and pressure).
if (param.has("init_saturation")) { if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state); initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else { } else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state); initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
} }
// Init polymer properties. // Init polymer properties.
poly_props.readFromDeck(*deck, *eclipseState); poly_props.readFromDeck(deck, *eclipseState);
} }
} else { } else {
// Grid init. // Grid init.
@ -299,12 +299,12 @@ try
WellState well_state; WellState well_state;
int step = 0; int step = 0;
TimeMap timeMap(*deck); const auto& timeMap = eclipseState->getSchedule().getTimeMap();
SimulatorTimer simtimer; SimulatorTimer simtimer;
simtimer.init(timeMap); simtimer.init(timeMap);
// Check for WPOLYMER presence in last epoch to decide // Check for WPOLYMER presence in last epoch to decide
// polymer injection control type. // polymer injection control type.
const bool use_wpolymer = deck->hasKeyword("WPOLYMER"); const bool use_wpolymer = deck.hasKeyword("WPOLYMER");
if (use_wpolymer) { if (use_wpolymer) {
if (param.has("poly_start_days")) { if (param.has("poly_start_days")) {
OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. " OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. "

View File

@ -151,12 +151,12 @@ try
Opm::OpmLog::addBackend( "COUNTER" , counterLog ); Opm::OpmLog::addBackend( "COUNTER" , counterLog );
} }
std::shared_ptr< Deck > deck; Deck deck;
std::shared_ptr<EclipseState> eclipseState; std::shared_ptr<EclipseState> eclipseState;
try { try {
*deck = parser.parseFile(deck_filename , parseContext); deck = parser.parseFile(deck_filename , parseContext);
Opm::checkDeck(*deck, parser); Opm::checkDeck(deck, parser);
eclipseState.reset(new Opm::EclipseState(*deck , parseContext)); eclipseState.reset(new Opm::EclipseState(deck , parseContext));
} }
catch (const std::invalid_argument& e) { catch (const std::invalid_argument& e) {
std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl; std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
@ -173,7 +173,7 @@ try
grid.reset(new GridManager(eclipseState->getInputGrid())); grid.reset(new GridManager(eclipseState->getInputGrid()));
} }
auto &cGrid = *grid->c_grid(); auto &cGrid = *grid->c_grid();
const PhaseUsage pu = Opm::phaseUsageFromDeck(*deck); const PhaseUsage pu = Opm::phaseUsageFromDeck(deck);
// Rock and fluid init // Rock and fluid init
@ -182,31 +182,31 @@ try
typedef BlackoilPropsAdFromDeck::MaterialLawManager MaterialLawManager; typedef BlackoilPropsAdFromDeck::MaterialLawManager MaterialLawManager;
auto materialLawManager = std::make_shared<MaterialLawManager>(); auto materialLawManager = std::make_shared<MaterialLawManager>();
materialLawManager->initFromDeck(*deck, *eclipseState, compressedToCartesianIdx); materialLawManager->initFromDeck(deck, *eclipseState, compressedToCartesianIdx);
props.reset(new BlackoilPropertiesFromDeck( *deck, *eclipseState, materialLawManager, props.reset(new BlackoilPropertiesFromDeck( deck, *eclipseState, materialLawManager,
Opm::UgGridHelpers::numCells(cGrid), Opm::UgGridHelpers::numCells(cGrid),
Opm::UgGridHelpers::globalCell(cGrid), Opm::UgGridHelpers::globalCell(cGrid),
Opm::UgGridHelpers::cartDims(cGrid), Opm::UgGridHelpers::cartDims(cGrid),
param)); param));
state.reset( new PolymerBlackoilState( Opm::UgGridHelpers::numCells(cGrid), Opm::UgGridHelpers::numFaces(cGrid), 2)); state.reset( new PolymerBlackoilState( Opm::UgGridHelpers::numCells(cGrid), Opm::UgGridHelpers::numFaces(cGrid), 2));
new_props.reset(new BlackoilPropsAdFromDeck(*deck, *eclipseState, materialLawManager, cGrid)); new_props.reset(new BlackoilPropsAdFromDeck(deck, *eclipseState, materialLawManager, cGrid));
PolymerProperties polymer_props(*deck, *eclipseState); PolymerProperties polymer_props(deck, *eclipseState);
PolymerPropsAd polymer_props_ad(polymer_props); PolymerPropsAd polymer_props_ad(polymer_props);
// Rock compressibility. // Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState)); rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// Gravity. // Gravity.
gravity[2] = deck->hasKeyword("NOGRAV") ? 0.0 : unit::gravity; gravity[2] = deck.hasKeyword("NOGRAV") ? 0.0 : unit::gravity;
// Init state variables (saturation and pressure). // Init state variables (saturation and pressure).
if (param.has("init_saturation")) { if (param.has("init_saturation")) {
initStateBasic(*grid->c_grid(), *props, param, gravity[2], *state); initStateBasic(*grid->c_grid(), *props, param, gravity[2], *state);
initBlackoilSurfvol(*grid->c_grid(), *props, *state); initBlackoilSurfvol(*grid->c_grid(), *props, *state);
} else { } else {
initStateFromDeck(*grid->c_grid(), *props, *deck, gravity[2], *state); initStateFromDeck(*grid->c_grid(), *props, deck, gravity[2], *state);
} }
bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0); bool use_gravity = (gravity[0] != 0.0 || gravity[1] != 0.0 || gravity[2] != 0.0);
@ -229,7 +229,7 @@ try
WellState well_state; WellState well_state;
// Check for WPOLYMER presence in last epoch to decide // Check for WPOLYMER presence in last epoch to decide
// polymer injection control type. // polymer injection control type.
const bool use_wpolymer = deck->hasKeyword("WPOLYMER"); const bool use_wpolymer = deck.hasKeyword("WPOLYMER");
if (use_wpolymer) { if (use_wpolymer) {
if (param.has("poly_start_days")) { if (param.has("poly_start_days")) {
OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. " OPM_MESSAGE("Warning: Using WPOLYMER to control injection since it was found in deck. "

View File

@ -109,7 +109,7 @@ namespace Opm
const RockCompressibility* rock_comp_props, const RockCompressibility* rock_comp_props,
std::shared_ptr<EclipseState> eclipse_state, std::shared_ptr<EclipseState> eclipse_state,
BlackoilOutputWriter& output_writer, BlackoilOutputWriter& output_writer,
std::shared_ptr< const Deck > deck, const Deck& deck,
NewtonIterationBlackoilInterface& linsolver, NewtonIterationBlackoilInterface& linsolver,
const double* gravity); const double* gravity);
@ -127,7 +127,7 @@ namespace Opm
const WellState& well_state, const WellState& well_state,
DynamicListEconLimited& list_econ_limited) const; DynamicListEconLimited& list_econ_limited) const;
private: private:
std::shared_ptr< const Deck > deck_; const Deck& deck_;
const PolymerPropsAd& polymer_props_; const PolymerPropsAd& polymer_props_;
}; };

View File

@ -34,7 +34,7 @@ SimulatorFullyImplicitCompressiblePolymer(const parameter::ParameterGroup& param
const RockCompressibility* rock_comp_props, const RockCompressibility* rock_comp_props,
std::shared_ptr<EclipseState> eclipse_state, std::shared_ptr<EclipseState> eclipse_state,
BlackoilOutputWriter& output_writer, BlackoilOutputWriter& output_writer,
std::shared_ptr< const Deck > deck, const Deck& deck,
NewtonIterationBlackoilInterface& linsolver, NewtonIterationBlackoilInterface& linsolver,
const double* gravity) const double* gravity)
: BaseType(param, : BaseType(param,
@ -82,7 +82,7 @@ handleAdditionalWellInflow(SimulatorTimer& timer,
{ {
// compute polymer inflow // compute polymer inflow
std::unique_ptr<PolymerInflowInterface> polymer_inflow_ptr; std::unique_ptr<PolymerInflowInterface> polymer_inflow_ptr;
if (deck_->hasKeyword("WPOLYMER")) { if (deck_.hasKeyword("WPOLYMER")) {
if (wells_manager.c_wells() == 0) { if (wells_manager.c_wells() == 0) {
OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells."); OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells.");
} }