fvbasenewtonconvergencewriter.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_FV_BASE_NEWTON_CONVERGENCE_WRITER_HH
29#define EWOMS_FV_BASE_NEWTON_CONVERGENCE_WRITER_HH
30
34
35#include <iostream>
36#include <memory>
37
39namespace Opm::Properties {
40
41// forward declaration of the required property tags
42template<class TypeTag, class MyTypeTag>
43struct SolutionVector;
44template<class TypeTag, class MyTypeTag>
45struct GlobalEqVector;
46template<class TypeTag, class MyTypeTag>
47struct NewtonMethod;
48template<class TypeTag, class MyTypeTag>
49struct VtkOutputFormat;
50
51} // namespace Opm::Properties
53
54namespace Opm {
55
62template <class TypeTag>
64{
66
70
71 static constexpr auto vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
73
74public:
75 explicit FvBaseNewtonConvergenceWriter(NewtonMethod& nm)
76 : newtonMethod_(nm)
77 {
78 timeStepIdx_ = 0;
79 iteration_ = 0;
80 }
81
87 {
88 ++timeStepIdx_;
89 iteration_ = 0;
90 }
91
97 {
98 ++iteration_;
99 if (!vtkMultiWriter_) {
100 vtkMultiWriter_ =
101 std::make_unique<VtkMultiWriter>(/*async=*/false,
102 newtonMethod_.problem().gridView(),
103 newtonMethod_.problem().outputDir(),
104 "convergence");
105 }
106 vtkMultiWriter_->beginWrite(timeStepIdx_ + iteration_ / 100.0);
107 }
108
118 void writeFields(const SolutionVector& uLastIter,
119 const GlobalEqVector& deltaU)
120 {
121 try {
122 newtonMethod_.problem().model().addConvergenceVtkFields(*vtkMultiWriter_,
123 uLastIter,
124 deltaU);
125 }
126 catch (...) {
127 std::cout << "Oops: exception thrown on rank "
128 << newtonMethod_.problem().gridView().comm().rank()
129 << " while writing the convergence\n" << std::flush;
130 }
131 }
132
138 { vtkMultiWriter_->endWrite(false); }
139
148 { iteration_ = 0; }
149
150private:
151 int timeStepIdx_;
152 int iteration_;
153 std::unique_ptr<VtkMultiWriter> vtkMultiWriter_{};
154 NewtonMethod& newtonMethod_;
155};
156
157} // namespace Opm
158
159#endif
Defines a type tags and some fundamental properties all models.
Writes the intermediate solutions during the Newton scheme for models using a finite volume discretiz...
Definition: fvbasenewtonconvergencewriter.hh:64
void writeFields(const SolutionVector &uLastIter, const GlobalEqVector &deltaU)
Write the Newton update to disk.
Definition: fvbasenewtonconvergencewriter.hh:118
void beginTimeStep()
Called by the Newton method before the actual algorithm is started for any given timestep.
Definition: fvbasenewtonconvergencewriter.hh:86
void endTimeStep()
Called by the Newton method after Newton algorithm has been completed for any given timestep.
Definition: fvbasenewtonconvergencewriter.hh:147
FvBaseNewtonConvergenceWriter(NewtonMethod &nm)
Definition: fvbasenewtonconvergencewriter.hh:75
void beginIteration()
Called by the Newton method before an iteration of the Newton algorithm is started.
Definition: fvbasenewtonconvergencewriter.hh:96
void endIteration()
Called by the Newton method after an iteration of the Newton algorithm has been completed.
Definition: fvbasenewtonconvergencewriter.hh:137
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:65
Definition: blackoilmodel.hh:79
Definition: blackoilboundaryratevector.hh:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
The Opm property system, traits with inheritance.