mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Rename NewtonSolver -> NonlinearSolver.
This commit is contained in:
parent
9a4bb383df
commit
7c21a630e5
@ -126,8 +126,8 @@ list (APPEND PUBLIC_HEADER_FILES
|
||||
opm/autodiff/NewtonIterationBlackoilInterleaved.hpp
|
||||
opm/autodiff/NewtonIterationBlackoilSimple.hpp
|
||||
opm/autodiff/NewtonIterationUtilities.hpp
|
||||
opm/autodiff/NewtonSolver.hpp
|
||||
opm/autodiff/NewtonSolver_impl.hpp
|
||||
opm/autodiff/NonlinearSolver.hpp
|
||||
opm/autodiff/NonlinearSolver_impl.hpp
|
||||
opm/autodiff/LinearisedBlackoilResidual.hpp
|
||||
opm/autodiff/ParallelDebugOutput.hpp
|
||||
opm/autodiff/RateConverter.hpp
|
||||
|
@ -18,8 +18,8 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_NEWTONSOLVER_HEADER_INCLUDED
|
||||
#define OPM_NEWTONSOLVER_HEADER_INCLUDED
|
||||
#ifndef OPM_NONLINEARSOLVER_HEADER_INCLUDED
|
||||
#define OPM_NONLINEARSOLVER_HEADER_INCLUDED
|
||||
|
||||
#include <opm/autodiff/AutoDiffBlock.hpp>
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
@ -28,9 +28,10 @@
|
||||
namespace Opm {
|
||||
|
||||
|
||||
/// A Newton solver class suitable for general fully-implicit models.
|
||||
/// A nonlinear solver class suitable for general fully-implicit models,
|
||||
/// as well as pressure, transport and sequential models.
|
||||
template <class PhysicalModel>
|
||||
class NewtonSolver
|
||||
class NonlinearSolver
|
||||
{
|
||||
public:
|
||||
// --------- Types and enums ---------
|
||||
@ -38,18 +39,18 @@ namespace Opm {
|
||||
typedef ADB::V V;
|
||||
typedef ADB::M M;
|
||||
|
||||
// The Newton relaxation scheme type
|
||||
// Available relaxation scheme types.
|
||||
enum RelaxType { DAMPEN, SOR };
|
||||
|
||||
// Solver parameters controlling nonlinear Newton process.
|
||||
// Solver parameters controlling nonlinear process.
|
||||
struct SolverParameters
|
||||
{
|
||||
enum RelaxType relax_type_;
|
||||
double relax_max_;
|
||||
double relax_increment_;
|
||||
double relax_rel_tol_;
|
||||
int max_iter_; // max newton iterations
|
||||
int min_iter_; // min newton iterations
|
||||
int max_iter_; // max nonlinear iterations
|
||||
int min_iter_; // min nonlinear iterations
|
||||
|
||||
explicit SolverParameters( const parameter::ParameterGroup& param );
|
||||
SolverParameters();
|
||||
@ -66,11 +67,11 @@ namespace Opm {
|
||||
/// Construct solver for a given model.
|
||||
///
|
||||
/// The model is a std::unique_ptr because the object to which model points to is
|
||||
/// not allowed to be deleted as long as the NewtonSolver object exists.
|
||||
/// not allowed to be deleted as long as the NonlinearSolver object exists.
|
||||
///
|
||||
/// \param[in] param parameters controlling nonlinear Newton process
|
||||
/// \param[in] param parameters controlling nonlinear process
|
||||
/// \param[in, out] model physical simulation model.
|
||||
explicit NewtonSolver(const SolverParameters& param,
|
||||
explicit NonlinearSolver(const SolverParameters& param,
|
||||
std::unique_ptr<PhysicalModel> model);
|
||||
|
||||
/// Take a single forward step, after which the states will be modified
|
||||
@ -84,14 +85,14 @@ namespace Opm {
|
||||
ReservoirState& reservoir_state,
|
||||
WellState& well_state);
|
||||
|
||||
/// Number of Newton iterations used in all calls to step().
|
||||
unsigned int newtonIterations() const;
|
||||
/// Number of nonlinear solver iterations used in all calls to step().
|
||||
unsigned int nonlinearIterations() const;
|
||||
|
||||
/// Number of linear solver iterations used in all calls to step().
|
||||
unsigned int linearIterations() const;
|
||||
|
||||
/// Number of linear solver iterations used in the last call to step().
|
||||
unsigned int newtonIterationsLastStep() const;
|
||||
/// Number of nonlinear solver iterations used in the last call to step().
|
||||
unsigned int nonlinearIterationsLastStep() const;
|
||||
|
||||
/// Number of linear solver iterations used in the last call to step().
|
||||
unsigned int linearIterationsLastStep() const;
|
||||
@ -103,9 +104,9 @@ namespace Opm {
|
||||
// --------- Data members ---------
|
||||
SolverParameters param_;
|
||||
std::unique_ptr<PhysicalModel> model_;
|
||||
unsigned int newtonIterations_;
|
||||
unsigned int nonlinearIterations_;
|
||||
unsigned int linearIterations_;
|
||||
unsigned int newtonIterationsLast_;
|
||||
unsigned int nonlinearIterationsLast_;
|
||||
unsigned int linearIterationsLast_;
|
||||
|
||||
// --------- Private methods ---------
|
||||
@ -115,13 +116,13 @@ namespace Opm {
|
||||
double relaxRelTol() const { return param_.relax_rel_tol_; }
|
||||
double maxIter() const { return param_.max_iter_; }
|
||||
double minIter() const { return param_.min_iter_; }
|
||||
void detectNewtonOscillations(const std::vector<std::vector<double>>& residual_history,
|
||||
const int it, const double relaxRelTol,
|
||||
bool& oscillate, bool& stagnate) const;
|
||||
void stabilizeNewton(V& dx, V& dxOld, const double omega, const RelaxType relax_type) const;
|
||||
void detectOscillations(const std::vector<std::vector<double>>& residual_history,
|
||||
const int it, const double relaxRelTol,
|
||||
bool& oscillate, bool& stagnate) const;
|
||||
void stabilizeNonlinearUpdate(V& dx, V& dxOld, const double omega, const RelaxType relax_type) const;
|
||||
};
|
||||
} // namespace Opm
|
||||
|
||||
#include "NewtonSolver_impl.hpp"
|
||||
#include "NonlinearSolver_impl.hpp"
|
||||
|
||||
#endif // OPM_NEWTONSOLVER_HEADER_INCLUDED
|
||||
#endif // OPM_NONLINEARSOLVER_HEADER_INCLUDED
|
@ -20,31 +20,33 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_NEWTONSOLVER_IMPL_HEADER_INCLUDED
|
||||
#define OPM_NEWTONSOLVER_IMPL_HEADER_INCLUDED
|
||||
#ifndef OPM_NONLINEARSOLVER_IMPL_HEADER_INCLUDED
|
||||
#define OPM_NONLINEARSOLVER_IMPL_HEADER_INCLUDED
|
||||
|
||||
#include <opm/autodiff/NewtonSolver.hpp>
|
||||
#include <opm/autodiff/NonlinearSolver.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
template <class PhysicalModel>
|
||||
NewtonSolver<PhysicalModel>::NewtonSolver(const SolverParameters& param,
|
||||
std::unique_ptr<PhysicalModel> model)
|
||||
NonlinearSolver<PhysicalModel>::NonlinearSolver(const SolverParameters& param,
|
||||
std::unique_ptr<PhysicalModel> model)
|
||||
: param_(param),
|
||||
model_(std::move(model)),
|
||||
newtonIterations_(0),
|
||||
linearIterations_(0)
|
||||
nonlinearIterations_(0),
|
||||
linearIterations_(0),
|
||||
nonlinearIterationsLast_(0),
|
||||
linearIterationsLast_(0)
|
||||
{
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
unsigned int NewtonSolver<PhysicalModel>::newtonIterations () const
|
||||
unsigned int NonlinearSolver<PhysicalModel>::nonlinearIterations() const
|
||||
{
|
||||
return newtonIterations_;
|
||||
return nonlinearIterations_;
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
unsigned int NewtonSolver<PhysicalModel>::linearIterations () const
|
||||
unsigned int NonlinearSolver<PhysicalModel>::linearIterations() const
|
||||
{
|
||||
return linearIterations_;
|
||||
}
|
||||
@ -56,9 +58,22 @@ namespace Opm
|
||||
return *model_;
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
unsigned int NonlinearSolver<PhysicalModel>::nonlinearIterationsLastStep() const
|
||||
{
|
||||
return nonlinearIterationsLast_;
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
unsigned int NonlinearSolver<PhysicalModel>::linearIterationsLastStep() const
|
||||
{
|
||||
return linearIterationsLast_;
|
||||
}
|
||||
|
||||
|
||||
template <class PhysicalModel>
|
||||
int
|
||||
NewtonSolver<PhysicalModel>::
|
||||
NonlinearSolver<PhysicalModel>::
|
||||
step(const double dt,
|
||||
ReservoirState& reservoir_state,
|
||||
WellState& well_state)
|
||||
@ -74,7 +89,7 @@ namespace Opm
|
||||
model_->assemble(reservoir_state, well_state, true);
|
||||
residual_norms_history.push_back(model_->computeResidualNorms());
|
||||
|
||||
// Set up for main Newton loop.
|
||||
// Set up for main solver loop.
|
||||
double omega = 1.0;
|
||||
int iteration = 0;
|
||||
bool converged = model_->getConvergence(dt, iteration);
|
||||
@ -85,16 +100,16 @@ namespace Opm
|
||||
const enum RelaxType relaxtype = relaxType();
|
||||
int linIters = 0;
|
||||
|
||||
// ---------- Main Newton loop ----------
|
||||
// ---------- Main nonlinear solver loop ----------
|
||||
while ( (!converged && (iteration < maxIter())) || (minIter() > iteration)) {
|
||||
// Compute the Newton update to the primary variables.
|
||||
// Compute the update to the primary variables.
|
||||
V dx = model_->solveJacobianSystem();
|
||||
|
||||
// Store number of linear iterations used.
|
||||
linIters += model_->linearIterationsLastSolve();
|
||||
|
||||
// Stabilize the Newton update.
|
||||
detectNewtonOscillations(residual_norms_history, iteration, relaxRelTol(), isOscillate, isStagnate);
|
||||
// Stabilize the nonlinear update.
|
||||
detectOscillations(residual_norms_history, iteration, relaxRelTol(), isOscillate, isStagnate);
|
||||
if (isOscillate) {
|
||||
omega -= relaxIncrement();
|
||||
omega = std::max(omega, relaxMax());
|
||||
@ -102,7 +117,7 @@ namespace Opm
|
||||
std::cout << " Oscillating behavior detected: Relaxation set to " << omega << std::endl;
|
||||
}
|
||||
}
|
||||
stabilizeNewton(dx, dxOld, omega, relaxtype);
|
||||
stabilizeNonlinearUpdate(dx, dxOld, omega, relaxtype);
|
||||
|
||||
// Apply the update, the model may apply model-dependent
|
||||
// limitations and chopping of the update.
|
||||
@ -126,9 +141,9 @@ namespace Opm
|
||||
}
|
||||
|
||||
linearIterations_ += linIters;
|
||||
newtonIterations_ += iteration;
|
||||
nonlinearIterations_ += iteration;
|
||||
linearIterationsLast_ = linIters;
|
||||
newtonIterationsLast_ = iteration;
|
||||
nonlinearIterationsLast_ = iteration;
|
||||
|
||||
// Do model-specific post-step actions.
|
||||
model_->afterStep(dt, reservoir_state, well_state);
|
||||
@ -139,7 +154,7 @@ namespace Opm
|
||||
|
||||
|
||||
template <class PhysicalModel>
|
||||
void NewtonSolver<PhysicalModel>::SolverParameters::
|
||||
void NonlinearSolver<PhysicalModel>::SolverParameters::
|
||||
reset()
|
||||
{
|
||||
// default values for the solver parameters
|
||||
@ -152,7 +167,7 @@ namespace Opm
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
NewtonSolver<PhysicalModel>::SolverParameters::
|
||||
NonlinearSolver<PhysicalModel>::SolverParameters::
|
||||
SolverParameters()
|
||||
{
|
||||
// set default values
|
||||
@ -160,7 +175,7 @@ namespace Opm
|
||||
}
|
||||
|
||||
template <class PhysicalModel>
|
||||
NewtonSolver<PhysicalModel>::SolverParameters::
|
||||
NonlinearSolver<PhysicalModel>::SolverParameters::
|
||||
SolverParameters( const parameter::ParameterGroup& param )
|
||||
{
|
||||
// set default values
|
||||
@ -183,9 +198,9 @@ namespace Opm
|
||||
|
||||
template <class PhysicalModel>
|
||||
void
|
||||
NewtonSolver<PhysicalModel>::detectNewtonOscillations(const std::vector<std::vector<double>>& residual_history,
|
||||
const int it, const double relaxRelTol_arg,
|
||||
bool& oscillate, bool& stagnate) const
|
||||
NonlinearSolver<PhysicalModel>::detectOscillations(const std::vector<std::vector<double>>& residual_history,
|
||||
const int it, const double relaxRelTol_arg,
|
||||
bool& oscillate, bool& stagnate) const
|
||||
{
|
||||
// The detection of oscillation in two primary variable results in the report of the detection
|
||||
// of oscillation for the solver.
|
||||
@ -220,8 +235,8 @@ namespace Opm
|
||||
|
||||
template <class PhysicalModel>
|
||||
void
|
||||
NewtonSolver<PhysicalModel>::stabilizeNewton(V& dx, V& dxOld, const double omega,
|
||||
const RelaxType relax_type) const
|
||||
NonlinearSolver<PhysicalModel>::stabilizeNonlinearUpdate(V& dx, V& dxOld, const double omega,
|
||||
const RelaxType relax_type) const
|
||||
{
|
||||
// The dxOld is updated with dx.
|
||||
// If omega is equal to 1., no relaxtion will be appiled.
|
@ -26,7 +26,6 @@
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
|
||||
#include <opm/autodiff/GeoProps.hpp>
|
||||
#include <opm/autodiff/NewtonSolver.hpp>
|
||||
#include <opm/autodiff/BlackoilModel.hpp>
|
||||
#include <opm/autodiff/BlackoilPropsAdInterface.hpp>
|
||||
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
||||
|
@ -106,7 +106,7 @@ namespace Opm
|
||||
output_writer_.restore( timer, state, prev_well_state, restorefilename, desiredRestoreStep );
|
||||
}
|
||||
|
||||
unsigned int totalNewtonIterations = 0;
|
||||
unsigned int totalNonlinearIterations = 0;
|
||||
unsigned int totalLinearIterations = 0;
|
||||
|
||||
// Main simulation loop.
|
||||
@ -167,8 +167,8 @@ namespace Opm
|
||||
// take time that was used to solve system for this reportStep
|
||||
solver_timer.stop();
|
||||
|
||||
// accumulate the number of Newton and Linear Iterations
|
||||
totalNewtonIterations += solver->newtonIterations();
|
||||
// accumulate the number of nonlinear and linear Iterations
|
||||
totalNonlinearIterations += solver->nonlinearIterations();
|
||||
totalLinearIterations += solver->linearIterations();
|
||||
|
||||
// Report timing.
|
||||
@ -201,7 +201,7 @@ namespace Opm
|
||||
report.pressure_time = stime;
|
||||
report.transport_time = 0.0;
|
||||
report.total_time = total_timer.secsSinceStart();
|
||||
report.total_newton_iterations = totalNewtonIterations;
|
||||
report.total_newton_iterations = totalNonlinearIterations;
|
||||
report.total_linear_iterations = totalLinearIterations;
|
||||
return report;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2015 Andreas Lauser
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
@ -21,9 +21,8 @@
|
||||
#ifndef OPM_SIMULATORFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
||||
#define OPM_SIMULATORFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
||||
|
||||
#include "SimulatorBase.hpp"
|
||||
|
||||
#include "NewtonSolver.hpp"
|
||||
#include <opm/autodiff/SimulatorBase.hpp>
|
||||
#include <opm/autodiff/NonlinearSolver.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -38,7 +37,7 @@ struct SimulatorTraits<SimulatorFullyImplicitBlackoil<GridT> >
|
||||
typedef BlackoilOutputWriter OutputWriter;
|
||||
typedef GridT Grid;
|
||||
typedef BlackoilModel<Grid> Model;
|
||||
typedef NewtonSolver<Model> Solver;
|
||||
typedef NonlinearSolver<Model> Solver;
|
||||
};
|
||||
|
||||
/// a simulator for the blackoil model
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <opm/autodiff/BlackoilPropsAdInterface.hpp>
|
||||
#include <opm/autodiff/SolventPropsAdFromDeck.hpp>
|
||||
#include <opm/autodiff/RateConverter.hpp>
|
||||
#include <opm/autodiff/NewtonSolver.hpp>
|
||||
#include <opm/autodiff/NonlinearSolver.hpp>
|
||||
#include <opm/autodiff/WellStateFullyImplicitBlackoilSolvent.hpp>
|
||||
|
||||
#include <opm/core/grid.h>
|
||||
@ -88,7 +88,7 @@ namespace Opm
|
||||
typedef BlackoilOutputWriter OutputWriter;
|
||||
typedef GridT Grid;
|
||||
typedef BlackoilSolventModel<Grid> Model;
|
||||
typedef NewtonSolver<Model> Solver;
|
||||
typedef NonlinearSolver<Model> Solver;
|
||||
};
|
||||
|
||||
/// Class collecting all necessary components for a blackoil simulation with polymer
|
||||
|
Loading…
Reference in New Issue
Block a user