deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
data_out.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
15
16// We use some exceptions declared in this header
18
20
21namespace Particles
22{
23 template <int dim, int spacedim>
24 void
27 const std::vector<std::string> &data_component_names,
28 const std::vector<DataComponentInterpretation::DataComponentInterpretation>
29 &data_component_interpretations_)
30 {
31 Assert(
32 data_component_names.size() == data_component_interpretations_.size(),
34 "When calling Particles::DataOut::build_patches with data component "
35 "names and interpretations you need to provide as many data component "
36 "names as interpretations. Provide the same name for components that "
37 "belong to a single vector or tensor."));
38
39 if ((data_component_names.size() > 0) &&
40 (particles.n_locally_owned_particles() > 0))
41 {
42 Assert(
43 particles.begin()->has_properties(),
45 "You called Particles::DataOut::build_patches with data component "
46 "names and interpretations, but the particles do not seem to own "
47 "any properties."));
48
49 Assert(
50 data_component_names.size() ==
51 particles.begin()->get_properties().size(),
53 "When calling Particles::DataOut::build_patches with data component "
54 "names and interpretations you need to provide as many data component "
55 "names as the particles have properties."));
56 }
57
58 dataset_names.clear();
59 dataset_names.emplace_back("id");
60 dataset_names.insert(dataset_names.end(),
61 data_component_names.begin(),
62 data_component_names.end());
63
64 data_component_interpretations.clear();
65 data_component_interpretations.emplace_back(
67 data_component_interpretations.insert(
68 data_component_interpretations.end(),
69 data_component_interpretations_.begin(),
70 data_component_interpretations_.end());
71
72 const unsigned int n_property_components = data_component_names.size();
73 const unsigned int n_data_components = dataset_names.size();
74
75 patches.resize(particles.n_locally_owned_particles());
76
77 auto particle = particles.begin();
78 for (unsigned int i = 0; particle != particles.end(); ++particle, ++i)
79 {
80 patches[i].vertices[0] = particle->get_location();
81 patches[i].patch_index = i;
82
83 // We have one more data components than dataset_names (the particle id)
84 patches[i].data.reinit(n_data_components, 1);
85
86 patches[i].data(0, 0) = particle->get_id();
87
88 if (n_data_components > 1)
89 {
90 const ArrayView<double> properties = particle->get_properties();
91 for (unsigned int property_index = 0;
92 property_index < n_property_components;
93 ++property_index)
94 patches[i].data(property_index + 1, 0) =
95 properties[property_index];
96 }
97 }
98 }
99
100
101
102 template <int dim, int spacedim>
103 const std::vector<DataOutBase::Patch<0, spacedim>> &
105 {
106 return patches;
107 }
108
109
110
111 template <int dim, int spacedim>
112 std::vector<std::string>
114 {
115 return dataset_names;
116 }
117
118
119
120 template <int dim, int spacedim>
121 std::vector<
122 std::tuple<unsigned int,
123 unsigned int,
124 std::string,
127 {
128 std::vector<
129 std::tuple<unsigned int,
130 unsigned int,
131 std::string,
133 ranges;
134
135 // Make sure the data structures were set up correctly. Since they
136 // can only be filled by build_patches() above, they should have
137 // been checked already.
138 Assert(dataset_names.size() == data_component_interpretations.size(),
140
141 // collect the ranges of particle data
142 const unsigned int n_output_components =
143 data_component_interpretations.size();
144 unsigned int output_component = 0;
145 for (unsigned int i = 0; i < n_output_components; /* i is updated below */)
146 // see what kind of data we have here. note that for the purpose of the
147 // current function all we care about is vector data
148 switch (data_component_interpretations[i])
149 {
151 {
152 // Just move component forward by one
153 ++i;
154 ++output_component;
155
156 break;
157 }
159 {
160 // ensure that there is a continuous number of next space_dim
161 // components that all deal with vectors
162 Assert(
163 i + spacedim <= n_output_components,
165 i, dataset_names[i]));
166 for (unsigned int dd = 1; dd < spacedim; ++dd)
167 Assert(
168 data_component_interpretations[i + dd] ==
171 ExcInvalidVectorDeclaration(i, dataset_names[i]));
172
173 // all seems right, so figure out whether there is a common
174 // name to these components. if not, leave the name empty and
175 // let the output format writer decide what to do here
176 std::string name = dataset_names[i];
177 for (unsigned int dd = 1; dd < spacedim; ++dd)
178 if (name != dataset_names[i + dd])
179 {
180 name = "";
181 break;
182 }
183
184 // Finally add a corresponding range.
185 //
186 // This sort of logic is also explained in some detail in
187 // DataOut::build_one_patch().
188 ranges.emplace_back(std::forward_as_tuple(
189 output_component,
190 output_component + spacedim - 1,
191 name,
193
194 // increase the 'component' counter by the appropriate amount,
195 // same for 'i', since we have already dealt with all these
196 // components
197 output_component += spacedim;
198 i += spacedim;
199
200 break;
201 }
202
204 {
205 const unsigned int size = spacedim * spacedim;
206 // ensure that there is a continuous number of next
207 // spacedim*spacedim components that all deal with tensors
208 Assert(
209 i + size <= n_output_components,
211 i, dataset_names[i]));
212 for (unsigned int dd = 1; dd < size; ++dd)
213 Assert(
214 data_component_interpretations[i + dd] ==
217 ExcInvalidTensorDeclaration(i, dataset_names[i]));
218
219 // all seems right, so figure out whether there is a common
220 // name to these components. if not, leave the name empty and
221 // let the output format writer decide what to do here
222 std::string name = dataset_names[i];
223 for (unsigned int dd = 1; dd < size; ++dd)
224 if (name != dataset_names[i + dd])
225 {
226 name = "";
227 break;
228 }
229
230 // Finally add a corresponding range.
231 ranges.emplace_back(std::forward_as_tuple(
232 output_component,
233 output_component + size - 1,
234 name,
236
237 // increase the 'component' counter by the appropriate amount,
238 // same for 'i', since we have already dealt with all these
239 // components
240 output_component += size;
241 i += size;
242 break;
243 }
244
245 default:
247 }
248
249 return ranges;
250 }
251
252} // namespace Particles
253
254#include "particles/data_out.inst"
255
virtual const std::vector< DataOutBase::Patch< 0, spacedim > > & get_patches() const override
Definition data_out.cc:104
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
Definition data_out.cc:126
void build_patches(const Particles::ParticleHandler< dim, spacedim > &particles, const std::vector< std::string > &data_component_names={}, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretations={})
Definition data_out.cc:25
virtual std::vector< std::string > get_dataset_names() const override
Definition data_out.cc:113
particle_iterator begin() const
particle_iterator end() const
types::particle_index n_locally_owned_particles() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInvalidTensorDeclaration(int arg1, std::string arg2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcInvalidVectorDeclaration(int arg1, std::string arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733