version 3.10-dev
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
31template <class MDTraits>
32class MultiDomainNewtonConvergenceWriter : public ConvergenceWriterInterface<typename MDTraits::SolutionVector,typename MDTraits::ResidualVector>
33{
34 template<std::size_t id>
35 using SubDomainGridGeometry = typename MDTraits::template SubDomain<id>::GridGeometry;
36
37 using GridGeometryPtrTuple = typename MDTraits::template TupleOfSharedPtrConst<SubDomainGridGeometry>;
38
39 using SolutionVector = typename MDTraits::SolutionVector;
40 using ResidualVector = typename MDTraits::ResidualVector;
41
42 template<std::size_t id>
43 using SubDomainSolutionVector = typename MDTraits::template SubDomain<id>::SolutionVector;
44 template<std::size_t id>
45 using SubDomainResidualVector = typename MDTraits::template SubDomain<id>::ResidualVector;
46
47 template<std::size_t id>
48 using SubDomainNewtonConvergenceWriter = NewtonConvergenceWriter<SubDomainGridGeometry<id>, SubDomainSolutionVector<id>, SubDomainResidualVector<id>>;
49
50 using ConvergenceWriterPtrTuple = typename MDTraits::template TupleOfSharedPtr<SubDomainNewtonConvergenceWriter>;
51
52public:
58 MultiDomainNewtonConvergenceWriter(GridGeometryPtrTuple gridGeometryPtrTuple,
59 const std::string& name = "newton_convergence")
60 : gridGeometryPtrTuple_(std::move(gridGeometryPtrTuple))
61 {
62 using namespace Dune::Hybrid;
63 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
64 {
65 using ConvWriter = SubDomainNewtonConvergenceWriter<std::decay_t<decltype(id)>::value>;
66 elementAt(convergenceWriterPtrTuple_, id) = std::make_shared<ConvWriter>(*elementAt(gridGeometryPtrTuple_, id), name + "_domain_" + std::to_string(id));
67 });
68 }
69
71 void resize()
72 {
73 using namespace Dune::Hybrid;
74 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
75 {
76 elementAt(convergenceWriterPtrTuple_, id)->resize();
77 });
78 }
79
82 void reset(std::size_t newId = 0UL)
83 {
84 using namespace Dune::Hybrid;
85 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
86 {
87 elementAt(convergenceWriterPtrTuple_, id)->reset(newId);
88 });
89 }
90
91 void write(const SolutionVector& uLastIter,
92 const ResidualVector& deltaU,
93 const ResidualVector& residual) override
94 {
95 using namespace Dune::Hybrid;
96 forEach(std::make_index_sequence<MDTraits::numSubDomains>{}, [&](auto&& id)
97 {
98 constexpr auto i = std::decay_t<decltype(id)>{};
99 elementAt(convergenceWriterPtrTuple_, id)->write(uLastIter[i], deltaU[i], residual[i]);
100 });
101 }
102
103private:
104 GridGeometryPtrTuple gridGeometryPtrTuple_;
105 ConvergenceWriterPtrTuple convergenceWriterPtrTuple_;
106};
107
108} // end namespace Dumux
109
110#endif
Writes the intermediate solutions for every Newton iteration.
Definition: multidomain/newtonconvergencewriter.hh:33
void reset(std::size_t newId=0UL)
Definition: multidomain/newtonconvergencewriter.hh:82
void resize()
Resizes the output fields. This has to be called whenever the grid changes.
Definition: multidomain/newtonconvergencewriter.hh:71
void write(const SolutionVector &uLastIter, const ResidualVector &deltaU, const ResidualVector &residual) override
Definition: multidomain/newtonconvergencewriter.hh:91
MultiDomainNewtonConvergenceWriter(GridGeometryPtrTuple gridGeometryPtrTuple, const std::string &name="newton_convergence")
Constructor.
Definition: multidomain/newtonconvergencewriter.hh:58
Writes the intermediate solutions for every Newton iteration.
Definition: nonlinear/newtonconvergencewriter.hh:46
Definition: adapt.hh:17
This class provides the infrastructure to write the convergence behaviour of the newton method into a...
A convergence writer interface Provide an interface that show the minimal requirements a convergence ...
Definition: nonlinear/newtonconvergencewriter.hh:32