version 3.8
multidomain/newtonconvergencewriter.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
15#ifndef DUMUX_MULTIDOMAIN_NEWTON_CONVERGENCE_WRITER_HH
16#define DUMUX_MULTIDOMAIN_NEWTON_CONVERGENCE_WRITER_HH
17
18#include <string>
19#include <dune/common/hybridutilities.hh>
21
22namespace Dumux {
23
33template <class MDTraits>
34class MultiDomainNewtonConvergenceWriter : public ConvergenceWriterInterface<typename MDTraits::SolutionVector,typename MDTraits::ResidualVector>
35{
36 template<std::size_t id>
37 using SubDomainGridGeometry = typename MDTraits::template SubDomain<id>::GridGeometry;
38
39 using GridGeometryTuple = typename MDTraits::template TupleOfSharedPtrConst<SubDomainGridGeometry>;
40
41 using SolutionVector = typename MDTraits::SolutionVector;
42 using ResidualVector = typename MDTraits::ResidualVector;
43
44 template<std::size_t id>
45 using SubDomainSolutionVector = typename MDTraits::template SubDomain<id>::SolutionVector;
46 template<std::size_t id>
47 using SubDomainResidualVector = typename MDTraits::template SubDomain<id>::ResidualVector;
48
49 template<std::size_t id>
50 using SubDomainNewtonConvergenceWriter = NewtonConvergenceWriter<SubDomainGridGeometry<id>, SubDomainSolutionVector<id>, SubDomainResidualVector<id>>;
51
52 using ConvergenceWriterPtrTuple = typename MDTraits::template TupleOfSharedPtr<SubDomainNewtonConvergenceWriter>;
53
54public:
60 MultiDomainNewtonConvergenceWriter(GridGeometryTuple gridGeometryTuple,
61 const std::string& name = "newton_convergence")
62 : gridGeometryTuple_(std::move(gridGeometryTuple))
63 {
64 using namespace Dune::Hybrid;
65 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
66 {
67 using ConvWriter = SubDomainNewtonConvergenceWriter<std::decay_t<decltype(id)>::value>;
68 elementAt(convergenceWriterPtrTuple_, id) = std::make_shared<ConvWriter>(*elementAt(gridGeometryTuple, id), name + "_domain_" + std::to_string(id));
69 });
70 }
71
73 void resize()
74 {
75 using namespace Dune::Hybrid;
76 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
77 {
78 elementAt(convergenceWriterPtrTuple_, id)->resize();
79 });
80 }
81
84 void reset(std::size_t newId = 0UL)
85 {
86 using namespace Dune::Hybrid;
87 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
88 {
89 elementAt(convergenceWriterPtrTuple_, id)->reset(newId);
90 });
91 }
92
93 void write(const SolutionVector& uLastIter,
94 const ResidualVector& deltaU,
95 const ResidualVector& residual) override
96 {
97 using namespace Dune::Hybrid;
98 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
99 {
100 constexpr auto i = std::decay_t<decltype(id)>{};
101 elementAt(convergenceWriterPtrTuple_, id)->write(uLastIter[i], deltaU[i], residual[i]);
102 });
103 }
104
105private:
106 GridGeometryTuple gridGeometryTuple_;
107 ConvergenceWriterPtrTuple convergenceWriterPtrTuple_;
108};
109
110} // end namespace Dumux
111
112#endif
Writes the intermediate solutions for every Newton iteration.
Definition: multidomain/newtonconvergencewriter.hh:35
void reset(std::size_t newId=0UL)
Definition: multidomain/newtonconvergencewriter.hh:84
void resize()
Resizes the output fields. This has to be called whenever the grid changes.
Definition: multidomain/newtonconvergencewriter.hh:73
void write(const SolutionVector &uLastIter, const ResidualVector &deltaU, const ResidualVector &residual) override
Definition: multidomain/newtonconvergencewriter.hh:93
MultiDomainNewtonConvergenceWriter(GridGeometryTuple gridGeometryTuple, const std::string &name="newton_convergence")
Constructor.
Definition: multidomain/newtonconvergencewriter.hh:60
Writes the intermediate solutions for every Newton iteration.
Definition: nonlinear/newtonconvergencewriter.hh:43
Definition: adapt.hh:17
This class provides the infrastructure to write the convergence behaviour of the newton method into a...
Definition: nonlinear/newtonconvergencewriter.hh:27