diff --git a/opm/autodiff/BlackoilModelEbos.hpp b/opm/autodiff/BlackoilModelEbos.hpp index a8378f524..6ee8469b2 100644 --- a/opm/autodiff/BlackoilModelEbos.hpp +++ b/opm/autodiff/BlackoilModelEbos.hpp @@ -84,6 +84,9 @@ namespace Properties { NEW_TYPE_TAG(EclFlowProblem, INHERITS_FROM(BlackOilModel, EclBaseProblem)); SET_BOOL_PROP(EclFlowProblem, DisableWells, true); SET_BOOL_PROP(EclFlowProblem, EnableDebuggingChecks, false); + +// SWATINIT is done by the flow part of flow_ebos. this can be removed once the legacy +// code for fluid and satfunc handling gets fully retired. SET_BOOL_PROP(EclFlowProblem, EnableSwatinit, false); }} @@ -145,7 +148,8 @@ namespace Opm { FIP_PV = 5, //< Pore volume FIP_WEIGHTED_PRESSURE = 6 }; - std::array, 7> fip; + static const int fipValues = FIP_WEIGHTED_PRESSURE + 1 ; + std::array, fipValues> fip; }; // --------- Public methods --------- @@ -298,7 +302,7 @@ namespace Opm { // Compute the nonlinear update. const int nc = AutoDiffGrid::numCells(grid_); - const int nw = wellModel().wells().number_of_wells; + const int nw = numWells(); BVector x(nc); BVector xw(nw); @@ -445,7 +449,7 @@ namespace Opm { int sizeNonLinear() const { const int nc = Opm::AutoDiffGrid::numCells(grid_); - const int nw = wellModel().wells().number_of_wells; + const int nw = numWells(); return numPhases() * (nc + nw); } @@ -474,8 +478,11 @@ namespace Opm { const auto& ebosJac = ebosSimulator_.model().linearizer().matrix(); auto& ebosResid = ebosSimulator_.model().linearizer().residual(); - // apply well residual to the residual. - wellModel().apply(ebosResid); + if( xw.size() > 0 ) + { + // apply well residual to the residual. + wellModel().apply(ebosResid); + } // set initial guess x = 0.0; @@ -495,9 +502,12 @@ namespace Opm { istlSolver().solve( opA, x, ebosResid ); } - // recover wells. - xw = 0.0; - wellModel().recoverVariable(x, xw); + if( xw.size() > 0 ) + { + // recover wells. + xw = 0.0; + wellModel().recoverVariable(x, xw); + } } //===================================================================== @@ -1012,7 +1022,7 @@ namespace Opm { const auto& pv = geo_.poreVolume(); const int maxnp = Opm::BlackoilPhases::MaxNumPhases; - for (int i = 0; i<7; i++) { + for (int i = 0; i> values(dims, std::vector(7,0.0)); + std::vector> values(dims, std::vector(FIPData::fipValues,0.0)); std::vector hcpv(dims, 0.0); std::vector pres(dims, 0.0); @@ -1104,11 +1114,12 @@ namespace Opm { // mask[c] is 1 if we need to compute something in parallel const auto & pinfo = boost::any_cast(istlSolver().parallelInformation()); - const auto& mask = pinfo.getOwnerMask(); + const auto& mask = pinfo.updateOwnerMask( fipnum ); + auto comm = pinfo.communicator(); // Compute the global dims value and resize values accordingly. dims = comm.max(dims); - values.resize(dims, std::vector(7,0.0)); + values.resize(dims, std::vector(FIPData::fipValues,0.0)); //Accumulate phases for each region for (int phase = 0; phase < maxnp; ++phase) { @@ -1246,6 +1257,8 @@ namespace Opm { /// return true if wells are available in the reservoir bool wellsActive() const { return well_model_.wellsActive(); } + int numWells() const { return wellsActive() ? wells().number_of_wells : 0; } + /// return true if wells are available on this process bool localWellsActive() const { return well_model_.localWellsActive(); } diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 61bd1f710..2e3d07d7b 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -152,7 +152,7 @@ namespace Opm asImpl().setupOutputWriter(); asImpl().setupLinearSolver(); asImpl().createSimulator(); - + // Run. auto ret = asImpl().runSimulator(); @@ -388,12 +388,12 @@ namespace Opm - // Setup OpmLog backend with output_dir. + // Setup OpmLog backend with output_dir. void setupLogging() { std::string deck_filename = param_.get("deck_filename"); // create logFile - using boost::filesystem::path; + using boost::filesystem::path; path fpath(deck_filename); std::string baseName; std::ostringstream debugFileStream; diff --git a/opm/autodiff/FlowMainEbos.hpp b/opm/autodiff/FlowMainEbos.hpp index 92ba98909..919e8e25d 100644 --- a/opm/autodiff/FlowMainEbos.hpp +++ b/opm/autodiff/FlowMainEbos.hpp @@ -649,7 +649,8 @@ namespace Opm FluidSystem::enableDissolvedGas(), FluidSystem::enableVaporizedOil(), eclState(), - *output_writer_)); + *output_writer_, + defunctWellNames())); } private: @@ -705,6 +706,9 @@ namespace Opm Grid& grid() { return ebosSimulator_->gridManager().grid(); } + std::unordered_set defunctWellNames() const + { return ebosSimulator_->gridManager().defunctWellNames(); } + std::unique_ptr ebosSimulator_; int mpi_rank_ = 0; bool output_cout_ = false; diff --git a/opm/autodiff/GridInit.hpp b/opm/autodiff/GridInit.hpp index 5b900ba22..1cbed0a49 100644 --- a/opm/autodiff/GridInit.hpp +++ b/opm/autodiff/GridInit.hpp @@ -73,18 +73,42 @@ namespace Opm class GridInit { public: + GridInit() + { + gridSelfManaged_ = false; + } + /// Initialize from a deck and/or an eclipse state and (logical cartesian) specified pore volumes. GridInit(const EclipseState& eclipse_state, const std::vector& porv) { - grid_.processEclipseFormat(eclipse_state.getInputGrid(), false, false, false, porv); + gridSelfManaged_ = true; + + grid_ = new Dune::CpGrid; + grid_->processEclipseFormat(eclipse_state.getInputGrid(), false, false, false, porv); } + + ~GridInit() + { + if (gridSelfManaged_) + delete grid_; + } + /// Access the created grid. Note that mutable access may be required for load balancing. Dune::CpGrid& grid() { - return grid_; + return *grid_; } + + /// set the grid from the outside + void setGrid(Dune::CpGrid& newGrid) + { + gridSelfManaged_ = false; + grid_ = &newGrid; + } + private: - Dune::CpGrid grid_; + Dune::CpGrid* grid_; + bool gridSelfManaged_; }; #endif // HAVE_OPM_GRID diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp index 015716f52..32fd09bed 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilEbos.hpp @@ -100,7 +100,8 @@ public: const bool has_disgas, const bool has_vapoil, const EclipseState& eclState, - BlackoilOutputWriterEbos& output_writer) + BlackoilOutputWriterEbos& output_writer, + const std::unordered_set& defunct_well_names) : ebosSimulator_(ebosSimulator), param_(param), model_param_(param), @@ -113,6 +114,7 @@ public: has_vapoil_(has_vapoil), terminal_output_(param.getDefault("output_terminal", true)), output_writer_(output_writer), + defunct_well_names_( defunct_well_names ), is_parallel_run_( false ) { DUNE_UNUSED_PARAMETER(eclState); @@ -224,7 +226,8 @@ public: props_.permeability(), dynamic_list_econ_limited, is_parallel_run_, - well_potentials ); + well_potentials, + defunct_well_names_ ); const Wells* wells = wells_manager.c_wells(); WellState well_state; @@ -724,6 +727,11 @@ protected: // output_writer OutputWriter& output_writer_; std::unique_ptr rateConverter_; + // The names of wells that should be defunct + // (e.g. in a parallel run when they are handeled by + // a different process) + std::unordered_set defunct_well_names_; + // Whether this a parallel simulation or not bool is_parallel_run_; diff --git a/opm/autodiff/StandardWellsDense.hpp b/opm/autodiff/StandardWellsDense.hpp index 0a7951085..c865713b4 100644 --- a/opm/autodiff/StandardWellsDense.hpp +++ b/opm/autodiff/StandardWellsDense.hpp @@ -92,14 +92,17 @@ enum WellVariablePositions { , fluid_(nullptr) , active_(nullptr) , vfp_properties_(nullptr) - , well_perforation_densities_(wells_arg->well_connpos[wells_arg->number_of_wells]) - , well_perforation_pressure_diffs_(wells_arg->well_connpos[wells_arg->number_of_wells]) - , wellVariables_(wells_arg->number_of_wells * wells_arg->number_of_phases) - , F0_(wells_arg->number_of_wells * wells_arg->number_of_phases) + , well_perforation_densities_( wells_ ? wells_arg->well_connpos[wells_arg->number_of_wells] : 0) + , well_perforation_pressure_diffs_( wells_ ? wells_arg->well_connpos[wells_arg->number_of_wells] : 0) + , wellVariables_( wells_ ? (wells_arg->number_of_wells * wells_arg->number_of_phases) : 0) + , F0_(wells_ ? (wells_arg->number_of_wells * wells_arg->number_of_phases) : 0 ) { - invDuneD_.setBuildMode( Mat::row_wise ); - duneC_.setBuildMode( Mat::row_wise ); - duneB_.setBuildMode( Mat::row_wise ); + if( wells_ ) + { + invDuneD_.setBuildMode( Mat::row_wise ); + duneC_.setBuildMode( Mat::row_wise ); + duneB_.setBuildMode( Mat::row_wise ); + } } void init(const BlackoilPropsAdInterface* fluid_arg, @@ -709,6 +712,10 @@ enum WellVariablePositions { std::vector residual() { + if( ! wellsActive() ) + { + return std::vector(); + } const int np = numPhases(); const int nw = wells().number_of_wells;