Refactored some computations into seperate methods in wells_example.cpp

This commit is contained in:
Kjetil Olsen Lye 2012-05-08 11:04:15 +02:00
parent e522a8df83
commit be956f2a70
3 changed files with 80 additions and 33 deletions

View File

@ -120,29 +120,11 @@ int main(int argc, char** argv)
// This will be refactored into a separate function once done.
const int np = incomp_properties.numPhases();
std::vector<double> fractional_flows(grid.c_grid()->number_of_cells*np, 0.0);
for (int cell = 0; cell < grid.c_grid()->number_of_cells; ++cell) {
double phase_sum = 0.0;
for (int phase = 0; phase < np; ++phase) {
phase_sum += phase_mob[cell * np + phase];
}
for (int phase = 0; phase < np; ++phase) {
fractional_flows[cell * np + phase] = phase_mob[cell * np + phase] / phase_sum;
}
}
// End stuff that needs to be refactored into a seperated function
//computeFractionalFlow(incomp_properties, all_cells, state.saturation(), fractional_flows);
// This will be refactored into a separate function once done
std::vector<double> well_resflows(wells.c_wells()->number_of_wells*np, 0.0);
for (int wix = 0; wix < wells.c_wells()->number_of_wells; ++wix) {
for (int i = wells.c_wells()->well_connpos[wix]; i < wells.c_wells()->well_connpos[wix + 1]; ++i) {
const int cell = wells.c_wells()->well_cells[i];
for (int phase = 0; phase < np; ++phase) {
well_resflows[wix * np + phase] += well_rate_per_cell[i] * fractional_flows[cell * np + phase];
}
}
}
computePhaseFlowRatesPerWell(*wells.c_wells(), well_rate_per_cell, fractional_flows, well_resflows);
// We approximate (for _testing_ that resflows = surfaceflows)
for (int wc_iter = 0; wc_iter < 10 && !wells.conditionsMet(well_bhp, well_resflows, well_resflows); ++wc_iter) {
std::cout << "Conditions not met for well, trying again" << std::endl;
@ -173,19 +155,7 @@ int main(int argc, char** argv)
}
std::cout << "Solved" << std::endl;
for (int wix = 0; wix < wells.c_wells()->number_of_wells; ++wix) {
for (int phase = 0; phase < np; ++phase) {
// Reset
well_resflows[wix * np + phase] = 0.0;
}
for (int i = wells.c_wells()->well_connpos[wix]; i < wells.c_wells()->well_connpos[wix + 1]; ++i) {
const int cell = wells.c_wells()->well_cells[i];
for (int phase = 0; phase < np; ++phase) {
well_resflows[wix * np + phase] += well_rate_per_cell[i] * fractional_flows[cell * np + phase];
}
}
}
computePhaseFlowRatesPerWell(*wells.c_wells(), well_rate_per_cell, fractional_flows, well_resflows);
}
#if 0

View File

@ -270,6 +270,32 @@ namespace Opm
}
}
}
/// Computes the fractional flow for each cell in the cells argument
/// @param[in] props rock and fluid properties
/// @param[in] cells cells with which the saturation values are associated
/// @param[in] saturations saturation values (for all phases)
/// @param[out] fractional_flow the fractional flow for each phase for each cell.
void computeFractionalFlow(const Opm::IncompPropertiesInterface& props,
const std::vector<int>& cells,
const std::vector<double>& saturations,
std::vector<double>& fractional_flows)
{
const int num_phases = props.numPhases();
std::vector<double> pc_mobs(cells.size() * num_phases);
computePhaseMobilities(props, cells, saturations, pc_mobs);
fractional_flows.resize(cells.size() * num_phases);
for (size_t i = 0; i < cells.size(); ++i) {
double phase_sum = 0.0;
for (int phase = 0; phase < num_phases; ++phase) {
phase_sum += pc_mobs[i * num_phases + phase];
}
for (int phase = 0; phase < num_phases; ++phase) {
fractional_flows[i * num_phases + phase] = pc_mobs[i * num_phases + phase] / phase_sum;
}
}
}
/// Compute two-phase transport source terms from face fluxes,
/// and pressure equation source terms. This puts boundary flows
@ -494,6 +520,34 @@ namespace Opm
}
}
/// Computes the phase flow rate per well
/// \param[in] wells The wells for which the flow rate should be computed
/// \param[in] flow_rates_per_cell The total flow rate for each cell (ordered the same
/// way as the wells struct
/// \param[in] fractional_flows the fractional flow for each cell in each well
/// \param[out] phase_flow_per_well Will contain the phase flow per well
void computePhaseFlowRatesPerWell(const Wells& wells,
const std::vector<double>& flow_rates_per_cell,
const std::vector<double>& fractional_flows,
std::vector<double> phase_flow_per_well)
{
const int np = wells.number_of_phases;
const int nw = wells.number_of_wells;
phase_flow_per_well.resize(nw * np);
for (int wix = 0; wix < nw; ++wix) {
for (int phase = 0; phase < np; ++phase) {
// Reset vector
phase_flow_per_well[wix + np*phase] = 0.0;
}
for (int i = wells.well_connpos[wix]; i < wells.well_connpos[wix + 1]; ++i) {
for (int phase = 0; phase < np; ++phase) {
phase_flow_per_well[wix * np + phase] += flow_rates_per_cell[i] * fractional_flows[i * np + phase];
}
}
}
}
void Watercut::push(double time, double fraction, double produced)

View File

@ -129,6 +129,17 @@ namespace Opm
const std::vector<int>& cells,
const std::vector<double>& s ,
std::vector<double>& pmobc);
/// Computes the fractional flow for each cell in the cells argument
/// @param[in] props rock and fluid properties
/// @param[in] cells cells with which the saturation values are associated
/// @param[in] saturations saturation values (for all phases)
/// @param[out] fractional_flow the fractional flow for each phase for each cell.
void computeFractionalFlow(const Opm::IncompPropertiesInterface& props,
const std::vector<int>& cells,
const std::vector<double>& saturations,
std::vector<double>& fractional_flows);
/// Compute two-phase transport source terms from face fluxes,
@ -203,6 +214,18 @@ namespace Opm
void computeFlowRatePerWell(const Wells& wells, const std::vector<double>& flow_rates_per_cell,
std::vector<double>& flow_rates_per_well);
/// Computes the phase flow rate per well
/// \param[in] wells The wells for which the flow rate should be computed
/// \param[in] flow_rates_per_cell The total flow rate for each cell (ordered the same
/// way as the wells struct
/// \param[in] fractional_flows the fractional flow for each cell in each well
/// \param[out] phase_flow_per_well Will contain the phase flow per well
void computePhaseFlowRatesPerWell(const Wells& wells,
const std::vector<double>& flow_rates_per_cell,
const std::vector<double>& fractional_flows,
std::vector<double> phase_flow_per_well);
/// Encapsulates the watercut curves.
class Watercut
{