Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
visualization.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2025 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_visualization_h
5#define lethe_visualization_h
6
8
9#include <deal.II/base/data_out_base.h>
10
11#include <deal.II/particles/particle_handler.h>
12
13#include <tuple>
14#include <vector>
15
16using namespace dealii;
17
18/**
19 * @brief Building patches of particle properties for visualization.
20 * This function is taken from Aspect and deal.ii and implemented here.
21 *
22 * @tparam dim An integer that denotes the number of spatial dimensions.
23 * @tparam PropertiesIndex Index of the properties used within the ParticleHandler.
24 *
25 */
26template <int dim, typename PropertiesIndex>
27class Visualization : public dealii::DataOutInterface<0, dim>
28{
29public:
31
32 /**
33 * @brief Build the patches of properties of particles for visualization.
34 *
35 * @param particle_handler The particle handler of active particles for
36 * visualization.
37 * @param properties Properties of particles for visualization. This is a
38 * vector of pairs and each pair contains the property name as the first
39 * element and the size of the property as the second element. For vectors
40 * only the size of the first element of the vector is defined equal to the
41 * dimension.
42 */
43 void
44 build_patches(Particles::ParticleHandler<dim> &particle_handler,
45 const std::vector<std::pair<std::string, int>> &properties);
46
47 /**
48 * @brief Print the data of particles in the xyz format.
49 *
50 * @param particle_handler The particle handler of active particles.
51 * @param pcout Printing in parallel.
52 */
53 void
54 print_xyz(dealii::Particles::ParticleHandler<dim> &particle_handler,
55 const MPI_Comm &mpi_communicator,
56 const ConditionalOStream &pcout);
57
58 /**
59 * @brief Print the data of particles in the deal.II intermediate format.
60 *
61 * @param data_to_print The vector of data to be printed.
62 * @param background_dh The DoFHandler of the background grid.
63 * @param mpi_communicator The MPI communicator.
64 * @param pcout Printing in parallel.
65 */
66 void
67 print_intermediate_format(const Vector<float> &data_to_print,
68 const DoFHandler<dim> &background_dh,
69 const MPI_Comm &mpi_communicator,
70 const ConditionalOStream &pcout);
71
73
74private:
75 /**
76 * @brief Implementation of the corresponding function of the base class.
77 */
78 virtual const std::vector<DataOutBase::Patch<0, dim>> &
79 get_patches() const override;
80
81 /**
82 * @brief Implementation of the corresponding function of the base class.
83 */
84 virtual std::vector<std::string>
85 get_dataset_names() const override;
86
87 virtual std::vector<
88 std::tuple<unsigned int,
89 unsigned int,
90 std::string,
91 DataComponentInterpretation::DataComponentInterpretation>>
92 get_nonscalar_data_ranges() const override;
93
94 /**
95 * @brief Output information that is filled by build_patches() and
96 * written by the write function of the base class.
97 */
98 std::vector<DataOutBase::Patch<0, dim>> patches;
99
100 /**
101 * @brief A list of field names for all data components stored in patches.
102 */
103 std::vector<std::string> dataset_names;
104
105 /**
106 * @brief Store which of the data fields are vectors.
107 */
108 std::vector<
109 std::tuple<unsigned int,
110 unsigned int,
111 std::string,
112 DataComponentInterpretation::DataComponentInterpretation>>
114
115 /**
116 * @brief Particle properties that are written in output files.
117 */
118 std::vector<std::pair<std::string, int>> properties_to_write;
119};
120#endif
void print_intermediate_format(const Vector< float > &data_to_print, const DoFHandler< dim > &background_dh, const MPI_Comm &mpi_communicator, const ConditionalOStream &pcout)
Print the data of particles in the deal.II intermediate format.
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > vector_datasets
Store which of the data fields are vectors.
void build_patches(Particles::ParticleHandler< dim > &particle_handler, const std::vector< std::pair< std::string, int > > &properties)
Build the patches of properties of particles for visualization.
std::vector< std::pair< std::string, int > > properties_to_write
Particle properties that are written in output files.
virtual std::vector< std::string > get_dataset_names() const override
Implementation of the corresponding function of the base class.
std::vector< DataOutBase::Patch< 0, dim > > patches
Output information that is filled by build_patches() and written by the write function of the base cl...
virtual const std::vector< DataOutBase::Patch< 0, dim > > & get_patches() const override
Implementation of the corresponding function of the base class.
std::vector< std::string > dataset_names
A list of field names for all data components stored in patches.
void print_xyz(dealii::Particles::ParticleHandler< dim > &particle_handler, const MPI_Comm &mpi_communicator, const ConditionalOStream &pcout)
Print the data of particles in the xyz format.