diff --git a/opm/autodiff/FullyImplicitBlackoilSolver.cpp b/opm/autodiff/FullyImplicitBlackoilSolver.cpp index 687c2d2b7..38190071d 100644 --- a/opm/autodiff/FullyImplicitBlackoilSolver.cpp +++ b/opm/autodiff/FullyImplicitBlackoilSolver.cpp @@ -1006,10 +1006,16 @@ namespace { rq_[ actph ].mob = tr_mult * kr[ phase ] / mu; const ADB rho = fluidDensity(phase, state.pressure, state.rs, cells_); - const ADB gflux = grav_ * rho; ADB& head = rq_[ actph ].head; - head = transi*(ops_.ngrad * state.pressure) + gflux; + + // compute gravity potensial using the face average as in eclipse and MRST + const ADB rhoavg = ops_.caver * rho; + + const ADB dp = ops_.ngrad * state.pressure - geo_.gravity()[2] * (rhoavg * (ops_.ngrad * geo_.z().matrix())); + + head = transi*dp; + //head = transi*(ops_.ngrad * state.pressure) + gflux; UpwindSelector upwind(grid_, ops_, head.value()); diff --git a/opm/autodiff/GeoProps.hpp b/opm/autodiff/GeoProps.hpp index fbf646295..112cbc1de 100644 --- a/opm/autodiff/GeoProps.hpp +++ b/opm/autodiff/GeoProps.hpp @@ -46,6 +46,7 @@ namespace Opm : pvol_ (grid.number_of_cells) , trans_(grid.number_of_faces) , gpot_ (Vector::Zero(grid.cell_facepos[ grid.number_of_cells ], 1)) + , z_(grid.number_of_cells) { // Pore volume const typename Vector::Index nc = grid.number_of_cells; @@ -59,6 +60,12 @@ namespace Opm tpfa_htrans_compute(ug, props.permeability(), htrans.data()); tpfa_trans_compute (ug, htrans.data() , trans_.data()); + // Compute z coordinates + for (int c = 0; c(file, "\n")); } } + static void outputWellStateMatlab(const Opm::WellState& well_state, + const int step, + const std::string& output_dir) + { + Opm::DataMap dm; + dm["bhp"] = &well_state.bhp(); + dm["wellrates"] = &well_state.wellRates(); + // Write data (not grid) in Matlab format + for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { + std::ostringstream fname; + fname << output_dir << "/" << it->first; + boost::filesystem::path fpath = fname.str(); + try { + create_directories(fpath); + } + catch (...) { + OPM_THROW(std::runtime_error,"Creating directories failed: " << fpath); + } + fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; + std::ofstream file(fname.str().c_str()); + if (!file) { + OPM_THROW(std::runtime_error,"Failed to open " << fname.str()); + } + file.precision(15); + const std::vector& d = *(it->second); + std::copy(d.begin(), d.end(), std::ostream_iterator(file, "\n")); + } + } #if 0 static void outputWaterCut(const Opm::Watercut& watercut, @@ -341,6 +369,8 @@ namespace Opm outputStateVtk(grid_, state, timer.currentStepNum(), output_dir_); } outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_); + outputWellStateMatlab(well_state,timer.currentStepNum(), output_dir_); + } SimulatorReport sreport; @@ -455,6 +485,7 @@ namespace Opm outputStateVtk(grid_, state, timer.currentStepNum(), output_dir_); } outputStateMatlab(grid_, state, timer.currentStepNum(), output_dir_); + outputWellStateMatlab(well_state,timer.currentStepNum(), output_dir_); #if 0 outputWaterCut(watercut, output_dir_); if (wells_) {