Commit a7d719d5 authored by Timo Koch's avatar Timo Koch
Browse files

[newton] Remove TypeTag dependency of NewtonMethod class

Adapt all tests accordingly. Classes that don't need a TypeTag and
only a few template arguments are more flexible.
parent 7c2d5339
......@@ -152,7 +152,7 @@ struct InstationaryNonLinearSimulationImpl<TypeTag, DiscretizationMethods::CCTpf
// the non-linear solver
using NewtonController = typename GET_PROP_TYPE(TypeTag, NewtonController);
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......@@ -297,7 +297,7 @@ struct InstationaryNonLinearSimulationImpl<TypeTag, DiscretizationMethods::Box,
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -76,7 +76,6 @@ class AMGBackend : public LinearSolver<TypeTag>
{
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using Grid = typename GET_PROP_TYPE(TypeTag, Grid);
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
using AmgTraits = typename GET_PROP(TypeTag, AmgTraits);
enum { numEq = AmgTraits::numEq };
using LinearOperator = typename AmgTraits::LinearOperator;
......
......@@ -38,8 +38,10 @@ namespace Dumux
template <class TypeTag>
class LinearSolver
{
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
public:
//! export scalar type (might be needed to set parameters from output)
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
//! default constructor sets some parameters
LinearSolver()
{
......
......@@ -21,7 +21,7 @@
*
* \brief The algorithmic part of the multi dimensional newton method.
*
* In order to use the method you need a Newtoncontroller_->
* In order to use the method you need a Newtoncontroller
*/
#ifndef DUMUX_NEWTONMETHOD_HH
#define DUMUX_NEWTONMETHOD_HH
......@@ -50,31 +50,26 @@ NEW_PROP_TAG(JacobianMatrix);
* \ingroup Newton
* \brief The algorithmic part of the multi dimensional newton method.
*
* In order to use the method you need a Newtoncontroller_->
* In order to use the method you need a Newtoncontroller
*/
template <class TypeTag, class NewtonController, class JacobianAssembler, class LinearSolver>
template <class NewtonController, class JacobianAssembler, class LinearSolver>
class NewtonMethod
{
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector);
using JacobianMatrix = typename GET_PROP_TYPE(TypeTag, JacobianMatrix);
public:
NewtonMethod(std::shared_ptr<NewtonController> controller,
std::shared_ptr<JacobianAssembler> assembler,
std::shared_ptr<LinearSolver> linearSolver)
std::shared_ptr<LinearSolver> linearSolver,
const std::string& modelParamGroup = "")
: controller_(controller)
, assembler_(assembler)
, linearSolver_(linearSolver)
, matrix_(std::make_shared<JacobianMatrix>())
, residual_(std::make_shared<SolutionVector>())
{
// set the linear system (matrix & residual) in the assembler
assembler_->setLinearSystem(matrix_, residual_);
assembler_->setLinearSystem();
// set a different default for the linear solver residual reduction
// within the Newton the linear solver doesn't need to solve too exact
static const std::string modelParamGroup = GET_PROP_VALUE(TypeTag, ModelParameterGroup);
using Scalar = typename LinearSolver::Scalar;
linearSolver_->setResidualReduction(getParamFromGroup<Scalar>(modelParamGroup, "LinearSolver.ResidualReduction", 1e-6));
}
......@@ -82,6 +77,7 @@ public:
* \brief Run the newton method to solve a non-linear system.
* The controller is responsible for all the strategic decisions.
*/
template<class SolutionVector>
bool solve(SolutionVector& u)
{
try
......@@ -146,9 +142,9 @@ public:
deltaU = 0;
// ask the controller to solve the linearized system
controller_->solveLinearSystem(*linearSolver_,
matrix(),
assembler_->jacobian(),
deltaU,
residual());
assembler_->residual());
solveTimer.stop();
///////////////
......@@ -203,20 +199,10 @@ public:
}
}
//! The jacobian for the Newton method
JacobianMatrix& matrix()
{ return *matrix_; }
//! The residual for the Newton method
SolutionVector& residual()
{ return *residual_; }
private:
std::shared_ptr<NewtonController> controller_;
std::shared_ptr<JacobianAssembler> assembler_;
std::shared_ptr<LinearSolver> linearSolver_;
std::shared_ptr<JacobianMatrix> matrix_; //! The jacobian for the Newton method
std::shared_ptr<SolutionVector> residual_; //! The residual for the Newton method
};
} // end namespace Dumux
......
......@@ -137,7 +137,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = NewtonController<TypeTag>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver> nonLinearSolver(newtonController, assembler, linearSolver);
NewtonMethod<NewtonController, Assembler, LinearSolver> nonLinearSolver(newtonController, assembler, linearSolver);
// set some check points for the time loop
timeLoop->setPeriodicCheckPoint(tEnd/10.0);
......
......@@ -116,7 +116,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = NewtonController<TypeTag>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm());
NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver> nonLinearSolver(newtonController, assembler, linearSolver);
NewtonMethod<NewtonController, Assembler, LinearSolver> nonLinearSolver(newtonController, assembler, linearSolver);
// linearize & solve
Dune::Timer timer;
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = NewtonController<TypeTag>;
using NewtonMethod = NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = NewtonController<TypeTag>;
using NewtonMethod = NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -160,7 +160,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = PriVarSwitchNewtonController<TypeTag>;
using NewtonMethod = NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -159,7 +159,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = PriVarSwitchNewtonController<TypeTag>;
using NewtonMethod = NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -162,7 +162,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -162,7 +162,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
......@@ -165,7 +165,7 @@ int main(int argc, char** argv) try
// the non-linear solver
using NewtonController = Dumux::NewtonController<TypeTag>;
using NewtonMethod = Dumux::NewtonMethod<TypeTag, NewtonController, Assembler, LinearSolver>;
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>;
auto newtonController = std::make_shared<NewtonController>(leafGridView.comm(), timeLoop);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment