Do not assign to dereferenced null pointers.

This commit is contained in:
Atgeirr Flø Rasmussen 2016-11-17 13:18:02 +01:00
parent 3e142e87ab
commit b3cb89ad22
7 changed files with 48 additions and 50 deletions

View File

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

View File

@ -101,7 +101,6 @@ try
bool use_deck = param.has("deck_filename");
std::shared_ptr< EclipseState > eclipseState;
std::shared_ptr< Deck > deck;
std::unique_ptr<GridManager> grid;
std::unique_ptr<IncompPropertiesInterface> props;
std::unique_ptr<RockCompressibility> rock_comp;
@ -112,28 +111,29 @@ try
if (use_deck) {
Parser parser;
ParseContext parseContext;
parseContext.update(ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN);
std::string deck_filename = param.get<std::string>("deck_filename");
*deck = parser.parseFile(deck_filename , parseContext);
eclipseState.reset( new EclipseState(*deck, parseContext));
auto deck = parser.parseFile(deck_filename , parseContext);
eclipseState.reset( new EclipseState(deck, parseContext));
// Grid init
grid.reset(new GridManager(eclipseState->getInputGrid()));
{
const UnstructuredGrid& ug_grid = *(grid->c_grid());
// 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 )));
// Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState));
rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// 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).
if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state);
initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
}
}
} else {

View File

@ -101,7 +101,6 @@ try
// If we have a "deck_filename", grid and props will be read from that.
bool use_deck = param.has("deck_filename");
Opm::Parser parser;
std::shared_ptr< Opm::Deck > deck;
std::unique_ptr<GridManager> grid;
std::unique_ptr<IncompPropertiesInterface> props;
std::unique_ptr<RockCompressibility> rock_comp;
@ -114,8 +113,8 @@ try
if (use_deck) {
std::string deck_filename = param.get<std::string>("deck_filename");
Opm::ParseContext parseContext;
*deck = parser.parseFile(deck_filename, parseContext);
eclipseState.reset(new EclipseState(*deck , parseContext));
auto deck = parser.parseFile(deck_filename, parseContext);
eclipseState.reset(new EclipseState(deck , parseContext));
// Grid init
grid.reset(new GridManager(eclipseState->getInputGrid()));
@ -123,20 +122,20 @@ try
const UnstructuredGrid& ug_grid = *(grid->c_grid());
// 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);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
state.reset( new TwophaseState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid )));
// Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState));
rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// 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).
if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state);
initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
}
}
} else {
@ -254,7 +253,7 @@ try
} else {
// With a deck, we may have more report steps etc.
WellState well_state;
Opm::TimeMap timeMap(*deck);
const auto& timeMap = eclipseState->getSchedule().getTimeMap();
SimulatorTimer simtimer;
for (size_t reportStepIdx = 0; reportStepIdx < timeMap.numTimesteps(); ++reportStepIdx) {
// 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.
bool use_deck = param.has("deck_filename");
std::shared_ptr< Deck > deck;
Deck deck;
boost::scoped_ptr<GridManager> grid;
boost::scoped_ptr<IncompPropertiesInterface> props;
boost::scoped_ptr<RockCompressibility> rock_comp;
@ -101,32 +101,32 @@ try
std::string deck_filename = param.get<std::string>("deck_filename");
Opm::ParseContext parseContext({{ ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE }});
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.reset(new GridManager(eclipseState->getInputGrid()));
{
const UnstructuredGrid& ug_grid = *(grid->c_grid());
// 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);
// max_well_control_iterations = param.getDefault("max_well_control_iterations", 10);
state.reset( new PolymerState( UgGridHelpers::numCells( ug_grid ) , UgGridHelpers::numFaces( ug_grid ), 2));
// Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState));
rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// 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).
if (param.has("init_saturation")) {
initStateBasic(ug_grid, *props, param, gravity[2], *state);
} else {
initStateFromDeck(ug_grid, *props, *deck, gravity[2], *state);
initStateFromDeck(ug_grid, *props, deck, gravity[2], *state);
}
// Init polymer properties.
poly_props.readFromDeck(*deck, *eclipseState);
poly_props.readFromDeck(deck, *eclipseState);
}
} else {
// Grid init.
@ -299,12 +299,12 @@ try
WellState well_state;
int step = 0;
TimeMap timeMap(*deck);
const auto& timeMap = eclipseState->getSchedule().getTimeMap();
SimulatorTimer simtimer;
simtimer.init(timeMap);
// Check for WPOLYMER presence in last epoch to decide
// polymer injection control type.
const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
const bool use_wpolymer = deck.hasKeyword("WPOLYMER");
if (use_wpolymer) {
if (param.has("poly_start_days")) {
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 );
}
std::shared_ptr< Deck > deck;
Deck deck;
std::shared_ptr<EclipseState> eclipseState;
try {
*deck = parser.parseFile(deck_filename , parseContext);
Opm::checkDeck(*deck, parser);
eclipseState.reset(new Opm::EclipseState(*deck , parseContext));
deck = parser.parseFile(deck_filename , parseContext);
Opm::checkDeck(deck, parser);
eclipseState.reset(new Opm::EclipseState(deck , parseContext));
}
catch (const std::invalid_argument& e) {
std::cerr << "Failed to create valid ECLIPSESTATE object. See logfile: " << logFile << std::endl;
@ -173,7 +173,7 @@ try
grid.reset(new GridManager(eclipseState->getInputGrid()));
}
auto &cGrid = *grid->c_grid();
const PhaseUsage pu = Opm::phaseUsageFromDeck(*deck);
const PhaseUsage pu = Opm::phaseUsageFromDeck(deck);
// Rock and fluid init
@ -182,31 +182,31 @@ try
typedef BlackoilPropsAdFromDeck::MaterialLawManager 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::globalCell(cGrid),
Opm::UgGridHelpers::cartDims(cGrid),
param));
state.reset( new PolymerBlackoilState( Opm::UgGridHelpers::numCells(cGrid), Opm::UgGridHelpers::numFaces(cGrid), 2));
new_props.reset(new BlackoilPropsAdFromDeck(*deck, *eclipseState, materialLawManager, cGrid));
PolymerProperties polymer_props(*deck, *eclipseState);
new_props.reset(new BlackoilPropsAdFromDeck(deck, *eclipseState, materialLawManager, cGrid));
PolymerProperties polymer_props(deck, *eclipseState);
PolymerPropsAd polymer_props_ad(polymer_props);
// Rock compressibility.
rock_comp.reset(new RockCompressibility(*deck, *eclipseState));
rock_comp.reset(new RockCompressibility(deck, *eclipseState));
// 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).
if (param.has("init_saturation")) {
initStateBasic(*grid->c_grid(), *props, param, gravity[2], *state);
initBlackoilSurfvol(*grid->c_grid(), *props, *state);
} 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);
@ -229,7 +229,7 @@ try
WellState well_state;
// Check for WPOLYMER presence in last epoch to decide
// polymer injection control type.
const bool use_wpolymer = deck->hasKeyword("WPOLYMER");
const bool use_wpolymer = deck.hasKeyword("WPOLYMER");
if (use_wpolymer) {
if (param.has("poly_start_days")) {
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,
std::shared_ptr<EclipseState> eclipse_state,
BlackoilOutputWriter& output_writer,
std::shared_ptr< const Deck > deck,
const Deck& deck,
NewtonIterationBlackoilInterface& linsolver,
const double* gravity);
@ -127,7 +127,7 @@ namespace Opm
const WellState& well_state,
DynamicListEconLimited& list_econ_limited) const;
private:
std::shared_ptr< const Deck > deck_;
const Deck& deck_;
const PolymerPropsAd& polymer_props_;
};

View File

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