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  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef EWOMS_FV_BASE_NEWTON_CONVERGENCE_WRITER_HH
27 #define EWOMS_FV_BASE_NEWTON_CONVERGENCE_WRITER_HH
28 
31 
32 #include <iostream>
33 
34 namespace Ewoms {
36 namespace Properties {
37 // forward declaration of the required property tags
38 NEW_PROP_TAG(GridView);
39 NEW_PROP_TAG(NewtonMethod);
40 NEW_PROP_TAG(SolutionVector);
41 NEW_PROP_TAG(GlobalEqVector);
42 NEW_PROP_TAG(VtkOutputFormat);
43 } // namespace Properties
45 
52 template <class TypeTag>
54 {
55  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
56 
57  typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
58  typedef typename GET_PROP_TYPE(TypeTag, GlobalEqVector) GlobalEqVector;
59  typedef typename GET_PROP_TYPE(TypeTag, NewtonMethod) NewtonMethod;
60 
61  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
63 
64 public:
66  : newtonMethod_(nm)
67  {
68  timeStepIdx_ = 0;
69  iteration_ = 0;
70  vtkMultiWriter_ = 0;
71  }
72 
74  { delete vtkMultiWriter_; }
75 
81  {
82  ++timeStepIdx_;
83  iteration_ = 0;
84  }
85 
91  {
92  ++ iteration_;
93  if (!vtkMultiWriter_)
94  vtkMultiWriter_ =
95  new VtkMultiWriter(newtonMethod_.problem().gridView(), "convergence");
96  vtkMultiWriter_->beginWrite(timeStepIdx_ + iteration_ / 100.0);
97  }
98 
108  void writeFields(const SolutionVector &uLastIter,
109  const GlobalEqVector &deltaU)
110  {
111  try {
112  newtonMethod_.problem().model().addConvergenceVtkFields(*vtkMultiWriter_,
113  uLastIter,
114  deltaU);
115  }
116  catch (...) {
117  std::cout << "Oops: exception thrown on rank "
118  << newtonMethod_.problem().gridView().comm().rank()
119  << " while writing the convergence\n" << std::flush;
120  }
121  }
122 
128  { vtkMultiWriter_->endWrite(); }
129 
137  void endTimeStep()
138  { iteration_ = 0; }
139 
140 private:
141  int timeStepIdx_;
142  int iteration_;
143  VtkMultiWriter *vtkMultiWriter_;
144  NewtonMethod &newtonMethod_;
145 };
146 
147 } // namespace Ewoms
148 
149 #endif
void endIteration()
Called by the Newton method after an iteration of the Newton algorithm has been completed.
Definition: fvbasenewtonconvergencewriter.hh:127
Problem & problem()
Returns a reference to the object describing the current physical problem.
Definition: newtonmethod.hh:233
void endTimeStep()
Called by the Newton method after Newton algorithm has been completed for any given timestep...
Definition: fvbasenewtonconvergencewriter.hh:137
The multi-dimensional Newton method.
Definition: newtonmethod.hh:54
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
void writeFields(const SolutionVector &uLastIter, const GlobalEqVector &deltaU)
Write the Newton update to disk.
Definition: fvbasenewtonconvergencewriter.hh:108
void beginTimeStep()
Called by the Newton method before the actual algorithm is started for any given timestep.
Definition: fvbasenewtonconvergencewriter.hh:80
void beginIteration()
Called by the Newton method before an iteration of the Newton algorithm is started.
Definition: fvbasenewtonconvergencewriter.hh:90
~FvBaseNewtonConvergenceWriter()
Definition: fvbasenewtonconvergencewriter.hh:73
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
Simplifies writing multi-file VTK datasets.
Definition: baseauxiliarymodule.hh:35
FvBaseNewtonConvergenceWriter(NewtonMethod &nm)
Definition: fvbasenewtonconvergencewriter.hh:65
Writes the intermediate solutions during the Newton scheme for models using a finite volume discretiz...
Definition: fvbasenewtonconvergencewriter.hh:53
void beginWrite(double t)
Called whenever a new time step must be written.
Definition: vtkmultiwriter.hh:128
Provides the magic behind the eWoms property system.
void endWrite(bool onlyDiscard=false)
Finalizes the current writer.
Definition: vtkmultiwriter.hh:339
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:61