Reference documentation for deal.II version 8.1.0
dof_print_solver_step.h
1 // ---------------------------------------------------------------------
2 // @f$Id: dof_print_solver_step.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2000 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__dof_print_solver_step_h
18 #define __deal2__dof_print_solver_step_h
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/logstream.h>
22 #include <deal.II/lac/solver_control.h>
23 #include <deal.II/lac/vector_memory.h>
24 #include <deal.II/numerics/data_out.h>
25 
26 #include <sstream>
27 #include <iomanip>
28 #include <fstream>
29 
31 
32 
54 template<int dim, class SOLVER, class VECTOR = Vector<double> >
55 class DoFPrintSolverStep : public SOLVER
56 {
57 public:
72  DataOut<dim> &data_out,
73  const std::string &basename);
74 
79  virtual void print_vectors (const unsigned int step,
80  const VECTOR &x,
81  const VECTOR &r,
82  const VECTOR &d) const;
83 private:
88 
92  const std::string basename;
93 };
94 
95 
96 /* ----------------------- template functions --------------- */
97 
98 template<int dim, class SOLVER, class VECTOR>
101  DataOut<dim> &data_out,
102  const std::string &basename)
103  : SOLVER (control, mem),
104  out (data_out),
105  basename (basename)
106 {}
107 
108 
109 template<int dim, class SOLVER, class VECTOR>
110 void
112  const VECTOR &x,
113  const VECTOR &r,
114  const VECTOR &d) const
115 {
116  out.clear_data_vectors();
117  out.add_data_vector(x, "solution");
118  out.add_data_vector(r, "residual");
119  out.add_data_vector(d, "update");
120 
121  std::ostringstream filename;
122  filename << basename
123  << std::setw(3) << std::setfill('0') << step
124  << out.default_suffix();
125 
126  const std::string fname = filename.str();
127 
128  deallog << "Writing file:" << fname << std::endl;
129 
130  out.build_patches();
131  std::ofstream of (fname.c_str());
132  out.write (of);
133 }
134 
135 DEAL_II_NAMESPACE_CLOSE
136 
137 #endif
const std::string basename
DoFPrintSolverStep(SolverControl &control, VectorMemory< VECTOR > &mem, DataOut< dim > &data_out, const std::string &basename)
virtual void print_vectors(const unsigned int step, const VECTOR &x, const VECTOR &r, const VECTOR &d) const