6#include <deal.II/numerics/data_out.h>
10template <
int dim,
typename PropertiesIndex>
13template <
int dim,
typename PropertiesIndex>
16 dealii::Particles::ParticleHandler<dim> &particle_handler,
17 const std::vector<std::pair<std::string, int>> &properties)
21 this->
dataset_names.reserve(PropertiesIndex::n_properties + 1);
27 for (
int field_position = 0; field_position < PropertiesIndex::n_properties;
31 const std::string field_name = properties[field_position].first;
34 const unsigned n_components = properties[field_position].second;
40 if (n_components == 3)
48 field_position + n_components,
50 DataComponentInterpretation::component_is_part_of_vector);
56 patches.resize(particle_handler.n_locally_owned_particles());
58 typename dealii::Particles::ParticleHandler<dim>::particle_iterator particle =
59 particle_handler.begin();
62 for (
unsigned int i = 0; particle != particle_handler.end(); ++particle, ++i)
65 patches[i].vertices[0] = particle->get_location();
67 patches[i].data.reinit(PropertiesIndex::n_properties + 1, 1);
70 if (particle->has_properties())
72 auto particle_properties = particle->get_properties();
75 patches[i].data(0, 0) = particle->get_id();
79 for (
unsigned int property_index = 0;
80 property_index < PropertiesIndex::n_properties;
82 patches[i].data(property_index + 1, 0) =
83 particle_properties[property_index];
88template <
int dim,
typename PropertiesIndex>
91 dealii::Particles::ParticleHandler<dim> &particle_handler,
92 const MPI_Comm &mpi_communicator,
93 const ConditionalOStream &pcout)
95 pcout <<
"id, type, dp, x, y, z";
100 pcout <<
" " << std::endl;
103 std::map<unsigned int, std::string> local_lines;
105 for (
auto particle = particle_handler.begin();
106 particle != particle_handler.end();
109 const unsigned int id = particle->get_id();
110 const auto &particle_properties = particle->get_properties();
111 const auto &particle_location = particle->get_location();
113 std::ostringstream oss;
114 oss << std::fixed << std::setprecision(0) <<
id <<
" "
115 << std::setprecision(0) << particle_properties[PropertiesIndex::type]
116 <<
" " << std::setprecision(5)
117 << particle_properties[PropertiesIndex::dp] <<
" "
118 << std::setprecision(4) << particle_location;
122 oss <<
" " << std::fixed << std::setprecision(4)
123 << particle_properties[PropertiesIndex::T];
126 local_lines[id] = oss.str();
133 const auto gathered =
134 Utilities::MPI::gather(mpi_communicator, local_lines, 0);
136 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
140 std::map<unsigned int, std::string> all_lines;
141 for (
const auto &proc_lines : gathered)
142 all_lines.insert(proc_lines.begin(), proc_lines.end());
144 for (
const auto &[
id, line] : all_lines)
145 pcout << line << std::endl;
149template <
int dim,
typename PropertiesIndex>
152 const Vector<float> &data_to_print,
153 const DoFHandler<dim> &background_dh,
154 const MPI_Comm &mpi_communicator,
155 const ConditionalOStream &pcout)
157 unsigned int this_mpi_process(
158 Utilities::MPI::this_mpi_process(mpi_communicator));
161 DataOut<dim> data_out;
162 data_out.attach_dof_handler(background_dh);
163 data_out.add_data_vector(data_to_print,
164 "print_from_processor_" +
165 Utilities::int_to_string(this_mpi_process),
166 DataOut<dim>::type_cell_data);
167 data_out.build_patches();
172 std::stringstream out;
173 data_out.write_deal_II_intermediate(out);
175 std::ostringstream local_block;
177 unsigned int counter = 0;
178 while (std::getline(out, line))
182 local_block << line << std::endl;
190 const auto gathered =
191 Utilities::MPI::gather(mpi_communicator, local_block.str(), 0);
193 if (this_mpi_process == 0)
195 for (
const auto &block : gathered)
200template <
int dim,
typename PropertiesIndex>
201const std::vector<DataOutBase::Patch<0, dim>> &
207template <
int dim,
typename PropertiesIndex>
208std::vector<std::string>
214template <
int dim,
typename PropertiesIndex>
216 std::tuple<
unsigned int,
219 DataComponentInterpretation::DataComponentInterpretation>>
225template <
int dim,
typename PropertiesIndex>
Building patches of particle properties for visualization. This function is taken from Aspect and dea...
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.
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.
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.