Commit 4ad85124 authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

Merge branch 'feature/test-newtonconvergencewriter' into 'master'

[feature] test newtonconvergencewriter on 2pni test

See merge request !1139
parents ec066f75 3b140681
...@@ -45,14 +45,14 @@ struct ConvergenceWriterInterface ...@@ -45,14 +45,14 @@ struct ConvergenceWriterInterface
/*! /*!
* \ingroup Nonlinear * \ingroup Nonlinear
* \brief Writes the intermediate solutions for every Newton iteration * \brief Writes the intermediate solutions for every Newton iteration
* \note To use this create a unique_ptr to an instance of this class in the main file * \note To use this create a shared_ptr to an instance of this class in the main file
* and pass it to newton.solve(x, convergencewriter). You can use the reset method * and pass it to newton.solve(x, convergencewriter). You can use the reset method
* to write out multiple Newton solves with a unique id, if you don't call use all * to write out multiple Newton solves with a unique id, if you don't call use all
* Newton iterations just come after each other in the pvd file. * Newton iterations just come after each other in the pvd file.
*/ */
// template <class Scalar, class GridView, int numEq> // template <class Scalar, class GridView, int numEq>
template <class GridView, class SolutionVector> template <class GridView, class SolutionVector>
class NewtonConvergenceWriter : virtual public ConvergenceWriterInterface<SolutionVector> class NewtonConvergenceWriter : public ConvergenceWriterInterface<SolutionVector>
{ {
static constexpr auto numEq = SolutionVector::block_type::dimension; static constexpr auto numEq = SolutionVector::block_type::dimension;
using Scalar = typename SolutionVector::block_type::value_type; using Scalar = typename SolutionVector::block_type::value_type;
......
...@@ -170,7 +170,7 @@ public: ...@@ -170,7 +170,7 @@ public:
*/ */
template<class TimeLoop> template<class TimeLoop>
void solve(SolutionVector& uCurrentIter, TimeLoop& timeLoop, void solve(SolutionVector& uCurrentIter, TimeLoop& timeLoop,
const std::unique_ptr<ConvergenceWriter>& convWriter = nullptr) std::shared_ptr<ConvergenceWriter> convWriter = nullptr)
{ {
if (assembler_->isStationaryProblem()) if (assembler_->isStationaryProblem())
DUNE_THROW(Dune::InvalidStateException, "Using time step control with stationary problem makes no sense!"); DUNE_THROW(Dune::InvalidStateException, "Using time step control with stationary problem makes no sense!");
...@@ -214,7 +214,7 @@ public: ...@@ -214,7 +214,7 @@ public:
* \brief Run the Newton method to solve a non-linear system. * \brief Run the Newton method to solve a non-linear system.
* The solver is responsible for all the strategic decisions. * The solver is responsible for all the strategic decisions.
*/ */
void solve(SolutionVector& uCurrentIter, const std::unique_ptr<ConvergenceWriter>& convWriter = nullptr) void solve(SolutionVector& uCurrentIter, std::shared_ptr<ConvergenceWriter>& convWriter = nullptr)
{ {
const bool converged = solve_(uCurrentIter, convWriter); const bool converged = solve_(uCurrentIter, convWriter);
if (!converged) if (!converged)
...@@ -646,7 +646,7 @@ private: ...@@ -646,7 +646,7 @@ private:
* \brief Run the Newton method to solve a non-linear system. * \brief Run the Newton method to solve a non-linear system.
* The solver is responsible for all the strategic decisions. * The solver is responsible for all the strategic decisions.
*/ */
bool solve_(SolutionVector& uCurrentIter, const std::unique_ptr<ConvergenceWriter>& convWriter = nullptr) bool solve_(SolutionVector& uCurrentIter, std::shared_ptr<ConvergenceWriter>& convWriter = nullptr)
{ {
// the given solution is the initial guess // the given solution is the initial guess
SolutionVector uLastIter(uCurrentIter); SolutionVector uLastIter(uCurrentIter);
......
...@@ -159,6 +159,11 @@ int main(int argc, char** argv) try ...@@ -159,6 +159,11 @@ int main(int argc, char** argv) try
using NewtonSolver = Dumux::NewtonSolver<Assembler, LinearSolver>; using NewtonSolver = Dumux::NewtonSolver<Assembler, LinearSolver>;
NewtonSolver nonLinearSolver(assembler, linearSolver); NewtonSolver nonLinearSolver(assembler, linearSolver);
//the convergence writer
using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
using NewtonConvergenceWriter = Dumux::NewtonConvergenceWriter<GridView, SolutionVector>;
auto convergenceWriter = std::make_shared<NewtonConvergenceWriter>(leafGridView, fvGridGeometry->numDofs());
// time loop // time loop
timeLoop->start(); do timeLoop->start(); do
{ {
...@@ -166,7 +171,7 @@ int main(int argc, char** argv) try ...@@ -166,7 +171,7 @@ int main(int argc, char** argv) try
assembler->setPreviousSolution(xOld); assembler->setPreviousSolution(xOld);
// solve the non-linear system with time step control // solve the non-linear system with time step control
nonLinearSolver.solve(x, *timeLoop); nonLinearSolver.solve(x, *timeLoop, convergenceWriter);
// make the new solution the old solution // make the new solution the old solution
xOld = x; xOld = x;
......
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