All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
33 
34 #include <iostream>
35 
36 namespace Ewoms {
38 namespace Properties {
39 // forward declaration of the required property tags
40 NEW_PROP_TAG(GridView);
41 NEW_PROP_TAG(NewtonMethod);
42 NEW_PROP_TAG(SolutionVector);
43 NEW_PROP_TAG(GlobalEqVector);
44 NEW_PROP_TAG(VtkOutputFormat);
45 } // namespace Properties
47 
54 template <class TypeTag>
56 {
57  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
58 
59  typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
60  typedef typename GET_PROP_TYPE(TypeTag, GlobalEqVector) GlobalEqVector;
61  typedef typename GET_PROP_TYPE(TypeTag, NewtonMethod) NewtonMethod;
62 
63  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
65 
66 public:
68  : newtonMethod_(nm)
69  {
70  timeStepIdx_ = 0;
71  iteration_ = 0;
72  vtkMultiWriter_ = 0;
73  }
74 
76  { delete vtkMultiWriter_; }
77 
83  {
84  ++timeStepIdx_;
85  iteration_ = 0;
86  }
87 
93  {
94  ++ iteration_;
95  if (!vtkMultiWriter_)
96  vtkMultiWriter_ =
97  new VtkMultiWriter(newtonMethod_.problem().gridView(), "convergence");
98  vtkMultiWriter_->beginWrite(timeStepIdx_ + iteration_ / 100.0);
99  }
100 
110  void writeFields(const SolutionVector& uLastIter,
111  const GlobalEqVector& deltaU)
112  {
113  try {
114  newtonMethod_.problem().model().addConvergenceVtkFields(*vtkMultiWriter_,
115  uLastIter,
116  deltaU);
117  }
118  catch (...) {
119  std::cout << "Oops: exception thrown on rank "
120  << newtonMethod_.problem().gridView().comm().rank()
121  << " while writing the convergence\n" << std::flush;
122  }
123  }
124 
130  { vtkMultiWriter_->endWrite(); }
131 
139  void endTimeStep()
140  { iteration_ = 0; }
141 
142 private:
143  int timeStepIdx_;
144  int iteration_;
145  VtkMultiWriter *vtkMultiWriter_;
146  NewtonMethod& newtonMethod_;
147 };
148 
149 } // namespace Ewoms
150 
151 #endif
void beginIteration()
Called by the Newton method before an iteration of the Newton algorithm is started.
Definition: fvbasenewtonconvergencewriter.hh:92
void endIteration()
Called by the Newton method after an iteration of the Newton algorithm has been completed.
Definition: fvbasenewtonconvergencewriter.hh:129
void beginWrite(double t)
Called whenever a new time step must be written.
Definition: vtkmultiwriter.hh:135
Writes the intermediate solutions during the Newton scheme for models using a finite volume discretiz...
Definition: fvbasenewtonconvergencewriter.hh:55
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:63
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
void endTimeStep()
Called by the Newton method after Newton algorithm has been completed for any given timestep...
Definition: fvbasenewtonconvergencewriter.hh:139
void endWrite(bool onlyDiscard=false)
Finalizes the current writer.
Definition: vtkmultiwriter.hh:340
The multi-dimensional Newton method.
Definition: newtonmethod.hh:56
Provides the magic behind the eWoms property system.
Simplifies writing multi-file VTK datasets.
void beginTimeStep()
Called by the Newton method before the actual algorithm is started for any given timestep.
Definition: fvbasenewtonconvergencewriter.hh:82
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247
Problem & problem()
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:244
void writeFields(const SolutionVector &uLastIter, const GlobalEqVector &deltaU)
Write the Newton update to disk.
Definition: fvbasenewtonconvergencewriter.hh:110