Skip to content

Commit

Permalink
Merge pull request #15 from atgeirr/master
Browse files Browse the repository at this point in the history
Add eclipse format output to SteadyStateUpscalerImplicit
  • Loading branch information
atgeirr committed Nov 26, 2012
2 parents 2687339 + a814aa6 commit 77ff7dc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 45 deletions.
93 changes: 48 additions & 45 deletions dune/upscaling/SteadyStateUpscalerImplicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <dune/upscaling/UpscalerBase.hpp>
#include <dune/porsol/euler/EulerUpstream.hpp>
#include <dune/porsol/euler/ImplicitCapillarity.hpp>
#include <opm/core/GridAdapter.hpp>
#include <boost/array.hpp>

namespace Dune
Expand All @@ -51,40 +52,40 @@ namespace Dune
class SteadyStateUpscalerImplicit : public UpscalerBase<Traits>
{
public:
// ------- Typedefs and enums -------
// ------- Typedefs and enums -------

typedef UpscalerBase<Traits> Super;
typedef typename Super::permtensor_t permtensor_t;
typedef typename UpscalerBase<Traits>::GridInterface GridInterface;
typedef typename UpscalerBase<Traits>::GridType GridType;
enum { Dimension = UpscalerBase<Traits>::Dimension };

// ------- Methods -------

/// 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.
// ------- Methods -------

/// 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.
std::pair<permtensor_t, permtensor_t> upscaleSteadyState(const int flow_direction,
const std::vector<double>& 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<double>& 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<double>& lastSaturationState() const;

/// Computes the upscaled saturation corresponding to the saturation field
/// returned by lastSaturationState(). Does this by computing total saturated
Expand All @@ -98,32 +99,34 @@ namespace Dune


protected:
// ------- Typedefs -------
// ------- Typedefs -------
typedef typename Traits::template TransportSolver<GridInterface, typename Super::BCs>::Type TransportSolver;

// ------- Methods -------
template <class FlowSol>
void computeInOutFlows(std::pair<double, double>& water_inout,
std::pair<double, double>& oil_inout,
const FlowSol& flow_solution,
const std::vector<double>& saturations) const;
/// Override from superclass.
virtual void initImpl(const Opm::parameter::ParameterGroup& param);


// ------- Data members -------
std::vector<double> 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_;
// ------- Methods -------
template <class FlowSol>
void computeInOutFlows(std::pair<double, double>& water_inout,
std::pair<double, double>& oil_inout,
const FlowSol& flow_solution,
const std::vector<double>& saturations) const;
/// Override from superclass.
virtual void initImpl(const Opm::parameter::ParameterGroup& param);


// ------- Data members -------
std::vector<double> 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
Expand Down
26 changes: 26 additions & 0 deletions dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <dune/porsol/common/ReservoirPropertyFixedMobility.hpp>
#include <dune/porsol/euler/MatchSaturatedVolumeFunctor.hpp>
#include <opm/core/utility/Units.hpp>
#include <opm/core/utility/writeECLData.hpp>
#include <opm/core/utility/miscUtilities.hpp>
#include <algorithm>

namespace Dune
Expand All @@ -54,6 +56,7 @@ namespace Dune
inline SteadyStateUpscalerImplicit<Traits>::SteadyStateUpscalerImplicit()
: Super(),
output_vtk_(false),
output_ecl_(false),
print_inoutflows_(false),
simulation_steps_(10),
init_stepsize_(10),
Expand All @@ -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_),
Expand Down Expand Up @@ -177,6 +184,9 @@ namespace Dune
bool stationary = false;
int it_count = 0;
double stepsize = init_stepsize_;
double ecl_time = 0.0;
std::vector<double> ecl_sat;
std::vector<double> ecl_press;
std::vector<double> init_saturation(saturation);
while ((!stationary) && (it_count < max_it_)) { // && transport_cost < max_transport_cost_)
// Run transport solver.
Expand Down Expand Up @@ -214,6 +224,22 @@ namespace Dune
+ '-' + boost::lexical_cast<std::string>(flow_direction)
+ '-' + boost::lexical_cast<std::string>(it_count));
}
if (output_ecl_) {
const char* fd = "xyz";
std::string basename = std::string("ecldump-steadystate")
+ '-' + boost::lexical_cast<std::string>(boundary_saturation)
+ '-' + boost::lexical_cast<std::string>(fd[flow_direction])
+ '-' + boost::lexical_cast<std::string>(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;
Expand Down

0 comments on commit 77ff7dc

Please sign in to comment.