Made the solveWellEq() method return if it converged.

Also use this to avoid updating if not converged in the
multi-segment version.
This commit is contained in:
Atgeirr Flø Rasmussen 2015-11-19 13:49:42 +01:00 committed by Kai Bao
parent b6ede37ca3
commit 233a275191
4 changed files with 35 additions and 30 deletions

View File

@ -392,7 +392,7 @@ namespace Opm {
extractWellPerfProperties(std::vector<ADB>& mob_perfcells, extractWellPerfProperties(std::vector<ADB>& mob_perfcells,
std::vector<ADB>& b_perfcells) const; std::vector<ADB>& b_perfcells) const;
void bool
solveWellEq(const std::vector<ADB>& mob_perfcells, solveWellEq(const std::vector<ADB>& mob_perfcells,
const std::vector<ADB>& b_perfcells, const std::vector<ADB>& b_perfcells,
SolutionState& state, SolutionState& state,

View File

@ -1574,7 +1574,7 @@ namespace detail {
template <class Grid, class Implementation> template <class Grid, class Implementation>
void BlackoilModelBase<Grid, Implementation>::solveWellEq(const std::vector<ADB>& mob_perfcells, bool BlackoilModelBase<Grid, Implementation>::solveWellEq(const std::vector<ADB>& mob_perfcells,
const std::vector<ADB>& b_perfcells, const std::vector<ADB>& b_perfcells,
SolutionState& state, SolutionState& state,
WellState& well_state) WellState& well_state)
@ -1629,7 +1629,7 @@ namespace detail {
const Eigen::SparseLU< Sp > solver(Jn0); const Eigen::SparseLU< Sp > solver(Jn0);
ADB::V total_residual_v = total_residual.value(); ADB::V total_residual_v = total_residual.value();
const Eigen::VectorXd& dx = solver.solve(total_residual_v.matrix()); const Eigen::VectorXd& dx = solver.solve(total_residual_v.matrix());
// assert(dx.size() == (well_state.numWells() * (well_state.numPhases()+1))); assert(dx.size() == total_residual_v.size());
asImpl().updateWellState(dx.array(), well_state); asImpl().updateWellState(dx.array(), well_state);
asImpl().updateWellControls(well_state); asImpl().updateWellControls(well_state);
} }
@ -1661,6 +1661,7 @@ namespace detail {
asImpl().computeWellConnectionPressures(state, well_state); asImpl().computeWellConnectionPressures(state, well_state);
} }
return converged;
} }

View File

@ -272,7 +272,7 @@ namespace Opm {
void computeWellConnectionPressures(const SolutionState& state, void computeWellConnectionPressures(const SolutionState& state,
const WellState& xw); const WellState& xw);
void bool
solveWellEq(const std::vector<ADB>& mob_perfcells, solveWellEq(const std::vector<ADB>& mob_perfcells,
const std::vector<ADB>& b_perfcells, const std::vector<ADB>& b_perfcells,
SolutionState& state, SolutionState& state,

View File

@ -1196,39 +1196,43 @@ namespace Opm {
template <class Grid> template <class Grid>
void BlackoilMultiSegmentModel<Grid>::solveWellEq(const std::vector<ADB>& mob_perfcells, bool BlackoilMultiSegmentModel<Grid>::solveWellEq(const std::vector<ADB>& mob_perfcells,
const std::vector<ADB>& b_perfcells, const std::vector<ADB>& b_perfcells,
SolutionState& state, SolutionState& state,
WellState& well_state) WellState& well_state)
{ {
Base::solveWellEq(mob_perfcells, b_perfcells, state, well_state); const bool converged = Base::solveWellEq(mob_perfcells, b_perfcells, state, well_state);
// We must now update the state.segp and state.segqs members, if (converged) {
// that the base version does not know about. // We must now update the state.segp and state.segqs members,
const int np = numPhases(); // that the base version does not know about.
const int nseg_total =well_state.numSegments(); const int np = numPhases();
{ const int nseg_total =well_state.numSegments();
// We will set the segp primary variable to the new ones, {
// but we do not change the derivatives here. // We will set the segp primary variable to the new ones,
ADB::V new_segp = Eigen::Map<ADB::V>(well_state.segPress().data(), nseg_total); // but we do not change the derivatives here.
// Avoiding the copy below would require a value setter method ADB::V new_segp = Eigen::Map<ADB::V>(well_state.segPress().data(), nseg_total);
// in AutoDiffBlock. // Avoiding the copy below would require a value setter method
std::vector<ADB::M> old_segp_derivs = state.segp.derivative(); // in AutoDiffBlock.
state.segp = ADB::function(std::move(new_segp), std::move(old_segp_derivs)); std::vector<ADB::M> old_segp_derivs = state.segp.derivative();
} state.segp = ADB::function(std::move(new_segp), std::move(old_segp_derivs));
{ }
// Need to reshuffle well rates, from phase running fastest {
// to wells running fastest. // Need to reshuffle well rates, from phase running fastest
// The transpose() below switches the ordering. // to wells running fastest.
const DataBlock segrates = Eigen::Map<const DataBlock>(well_state.segPhaseRates().data(), nseg_total, np).transpose(); // The transpose() below switches the ordering.
ADB::V new_segqs = Eigen::Map<const V>(segrates.data(), nseg_total * np); const DataBlock segrates = Eigen::Map<const DataBlock>(well_state.segPhaseRates().data(), nseg_total, np).transpose();
std::vector<ADB::M> old_segqs_derivs = state.segqs.derivative(); ADB::V new_segqs = Eigen::Map<const V>(segrates.data(), nseg_total * np);
state.segqs = ADB::function(std::move(new_segqs), std::move(old_segqs_derivs)); std::vector<ADB::M> old_segqs_derivs = state.segqs.derivative();
state.segqs = ADB::function(std::move(new_segqs), std::move(old_segqs_derivs));
}
// This is also called by the base version, but since we have updated
// state.segp we must call it again.
asImpl().computeWellConnectionPressures(state, well_state);
} }
// This is also called by the base version, but since we have updated return converged;
// state.segp we must call it again.
asImpl().computeWellConnectionPressures(state, well_state);
} }