From a814aa618d86a16419bf5eddbf51a8065e857824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 26 Nov 2012 11:04:23 +0100 Subject: [PATCH] Add eclipse format output to SteadyStateUpscalerImplicit. Option activated with output_ecl=true. Requires libert support in opm-core. If opm-core has not been compiled with the necessary --with-ert= option, the program should abort upon trying to write the output. Hopefully this enables to keep ERT-detection macros and the like out of this module. --- .../upscaling/SteadyStateUpscalerImplicit.hpp | 85 ++++++++++--------- .../SteadyStateUpscalerImplicit_impl.hpp | 26 ++++++ 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/dune/upscaling/SteadyStateUpscalerImplicit.hpp b/dune/upscaling/SteadyStateUpscalerImplicit.hpp index 51011de..18ededa 100644 --- a/dune/upscaling/SteadyStateUpscalerImplicit.hpp +++ b/dune/upscaling/SteadyStateUpscalerImplicit.hpp @@ -39,6 +39,7 @@ #include #include #include +#include #include namespace Dune @@ -51,7 +52,7 @@ namespace Dune class SteadyStateUpscalerImplicit : public UpscalerBase { public: - // ------- Typedefs and enums ------- + // ------- Typedefs and enums ------- typedef UpscalerBase Super; typedef typename Super::permtensor_t permtensor_t; @@ -59,32 +60,32 @@ namespace Dune typedef typename UpscalerBase::GridType GridType; enum { Dimension = UpscalerBase::Dimension }; - // ------- Methods ------- + // ------- Methods ------- - /// Default constructor. - SteadyStateUpscalerImplicit(); + /// Default constructor. + SteadyStateUpscalerImplicit(); - /// Does a steady-state upscaling. - /// @param flow_direction The cardinal direction in which to impose a pressure gradient for the purpose of converging to steady state. - /// @param initial_saturation the initial saturation profile for the steady-state computation. - /// The vector must have size equal to the number of cells in the grid. - /// @param boundary_saturation the saturation of fluid flowing in across the boundary, - /// only needed for nonperiodic upscaling. - /// @param pressure_drop the pressure drop in Pascal over the domain. - /// @param upscaled_perm typically the output of upscaleSinglePhase(). - /// @return the upscaled relative permeability matrices of both phases. - /// The relative permeability matrix, call it k, is such that if K_w is the phase - /// permeability and K the absolute permeability, K_w = k*K. + /// Does a steady-state upscaling. + /// @param flow_direction The cardinal direction in which to impose a pressure gradient for the purpose of converging to steady state. + /// @param initial_saturation the initial saturation profile for the steady-state computation. + /// The vector must have size equal to the number of cells in the grid. + /// @param boundary_saturation the saturation of fluid flowing in across the boundary, + /// only needed for nonperiodic upscaling. + /// @param pressure_drop the pressure drop in Pascal over the domain. + /// @param upscaled_perm typically the output of upscaleSinglePhase(). + /// @return the upscaled relative permeability matrices of both phases. + /// The relative permeability matrix, call it k, is such that if K_w is the phase + /// permeability and K the absolute permeability, K_w = k*K. std::pair upscaleSteadyState(const int flow_direction, const std::vector& initial_saturation, const double boundary_saturation, const double pressure_drop, const permtensor_t& upscaled_perm,bool& success); - /// Accessor for the steady state saturation field. This is empty until - /// upscaleSteadyState() is called, at which point it will - /// contain the last computed (steady) saturation state. - const std::vector& lastSaturationState() const; + /// Accessor for the steady state saturation field. This is empty until + /// upscaleSteadyState() is called, at which point it will + /// contain the last computed (steady) saturation state. + const std::vector& lastSaturationState() const; /// Computes the upscaled saturation corresponding to the saturation field /// returned by lastSaturationState(). Does this by computing total saturated @@ -98,32 +99,34 @@ namespace Dune protected: - // ------- Typedefs ------- + // ------- Typedefs ------- typedef typename Traits::template TransportSolver::Type TransportSolver; - // ------- Methods ------- - template - void computeInOutFlows(std::pair& water_inout, - std::pair& oil_inout, - const FlowSol& flow_solution, - const std::vector& saturations) const; - /// Override from superclass. - virtual void initImpl(const Opm::parameter::ParameterGroup& param); + // ------- Methods ------- + template + void computeInOutFlows(std::pair& water_inout, + std::pair& oil_inout, + const FlowSol& flow_solution, + const std::vector& saturations) const; + /// Override from superclass. + virtual void initImpl(const Opm::parameter::ParameterGroup& param); - // ------- Data members ------- - std::vector last_saturation_state_; - bool output_vtk_; - bool print_inoutflows_; - int simulation_steps_; - double init_stepsize_; - double relperm_threshold_; - double maximum_mobility_contrast_; - double sat_change_year_; - int max_it_; - double max_stepsize_; - double dt_sat_tol_; - TransportSolver transport_solver_; + // ------- Data members ------- + std::vector last_saturation_state_; + bool output_vtk_; + bool output_ecl_; + bool print_inoutflows_; + int simulation_steps_; + double init_stepsize_; + double relperm_threshold_; + double maximum_mobility_contrast_; + double sat_change_year_; + int max_it_; + double max_stepsize_; + double dt_sat_tol_; + TransportSolver transport_solver_; + GridAdapter grid_adapter_; }; } // namespace Dune diff --git a/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp b/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp index 2964620..5132f45 100644 --- a/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp +++ b/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include namespace Dune @@ -54,6 +56,7 @@ namespace Dune inline SteadyStateUpscalerImplicit::SteadyStateUpscalerImplicit() : Super(), output_vtk_(false), + output_ecl_(false), print_inoutflows_(false), simulation_steps_(10), init_stepsize_(10), @@ -74,6 +77,10 @@ namespace Dune { Super::initImpl(param); output_vtk_ = param.getDefault("output_vtk", output_vtk_); + output_ecl_ = param.getDefault("output_ecl", output_ecl_); + if (output_ecl_) { + grid_adapter_.init(Super::grid()); + } print_inoutflows_ = param.getDefault("print_inoutflows", print_inoutflows_); simulation_steps_ = param.getDefault("simulation_steps", simulation_steps_); init_stepsize_ = Opm::unit::convert::from(param.getDefault("init_stepsize", init_stepsize_), @@ -177,6 +184,9 @@ namespace Dune bool stationary = false; int it_count = 0; double stepsize = init_stepsize_; + double ecl_time = 0.0; + std::vector ecl_sat; + std::vector ecl_press; std::vector init_saturation(saturation); while ((!stationary) && (it_count < max_it_)) { // && transport_cost < max_transport_cost_) // Run transport solver. @@ -214,6 +224,22 @@ namespace Dune + '-' + boost::lexical_cast(flow_direction) + '-' + boost::lexical_cast(it_count)); } + if (output_ecl_) { + const char* fd = "xyz"; + std::string basename = std::string("ecldump-steadystate") + + '-' + boost::lexical_cast(boundary_saturation) + + '-' + boost::lexical_cast(fd[flow_direction]) + + '-' + boost::lexical_cast(pressure_drop); + Opm::toBothSat(saturation, ecl_sat); + getCellPressure(ecl_press, this->ginterf_, this->flow_solver_.getSolution()); + Opm::DataMap datamap; + datamap["saturation"] = &ecl_sat; + datamap["pressure"] = &ecl_press; + ecl_time += stepsize; + boost::posix_time::ptime ecl_startdate( boost::gregorian::date(2012, 1, 1) ); + boost::posix_time::ptime ecl_curdate = ecl_startdate + boost::posix_time::seconds(int(ecl_time)); + Opm::writeECLData(*grid_adapter_.c_grid(), datamap, it_count, ecl_time, ecl_curdate, "./", basename); + } // Comparing old to new. int num_cells = saturation.size(); double maxdiff = 0.0;