| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2019 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
#ifndef dealii_particles_data_out_h |
| 15 |
#define dealii_particles_data_out_h |
| 16 |
|
| 17 |
#include <deal.II/base/config.h> |
| 18 |
|
| 19 |
#include <deal.II/base/data_out_base.h> |
| 20 |
|
| 21 |
#include <deal.II/numerics/data_component_interpretation.h> |
| 22 |
|
| 23 |
#include <string> |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
DEAL_II_NAMESPACE_OPEN |
| 27 |
|
| 28 |
namespace Particles |
| 29 |
{ |
| 30 |
template <int dim, int spacedim> |
| 31 |
class ParticleHandler; |
| 32 |
|
| 33 |
/** |
| 34 |
* This class generates graphical output for the particles stored by a |
| 35 |
* ParticleHandler object. From a particle handler, it generates patches which |
| 36 |
* can then be used to write traditional output files. |
| 37 |
* |
| 38 |
* The class does, in essence, for particles what ::DataOut does for |
| 39 |
* finite element fields, using a similar interface. It is used in |
| 40 |
* step-19, for example. |
| 41 |
*/ |
| 42 |
template <int dim, int spacedim = dim> |
| 43 |
class DataOut : public dealii::DataOutInterface<0, spacedim> |
| 44 |
{ |
| 45 |
public: |
| 46 |
/** |
| 47 |
* Default constructor for the Particles::DataOut class. |
| 48 |
*/ |
| 49 |
DataOut() = default; |
| 50 |
|
| 51 |
/** |
| 52 |
* Destructor for the Particles::DataOut class. |
| 53 |
*/ |
| 54 |
~DataOut() = default; |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Build the patches for a given particle handler. |
| 59 |
* |
| 60 |
* @param [in] particles A particle handler for which the patches will be built. |
| 61 |
* A dim=0 patch is built for each particle. The position of the particle is |
| 62 |
* used to build the node position and the ID of the particle is added as a |
| 63 |
* single data element. |
| 64 |
* @param [in] data_component_names An optional vector of strings that |
| 65 |
* describe the properties of each particle. Particle properties will only |
| 66 |
* be written if this vector |
| 67 |
* is provided. |
| 68 |
* @param [in] data_component_interpretations An optional vector that |
| 69 |
* controls if the particle properties are interpreted as scalars, vectors, |
| 70 |
* or tensors. Has to be of the same length as @p data_component_names. |
| 71 |
*/ |
| 72 |
void |
| 73 |
build_patches(const Particles::ParticleHandler<dim, spacedim> &particles, |
| 74 |
const std::vector<std::string> &data_component_names = {}, |
| 75 |
const std::vector< |
| 76 |
DataComponentInterpretation::DataComponentInterpretation> |
| 77 |
&data_component_interpretations = {}); |
| 78 |
|
| 79 |
protected: |
| 80 |
/** |
| 81 |
* Returns the patches built by the data_out class which was previously |
| 82 |
* built using a particle handler |
| 83 |
*/ |
| 84 |
virtual const std::vector<DataOutBase::Patch<0, spacedim>> & |
| 85 |
get_patches() const override; |
| 86 |
|
| 87 |
/** |
| 88 |
* Virtual function through which the names of data sets are obtained from |
| 89 |
* this class |
| 90 |
*/ |
| 91 |
virtual std::vector<std::string> |
| 92 |
get_dataset_names() const override; |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* Overload of the respective DataOutInterface::get_nonscalar_data_ranges() |
| 97 |
* function. See there for a more extensive documentation. |
| 98 |
* This function is a reimplementation of the function |
| 99 |
* DataOut_DoFData::get_nonscalar_data_ranges(). |
| 100 |
*/ |
| 101 |
virtual std::vector< |
| 102 |
std::tuple<unsigned int, |
| 103 |
unsigned int, |
| 104 |
std::string, |
| 105 |
DataComponentInterpretation::DataComponentInterpretation>> |
| 106 |
get_nonscalar_data_ranges() const override; |
| 107 |
|
| 108 |
private: |
| 109 |
/** |
| 110 |
* This is a vector of patches that is created each time build_patches() is |
| 111 |
* called. These patches are used in the output routines of the base |
| 112 |
* classes. |
| 113 |
*/ |
| 114 |
std::vector<DataOutBase::Patch<0, spacedim>> patches; |
| 115 |
|
| 116 |
/** |
| 117 |
* A vector of field names for all data components stored in patches. |
| 118 |
*/ |
| 119 |
std::vector<std::string> dataset_names; |
| 120 |
|
| 121 |
/** |
| 122 |
* A vector that for each of the data components of the |
| 123 |
* current data set indicates whether they are scalar fields, parts of a |
| 124 |
* vector-field, or any of the other supported kinds of data. |
| 125 |
*/ |
| 126 |
std::vector<DataComponentInterpretation::DataComponentInterpretation> |
| 127 |
data_component_interpretations; |
| 128 |
}; |
| 129 |
|
| 130 |
} // namespace Particles |
| 131 |
|
| 132 |
DEAL_II_NAMESPACE_CLOSE |
| 133 |
|
| 134 |
#endif |