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