17#ifndef rdl_vtk_utils_h
18#define rdl_vtk_utils_h
42#include <unordered_map>
45#ifdef DEAL_II_WITH_VTK
91 template <
int dim,
int spacedim>
93 read_vtk(
const std::string &vtk_filename,
94 Triangulation<dim, spacedim> &tria,
95 const bool cleanup =
true);
111 read_cell_data(
const std::string &vtk_filename,
112 const std::string &cell_data_name,
113 Vector<double> &output_vector);
126 read_vertex_data(
const std::string &vtk_filename,
127 const std::string &vertex_data_name,
128 Vector<double> &output_vector);
153 read_data(
const std::string &vtk_filename, Vector<double> &output_vector);
171 template <
int dim,
int spacedim>
172 std::pair<std::unique_ptr<FiniteElement<dim, spacedim>>,
173 std::vector<std::string>>
174 vtk_to_finite_element(
const std::string &vtk_filename);
191 template <
int dim,
int spacedim>
193 get_block_indices(
const FiniteElement<dim, spacedim> &fe);
214 template <
int dim,
int spacedim,
typename VectorType>
216 data_to_dealii_vector(
const Triangulation<dim, spacedim> &serial_tria,
217 const Vector<double> &data,
218 const DoFHandler<dim, spacedim> &dh,
219 VectorType &output_vector);
240 template <
int dim,
int spacedim>
242 read_vtk(
const std::string &vtk_filename,
243 DoFHandler<dim, spacedim> &dof_handler,
244 Vector<double> &output_vector,
245 std::vector<std::string> &data_names);
260 template <
int dim,
int spacedim>
262 serial_vector_to_distributed_vector(
263 const DoFHandler<dim, spacedim> &serial_dh,
264 const DoFHandler<dim, spacedim> ¶llel_dh,
265 const Vector<double> &serial_vec,
266 LinearAlgebra::distributed::Vector<double> ¶llel_vec);
283 template <
int dim,
int spacedim>
284 std::vector<types::global_vertex_index>
285 distributed_to_serial_vertex_indices(
286 const Triangulation<dim, spacedim> &serial_tria,
287 const Triangulation<dim, spacedim> ¶llel_tria);
292 template <
int dim,
int spacedim,
typename VectorType>
294 data_to_dealii_vector(
const Triangulation<dim, spacedim> &serial_tria,
295 const Vector<double> &data,
296 const DoFHandler<dim, spacedim> &dh,
297 VectorType &output_vector)
300 const auto &fe = dh.
get_fe();
302 const auto dist_to_serial_vertices =
308 unsigned int vertex_comp_offset = 0;
309 unsigned int cell_comp_offset = 0;
310 for (
unsigned int field = 0; field < fe.n_blocks(); ++field)
312 const auto &field_fe = fe.base_element(field);
313 const unsigned int n_comps = field_fe.n_components();
314 if (field_fe.n_dofs_per_vertex() > 0)
320 if (cell->is_locally_owned())
321 for (
const auto v : cell->vertex_indices())
324 dist_to_serial_vertices[cell->vertex_index(v)];
326 for (
unsigned int c = 0; c < n_comps; ++c)
329 cell->vertex_dof_index(v, vertex_comp_offset + c);
330 Assert(locally_owned_dofs.is_element(dof_index),
332 output_vector[dof_index] =
333 data[dofs_offset + n_comps * serial_vertex_index +
337 dofs_offset += n_local_dofs;
338 vertex_comp_offset += n_comps;
340 else if (field_fe.template n_dofs_per_object<dim>() > 0)
350 for (; parallel_cell != dh.
end(); ++parallel_cell)
351 if (parallel_cell->is_locally_owned())
355 while (serial_cell->id() < parallel_cell->id())
357 const auto serial_cell_index =
358 serial_cell->global_active_cell_index();
359 for (
unsigned int c = 0; c < n_comps; ++c)
362 parallel_cell->dof_index(cell_comp_offset + c);
363 Assert(locally_owned_dofs.is_element(dof_index),
365 output_vector[dof_index] =
366 data[dofs_offset + n_comps * serial_cell_index + c];
369 dofs_offset += n_local_dofs;
370 cell_comp_offset += n_comps;
375 template <
int dim,
int spacedim>
377 get_block_indices(
const FiniteElement<dim, spacedim> &fe)
379 BlockIndices block_indices;
380 for (
unsigned int i = 0; i < fe.
n_blocks(); ++i)
383 block_indices.
push_back(block_fe.n_components());
385 return block_indices;
void push_back(const size_type size)
cell_iterator end() const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
const IndexSet & locally_owned_dofs() const
active_cell_iterator begin_active(const unsigned int level=0) const
types::global_dof_index n_dofs() const
unsigned int n_blocks() const
virtual const FiniteElement< dim, spacedim > & base_element(const unsigned int index) const
virtual types::global_cell_index n_global_active_cells() const
unsigned int n_vertices() const
active_cell_iterator begin_active(const unsigned int level=0) const
IteratorRange< active_cell_iterator > active_cell_iterators() const
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
std::vector< index_type > data
constexpr unsigned int invalid_unsigned_int
unsigned int global_dof_index