diff --git a/dumux/common/start/instationarynonlinear.hh b/dumux/common/start/instationarynonlinear.hh index 9c69a1e240eb638a56d9cfdd8cca8d684526c16b..8811872d64373e93075bf732aca41826f4b8c450 100644 --- a/dumux/common/start/instationarynonlinear.hh +++ b/dumux/common/start/instationarynonlinear.hh @@ -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); diff --git a/dumux/linear/amgbackend.hh b/dumux/linear/amgbackend.hh index 1cca191c98c16bb5978a8c68b83bd08819112746..5fb8dcbc34e3825cbb0a5d1336e7319647089972 100644 --- a/dumux/linear/amgbackend.hh +++ b/dumux/linear/amgbackend.hh @@ -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; diff --git a/dumux/linear/solver.hh b/dumux/linear/solver.hh index 1c74fb10b7771d99bd4e63e75fac5b07f751e876..5e0299603fe513ed9412c46d813865f6516c517c 100644 --- a/dumux/linear/solver.hh +++ b/dumux/linear/solver.hh @@ -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() { diff --git a/dumux/nonlinear/newtonmethod.hh b/dumux/nonlinear/newtonmethod.hh index d40d2a042cc45b9756c200f202d593414b59d784..87f4da3d27ab9f102f7785fd43272d7bcf82dad8 100644 --- a/dumux/nonlinear/newtonmethod.hh +++ b/dumux/nonlinear/newtonmethod.hh @@ -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 diff --git a/test/porousmediumflow/1p/implicit/compressible/test_1p.cc b/test/porousmediumflow/1p/implicit/compressible/test_1p.cc index 203731222fbe8f05e6ae05ed2ed337e06bf62ced..c8014ecbbdd7ecf8052fbdfe1da996098f4b187e 100644 --- a/test/porousmediumflow/1p/implicit/compressible/test_1p.cc +++ b/test/porousmediumflow/1p/implicit/compressible/test_1p.cc @@ -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); diff --git a/test/porousmediumflow/1p/implicit/compressible/test_1p_stationary.cc b/test/porousmediumflow/1p/implicit/compressible/test_1p_stationary.cc index 2d49aee7b99702801c82a5be19fc584df6b54949..5ff4f03429fd68b2990fd496159b0b3bf459b72a 100644 --- a/test/porousmediumflow/1p/implicit/compressible/test_1p_stationary.cc +++ b/test/porousmediumflow/1p/implicit/compressible/test_1p_stationary.cc @@ -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; diff --git a/test/porousmediumflow/2p/implicit/incompressible/test_2p_box.cc b/test/porousmediumflow/2p/implicit/incompressible/test_2p_box.cc index 79088fd7f48ca17a334bff4cc13ad02e2ec03b8e..f95fc37f0988ba0e2728383d385b5f636499ecc6 100644 --- a/test/porousmediumflow/2p/implicit/incompressible/test_2p_box.cc +++ b/test/porousmediumflow/2p/implicit/incompressible/test_2p_box.cc @@ -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); diff --git a/test/porousmediumflow/2p/implicit/incompressible/test_2p_cc.cc b/test/porousmediumflow/2p/implicit/incompressible/test_2p_cc.cc index 8a6bfa29bc3f5d64428594a647951b10eb24e707..d1a30de101103b589fba1b1ea9315669e0fc7adb 100644 --- a/test/porousmediumflow/2p/implicit/incompressible/test_2p_cc.cc +++ b/test/porousmediumflow/2p/implicit/incompressible/test_2p_cc.cc @@ -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); diff --git a/test/porousmediumflow/2pnc/implicit/test_box2pnc.cc b/test/porousmediumflow/2pnc/implicit/test_box2pnc.cc index fccc63e4a6df192ceead115fd8ee166bedea3583..fe2d17a33de947cd65938a695dae5398439a3a54 100644 --- a/test/porousmediumflow/2pnc/implicit/test_box2pnc.cc +++ b/test/porousmediumflow/2pnc/implicit/test_box2pnc.cc @@ -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); diff --git a/test/porousmediumflow/2pnc/implicit/test_cc2pnc.cc b/test/porousmediumflow/2pnc/implicit/test_cc2pnc.cc index 4fab0c76bcaf39eacf42854c9cbd3bce3bea72ae..7ba7e44d6cb580c6c4c065b41adca756cf533bbe 100644 --- a/test/porousmediumflow/2pnc/implicit/test_cc2pnc.cc +++ b/test/porousmediumflow/2pnc/implicit/test_cc2pnc.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_box3p.cc b/test/porousmediumflow/3p/implicit/test_box3p.cc index 0af33e750d4ac7d5aa18a4e4c11bda0d7741c551..1f2ae7a3d71f3f027cbc60441466ac7ea2cbe25c 100644 --- a/test/porousmediumflow/3p/implicit/test_box3p.cc +++ b/test/porousmediumflow/3p/implicit/test_box3p.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_box3pniconduction.cc b/test/porousmediumflow/3p/implicit/test_box3pniconduction.cc index ec1298f9a0b403a3b097b653111f3905ea1c2ffe..bb5ab3447fe9ffc5114bfeedb8ba1b9a788ff602 100644 --- a/test/porousmediumflow/3p/implicit/test_box3pniconduction.cc +++ b/test/porousmediumflow/3p/implicit/test_box3pniconduction.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_box3pniconvection.cc b/test/porousmediumflow/3p/implicit/test_box3pniconvection.cc index f6ea0553f8f5e6aa8a3627c35ca1ba4d90f3b683..7cca3428373c63fe449cef5ce1adaa6d4bd5c8b5 100644 --- a/test/porousmediumflow/3p/implicit/test_box3pniconvection.cc +++ b/test/porousmediumflow/3p/implicit/test_box3pniconvection.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_cc3p.cc b/test/porousmediumflow/3p/implicit/test_cc3p.cc index d7c1e3d44e90bf2fad48fef1adab26787b939e25..5f09e831f7cb37ce35d5484491b96d43be4a5218 100644 --- a/test/porousmediumflow/3p/implicit/test_cc3p.cc +++ b/test/porousmediumflow/3p/implicit/test_cc3p.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_cc3pniconduction.cc b/test/porousmediumflow/3p/implicit/test_cc3pniconduction.cc index df082b77967ba9af093c3f0af5780434826f215e..858dbea7e6fbbd83103992f8541efb8d91fd5b6e 100644 --- a/test/porousmediumflow/3p/implicit/test_cc3pniconduction.cc +++ b/test/porousmediumflow/3p/implicit/test_cc3pniconduction.cc @@ -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); diff --git a/test/porousmediumflow/3p/implicit/test_cc3pniconvection.cc b/test/porousmediumflow/3p/implicit/test_cc3pniconvection.cc index f00dacb3d6fb3cad808dd5aa0457967a211f7cba..77ee4c8b207e1bd23a59e3c8aea041a531e8a872 100644 --- a/test/porousmediumflow/3p/implicit/test_cc3pniconvection.cc +++ b/test/porousmediumflow/3p/implicit/test_cc3pniconvection.cc @@ -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);