Merge pull request #14 from atgeirr/master

Output during upscaling run
This commit is contained in:
Atgeirr Flø Rasmussen 2012-11-21 04:47:29 -08:00
commit 26873393af
2 changed files with 59 additions and 67 deletions

View File

@ -137,7 +137,8 @@ namespace Dune
const std::vector<double>& initial_saturation,
const double boundary_saturation,
const double pressure_drop,
const permtensor_t& upscaled_perm,bool& success)
const permtensor_t& upscaled_perm,
bool& success)
{
static int count = 0;
++count;
@ -171,28 +172,26 @@ namespace Dune
double max_mod = this->flow_solver_.postProcessFluxes();
std::cout << "Max mod = " << max_mod << std::endl;
// Do a run till steady state. For now, we just do some pressure and transport steps...
// Do a run till steady state.
std::vector<double> saturation_old = saturation;
bool stationary = false;
int it_count=0;
double stepsize=init_stepsize_;
int it_count = 0;
double stepsize = init_stepsize_;
std::vector<double> init_saturation(saturation);
while((!stationary) & (it_count < max_it_)){// & transport_cost < max_transport_cost_)
//for (int iter = 0; iter < simulation_steps_; ++iter) {
while ((!stationary) && (it_count < max_it_)) { // && transport_cost < max_transport_cost_)
// Run transport solver.
std::cout << "Running transport step " << it_count <<" with stepsize " << stepsize/Opm::unit::year << " year \n";
bool converged=transport_solver_.transportSolve(saturation, stepsize, gravity, this->flow_solver_.getSolution(), injection);
std::cout << "Running transport step " << it_count << " with stepsize "
<< stepsize/Opm::unit::year << " years." << std::endl;
bool converged = transport_solver_.transportSolve(saturation, stepsize, gravity,
this->flow_solver_.getSolution(), injection);
// Run pressure solver.
if(converged){
init_saturation=saturation;
/*
this->flow_solver_.solve(this->res_prop_, saturation, this->bcond_, src,
this->residual_tolerance_, this->linsolver_verbosity_, this->linsolver_type_);
*/
max_mod = this->flow_solver_.postProcessFluxes();
std::cout << "Max mod of fluxes= " << max_mod << std::endl;
if (converged) {
init_saturation = saturation;
// this->flow_solver_.solve(this->res_prop_, saturation, this->bcond_, src,
// this->residual_tolerance_, this->linsolver_verbosity_, this->linsolver_type_);
// max_mod = this->flow_solver_.postProcessFluxes();
// std::cout << "Max mod of fluxes= " << max_mod << std::endl;
this->flow_solver_.postProcessFluxes();
// Print in-out flows if requested.
if (print_inoutflows_) {
std::pair<double, double> w_io, o_io;
@ -221,27 +220,24 @@ namespace Dune
for (int i = 0; i < num_cells; ++i) {
maxdiff = std::max(maxdiff, std::fabs(saturation[i] - saturation_old[i]));
}
double ds_year=maxdiff*Opm::unit::year/stepsize;
double ds_year = maxdiff*Opm::unit::year/stepsize;
std::cout << "Maximum saturation change/year: " << ds_year << std::endl;
if( ds_year < sat_change_year_){
stationary=true;
if (ds_year < sat_change_year_) {
stationary = true;
}
if(maxdiff< dt_sat_tol_){
if (maxdiff< dt_sat_tol_) {
stepsize=std::min(max_stepsize_,2*stepsize);
}
}else{
} else {
std::cerr << "Cutting time step\n";
init_saturation = saturation_old;
stepsize=stepsize/2.0;
}
it_count+=1;
++it_count;
// Copy to old.
saturation_old = saturation;
}
success=stationary;
success = stationary;
// Compute phase mobilities.
// First: compute maximal mobilities.

View File

@ -181,39 +181,35 @@ namespace Dune
// Print the saturations and pressure drops.
// writeControl(std::cout, saturations, all_pdrops);
// Initialize upscaler.
//typedef SteadyStateUpscaler<Traits> Upscaler;
typedef typename Upscaler::permtensor_t permtensor_t;
Upscaler upscaler;
upscaler.init(param);
// First, compute an upscaled permeability.
permtensor_t upscaled_K = upscaler.upscaleSinglePhase();
permtensor_t upscaled_K_copy = upscaled_K;
upscaled_K_copy *= (1.0/(Opm::prefix::milli*Opm::unit::darcy));
std::cout.precision(15);
std::cout << "Upscaled K in millidarcy:\n" << upscaled_K_copy << std::endl;
std::cout << "Upscaled porosity: " << upscaler.upscalePorosity() << std::endl;
// Create output streams for upscaled relative permeabilities
std::string kr_filename = param.getDefault<std::string>("kr_filename", "upscaled_relperm");
std::string krwtmpname = kr_filename + "_water";
std::string krotmpname = kr_filename + "_oil";
std::string krw_filename = param.getDefault<std::string>("outputWater", krwtmpname);
std::string kro_filename = param.getDefault<std::string>("outputOil", krotmpname);
//std::ofstream krw_out(krw_filename.c_str());
//std::ofstream kro_out(kro_filename.c_str());
std::stringstream krw_out;
std::stringstream kro_out;
std::ofstream krw_out(krw_filename.c_str());
std::ofstream kro_out(kro_filename.c_str());
// std::stringstream krw_out;
// std::stringstream kro_out;
krw_out << "# Result from steady state upscaling" << std::endl;
krw_out << "# Pressuredrop Sw Krxx Kryy Krzz" << std::endl;
kro_out << "# Result from steady state upscaling" << std::endl;
kro_out << "# Pressuredrop Sw Krxx Kryy Krzz" << std::endl;
krw_out.precision(4); krw_out.setf(std::ios::scientific | std::ios::showpoint);
kro_out.precision(4); kro_out.setf(std::ios::scientific | std::ios::showpoint);
//#endif
// Initialize upscaler.
Upscaler upscaler;
upscaler.init(param);
// First, compute an upscaled permeability.
typedef typename Upscaler::permtensor_t permtensor_t;
permtensor_t upscaled_K = upscaler.upscaleSinglePhase();
permtensor_t upscaled_K_copy = upscaled_K;
upscaled_K_copy *= (1.0/(Opm::prefix::milli*Opm::unit::darcy));
std::cout.precision(15);
std::cout << "Upscaled K in millidarcy:\n" << upscaled_K_copy << std::endl;
std::cout << "Upscaled porosity: " << upscaler.upscalePorosity() << std::endl;
// Then, compute some upscaled relative permeabilities.
int num_cells = upscaler.grid().size(0);
@ -225,12 +221,12 @@ namespace Dune
if (start_from_cl) {
try {
upscaler.setToCapillaryLimit(saturations[i], init_sat);
}catch (...){
} catch (...) {
init_sat.resize(num_cells, saturations[i]);
std::cout << "Failed to initialize with capillary limit for s = " << saturations[i]
<< ". Init with uniform distribution." << std::endl;
}
} {
} else {
init_sat.resize(num_cells, saturations[i]);
}
@ -259,22 +255,22 @@ namespace Dune
}
}
std::cout << krw_out << std::endl;
std::cout << kro_out << std::endl;
if (param.get<std::string>("outputWater") != "") {
// write water results to file
std::ofstream krw_outfile;
krw_outfile.open(krw_filename.c_str(), std::ios::out | std::ios::trunc);
krw_outfile << krw_out.str();
krw_outfile.close();
}
if (param.get<std::string>("outputOil") != "") {
// write water results to file
std::ofstream kro_outfile;
kro_outfile.open(kro_filename.c_str());
kro_outfile << kro_out.str();
kro_outfile.close();
}
// std::cout << krw_out << std::endl;
// std::cout << kro_out << std::endl;
// if (!krw_filename.empty()) {
// // write water results to file
// std::ofstream krw_outfile;
// krw_outfile.open(krw_filename.c_str(), std::ios::out | std::ios::trunc);
// krw_outfile << krw_out.str();
// krw_outfile.close();
// }
// if (!kro_filename.empty()) {
// // write water results to file
// std::ofstream kro_outfile;
// kro_outfile.open(kro_filename.c_str());
// kro_outfile << kro_out.str();
// kro_outfile.close();
// }
}
};