2013-04-10 05:56:14 -05:00
|
|
|
#include "config.h"
|
2014-04-17 04:47:50 -05:00
|
|
|
|
2012-03-27 03:56:32 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
2012-04-11 08:29:58 -05:00
|
|
|
|
2013-03-18 06:47:23 -05:00
|
|
|
#include <opm/core/simulator/initState.hpp>
|
2012-06-14 07:02:22 -05:00
|
|
|
#include <opm/core/simulator/SimulatorTimer.hpp>
|
2012-06-05 08:42:49 -05:00
|
|
|
#include <opm/core/wells/WellsManager.hpp>
|
2013-03-18 04:16:46 -05:00
|
|
|
#include <opm/core/grid/GridManager.hpp>
|
2012-04-10 07:47:29 -05:00
|
|
|
#include <opm/core/pressure/IncompTpfa.hpp>
|
2013-03-14 04:29:42 -05:00
|
|
|
#include <opm/core/props/IncompPropertiesFromDeck.hpp>
|
2013-03-18 04:33:34 -05:00
|
|
|
#include <opm/core/wells.h>
|
2012-04-11 08:29:58 -05:00
|
|
|
#include <opm/core/grid.h>
|
|
|
|
#include <opm/core/utility/miscUtilities.hpp>
|
2012-06-05 08:42:49 -05:00
|
|
|
#include <opm/core/simulator/TwophaseState.hpp>
|
2012-06-12 08:28:53 -05:00
|
|
|
#include <opm/core/simulator/WellState.hpp>
|
2012-04-11 08:29:58 -05:00
|
|
|
#include <opm/core/pressure/FlowBCManager.hpp>
|
2012-04-16 05:18:37 -05:00
|
|
|
#include <opm/core/linalg/LinearSolverFactory.hpp>
|
2013-03-14 04:29:42 -05:00
|
|
|
#include <opm/core/props/rock/RockCompressibility.hpp>
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2016-03-16 20:57:59 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
2014-03-25 12:57:58 -05:00
|
|
|
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
2014-04-17 04:47:50 -05:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2014-03-25 12:57:58 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
|
|
|
|
2012-05-07 08:51:54 -05:00
|
|
|
int main(int argc, char** argv)
|
2013-09-02 10:35:33 -05:00
|
|
|
try
|
2012-05-07 08:51:54 -05:00
|
|
|
{
|
2012-03-27 03:56:32 -05:00
|
|
|
using namespace Opm::parameter;
|
|
|
|
using namespace Opm;
|
2012-05-07 08:51:54 -05:00
|
|
|
ParameterGroup parameters(argc, argv, false);
|
|
|
|
std::string file_name = parameters.getDefault<std::string > ("inputdeck", "data.data");
|
2012-04-10 07:47:29 -05:00
|
|
|
|
2012-05-07 06:29:52 -05:00
|
|
|
SimulatorTimer simtimer;
|
|
|
|
simtimer.init(parameters);
|
|
|
|
|
2012-03-27 03:56:32 -05:00
|
|
|
// Read input file
|
2016-03-16 20:57:59 -05:00
|
|
|
ParseContext parseContext;
|
2016-10-13 09:03:35 -05:00
|
|
|
Opm::Parser parser;
|
|
|
|
Opm::Deck deck = parser.parseFile(file_name , parseContext);
|
|
|
|
Opm::EclipseState eclipseState(deck , parseContext);
|
2012-03-27 03:56:32 -05:00
|
|
|
std::cout << "Done!" << std::endl;
|
2014-04-17 04:47:50 -05:00
|
|
|
|
2012-03-27 03:56:32 -05:00
|
|
|
// Setup grid
|
2016-10-13 09:03:35 -05:00
|
|
|
GridManager grid(eclipseState.getInputGrid());
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2013-09-25 08:11:14 -05:00
|
|
|
// Define rock and fluid properties
|
2014-06-06 07:07:14 -05:00
|
|
|
IncompPropertiesFromDeck incomp_properties(deck, eclipseState, *grid.c_grid());
|
2016-12-20 05:24:27 -06:00
|
|
|
RockCompressibility rock_comp(eclipseState);
|
2012-05-07 06:29:52 -05:00
|
|
|
|
2013-09-25 08:11:14 -05:00
|
|
|
// Finally handle the wells
|
2017-01-26 10:36:00 -06:00
|
|
|
WellsManager wells(eclipseState , 0 , *grid.c_grid());
|
2013-09-25 08:11:14 -05:00
|
|
|
|
|
|
|
double gravity[3] = {0.0, 0.0, parameters.getDefault<double>("gravity", 0.0)};
|
2012-04-16 05:18:37 -05:00
|
|
|
Opm::LinearSolverFactory linsolver(parameters);
|
2012-06-12 08:28:53 -05:00
|
|
|
double nl_pressure_residual_tolerance = 1e-8;
|
|
|
|
double nl_pressure_change_tolerance = 0.0;
|
|
|
|
int nl_pressure_maxiter = 100;
|
|
|
|
if (rock_comp.isActive()) {
|
|
|
|
nl_pressure_residual_tolerance = parameters.getDefault("nl_pressure_residual_tolerance", 1e-8);
|
|
|
|
nl_pressure_change_tolerance = parameters.getDefault("nl_pressure_change_tolerance", 1.0); // in Pascal
|
|
|
|
nl_pressure_maxiter = parameters.getDefault("nl_pressure_maxiter", 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<double> src;
|
|
|
|
Opm::FlowBCManager bcs;
|
2012-04-16 05:18:37 -05:00
|
|
|
|
|
|
|
// EXPERIMENT_ISTL
|
2012-06-12 08:28:53 -05:00
|
|
|
IncompTpfa pressure_solver(*grid.c_grid(), incomp_properties, &rock_comp, linsolver,
|
|
|
|
nl_pressure_residual_tolerance, nl_pressure_change_tolerance, nl_pressure_maxiter,
|
|
|
|
gravity, wells.c_wells(), src, bcs.c_bcs());
|
2012-05-07 08:51:54 -05:00
|
|
|
|
|
|
|
|
2012-04-11 08:29:58 -05:00
|
|
|
std::vector<int> all_cells;
|
2012-05-07 08:51:54 -05:00
|
|
|
for (int i = 0; i < grid.c_grid()->number_of_cells; i++) {
|
2012-04-11 08:29:58 -05:00
|
|
|
all_cells.push_back(i);
|
|
|
|
}
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2016-02-25 14:47:47 -06:00
|
|
|
Opm::TwophaseState state( grid.c_grid()->number_of_cells , grid.c_grid()->number_of_faces );
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2014-04-26 05:03:07 -05:00
|
|
|
initStateFromDeck(*grid.c_grid(), incomp_properties, deck, gravity[2], state);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2012-06-12 08:28:53 -05:00
|
|
|
Opm::WellState well_state;
|
|
|
|
well_state.init(wells.c_wells(), state);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2012-06-12 08:28:53 -05:00
|
|
|
pressure_solver.solve(simtimer.currentStepLength(), state, well_state);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2012-05-03 05:29:18 -05:00
|
|
|
const int np = incomp_properties.numPhases();
|
|
|
|
std::vector<double> fractional_flows(grid.c_grid()->number_of_cells*np, 0.0);
|
2012-05-08 05:23:58 -05:00
|
|
|
computeFractionalFlow(incomp_properties, all_cells, state.saturation(), fractional_flows);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2012-05-03 05:29:18 -05:00
|
|
|
// This will be refactored into a separate function once done
|
|
|
|
std::vector<double> well_resflows(wells.c_wells()->number_of_wells*np, 0.0);
|
2012-06-12 08:28:53 -05:00
|
|
|
computePhaseFlowRatesPerWell(*wells.c_wells(), well_state.perfRates(), fractional_flows, well_resflows);
|
2012-05-03 05:29:18 -05:00
|
|
|
// We approximate (for _testing_ that resflows = surfaceflows)
|
2012-06-12 08:28:53 -05:00
|
|
|
for (int wc_iter = 0; wc_iter < 10 && !wells.conditionsMet(well_state.bhp(), well_resflows, well_resflows); ++wc_iter) {
|
2012-04-25 09:14:40 -05:00
|
|
|
std::cout << "Conditions not met for well, trying again" << std::endl;
|
2012-06-12 08:28:53 -05:00
|
|
|
pressure_solver.solve(simtimer.currentStepLength(), state, well_state);
|
2012-04-25 09:14:40 -05:00
|
|
|
std::cout << "Solved" << std::endl;
|
|
|
|
|
2012-06-12 08:28:53 -05:00
|
|
|
computePhaseFlowRatesPerWell(*wells.c_wells(), well_state.perfRates(), fractional_flows, well_resflows);
|
2012-04-25 09:14:40 -05:00
|
|
|
}
|
2012-04-23 06:24:47 -05:00
|
|
|
|
2012-05-03 05:29:18 -05:00
|
|
|
#if 0
|
2012-04-23 06:24:47 -05:00
|
|
|
std::vector<double> porevol;
|
|
|
|
computePorevolume(*grid->c_grid(), incomp_properties, porevol);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
|
|
|
|
2012-04-23 06:24:47 -05:00
|
|
|
|
|
|
|
TwophaseFluid fluid(incomp_properties);
|
2016-03-16 20:57:59 -05:00
|
|
|
TransportContextl model(fluid, *grid->c_grid(), porevol, gravity[2], true);
|
2012-04-23 06:24:47 -05:00
|
|
|
|
|
|
|
TransportSolver tsolver(model);
|
|
|
|
|
|
|
|
TransportSource* tsrc = create_transport_source(2, 2);
|
2012-05-07 08:51:54 -05:00
|
|
|
double ssrc[] = {1.0, 0.0};
|
|
|
|
double ssink[] = {0.0, 1.0};
|
|
|
|
double zdummy[] = {0.0, 0.0};
|
|
|
|
|
2012-04-12 07:25:39 -05:00
|
|
|
{
|
2012-04-23 06:24:47 -05:00
|
|
|
int well_cell_index = 0;
|
|
|
|
for (int well = 0; well < wells.c_wells()->number_of_wells; ++well) {
|
2012-05-07 08:51:54 -05:00
|
|
|
for (int cell = wells.c_wells()->well_connpos[well]; cell < wells.c_wells()->well_connpos[well + 1]; ++cell) {
|
2012-04-23 06:24:47 -05:00
|
|
|
if (well_rate_per_cell[well_cell_index] > 0.0) {
|
2012-05-07 08:51:54 -05:00
|
|
|
append_transport_source(well_cell_index, 2, 0,
|
2012-04-23 06:24:47 -05:00
|
|
|
well_rate_per_cell[well_cell_index], ssrc, zdummy, tsrc);
|
|
|
|
} else if (well_rate_per_cell[well_cell_index] < 0.0) {
|
2012-05-07 08:51:54 -05:00
|
|
|
append_transport_source(well_cell_index, 2, 0,
|
2012-04-23 06:24:47 -05:00
|
|
|
well_rate_per_cell[well_cell_index], ssink, zdummy, tsrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 07:25:39 -05:00
|
|
|
}
|
2012-04-23 06:24:47 -05:00
|
|
|
|
|
|
|
tsolver.solve(*grid->c_grid(), tsrc, stepsize, ctrl, state, linsolve, rpt);
|
2012-05-07 08:51:54 -05:00
|
|
|
|
2012-04-23 06:24:47 -05:00
|
|
|
Opm::computeInjectedProduced(*props, state.saturation(), src, stepsize, injected, produced);
|
|
|
|
#endif
|
2012-03-27 03:56:32 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2013-09-02 10:35:33 -05:00
|
|
|
catch (const std::exception &e) {
|
|
|
|
std::cerr << "Program threw an exception: " << e.what() << "\n";
|
|
|
|
throw;
|
|
|
|
}
|