Fluid structure interaction suite
data_out.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef parsed_tools_data_out_h
17 #define parsed_tools_data_out_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/logstream.h>
22 #include <deal.II/base/mpi.h>
24 
26 
27 #include <deal.II/fe/mapping_q1.h>
28 
29 #include <deal.II/grid/tria.h>
30 
32 
33 #include <filesystem>
34 #include <fstream>
35 
36 #include "parsed_tools/enum.h"
37 
38 namespace ParsedTools
39 {
40  template <int dim, int spacedim = dim>
41  class DataOut : public dealii::ParameterAcceptor
42  {
43  public:
54  DataOut(const std::string &section_name = "",
55  const std::string &base_name = "solution",
56  const std::string &output_format = "vtu",
57  const unsigned int &subdivisions = 0,
58  const bool &write_higher_order_cells = true,
59  const MPI_Comm &comm = MPI_COMM_WORLD);
60 
67  void
68  attach_dof_handler(const dealii::DoFHandler<dim, spacedim> &dh,
69  const std::string &suffix = "");
70 
80  template <typename VECTOR>
81  void
83  const VECTOR &data_vector,
84  const std::string &desc,
85  const typename dealii::DataOut<dim, spacedim>::DataVectorType &type =
86  dealii::DataOut<dim, spacedim>::type_automatic);
87 
91  template <typename VECTOR>
92  void
93  add_data_vector(const VECTOR &data_vector,
94  const dealii::DataPostprocessor<spacedim> &postproc);
95 
96 
106  void
107  write_data_and_clear(const dealii::Mapping<dim, spacedim> &mapping =
108  dealii::StaticMappingQ1<dim, spacedim>::mapping);
109 
111  void
113 
114  private:
116  const std::string component_names;
117 
119  const MPI_Comm &comm;
120 
122  const unsigned int n_mpi_processes;
123 
125  const unsigned int this_mpi_process;
126 
128  std::string output_format;
129 
131  unsigned int subdivisions;
132 
135 
138  std::string base_name;
139 
141  std::string current_directory;
142 
144  std::string current_filename;
145 
147  std::string master_name;
148 
152  std::string current_name;
153 
156 
159 
161  std::ofstream output_file;
162 
164  std::unique_ptr<dealii::DataOut<dim, spacedim>> data_out;
165 
166  typename dealii::DataOut<dim, spacedim>::CurvedCellRegion
167  curved_cells_region = dealii::DataOut<dim, spacedim>::curved_inner_cells;
168 
172  std::vector<std::pair<double, std::string>> pvd_record;
173  };
174 
175 
176  // ============================================================
177  // Template specializations
178  // ============================================================
179 
180  template <int dim, int spacedim>
181  template <typename VECTOR>
182  void
184  const VECTOR &data_vector,
185  const std::string &desc,
186  const typename dealii::DataOut<dim, spacedim>::DataVectorType &type)
187  {
188  std::vector<std::string> dd = dealii::Utilities::split_string_list(desc);
189  if (data_out->default_suffix() != "")
190  {
191  if (dd.size() == 1)
192  {
193  data_out->add_data_vector(data_vector, desc, type);
194  }
195  else
196  {
197  std::vector<std::string>::iterator sit = dd.begin();
198  std::vector<int> occurrances;
199 
200  for (; sit != dd.end(); ++sit)
201  occurrances.push_back(std::count(dd.begin(), dd.end(), *sit));
202 
203  std::vector<int>::iterator iit = occurrances.begin();
204  sit = dd.begin();
205 
206  std::vector<
207  dealii::DataComponentInterpretation::DataComponentInterpretation>
208  data_component_interpretation;
209 
210  for (; iit != occurrances.end(); ++iit, ++sit)
211  {
212  if (*iit > 1)
213  data_component_interpretation.push_back(
214  dealii::DataComponentInterpretation::
215  component_is_part_of_vector);
216  else
217  data_component_interpretation.push_back(
218  dealii::DataComponentInterpretation::component_is_scalar);
219  }
220 
221  data_out->add_data_vector(data_vector,
222  dd,
223  type,
224  data_component_interpretation);
225  }
226  }
227  }
228 
229 
230  template <int dim, int spacedim>
231  template <typename VECTOR>
232  void
234  const VECTOR &data_vector,
235  const dealii::DataPostprocessor<spacedim> &postproc)
236  {
237  data_out->add_data_vector(data_vector, postproc);
238  }
239 
240 } // namespace ParsedTools
241 
242 #endif
const std::string section_name
unsigned int subdivisions
Number of subdivisions.
Definition: data_out.h:131
bool write_higher_order_cells
If available, output high order data.
Definition: data_out.h:134
std::vector< std::pair< double, std::string > > pvd_record
Record of all output files and times.
Definition: data_out.h:172
std::string current_name
Current output name.
Definition: data_out.h:152
std::string master_name
The name used for the master pvd file.
Definition: data_out.h:147
std::ofstream output_file
Output file.
Definition: data_out.h:161
void write_data_and_clear(const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
Actually write the file.
Definition: data_out.cc:194
std::string output_format
Output format.
Definition: data_out.h:128
const unsigned int this_mpi_process
My mpi process.
Definition: data_out.h:125
bool output_material_ids
Output the material ids of the domain.
Definition: data_out.h:158
bool output_partitioning
Output the partitioning of the domain.
Definition: data_out.h:155
void add_data_vector(const VECTOR &data_vector, const std::string &desc, const typename DataOut< dim, spacedim >::DataVectorType &type=DataOut< dim, spacedim >::type_automatic)
Add the given vector to the output file.
Definition: data_out.h:183
std::string base_name
Base name for output files.
Definition: data_out.h:138
DataOut(const std::string &section_name="", const std::string &base_name="solution", const std::string &output_format="vtu", const unsigned int &subdivisions=0, const bool &write_higher_order_cells=true, const MPI_Comm &comm=MPI_COMM_WORLD)
Construct a new DataOut object.
Definition: data_out.cc:72
const std::string component_names
Initialization flag.
Definition: data_out.h:116
void add_data_vector(const VECTOR &data_vector, const DataPostprocessor< spacedim > &postproc)
Wrapper for the corrisponding function in dealii.
Definition: data_out.h:233
const MPI_Comm & comm
MPI communicator.
Definition: data_out.h:119
std::string current_filename
The name of last written filew.
Definition: data_out.h:144
std::unique_ptr< DataOut< dim, spacedim > > data_out
Outputs only the data that refers to this process.
Definition: data_out.h:164
DataOut< dim, spacedim >::CurvedCellRegion curved_cells_region
Definition: data_out.h:167
void attach_dof_handler(const DoFHandler< dim, spacedim > &dh, const std::string &suffix="")
Prepare to output data on the given file.
Definition: data_out.cc:119
const unsigned int n_mpi_processes
Number of processes.
Definition: data_out.h:122
void clear_pvd_record()
Resets the pvd_record.
Definition: data_out.cc:110
std::string current_directory
Folder where solutions are stored.
Definition: data_out.h:141
Type type(const std::string &component_name, const std::string &selected_component)
Return the component type for the given selected component.
Definition: components.cc:186
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...