deal2lkit: A ToolKit library for Deal.II
parsed_data_out.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2015 by the deal2lkit authors
4 //
5 // This file is part of the deal2lkit library.
6 //
7 // The deal2lkit 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 deal2lkit distribution.
13 //
14 //-----------------------------------------------------------
15 
16 #ifndef _d2k_parsed_data_out_h
17 #define _d2k_parsed_data_out_h
18 
19 #include <deal2lkit/config.h>
20 #include <fstream>
21 
22 #include <deal.II/base/config.h>
24 #include <deal.II/grid/tria.h>
26 
27 #include <deal.II/base/logstream.h>
29 
31 #include <deal2lkit/utilities.h>
32 
33 D2K_NAMESPACE_OPEN
34 
35 
36 template <int dim, int spacedim=dim>
38 {
39 public:
45  ParsedDataOut (const std::string &name="",
46  const std::string &output_format="vtu",
47  const unsigned int &subdivisions=1,
48  const std::string &incremental_run_prefix="",
49  const std::string &base_name_input="solution",
50  const std::string &files_to_save="",
51  const MPI_Comm &comm=MPI_COMM_WORLD);
52 
55 
57  virtual void parse_parameters_call_back();
58 
64  const std::string &suffix="");
65 
71  template<typename VECTOR>
72  void add_data_vector(const VECTOR &data_vector, const std::string &desc);
73 
74 
78  template<typename VECTOR>
79  void add_data_vector(const VECTOR &data_vector, const DataPostprocessor<spacedim> &postproc);
80 
81 
91 
92 private:
95 
97  const MPI_Comm &comm;
98 
100  const unsigned int n_mpi_processes;
101 
103  const unsigned int this_mpi_process;
104 
106  std::string path_solution_dir;
107 
109  std::string output_format;
110 
112  unsigned int subdivisions;
113 
116  std::string base_name;
117 
122 
128  std::string files_to_save;
129 
131  std::string solution_names;
132 
136  std::string current_name;
137 
140 
142  std::ofstream output_file;
143 
145  shared_ptr<DataOut<dim, DoFHandler<dim, spacedim> > > data_out;
146 };
147 
148 
149 // ============================================================
150 // Template specializations
151 // ============================================================
152 
153 template <int dim, int spacedim>
154 template<typename VECTOR>
155 void ParsedDataOut<dim,spacedim>::add_data_vector(const VECTOR &data_vector,
156  const std::string &desc)
157 {
159  deallog.push("AddingData");
160  std::vector<std::string> dd = Utilities::split_string_list(desc);
161  if (data_out->default_suffix() != "")
162  {
163  if (dd.size() ==1 )
164  {
165  data_out->add_data_vector (data_vector, desc);
166  }
167  else
168  {
169  std::vector<std::string>::iterator sit = dd.begin();
170  std::vector<int> occurrances;
171 
172  for (; sit!=dd.end(); ++sit)
173  occurrances.push_back(std::count (dd.begin(), dd.end(), *sit));
174 
175  std::vector<int>::iterator iit = occurrances.begin();
176  sit = dd.begin();
177 
178  std::vector<DataComponentInterpretation::DataComponentInterpretation>
179  data_component_interpretation;
180 
181  for (; iit !=occurrances.end(); ++iit, ++sit)
182  {
183  if (*iit > 1)
184  data_component_interpretation.push_back(DataComponentInterpretation::component_is_part_of_vector);
185  else
186  data_component_interpretation.push_back(DataComponentInterpretation::component_is_scalar);
187  }
188 
189  data_out->add_data_vector (data_vector, dd, DataOut<dim, DoFHandler<dim, spacedim> >::type_dof_data,
190  data_component_interpretation);
191 
192  }
193  deallog << "Added data: " << desc << std::endl;
194  }
195  deallog.pop();
196 }
197 
198 
199 template <int dim, int spacedim>
200 template<typename VECTOR>
201 void ParsedDataOut<dim,spacedim>::add_data_vector(const VECTOR &data_vector,
202  const DataPostprocessor<spacedim> &postproc)
203 {
205  data_out->add_data_vector(data_vector,postproc);
206 }
207 
208 D2K_NAMESPACE_CLOSE
209 
210 #endif
virtual void parse_parameters_call_back()
Prepare names for output directories.
std::string base_name
Base name for output files.
shared_ptr< DataOut< dim, DoFHandler< dim, spacedim > > > data_out
Outputs only the data that refers to this process.
std::string incremental_run_prefix
name of progressive directories.
std::string files_to_save
a list of file to save at each run in @ incremental_run_prefix directory.
A parameter acceptor base class.
static ParameterHandler prm
Static parameter.
bool output_partitioning
Output the partitioning of the domain.
const unsigned int this_mpi_process
My mpi process.
std::string output_format
Output format.
static::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
const unsigned int n_mpi_processes
Number of processes.
unsigned int subdivisions
Number of subdivisions.
std::ofstream output_file
Output file.
bool initialized
Initialization flag.
std::string current_name
Current output name.
std::string solution_names
Solution names.
std::string path_solution_dir
Folder where solutions are stored.
void write_data_and_clear(const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
Actually write the file.
void prepare_data_output(const DoFHandler< dim, spacedim > &dh, const std::string &suffix="")
Prepare to output data on the given file.
std::vector< std::string > split_string_list(const std::string &s, const char delimiter=',')
virtual void declare_parameters(ParameterHandler &prm)
Initialize the given values for the paramter file.
ParsedDataOut(const std::string &name="", const std::string &output_format="vtu", const unsigned int &subdivisions=1, const std::string &incremental_run_prefix="", const std::string &base_name_input="solution", const std::string &files_to_save="", const MPI_Comm &comm=MPI_COMM_WORLD)
Optional name for parameter section.
const MPI_Comm & comm
MPI communicator.
void add_data_vector(const VECTOR &data_vector, const std::string &desc)
Add the given vector to the output file.