Skip to content
Snippets Groups Projects
Commit 78686c9f authored by Kilian Weishaupt's avatar Kilian Weishaupt
Browse files

[test][2p2c][implicit] Use NewtonSolver

parent 59a2a1cc
No related branches found
No related tags found
1 merge request!898Use NewtonSolver
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
#include <dumux/common/defaultusagemessage.hh> #include <dumux/common/defaultusagemessage.hh>
#include <dumux/linear/amgbackend.hh> #include <dumux/linear/amgbackend.hh>
#include <dumux/nonlinear/newtonmethod.hh> #include <dumux/nonlinear/privarswitchnewtonsolver.hh>
#include <dumux/porousmediumflow/compositional/privarswitchnewtoncontroller.hh>
#include <dumux/assembly/fvassembler.hh> #include <dumux/assembly/fvassembler.hh>
#include <dumux/assembly/diffmethod.hh> #include <dumux/assembly/diffmethod.hh>
...@@ -129,7 +128,6 @@ int main(int argc, char** argv) try ...@@ -129,7 +128,6 @@ int main(int argc, char** argv) try
// get some time loop parameters // get some time loop parameters
using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar); using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
const auto tEnd = getParam<Scalar>("TimeLoop.TEnd"); const auto tEnd = getParam<Scalar>("TimeLoop.TEnd");
const auto maxDivisions = getParam<int>("TimeLoop.MaxTimeStepDivisions");
const auto maxDt = getParam<Scalar>("TimeLoop.MaxTimeStepSize"); const auto maxDt = getParam<Scalar>("TimeLoop.MaxTimeStepSize");
auto dt = getParam<Scalar>("TimeLoop.DtInitial"); auto dt = getParam<Scalar>("TimeLoop.DtInitial");
...@@ -157,10 +155,9 @@ int main(int argc, char** argv) try ...@@ -157,10 +155,9 @@ int main(int argc, char** argv) try
auto linearSolver = std::make_shared<LinearSolver>(leafGridView, fvGridGeometry->dofMapper()); auto linearSolver = std::make_shared<LinearSolver>(leafGridView, fvGridGeometry->dofMapper());
// the non-linear solver // the non-linear solver
using NewtonController = PriVarSwitchNewtonController<TypeTag>; using NewtonSolver = PriVarSwitchNewtonSolver<Assembler, LinearSolver,
using NewtonMethod = Dumux::NewtonMethod<NewtonController, Assembler, LinearSolver>; typename GET_PROP_TYPE(TypeTag, PrimaryVariableSwitch)>;
auto newtonController = std::make_shared<NewtonController>(timeLoop); NewtonSolver nonLinearSolver(assembler, linearSolver);
NewtonMethod nonLinearSolver(newtonController, assembler, linearSolver);
// time loop // time loop
timeLoop->start(); do timeLoop->start(); do
...@@ -168,24 +165,8 @@ int main(int argc, char** argv) try ...@@ -168,24 +165,8 @@ int main(int argc, char** argv) try
// set previous solution for storage evaluations // set previous solution for storage evaluations
assembler->setPreviousSolution(xOld); assembler->setPreviousSolution(xOld);
// try solving the non-linear system // solve the non-linear system with time step control
for (int i = 0; i < maxDivisions; ++i) nonLinearSolver.solve(x, *timeLoop);
{
// linearize & solve
auto converged = nonLinearSolver.solve(x);
if (converged)
break;
if (!converged && i == maxDivisions-1)
DUNE_THROW(Dune::MathError,
"Newton solver didn't converge after "
<< maxDivisions
<< " time-step divisions. dt="
<< timeLoop->timeStepSize()
<< ".\nThe solutions of the current and the previous time steps "
<< "have been saved to restart files.");
}
// make the new solution the old solution // make the new solution the old solution
xOld = x; xOld = x;
...@@ -200,8 +181,8 @@ int main(int argc, char** argv) try ...@@ -200,8 +181,8 @@ int main(int argc, char** argv) try
// report statistics of this time step // report statistics of this time step
timeLoop->reportTimeStep(); timeLoop->reportTimeStep();
// set new dt as suggested by newton controller // set new dt as suggested by the newton solver
timeLoop->setTimeStepSize(newtonController->suggestTimeStepSize(timeLoop->timeStepSize())); timeLoop->setTimeStepSize(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()));
} while (!timeLoop->finished()); } while (!timeLoop->finished());
......
...@@ -153,7 +153,7 @@ int main(int argc, char** argv) try ...@@ -153,7 +153,7 @@ int main(int argc, char** argv) try
// report statistics of this time step // report statistics of this time step
timeLoop->reportTimeStep(); timeLoop->reportTimeStep();
// set new dt as suggested by newton controller // set new dt as suggested by the newton solver
timeLoop->setTimeStepSize(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize())); timeLoop->setTimeStepSize(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()));
// write vtk output // write vtk output
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment