Change msim simulator to not hold Schedule object
This commit is contained in:
parent
261f7c3c03
commit
59b4ca4b20
@ -17,12 +17,37 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/output/eclipse/EclipseIO.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
||||
|
||||
#include <opm/msim/msim.hpp>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Opm::msim msim(argv[1]);
|
||||
msim.run();
|
||||
std::string deck_file = argv[1];
|
||||
Opm::Parser parser;
|
||||
Opm::ParseContext parse_context;
|
||||
Opm::ErrorGuard error_guard;
|
||||
|
||||
Opm::Deck deck = parser.parseFile(deck_file, parse_context, error_guard);
|
||||
Opm::EclipseState state(deck, parse_context, error_guard);
|
||||
Opm::Schedule schedule(deck, state.getInputGrid(), state.get3DProperties(), state.runspec(), parse_context, error_guard);
|
||||
Opm::SummaryConfig summary_config(deck, schedule, state.getTableManager(), parse_context, error_guard);
|
||||
|
||||
if (error_guard) {
|
||||
error_guard.dump();
|
||||
error_guard.terminate();
|
||||
}
|
||||
|
||||
Opm::msim msim(state);
|
||||
Opm::EclipseIO io(state, state.getInputGrid(), schedule, summary_config);
|
||||
msim.run(schedule, io);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
@ -18,7 +19,8 @@
|
||||
namespace Opm {
|
||||
|
||||
class EclipseIO;
|
||||
|
||||
class ParseContext;
|
||||
class Parser;
|
||||
|
||||
class msim {
|
||||
|
||||
@ -26,23 +28,19 @@ public:
|
||||
using well_rate_function = double(const EclipseState&, const Schedule&, const data::Solution&, size_t report_step, double seconds_elapsed);
|
||||
using solution_function = void(const EclipseState&, const Schedule&, data::Solution&, size_t report_step, double seconds_elapsed);
|
||||
|
||||
msim(const std::string& deck_file);
|
||||
msim(const std::string& deck_file, const Parser& parser, const ParseContext& parse_context);
|
||||
msim(const EclipseState& state);
|
||||
|
||||
void well_rate(const std::string& well, data::Rates::opt rate, std::function<well_rate_function> func);
|
||||
void solution(const std::string& field, std::function<solution_function> func);
|
||||
void run();
|
||||
void run(const Schedule& schedule, EclipseIO& io);
|
||||
private:
|
||||
|
||||
void run_step(data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const;
|
||||
void run_step(data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const;
|
||||
void run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const;
|
||||
void run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const;
|
||||
void output(size_t report_step, bool substep, double seconds_elapsed, const data::Solution& sol, const data::Wells& well_data, EclipseIO& io) const;
|
||||
void simulate(data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const;
|
||||
void simulate(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const;
|
||||
|
||||
Deck deck;
|
||||
EclipseState state;
|
||||
Schedule schedule;
|
||||
SummaryConfig summary_config;
|
||||
|
||||
std::map<std::string, std::map<data::Rates::opt, std::function<well_rate_function>>> well_rates;
|
||||
std::map<std::string, std::function<solution_function>> solutions;
|
||||
|
@ -26,46 +26,36 @@
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/msim/msim.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
msim::msim(const std::string& deck_file, const Parser& parser, const ParseContext& parse_context) :
|
||||
deck(parser.parseFile(deck_file, parse_context)),
|
||||
state(deck, parse_context),
|
||||
schedule(deck, state.getInputGrid(), state.get3DProperties(), state.runspec(), parse_context),
|
||||
summary_config(deck, schedule, state.getTableManager(), parse_context)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
msim::msim(const std::string& deck_file) :
|
||||
msim(deck_file, Parser(), ParseContext())
|
||||
msim::msim(const EclipseState& state) :
|
||||
state(state)
|
||||
{}
|
||||
|
||||
|
||||
void msim::run() {
|
||||
void msim::run(const Schedule& schedule, EclipseIO& io) {
|
||||
const double week = 7 * 86400;
|
||||
EclipseIO io(this->state, this->state.getInputGrid(), this->schedule, this->summary_config);
|
||||
data::Solution sol;
|
||||
data::Wells well_data;
|
||||
|
||||
io.writeInitial();
|
||||
for (size_t report_step = 1; report_step < this->schedule.size(); report_step++) {
|
||||
double time_step = std::min(week, 0.5*this->schedule.stepLength(report_step - 1));
|
||||
run_step(sol, well_data, report_step, time_step, io);
|
||||
for (size_t report_step = 1; report_step < schedule.size(); report_step++) {
|
||||
double time_step = std::min(week, 0.5*schedule.stepLength(report_step - 1));
|
||||
run_step(schedule, sol, well_data, report_step, time_step, io);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void msim::run_step(data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const {
|
||||
this->run_step(sol, well_data, report_step, this->schedule.stepLength(report_step - 1), io);
|
||||
void msim::run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, EclipseIO& io) const {
|
||||
this->run_step(schedule, sol, well_data, report_step, schedule.stepLength(report_step - 1), io);
|
||||
}
|
||||
|
||||
|
||||
void msim::run_step(data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const {
|
||||
double start_time = this->schedule.seconds(report_step - 1);
|
||||
double end_time = this->schedule.seconds(report_step);
|
||||
void msim::run_step(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double dt, EclipseIO& io) const {
|
||||
double start_time = schedule.seconds(report_step - 1);
|
||||
double end_time = schedule.seconds(report_step);
|
||||
double seconds_elapsed = start_time;
|
||||
|
||||
while (seconds_elapsed < end_time) {
|
||||
@ -73,7 +63,7 @@ void msim::run_step(data::Solution& sol, data::Wells& well_data, size_t report_s
|
||||
if ((seconds_elapsed + time_step) > end_time)
|
||||
time_step = end_time - seconds_elapsed;
|
||||
|
||||
this->simulate(sol, well_data, report_step, seconds_elapsed, time_step);
|
||||
this->simulate(schedule, sol, well_data, report_step, seconds_elapsed, time_step);
|
||||
|
||||
seconds_elapsed += time_step;
|
||||
this->output(report_step,
|
||||
@ -99,10 +89,10 @@ void msim::output(size_t report_step, bool substep, double seconds_elapsed, cons
|
||||
}
|
||||
|
||||
|
||||
void msim::simulate(data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const {
|
||||
void msim::simulate(const Schedule& schedule, data::Solution& sol, data::Wells& well_data, size_t report_step, double seconds_elapsed, double time_step) const {
|
||||
for (const auto& sol_pair : this->solutions) {
|
||||
auto func = sol_pair.second;
|
||||
func(this->state, this->schedule, sol, report_step, seconds_elapsed + time_step);
|
||||
func(this->state, schedule, sol, report_step, seconds_elapsed + time_step);
|
||||
}
|
||||
|
||||
for (const auto& well_pair : this->well_rates) {
|
||||
@ -112,8 +102,12 @@ void msim::simulate(data::Solution& sol, data::Wells& well_data, size_t report_s
|
||||
auto rate = rate_pair.first;
|
||||
auto func = rate_pair.second;
|
||||
|
||||
well.rates.set(rate, func(this->state, this->schedule, sol, report_step, seconds_elapsed + time_step));
|
||||
well.rates.set(rate, func(this->state, schedule, sol, report_step, seconds_elapsed + time_step));
|
||||
}
|
||||
|
||||
// This is complete bogus; a temporary fix to pass an assert() in the
|
||||
// the restart output.
|
||||
well.connections.resize(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,12 @@
|
||||
|
||||
#include <opm/msim/msim.hpp>
|
||||
#include <opm/output/data/Wells.hpp>
|
||||
#include <opm/output/eclipse/EclipseIO.hpp>
|
||||
#include <opm/parser/eclipse/Units/Units.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@ -56,12 +61,20 @@ void pressure(const EclipseState& es, const Schedule& sched, data::Solution& sol
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RUN) {
|
||||
msim msim("SPE1CASE1.DATA");
|
||||
Parser parser;
|
||||
Deck deck = parser.parseFile("SPE1CASE1.DATA");
|
||||
EclipseState state(deck);
|
||||
Schedule schedule(deck, state.getInputGrid(), state.get3DProperties(), state.runspec());
|
||||
SummaryConfig summary_config(deck, schedule, state.getTableManager());
|
||||
msim msim(state);
|
||||
|
||||
msim.well_rate("PROD", data::Rates::opt::oil, prod_opr);
|
||||
msim.solution("PRESSURE", pressure);
|
||||
{
|
||||
test_work_area_type * work_area = test_work_area_alloc("test_msim");
|
||||
msim.run();
|
||||
EclipseIO io(state, state.getInputGrid(), schedule, summary_config);
|
||||
|
||||
msim.run(schedule, io);
|
||||
|
||||
for (const auto& fname : {"SPE1CASE1.INIT", "SPE1CASE1.UNRST", "SPE1CASE1.EGRID", "SPE1CASE1.SMSPEC", "SPE1CASE1.UNSMRY"})
|
||||
BOOST_CHECK( util_is_file( fname ));
|
||||
|
Loading…
Reference in New Issue
Block a user