Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__dof_print_solver_step_h
00013 #define __deal2__dof_print_solver_step_h
00014
00015 #include <deal.II/base/config.h>
00016 #include <deal.II/base/logstream.h>
00017 #include <deal.II/lac/solver_control.h>
00018 #include <deal.II/lac/vector_memory.h>
00019 #include <deal.II/numerics/data_out.h>
00020
00021 #include <sstream>
00022 #include <iomanip>
00023 #include <fstream>
00024
00025 DEAL_II_NAMESPACE_OPEN
00026
00027
00049 template<int dim, class SOLVER, class VECTOR = Vector<double> >
00050 class DoFPrintSolverStep : public SOLVER
00051 {
00052 public:
00065 DoFPrintSolverStep (SolverControl& control,
00066 VectorMemory<VECTOR>& mem,
00067 DataOut<dim>& data_out,
00068 const std::string& basename);
00069
00074 virtual void print_vectors (const unsigned int step,
00075 const VECTOR& x,
00076 const VECTOR& r,
00077 const VECTOR& d) const;
00078 private:
00082 DataOut<dim>& out;
00083
00087 const std::string basename;
00088 };
00089
00090
00091
00092
00093 template<int dim, class SOLVER, class VECTOR>
00094 DoFPrintSolverStep<dim, SOLVER, VECTOR>::DoFPrintSolverStep (SolverControl& control,
00095 VectorMemory<VECTOR>& mem,
00096 DataOut<dim>& data_out,
00097 const std::string& basename)
00098 : SOLVER (control, mem),
00099 out (data_out),
00100 basename (basename)
00101 {}
00102
00103
00104 template<int dim, class SOLVER, class VECTOR>
00105 void
00106 DoFPrintSolverStep<dim, SOLVER, VECTOR>::print_vectors (const unsigned int step,
00107 const VECTOR& x,
00108 const VECTOR& r,
00109 const VECTOR& d) const
00110 {
00111 out.clear_data_vectors();
00112 out.add_data_vector(x, "solution");
00113 out.add_data_vector(r, "residual");
00114 out.add_data_vector(d, "update");
00115
00116 std::ostringstream filename;
00117 filename << basename
00118 << std::setw(3) << std::setfill('0') << step
00119 << out.default_suffix();
00120
00121 const std::string fname = filename.str();
00122
00123 deallog << "Writing file:" << fname << std::endl;
00124
00125 out.build_patches();
00126 std::ofstream of (fname.c_str());
00127 out.write (of);
00128 }
00129
00130 DEAL_II_NAMESPACE_CLOSE
00131
00132 #endif
00133