2014-05-12 04:06:42 -05:00
|
|
|
/*
|
|
|
|
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
2015-02-03 04:31:57 -06:00
|
|
|
Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015 NTNU
|
2015-05-20 02:26:25 -05:00
|
|
|
Copyright 2015 Statoil AS
|
2014-05-12 04:06:42 -05:00
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2014-09-26 08:03:59 -05:00
|
|
|
#include <opm/autodiff/DuneMatrix.hpp>
|
|
|
|
|
2014-05-12 04:06:42 -05:00
|
|
|
#include <opm/autodiff/NewtonIterationBlackoilCPR.hpp>
|
2015-06-16 03:18:11 -05:00
|
|
|
#include <opm/autodiff/NewtonIterationUtilities.hpp>
|
2014-05-12 04:06:42 -05:00
|
|
|
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
2016-10-10 09:57:06 -05:00
|
|
|
#include <opm/parser/eclipse/Units/Units.hpp>
|
2015-10-08 04:43:36 -05:00
|
|
|
#include <opm/common/Exceptions.hpp>
|
2015-01-28 08:37:07 -06:00
|
|
|
#include <opm/core/linalg/ParallelIstlInformation.hpp>
|
2015-06-16 03:18:11 -05:00
|
|
|
|
2015-10-06 05:11:49 -05:00
|
|
|
#include <opm/common/utility/platform_dependent/disable_warnings.h>
|
2014-11-19 04:22:57 -06:00
|
|
|
#if HAVE_UMFPACK
|
2014-11-13 09:56:11 -06:00
|
|
|
#include <Eigen/UmfPackSupport>
|
2014-11-19 04:22:57 -06:00
|
|
|
#else
|
|
|
|
#include <Eigen/SparseLU>
|
|
|
|
#endif
|
2015-10-06 05:11:49 -05:00
|
|
|
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
|
2014-05-14 08:53:54 -05:00
|
|
|
|
2015-06-16 03:42:50 -05:00
|
|
|
|
2014-05-12 04:06:42 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
typedef AutoDiffBlock<double> ADB;
|
|
|
|
typedef ADB::V V;
|
|
|
|
typedef ADB::M M;
|
2014-05-14 08:53:54 -05:00
|
|
|
|
|
|
|
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-12 04:06:42 -05:00
|
|
|
/// Construct a system solver.
|
2017-04-28 08:36:25 -05:00
|
|
|
NewtonIterationBlackoilCPR::NewtonIterationBlackoilCPR(const ParameterGroup& param,
|
2015-09-02 06:02:27 -05:00
|
|
|
const boost::any& parallelInformation_arg)
|
2015-04-08 04:48:16 -05:00
|
|
|
: cpr_param_( param ),
|
|
|
|
iterations_( 0 ),
|
2015-09-02 06:02:27 -05:00
|
|
|
parallelInformation_(parallelInformation_arg),
|
2015-04-21 05:40:21 -05:00
|
|
|
newton_use_gmres_( param.getDefault("newton_use_gmres", false ) ),
|
|
|
|
linear_solver_reduction_( param.getDefault("linear_solver_reduction", 1e-2 ) ),
|
|
|
|
linear_solver_maxiter_( param.getDefault("linear_solver_maxiter", 50 ) ),
|
2015-04-08 04:48:16 -05:00
|
|
|
linear_solver_restart_( param.getDefault("linear_solver_restart", 40 ) ),
|
2016-06-06 03:43:56 -05:00
|
|
|
linear_solver_verbosity_( param.getDefault("linear_solver_verbosity", 0 )),
|
2016-06-07 05:40:24 -05:00
|
|
|
linear_solver_ignoreconvergencefailure_(param.getDefault("linear_solver_ignoreconvergencefailure", false))
|
2014-05-12 04:06:42 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
|
2015-06-16 03:18:11 -05:00
|
|
|
|
|
|
|
|
2014-05-12 04:06:42 -05:00
|
|
|
/// Solve the linear system Ax = b, with A being the
|
|
|
|
/// combined derivative matrix of the residual and b
|
|
|
|
/// being the residual itself.
|
|
|
|
/// \param[in] residual residual object containing A and b.
|
|
|
|
/// \return the solution x
|
|
|
|
NewtonIterationBlackoilCPR::SolutionVector
|
|
|
|
NewtonIterationBlackoilCPR::computeNewtonIncrement(const LinearisedBlackoilResidual& residual) const
|
|
|
|
{
|
2014-05-13 08:02:11 -05:00
|
|
|
// Build the vector of equations.
|
2014-05-12 04:06:42 -05:00
|
|
|
const int np = residual.material_balance_eq.size();
|
2014-05-13 08:02:11 -05:00
|
|
|
std::vector<ADB> eqs;
|
|
|
|
eqs.reserve(np + 2);
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
eqs.push_back(residual.material_balance_eq[phase]);
|
|
|
|
}
|
|
|
|
|
2015-01-19 07:14:18 -06:00
|
|
|
// check if wells are present
|
|
|
|
const bool hasWells = residual.well_flux_eq.size() > 0 ;
|
2014-05-13 08:02:11 -05:00
|
|
|
std::vector<ADB> elim_eqs;
|
2015-01-19 07:14:18 -06:00
|
|
|
if( hasWells )
|
|
|
|
{
|
|
|
|
eqs.push_back(residual.well_flux_eq);
|
|
|
|
eqs.push_back(residual.well_eq);
|
|
|
|
|
|
|
|
// Eliminate the well-related unknowns, and corresponding equations.
|
|
|
|
elim_eqs.reserve(2);
|
|
|
|
elim_eqs.push_back(eqs[np]);
|
|
|
|
eqs = eliminateVariable(eqs, np); // Eliminate well flux unknowns.
|
|
|
|
elim_eqs.push_back(eqs[np]);
|
|
|
|
eqs = eliminateVariable(eqs, np); // Eliminate well bhp unknowns.
|
|
|
|
assert(int(eqs.size()) == np);
|
|
|
|
}
|
2014-05-13 08:02:11 -05:00
|
|
|
|
2014-05-16 07:21:14 -05:00
|
|
|
// Scale material balance equations.
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2015-08-27 09:58:44 -05:00
|
|
|
eqs[phase] = eqs[phase] * residual.matbalscale[phase];
|
2014-05-16 07:21:14 -05:00
|
|
|
}
|
|
|
|
|
2014-05-20 07:24:24 -05:00
|
|
|
// Add material balance equations (or other manipulations) to
|
|
|
|
// form pressure equation in top left of full system.
|
|
|
|
Eigen::SparseMatrix<double, Eigen::RowMajor> A;
|
|
|
|
V b;
|
|
|
|
formEllipticSystem(np, eqs, A, b);
|
2014-05-16 07:21:14 -05:00
|
|
|
|
|
|
|
// Scale pressure equation.
|
|
|
|
const double pscale = 200*unit::barsa;
|
2014-05-20 07:24:24 -05:00
|
|
|
const int nc = residual.material_balance_eq[0].size();
|
|
|
|
A.topRows(nc) *= pscale;
|
|
|
|
b.topRows(nc) *= pscale;
|
2014-05-12 04:06:42 -05:00
|
|
|
|
2014-05-13 08:02:11 -05:00
|
|
|
// Solve reduced system.
|
2014-05-20 07:24:24 -05:00
|
|
|
SolutionVector dx(SolutionVector::Zero(b.size()));
|
2014-05-14 08:53:54 -05:00
|
|
|
|
|
|
|
// Create ISTL matrix.
|
2014-10-09 07:06:02 -05:00
|
|
|
DuneMatrix istlA( A );
|
2014-05-14 08:53:54 -05:00
|
|
|
|
2014-05-15 08:49:14 -05:00
|
|
|
// Create ISTL matrix for elliptic part.
|
2014-10-09 07:06:02 -05:00
|
|
|
DuneMatrix istlAe( A.topLeftCorner(nc, nc) );
|
2015-03-03 06:23:33 -06:00
|
|
|
|
2014-05-14 08:53:54 -05:00
|
|
|
// Right hand side.
|
2015-01-28 08:37:07 -06:00
|
|
|
Vector istlb(istlA.N());
|
2014-05-20 07:24:24 -05:00
|
|
|
std::copy_n(b.data(), istlb.size(), istlb.begin());
|
2014-05-14 08:53:54 -05:00
|
|
|
// System solution
|
2015-01-28 08:37:07 -06:00
|
|
|
Vector x(istlA.M());
|
2014-05-14 08:53:54 -05:00
|
|
|
x = 0.0;
|
|
|
|
|
|
|
|
Dune::InverseOperatorResult result;
|
2015-01-28 08:37:07 -06:00
|
|
|
#if HAVE_MPI
|
|
|
|
if(parallelInformation_.type()==typeid(ParallelISTLInformation))
|
|
|
|
{
|
|
|
|
typedef Dune::OwnerOverlapCopyCommunication<int,int> Comm;
|
|
|
|
const ParallelISTLInformation& info =
|
|
|
|
boost::any_cast<const ParallelISTLInformation&>( parallelInformation_);
|
|
|
|
Comm istlComm(info.communicator());
|
2015-05-19 12:41:32 -05:00
|
|
|
Comm istlAeComm(info.communicator());
|
|
|
|
info.copyValuesTo(istlAeComm.indexSet(), istlAeComm.remoteIndices());
|
|
|
|
info.copyValuesTo(istlComm.indexSet(), istlComm.remoteIndices(),
|
|
|
|
istlAe.N(), istlA.N()/istlAe.N());
|
2015-01-28 08:37:07 -06:00
|
|
|
// Construct operator, scalar product and vectors needed.
|
|
|
|
typedef Dune::OverlappingSchwarzOperator<Mat,Vector,Vector,Comm> Operator;
|
|
|
|
Operator opA(istlA, istlComm);
|
2015-05-19 12:41:32 -05:00
|
|
|
constructPreconditionerAndSolve<Dune::SolverCategory::overlapping>(opA, istlAe, x, istlb, istlComm, istlAeComm, result);
|
2015-01-28 08:37:07 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// Construct operator, scalar product and vectors needed.
|
|
|
|
typedef Dune::MatrixAdapter<Mat,Vector,Vector> Operator;
|
|
|
|
Operator opA(istlA);
|
|
|
|
Dune::Amg::SequentialInformation info;
|
2015-05-19 12:41:32 -05:00
|
|
|
constructPreconditionerAndSolve(opA, istlAe, x, istlb, info, info, result);
|
2015-01-28 08:37:07 -06:00
|
|
|
}
|
2015-03-03 06:23:33 -06:00
|
|
|
|
2014-10-01 06:50:08 -05:00
|
|
|
// store number of iterations
|
|
|
|
iterations_ = result.iterations;
|
|
|
|
|
2014-05-19 04:21:23 -05:00
|
|
|
// Check for failure of linear solver.
|
2016-06-07 05:38:56 -05:00
|
|
|
if (!result.converged && !linear_solver_ignoreconvergencefailure_) {
|
2015-04-16 04:41:28 -05:00
|
|
|
OPM_THROW(LinearSolverProblem, "Convergence failure for linear solver.");
|
2014-05-19 04:21:23 -05:00
|
|
|
}
|
2014-05-14 08:53:54 -05:00
|
|
|
|
2014-05-19 04:21:23 -05:00
|
|
|
// Copy solver output to dx.
|
2014-05-16 07:21:14 -05:00
|
|
|
std::copy(x.begin(), x.end(), dx.data());
|
2014-05-14 08:53:54 -05:00
|
|
|
|
2015-06-16 03:42:50 -05:00
|
|
|
if ( hasWells ) {
|
2015-01-19 07:14:18 -06:00
|
|
|
// Compute full solution using the eliminated equations.
|
|
|
|
// Recovery in inverse order of elimination.
|
|
|
|
dx = recoverVariable(elim_eqs[1], dx, np);
|
|
|
|
dx = recoverVariable(elim_eqs[0], dx, np);
|
|
|
|
}
|
2014-05-12 04:06:42 -05:00
|
|
|
return dx;
|
|
|
|
}
|
|
|
|
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-16 03:18:11 -05:00
|
|
|
const boost::any& NewtonIterationBlackoilCPR::parallelInformation() const
|
|
|
|
{
|
|
|
|
return parallelInformation_;
|
|
|
|
}
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
|
2014-05-20 07:24:24 -05:00
|
|
|
|
2014-05-13 07:58:13 -05:00
|
|
|
|
|
|
|
|
2014-05-12 04:06:42 -05:00
|
|
|
} // namespace Opm
|
|
|
|
|