From 668f5d63a84a7366b8c8a900b5630a6ff078c6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 21 Nov 2012 10:54:10 +0100 Subject: [PATCH 1/3] Comment and formatting improvements. --- .../SteadyStateUpscalerImplicit_impl.hpp | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp b/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp index 427141c..2964620 100644 --- a/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp +++ b/dune/upscaling/SteadyStateUpscalerImplicit_impl.hpp @@ -137,7 +137,8 @@ namespace Dune const std::vector& 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 saturation_old = saturation; bool stationary = false; - int it_count=0; - double stepsize=init_stepsize_; - - + int it_count = 0; + double stepsize = init_stepsize_; std::vector 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 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. From 37e0d2148b0fe0e356f201cc7df9fd1e35f02a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 21 Nov 2012 10:55:22 +0100 Subject: [PATCH 2/3] Use input parameters outputOil and outputWater earlier. Avoid aborting due to lack of these paramteters at the end of a long run. --- dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp b/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp index 7d765f4..50600a5 100644 --- a/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp +++ b/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp @@ -225,12 +225,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]); } @@ -261,14 +261,14 @@ namespace Dune } std::cout << krw_out << std::endl; std::cout << kro_out << std::endl; - if (param.get("outputWater") != "") { + 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 (param.get("outputOil") != "") { + if (!kro_filename.empty()) { // write water results to file std::ofstream kro_outfile; kro_outfile.open(kro_filename.c_str()); From ca0c3eb5f2a1cc0f4f84d79dcc7037521f4566df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 21 Nov 2012 13:41:44 +0100 Subject: [PATCH 3/3] Write output during run. Fix init order. Init order fixed so that the "unused parameters" message is correct. --- .../SteadyStateUpscalerManagerImplicit.hpp | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp b/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp index 50600a5..d27de1a 100644 --- a/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp +++ b/dune/upscaling/SteadyStateUpscalerManagerImplicit.hpp @@ -181,39 +181,35 @@ namespace Dune // Print the saturations and pressure drops. // writeControl(std::cout, saturations, all_pdrops); - // Initialize upscaler. - //typedef SteadyStateUpscaler 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("kr_filename", "upscaled_relperm"); std::string krwtmpname = kr_filename + "_water"; std::string krotmpname = kr_filename + "_oil"; std::string krw_filename = param.getDefault("outputWater", krwtmpname); std::string kro_filename = param.getDefault("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); @@ -259,22 +255,22 @@ namespace Dune } } - 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(); - } + // 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(); + // } } };