13#ifndef DUMUX_NEWTON_CONVERGENCE_WRITER_HH
14#define DUMUX_NEWTON_CONVERGENCE_WRITER_HH
18#include <dune/grid/io/file/vtk/vtksequencewriter.hh>
30template <
class SolutionVector,
class Res
idualVector>
35 virtual void write(
const SolutionVector &uLastIter,
const ResidualVector &deltaU,
const ResidualVector &residual) {}
44template <
class Gr
idGeometry,
class SolutionVector,
class Res
idualVector>
47 using GridView =
typename GridGeometry::GridView;
48 static constexpr auto numEq = SolutionVector::block_type::dimension;
49 using Scalar =
typename SolutionVector::block_type::value_type;
52 "This convergence writer does not work for the staggered method, use the StaggeredNewtonConvergenceWriter instead");
60 const std::string& name =
"newton_convergence")
61 : gridGeometry_(gridGeometry)
62 , writer_(gridGeometry.gridView(), name,
"",
"")
68 for (
int eqIdx = 0; eqIdx < numEq; ++eqIdx)
70 writer_.addVertexData(x_[eqIdx],
"x_" + std::to_string(eqIdx));
71 writer_.addVertexData(delta_[eqIdx],
"delta_" + std::to_string(eqIdx));
72 writer_.addVertexData(def_[eqIdx],
"defect_" + std::to_string(eqIdx));
77 for (
int eqIdx = 0; eqIdx < numEq; ++eqIdx)
79 writer_.addCellData(x_[eqIdx],
"x_" + std::to_string(eqIdx));
80 writer_.addCellData(delta_[eqIdx],
"delta_" + std::to_string(eqIdx));
81 writer_.addCellData(def_[eqIdx],
"defect_" + std::to_string(eqIdx));
89 const auto numDofs = gridGeometry_.numDofs();
92 for (
int eqIdx = 0; eqIdx < numEq; ++eqIdx)
94 def_[eqIdx].resize(numDofs);
95 delta_[eqIdx].resize(numDofs);
96 x_[eqIdx].resize(numDofs);
103 { id_ = newId; iteration_ = 0UL; }
105 void write(
const SolutionVector& uLastIter,
106 const ResidualVector& deltaU,
107 const ResidualVector& residual)
override
109 assert(uLastIter.size() == deltaU.size() && uLastIter.size() == residual.size());
111 for (std::size_t dofIdxGlobal = 0; dofIdxGlobal < deltaU.size(); ++dofIdxGlobal)
113 for (
int eqIdx = 0; eqIdx < numEq; ++eqIdx)
115 x_[eqIdx][dofIdxGlobal] = uLastIter[dofIdxGlobal][eqIdx];
116 delta_[eqIdx][dofIdxGlobal] = - deltaU[dofIdxGlobal][eqIdx];
117 def_[eqIdx][dofIdxGlobal] = residual[dofIdxGlobal][eqIdx];
121 writer_.write(
static_cast<double>(id_) +
static_cast<double>(iteration_)/1000);
126 std::size_t id_ = 0UL;
127 std::size_t iteration_ = 0UL;
129 const GridGeometry& gridGeometry_;
131 Dune::VTKSequenceWriter<GridView> writer_;
133 std::array<std::vector<Scalar>, numEq> def_;
134 std::array<std::vector<Scalar>, numEq> delta_;
135 std::array<std::vector<Scalar>, numEq> x_;
Writes the intermediate solutions for every Newton iteration.
Definition: nonlinear/newtonconvergencewriter.hh:46
void resize()
Resizes the output fields. This has to be called whenever the grid changes.
Definition: nonlinear/newtonconvergencewriter.hh:87
void reset(std::size_t newId=0UL)
Definition: nonlinear/newtonconvergencewriter.hh:102
void write(const SolutionVector &uLastIter, const ResidualVector &deltaU, const ResidualVector &residual) override
Definition: nonlinear/newtonconvergencewriter.hh:105
NewtonConvergenceWriter(const GridGeometry &gridGeometry, const std::string &name="newton_convergence")
Constructor.
Definition: nonlinear/newtonconvergencewriter.hh:59
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
constexpr Staggered staggered
Definition: method.hh:149
A convergence writer interface Provide an interface that show the minimal requirements a convergence ...
Definition: nonlinear/newtonconvergencewriter.hh:32
virtual void write(const SolutionVector &uLastIter, const ResidualVector &deltaU, const ResidualVector &residual)
Definition: nonlinear/newtonconvergencewriter.hh:35
virtual ~ConvergenceWriterInterface()=default