computeFractionalFlow(): Reuse the output array in all intermediate calculations.

This eliminates a number of free-store operations and data movements.
This commit is contained in:
Bård Skaflestad 2012-06-13 17:07:56 +02:00
parent e041407c81
commit cc054d474d
2 changed files with 12 additions and 12 deletions

View File

@ -280,16 +280,16 @@ namespace Opm
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) {
computePhaseMobilities(props, cells, saturations, fractional_flows);
for (std::vector<int>::size_type 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];
phase_sum += fractional_flows[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;
fractional_flows[i * num_phases + phase] /= phase_sum;
}
}
}

View File

@ -206,16 +206,16 @@ namespace Opm
std::vector<double>& fractional_flows)
{
const int num_phases = props.numPhases();
std::vector<double> pc_mobs(cells.size() * num_phases);
computePhaseMobilities(props, cells, p, z, s, pc_mobs);
fractional_flows.resize(cells.size() * num_phases);
for (size_t i = 0; i < cells.size(); ++i) {
computePhaseMobilities(props, cells, p, z, s, fractional_flows);
for (std::vector<int>::size_type 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];
phase_sum += fractional_flows[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;
fractional_flows[i * num_phases + phase] /= phase_sum;
}
}
}