Commit 3b140681 authored by Katharina Heck's avatar Katharina Heck
Browse files

[feature] test newtonconvergencewriter on 2pni test

parent c2973437
......@@ -45,14 +45,14 @@ struct ConvergenceWriterInterface
/*!
* \ingroup Nonlinear
* \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
* 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.
*/
// template <class Scalar, class GridView, int numEq>
template <class GridView, class SolutionVector>
class NewtonConvergenceWriter : virtual public ConvergenceWriterInterface<SolutionVector>
class NewtonConvergenceWriter : public ConvergenceWriterInterface<SolutionVector>
{
static constexpr auto numEq = SolutionVector::block_type::dimension;
using Scalar = typename SolutionVector::block_type::value_type;
......
......@@ -170,7 +170,7 @@ public:
*/
template<class TimeLoop>
void solve(SolutionVector& uCurrentIter, TimeLoop& timeLoop,
const std::unique_ptr<ConvergenceWriter>& convWriter = nullptr)
std::shared_ptr<ConvergenceWriter> convWriter = nullptr)
{
if (assembler_->isStationaryProblem())
DUNE_THROW(Dune::InvalidStateException, "Using time step control with stationary problem makes no sense!");
......@@ -214,7 +214,7 @@ public:
* \brief Run the Newton method to solve a non-linear system.
* 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);
if (!converged)
......@@ -646,7 +646,7 @@ private:
* \brief Run the Newton method to solve a non-linear system.
* 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
SolutionVector uLastIter(uCurrentIter);
......
......@@ -159,6 +159,11 @@ int main(int argc, char** argv) try
using NewtonSolver = Dumux::NewtonSolver<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
timeLoop->start(); do
{
......@@ -166,7 +171,7 @@ int main(int argc, char** argv) try
assembler->setPreviousSolution(xOld);
// 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
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