RockCompressibility::RockCompressibility(const parameter::ParameterGroup& param) : pref_(0.0), rock_comp_(0.0) { pref_ = param.getDefault("rock_compressibility_pref", 100.0)*unit::barsa; rock_comp_ = param.getDefault("rock_compressibility", 0.0)/unit::barsa; }
/// Initialize from parameters. Accepts the following: /// num_psteps (default 1) /// stepsize_days (default 1) void SimulatorTimer::init(const parameter::ParameterGroup& param) { const int num_psteps = param.getDefault("num_psteps", 1); const double stepsize_days = param.getDefault("stepsize_days", 1.0); const double stepsize = Opm::unit::convert::from(stepsize_days, Opm::unit::day); timesteps_.clear(); timesteps_.resize(num_psteps, stepsize); total_time_ = num_psteps*stepsize; }
/// Construct a system solver. NewtonIterationBlackoilInterleaved::NewtonIterationBlackoilInterleaved(const parameter::ParameterGroup& param, const boost::any& parallelInformation) : iterations_( 0 ), parallelInformation_(parallelInformation), newton_use_gmres_( param.getDefault("newton_use_gmres", false ) ), linear_solver_reduction_( param.getDefault("linear_solver_reduction", 1e-2 ) ), linear_solver_maxiter_( param.getDefault("linear_solver_maxiter", 50 ) ), linear_solver_restart_( param.getDefault("linear_solver_restart", 40 ) ), linear_solver_verbosity_( param.getDefault("linear_solver_verbosity", 0 )) { }
// read values from parameter class NewtonIterationBlackoilInterleavedParameters( const parameter::ParameterGroup& param ) { // set default parameters reset(); // read parameters (using previsouly set default values) newton_use_gmres_ = param.getDefault("newton_use_gmres", newton_use_gmres_ ); linear_solver_reduction_ = param.getDefault("linear_solver_reduction", linear_solver_reduction_ ); linear_solver_maxiter_ = param.getDefault("linear_solver_maxiter", linear_solver_maxiter_); linear_solver_restart_ = param.getDefault("linear_solver_restart", linear_solver_restart_); linear_solver_verbosity_ = param.getDefault("linear_solver_verbosity", linear_solver_verbosity_); }
/// Construct a system solver. NewtonIterationBlackoilCPR::NewtonIterationBlackoilCPR(const parameter::ParameterGroup& param, const boost::any& parallelInformation_arg) : cpr_param_( param ), iterations_( 0 ), parallelInformation_(parallelInformation_arg), newton_use_gmres_( param.getDefault("newton_use_gmres", false ) ), linear_solver_reduction_( param.getDefault("linear_solver_reduction", 1e-2 ) ), linear_solver_maxiter_( param.getDefault("linear_solver_maxiter", 50 ) ), linear_solver_restart_( param.getDefault("linear_solver_restart", 40 ) ), linear_solver_verbosity_( param.getDefault("linear_solver_verbosity", 0 )), linear_solver_ignoreconvergencefailure_(param.getDefault("linear_solver_ignoreconvergencefailure", false)) { }
BlackoilPropertiesBasic::BlackoilPropertiesBasic(const parameter::ParameterGroup& param, const int dim, const int num_cells) { double poro = param.getDefault("porosity", 1.0); using namespace Opm::unit; using namespace Opm::prefix; double perm = param.getDefault("permeability", 100.0)*milli*darcy; rock_.init(dim, num_cells, poro, perm); pvt_.init(param); satprops_.init(param); if (pvt_.numPhases() != satprops_.numPhases()) { OPM_THROW(std::runtime_error, "BlackoilPropertiesBasic::BlackoilPropertiesBasic() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_.numPhases() << ")."); } }
BlackoilModelParameters::BlackoilModelParameters( const parameter::ParameterGroup& param ) { // set default values reset(); // overload with given parameters dp_max_rel_ = param.getDefault("dp_max_rel", dp_max_rel_); ds_max_ = param.getDefault("ds_max", ds_max_); dr_max_rel_ = param.getDefault("dr_max_rel", dr_max_rel_); max_residual_allowed_ = param.getDefault("max_residual_allowed", max_residual_allowed_); tolerance_mb_ = param.getDefault("tolerance_mb", tolerance_mb_); tolerance_cnv_ = param.getDefault("tolerance_cnv", tolerance_cnv_); tolerance_wells_ = param.getDefault("tolerance_wells", tolerance_wells_ ); solve_welleq_initially_ = param.getDefault("solve_welleq_initially",solve_welleq_initially_); update_equations_scaling_ = param.getDefault("update_equations_scaling", update_equations_scaling_); compute_well_potentials_ = param.getDefault("compute_well_potentials", compute_well_potentials_); }
AdaptiveTimeStepping::AdaptiveTimeStepping( const Tuning& tuning, size_t time_step, const parameter::ParameterGroup& param, const bool terminal_output ) : timeStepControl_() , restart_factor_( tuning.getTSFCNV(time_step) ) , growth_factor_(tuning.getTFDIFF(time_step) ) , max_growth_( tuning.getTSFMAX(time_step) ) // default is 1 year, convert to seconds , max_time_step_( tuning.getTSMAXZ(time_step) ) , solver_restart_max_( param.getDefault("solver.restart", int(10) ) ) , solver_verbose_( param.getDefault("solver.verbose", bool(true) ) && terminal_output ) , timestep_verbose_( param.getDefault("timestep.verbose", bool(true) ) && terminal_output ) , suggested_next_timestep_( tuning.getTSINIT(time_step) ) , full_timestep_initially_( param.getDefault("full_timestep_initially", bool(false) ) ) { init(param); }
AdaptiveTimeStepping::AdaptiveTimeStepping( const parameter::ParameterGroup& param, const bool terminal_output ) : timeStepControl_() , restart_factor_( param.getDefault("solver.restartfactor", double(0.33) ) ) , growth_factor_( param.getDefault("solver.growthfactor", double(2) ) ) , max_growth_( param.getDefault("timestep.control.maxgrowth", double(3.0) ) ) // default is 1 year, convert to seconds , max_time_step_( unit::convert::from(param.getDefault("timestep.max_timestep_in_days", 365.0 ), unit::day) ) , solver_restart_max_( param.getDefault("solver.restart", int(10) ) ) , solver_verbose_( param.getDefault("solver.verbose", bool(true) ) && terminal_output ) , timestep_verbose_( param.getDefault("timestep.verbose", bool(true) ) && terminal_output ) , suggested_next_timestep_( unit::convert::from(param.getDefault("timestep.initial_timestep_in_days", -1.0 ), unit::day) ) , full_timestep_initially_( param.getDefault("full_timestep_initially", bool(false) ) ) { init(param); }
TransportSolverTwophaseImplicit::TransportSolverTwophaseImplicit( const UnstructuredGrid& grid, const Opm::IncompPropertiesInterface& props, const std::vector<double>& porevol, const double* gravity, const std::vector<double>& half_trans, const parameter::ParameterGroup& param) : fluid_(props), model_(fluid_, grid, porevol, gravity, param.getDefault("guess_old_solution", false)), tsolver_(model_), grid_(grid), props_(props) { ctrl_.max_it = param.getDefault("max_it", 20); ctrl_.verbosity = param.getDefault("verbosity", 0); ctrl_.max_it_ls = param.getDefault("max_it_ls", 5); model_.initGravityTrans(grid_, half_trans); tsrc_ = create_transport_source(2, 2); initial_porevolume_cell0_ = porevol[0]; }
NewtonSolver<PhysicalModel>::SolverParameters:: SolverParameters( const parameter::ParameterGroup& param ) { // set default values reset(); // overload with given parameters relax_max_ = param.getDefault("relax_max", relax_max_); max_iter_ = param.getDefault("max_iter", max_iter_); min_iter_ = param.getDefault("min_iter", min_iter_); std::string relaxation_type = param.getDefault("relax_type", std::string("dampen")); if (relaxation_type == "dampen") { relax_type_ = DAMPEN; } else if (relaxation_type == "sor") { relax_type_ = SOR; } else { OPM_THROW(std::runtime_error, "Unknown Relaxtion Type " << relaxation_type); } }
inline void setupRegionBasedConditions(const parameter::ParameterGroup& param, const GridInterface& g, BCs& bcs) { // Extract region and pressure value for Dirichlet bcs. typedef typename GridInterface::Vector Vector; Vector low; low[0] = param.getDefault("dir_block_low_x", 0.0); low[1] = param.getDefault("dir_block_low_y", 0.0); low[2] = param.getDefault("dir_block_low_z", 0.0); Vector high; high[0] = param.getDefault("dir_block_high_x", 1.0); high[1] = param.getDefault("dir_block_high_y", 1.0); high[2] = param.getDefault("dir_block_high_z", 1.0); double dir_block_pressure = param.get<double>("dir_block_pressure"); // Set flow conditions for that region. // For this to work correctly, unique boundary ids should be used, // otherwise conditions may spread outside the given region, to all // faces with the same bid as faces inside the region. typedef typename GridInterface::CellIterator CI; typedef typename CI::FaceIterator FI; int max_bid = 0; std::vector<int> dir_bids; for (CI c = g.cellbegin(); c != g.cellend(); ++c) { for (FI f = c->facebegin(); f != c->faceend(); ++f) { int bid = f->boundaryId(); max_bid = std::max(bid, max_bid); if (bid != 0 && isInside(low, high, f->centroid())) { dir_bids.push_back(bid); } } } bcs.resize(max_bid + 1); for (std::vector<int>::const_iterator it = dir_bids.begin(); it != dir_bids.end(); ++it) { bcs.flowCond(*it) = FlowBC(FlowBC::Dirichlet, dir_block_pressure); } // Transport BCs are defaulted. }
void AdaptiveTimeStepping:: init(const parameter::ParameterGroup& param) { // valid are "pid" and "pid+iteration" std::string control = param.getDefault("timestep.control", std::string("pid") ); // iterations is the accumulation of all linear iterations over all newton steops per time step const int defaultTargetIterations = 30; const double tol = param.getDefault("timestep.control.tol", double(1e-1) ); if( control == "pid" ) { timeStepControl_ = TimeStepControlType( new PIDTimeStepControl( tol ) ); } else if ( control == "pid+iteration" ) { const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations ); timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol ) ); } else if ( control == "iterationcount" ) { const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations ); const double decayrate = param.getDefault("timestep.control.decayrate", double(0.75) ); const double growthrate = param.getDefault("timestep.control.growthrate", double(1.25) ); timeStepControl_ = TimeStepControlType( new SimpleIterationCountTimeStepControl( iterations, decayrate, growthrate ) ); } else if ( control == "hardcoded") { const std::string filename = param.getDefault("timestep.control.filename", std::string("timesteps")); timeStepControl_ = TimeStepControlType( new HardcodedTimeStepControl( filename ) ); } else OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control ); // make sure growth factor is something reasonable assert( growth_factor_ >= 1.0 ); }
CPRParameter( const parameter::ParameterGroup& param) { // reset values to default reset(); cpr_relax_ = param.getDefault("cpr_relax", cpr_relax_); cpr_solver_tol_ = param.getDefault("cpr_solver_tol", cpr_solver_tol_); cpr_ilu_n_ = param.getDefault("cpr_ilu_n", cpr_ilu_n_); cpr_max_ell_iter_ = param.getDefault("cpr_max_elliptic_iter",cpr_max_ell_iter_); cpr_use_amg_ = param.getDefault("cpr_use_amg", cpr_use_amg_); cpr_use_bicgstab_ = param.getDefault("cpr_use_bicgstab", cpr_use_bicgstab_); cpr_solver_verbose_ = param.getDefault("cpr_solver_verbose", cpr_solver_verbose_); }
inline void SteadyStateUpscaler<Traits>::initImpl(const parameter::ParameterGroup& param) { Super::initImpl(param); output_vtk_ = param.getDefault("output_vtk", output_vtk_); print_inoutflows_ = param.getDefault("print_inoutflows", print_inoutflows_); simulation_steps_ = param.getDefault("simulation_steps", simulation_steps_); stepsize_ = Dune::unit::convert::from(param.getDefault("stepsize", stepsize_), Dune::unit::day); relperm_threshold_ = param.getDefault("relperm_threshold", relperm_threshold_); sat_change_threshold_ = param.getDefault("sat_change_threshold", sat_change_threshold_); transport_solver_.init(param); // Set viscosities and densities if given. double v1_default = this->res_prop_.viscosityFirstPhase(); double v2_default = this->res_prop_.viscositySecondPhase(); this->res_prop_.setViscosities(param.getDefault("viscosity1", v1_default), param.getDefault("viscosity2", v2_default)); double d1_default = this->res_prop_.densityFirstPhase(); double d2_default = this->res_prop_.densitySecondPhase(); this->res_prop_.setDensities(param.getDefault("density1", d1_default), param.getDefault("density2", d2_default)); }
SimulatorBase<Implementation>::SimulatorBase(const parameter::ParameterGroup& param, const Grid& grid, const DerivedGeology& geo, BlackoilPropsAdInterface& props, const RockCompressibility* rock_comp_props, NewtonIterationBlackoilInterface& linsolver, const double* gravity, const bool has_disgas, const bool has_vapoil, std::shared_ptr<EclipseState> eclipse_state, OutputWriter& output_writer, const std::vector<double>& threshold_pressures_by_face) : param_(param), model_param_(param), solver_param_(param), grid_(grid), props_(props), rock_comp_props_(rock_comp_props), gravity_(gravity), geo_(geo), solver_(linsolver), has_disgas_(has_disgas), has_vapoil_(has_vapoil), terminal_output_(param.getDefault("output_terminal", true)), eclipse_state_(eclipse_state), output_writer_(output_writer), rateConverter_(props_, std::vector<int>(AutoDiffGrid::numCells(grid_), 0)), threshold_pressures_by_face_(threshold_pressures_by_face) { // Misc init. const int num_cells = AutoDiffGrid::numCells(grid); allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } #if HAVE_MPI if ( terminal_output_ ) { if ( solver_.parallelInformation().type() == typeid(ParallelISTLInformation) ) { const ParallelISTLInformation& info = boost::any_cast<const ParallelISTLInformation&>(solver_.parallelInformation()); // Only rank 0 does print to std::cout terminal_output_ = ( info.communicator().rank() == 0 ); is_parallel_run_ = ( info.communicator().size() > 1 ); } } #endif }
LinearSolverIstl::LinearSolverIstl(const parameter::ParameterGroup& param) : linsolver_residual_tolerance_(1e-8), linsolver_verbosity_(0), linsolver_type_(CG_AMG), linsolver_save_system_(false), linsolver_max_iterations_(0), linsolver_smooth_steps_(2), linsolver_prolongate_factor_(1.6) { linsolver_residual_tolerance_ = param.getDefault("linsolver_residual_tolerance", linsolver_residual_tolerance_); linsolver_verbosity_ = param.getDefault("linsolver_verbosity", linsolver_verbosity_); linsolver_type_ = LinsolverType(param.getDefault("linsolver_type", int(linsolver_type_))); linsolver_save_system_ = param.getDefault("linsolver_save_system", linsolver_save_system_); if (linsolver_save_system_) { linsolver_save_filename_ = param.getDefault("linsolver_save_filename", std::string("linsys")); } linsolver_max_iterations_ = param.getDefault("linsolver_max_iterations", linsolver_max_iterations_); linsolver_smooth_steps_ = param.getDefault("linsolver_smooth_steps", linsolver_smooth_steps_); linsolver_prolongate_factor_ = param.getDefault("linsolver_prolongate_factor", linsolver_prolongate_factor_); }
// read values from parameter class NewtonIterationBlackoilInterleavedParameters( const parameter::ParameterGroup& param ) { // set default parameters reset(); // read parameters (using previsouly set default values) newton_use_gmres_ = param.getDefault("newton_use_gmres", newton_use_gmres_ ); linear_solver_reduction_ = param.getDefault("linear_solver_reduction", linear_solver_reduction_ ); linear_solver_maxiter_ = param.getDefault("linear_solver_maxiter", linear_solver_maxiter_); linear_solver_restart_ = param.getDefault("linear_solver_restart", linear_solver_restart_); linear_solver_verbosity_ = param.getDefault("linear_solver_verbosity", linear_solver_verbosity_); require_full_sparsity_pattern_ = param.getDefault("require_full_sparsity_pattern", require_full_sparsity_pattern_); ignoreConvergenceFailure_ = param.getDefault("linear_solver_ignoreconvergencefailure", ignoreConvergenceFailure_); }
LinearSolverFactory::LinearSolverFactory(const parameter::ParameterGroup& param) { #if HAVE_SUITESPARSE_UMFPACK_H std::string default_solver = "umfpack"; #elif HAVE_DUNE_ISTL std::string default_solver = "istl"; #elif HAVE_PETSC std::string default_solver = "petsc"; #else std::string default_solver = "no_solver_available"; OPM_THROW(std::runtime_error, "No linear solver available, you must have UMFPACK , dune-istl or Petsc installed to use LinearSolverFactory."); #endif const std::string ls = param.getDefault("linsolver", default_solver); if (ls == "umfpack") { #if HAVE_SUITESPARSE_UMFPACK_H solver_.reset(new LinearSolverUmfpack); #endif } else if (ls == "istl") { #if HAVE_DUNE_ISTL solver_.reset(new LinearSolverIstl(param)); #endif } else if (ls == "petsc"){ #if HAVE_PETSC solver_.reset(new LinearSolverPetsc(param)); #endif } else { OPM_THROW(std::runtime_error, "Linear solver " << ls << " is unknown."); } if (! solver_) { OPM_THROW(std::runtime_error, "Linear solver " << ls << " is not enabled in " "this configuration."); } }
// \TODO: Treat bcs. SimulatorFullyImplicitCompressiblePolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const DerivedGeology& geo, const BlackoilPropsAdInterface& props, const PolymerPropsAd& polymer_props, const RockCompressibility* rock_comp_props, std::shared_ptr<EclipseState> eclipse_state, EclipseWriter& output_writer, Opm::DeckConstPtr& deck, NewtonIterationBlackoilInterface& linsolver, const double* gravity) : grid_(grid), props_(props), polymer_props_(polymer_props), rock_comp_props_(rock_comp_props), eclipse_state_(eclipse_state), output_writer_(output_writer), deck_(deck), linsolver_(linsolver), gravity_(gravity), geo_(geo) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
// \TODO: Treat bcs. SimulatorFullyImplicitBlackoil::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropsAdInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), gravity_(gravity), geo_(grid_, props_, gravity_), solver_(grid_, props_, geo_, rock_comp_props, *wells_manager.c_wells(), linsolver) /* param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, */ { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, std::shared_ptr<MaterialLawManager> materialLawManager, int number_of_cells, const int* global_cell, const int* cart_dims, const parameter::ParameterGroup& param, bool init_rock) { // retrieve the cell specific PVT table index from the deck // and using the grid... extractPvtTableIndex(cellPvtRegionIdx_, eclState, number_of_cells, global_cell); if(init_rock){ rock_.init(eclState, number_of_cells, global_cell, cart_dims); } const int pvt_samples = param.getDefault("pvt_tab_size", -1); pvt_.init(deck, eclState, pvt_samples); // Unfortunate lack of pointer smartness here... std::string threephase_model = param.getDefault<std::string>("threephase_model", "gwseg"); if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") { OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only."); } SaturationPropsFromDeck* ptr = new SaturationPropsFromDeck(); ptr->init(phaseUsageFromDeck(deck), materialLawManager); satprops_.reset(ptr); if (pvt_.numPhases() != satprops_->numPhases()) { OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); } }
inline void setupBoundaryConditions(const parameter::ParameterGroup& param, const GridInterface& g, BCs& bcs) { if (param.getDefault("upscaling", false)) { int bct = param.get<int>("boundary_condition_type"); int pddir = param.getDefault("pressure_drop_direction", 0); double pdrop = param.getDefault("boundary_pressuredrop", 1.0e5); double bdy_sat = param.getDefault("boundary_saturation", 1.0); bool twodim_hack = param.getDefault("2d_hack", false); setupUpscalingConditions(g, bct, pddir, pdrop, bdy_sat, twodim_hack, bcs); return; } if (param.getDefault("region_based_bcs", false)) { setupRegionBasedConditions(param, g, bcs); return; } // Make flow equation boundary conditions. // Default is pressure 1.0e5 on the left, 0.0 on the right. // Recall that the boundary ids range from 1 to 6 for the cartesian edges, // and that boundary id 0 means interiour face/intersection. std::string flow_bc_type = param.getDefault<std::string>("flow_bc_type", "dirichlet"); FlowBC::BCType bct = FlowBC::Dirichlet; double leftval = 1.0*Dune::unit::barsa; double rightval = 0.0; if (flow_bc_type == "neumann") { bct = FlowBC::Neumann; leftval = param.get<double>("left_flux"); rightval = param.getDefault<double>("right_flux", -leftval); } else if (flow_bc_type == "dirichlet") { leftval = param.getDefault<double>("left_pressure", leftval); rightval = param.getDefault<double>("right_pressure", rightval); } else if (flow_bc_type == "periodic") { THROW("Periodic conditions not here yet."); } else { THROW("Unknown flow boundary condition type " << flow_bc_type); } bcs.resize(7); bcs.flowCond(1) = FlowBC(bct, leftval); bcs.flowCond(2) = FlowBC(bct, rightval); // Default transport boundary conditions are used. }
void initStateBasic(const UnstructuredGrid& grid, const BlackoilPropertiesInterface& props, const parameter::ParameterGroup& param, const double gravity, State& state) { // TODO: Refactor to exploit similarity with IncompProp* case. const int num_phases = props.numPhases(); if (num_phases != 2) { THROW("initStateTwophaseBasic(): currently handling only two-phase scenarios."); } state.init(grid, num_phases); const int num_cells = props.numCells(); // By default: initialise water saturation to minimum everywhere. std::vector<int> all_cells(num_cells); for (int i = 0; i < num_cells; ++i) { all_cells[i] = i; } state.setFirstSat(all_cells, props, State::MinSat); const bool convection_testcase = param.getDefault("convection_testcase", false); if (convection_testcase) { // Initialise water saturation to max in the 'left' part. std::vector<int> left_cells; left_cells.reserve(num_cells/2); const int *glob_cell = grid.global_cell; const int* cd = grid.cartdims; for (int cell = 0; cell < num_cells; ++cell) { const int gc = glob_cell == 0 ? cell : glob_cell[cell]; bool left = (gc % cd[0]) < cd[0]/2; if (left) { left_cells.push_back(cell); } } state.setFirstSat(left_cells, props, State::MaxSat); const double init_p = param.getDefault("ref_pressure", 100.0)*unit::barsa; std::fill(state.pressure().begin(), state.pressure().end(), init_p); } else if (param.has("water_oil_contact")) { // Warn against error-prone usage. if (gravity == 0.0) { std::cout << "**** Warning: running gravity convection scenario, but gravity is zero." << std::endl; } if (grid.cartdims[2] <= 1) { std::cout << "**** Warning: running gravity convection scenario, which expects nz > 1." << std::endl; } // Initialise water saturation to max below water-oil contact. const double woc = param.get<double>("water_oil_contact"); initWaterOilContact(grid, props, woc, WaterBelow, state); // Initialise pressure to hydrostatic state. const double ref_p = param.getDefault("ref_pressure", 100.0)*unit::barsa; initHydrostaticPressure(grid, props, woc, gravity, woc, ref_p, state); } else { // Use default: water saturation is minimum everywhere. // Initialise pressure to hydrostatic state. const double ref_p = param.getDefault("ref_pressure", 100.0)*unit::barsa; const double ref_z = grid.cell_centroids[0 + grid.dimensions - 1]; const double woc = -1e100; initHydrostaticPressure(grid, props, woc, gravity, ref_z, ref_p, state); } // Finally, init face pressures. initFacePressure(grid, state); }
// \TODO: make CompressibleTpfa take src and bcs. SimulatorCompressibleTwophase::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropertiesInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const std::vector<double>&, const FlowBoundaryConditions*, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), //src_(src), //bcs_(bcs), gravity_(gravity), psolver_(grid, props, rock_comp_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells() /*, src, bcs*/), tsolver_(grid, props, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_){ tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
SimulatorPolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const IncompPropertiesInterface& props, const PolymerProperties& poly_props, const RockCompressibility* rock_comp_props, const Wells* wells, const std::vector<double>& src, const FlowBoundaryConditions* bcs, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), poly_props_(poly_props), rock_comp_props_(rock_comp_props), wells_(wells), src_(src), bcs_(bcs), linsolver_(linsolver), gravity_(gravity), psolver_(grid, props, rock_comp_props, poly_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells, src, bcs), tsolver_(grid, props, poly_props, TransportModelPolymer::Bracketing, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)), poly_inflow_(param.getDefault("poly_start_days", 300.0)*Opm::unit::day, param.getDefault("poly_end_days", 800.0)*Opm::unit::day, param.getDefault("poly_amount", poly_props.cMax())) { // For output. output_ = param.getDefault("output", true); if (output_) { output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { THROW("Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Transport related init. TransportModelPolymer::SingleCellMethod method; std::string method_string = param.getDefault("single_cell_method", std::string("Bracketing")); if (method_string == "Bracketing") { method = Opm::TransportModelPolymer::Bracketing; } else if (method_string == "Newton") { method = Opm::TransportModelPolymer::Newton; } else { THROW("Unknown method: " << method_string); } tsolver_.setPreferredMethod(method); num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_){ tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
SimulatorIncompTwophase::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const IncompPropertiesInterface& props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const std::vector<double>& src, const FlowBoundaryConditions* bcs, LinearSolverInterface& linsolver, const double* gravity) : use_reorder_(param.getDefault("use_reorder", true)), use_segregation_split_(param.getDefault("use_segregation_split", false)), grid_(grid), props_(props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), src_(src), bcs_(bcs), psolver_(grid, props, rock_comp_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells(), src, bcs) { // Initialize transport solver. if (use_reorder_) { tsolver_.reset(new Opm::TransportSolverTwophaseReorder(grid, props, use_segregation_split_ ? gravity : NULL, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30))); } else { if (rock_comp_props && rock_comp_props->isActive()) { OPM_THROW(std::runtime_error, "The implicit pressure solver cannot handle rock compressibility."); } if (use_segregation_split_) { OPM_THROW(std::runtime_error, "The implicit pressure solver is not set up to use segregation splitting."); } std::vector<double> porevol; computePorevolume(grid, props.porosity(), porevol); tsolver_.reset(new Opm::TransportSolverTwophaseImplicit(grid, props, porevol, gravity, psolver_.getHalfTrans(), param)); } // For output. log_ = param.getDefault("quiet", false) ? &Opm::null_stream : &std::cout; output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
AdaptiveTimeStepping::AdaptiveTimeStepping( const parameter::ParameterGroup& param ) : timeStepControl_() , restart_factor_( param.getDefault("solver.restartfactor", double(0.1) ) ) , growth_factor_( param.getDefault("solver.growthfactor", double(1.25) ) ) // default is 1 year, convert to seconds , max_time_step_( unit::convert::from(param.getDefault("timestep.max_timestep_in_days", 365.0 ), unit::day) ) , solver_restart_max_( param.getDefault("solver.restart", int(3) ) ) , solver_verbose_( param.getDefault("solver.verbose", bool(false) ) ) , timestep_verbose_( param.getDefault("timestep.verbose", bool(false) ) ) , last_timestep_( -1.0 ) { // valid are "pid" and "pid+iteration" std::string control = param.getDefault("timestep.control", std::string("pid+iteration") ); // iterations is the accumulation of all linear iterations over all newton steops per time step const int defaultTargetIterations = 30; const double tol = param.getDefault("timestep.control.tol", double(1e-3) ); if( control == "pid" ) { timeStepControl_ = TimeStepControlType( new PIDTimeStepControl( tol ) ); } else if ( control == "pid+iteration" ) { const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations ); const double maxgrowth = param.getDefault("timestep.control.maxgrowth", double(3.0) ); timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol, maxgrowth ) ); } else if ( control == "iterationcount" ) { const int iterations = param.getDefault("timestep.control.targetiteration", defaultTargetIterations ); const double decayrate = param.getDefault("timestep.control.decayrate", double(0.75) ); const double growthrate = param.getDefault("timestep.control.growthrate", double(1.25) ); timeStepControl_ = TimeStepControlType( new SimpleIterationCountTimeStepControl( iterations, decayrate, growthrate ) ); } else OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control ); // make sure growth factor is something reasonable assert( growth_factor_ >= 1.0 ); }
SimulatorCompressiblePolymer::Impl::Impl(const parameter::ParameterGroup& param, const UnstructuredGrid& grid, const BlackoilPropertiesInterface& props, const PolymerProperties& poly_props, const RockCompressibility* rock_comp_props, WellsManager& wells_manager, const PolymerInflowInterface& polymer_inflow, LinearSolverInterface& linsolver, const double* gravity) : grid_(grid), props_(props), poly_props_(poly_props), rock_comp_props_(rock_comp_props), wells_manager_(wells_manager), wells_(wells_manager.c_wells()), polymer_inflow_(polymer_inflow), gravity_(gravity), psolver_(grid, props, rock_comp_props, poly_props, linsolver, param.getDefault("nl_pressure_residual_tolerance", 0.0), param.getDefault("nl_pressure_change_tolerance", 1.0), param.getDefault("nl_pressure_maxiter", 10), gravity, wells_manager.c_wells()), tsolver_(grid, props, poly_props, TransportSolverTwophaseCompressiblePolymer::Bracketing, param.getDefault("nl_tolerance", 1e-9), param.getDefault("nl_maxiter", 30)) { // For output. output_ = param.getDefault("output", true); if (output_) { output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists boost::filesystem::path fpath(output_dir_); try { create_directories(fpath); } catch (...) { OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); } output_interval_ = param.getDefault("output_interval", 1); } // Well control related init. check_well_controls_ = param.getDefault("check_well_controls", false); max_well_control_iterations_ = param.getDefault("max_well_control_iterations", 10); // Transport related init. TransportSolverTwophaseCompressiblePolymer::SingleCellMethod method; std::string method_string = param.getDefault("single_cell_method", std::string("Bracketing")); if (method_string == "Bracketing") { method = Opm::TransportSolverTwophaseCompressiblePolymer::Bracketing; } else if (method_string == "Newton") { method = Opm::TransportSolverTwophaseCompressiblePolymer::Newton; } else { OPM_THROW(std::runtime_error, "Unknown method: " << method_string); } tsolver_.setPreferredMethod(method); num_transport_substeps_ = param.getDefault("num_transport_substeps", 1); use_segregation_split_ = param.getDefault("use_segregation_split", false); if (gravity != 0 && use_segregation_split_) { tsolver_.initGravity(gravity); extractColumn(grid_, columns_); } // Misc init. const int num_cells = grid.number_of_cells; allcells_.resize(num_cells); for (int cell = 0; cell < num_cells; ++cell) { allcells_[cell] = cell; } }
inline void BlackoilPropertiesFromDeck::init(Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclState, int number_of_cells, const int* global_cell, const int* cart_dims, const CentroidIterator& begin_cell_centroids, int dimension, const parameter::ParameterGroup& param, bool init_rock) { // retrieve the cell specific PVT table index from the deck // and using the grid... extractPvtTableIndex(cellPvtRegionIdx_, deck, number_of_cells, global_cell); if(init_rock){ rock_.init(eclState, number_of_cells, global_cell, cart_dims); } const int pvt_samples = param.getDefault("pvt_tab_size", 200); pvt_.init(deck, pvt_samples); // Unfortunate lack of pointer smartness here... const int sat_samples = param.getDefault("sat_tab_size", 200); std::string threephase_model = param.getDefault<std::string>("threephase_model", "simple"); if (deck->hasKeyword("ENDSCALE") && threephase_model != "gwseg") { OPM_THROW(std::runtime_error, "Sorry, end point scaling currently available for the 'gwseg' model only."); } if (sat_samples > 1) { if (threephase_model == "stone2") { SaturationPropsFromDeck<SatFuncStone2Uniform>* ptr = new SaturationPropsFromDeck<SatFuncStone2Uniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else if (threephase_model == "simple") { SaturationPropsFromDeck<SatFuncSimpleUniform>* ptr = new SaturationPropsFromDeck<SatFuncSimpleUniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else if (threephase_model == "gwseg") { SaturationPropsFromDeck<SatFuncGwsegUniform>* ptr = new SaturationPropsFromDeck<SatFuncGwsegUniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else { OPM_THROW(std::runtime_error, "Unknown threephase_model: " << threephase_model); } } else { if (threephase_model == "stone2") { SaturationPropsFromDeck<SatFuncStone2Nonuniform>* ptr = new SaturationPropsFromDeck<SatFuncStone2Nonuniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else if (threephase_model == "simple") { SaturationPropsFromDeck<SatFuncSimpleNonuniform>* ptr = new SaturationPropsFromDeck<SatFuncSimpleNonuniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else if (threephase_model == "gwseg") { SaturationPropsFromDeck<SatFuncGwsegNonuniform>* ptr = new SaturationPropsFromDeck<SatFuncGwsegNonuniform>(); satprops_.reset(ptr); ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, sat_samples); } else { OPM_THROW(std::runtime_error, "Unknown threephase_model: " << threephase_model); } } if (pvt_.numPhases() != satprops_->numPhases()) { OPM_THROW(std::runtime_error, "BlackoilPropertiesFromDeck::BlackoilPropertiesFromDeck() - Inconsistent number of phases in pvt data (" << pvt_.numPhases() << ") and saturation-dependent function data (" << satprops_->numPhases() << ")."); } }