Reference documentation for deal.II version GIT relicensing-677-g613a5db665 2024-05-19 13:30:02+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: 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
17
18// We use some exceptions declared in this header
20
22
23namespace Particles
24{
25 template <int dim, int spacedim>
26 void
29 const std::vector<std::string> &data_component_names,
30 const std::vector<DataComponentInterpretation::DataComponentInterpretation>
31 &data_component_interpretations_)
32 {
33 Assert(
34 data_component_names.size() == data_component_interpretations_.size(),
36 "When calling Particles::DataOut::build_patches with data component "
37 "names and interpretations you need to provide as many data component "
38 "names as interpretations. Provide the same name for components that "
39 "belong to a single vector or tensor."));
40
41 if ((data_component_names.size() > 0) &&
42 (particles.n_locally_owned_particles() > 0))
43 {
44 Assert(
45 particles.begin()->has_properties(),
47 "You called Particles::DataOut::build_patches with data component "
48 "names and interpretations, but the particles do not seem to own "
49 "any properties."));
50
51 Assert(
52 data_component_names.size() ==
53 particles.begin()->get_properties().size(),
55 "When calling Particles::DataOut::build_patches with data component "
56 "names and interpretations you need to provide as many data component "
57 "names as the particles have properties."));
58 }
59
60 dataset_names.clear();
61 dataset_names.emplace_back("id");
62 dataset_names.insert(dataset_names.end(),
63 data_component_names.begin(),
64 data_component_names.end());
65
66 data_component_interpretations.clear();
67 data_component_interpretations.emplace_back(
69 data_component_interpretations.insert(
70 data_component_interpretations.end(),
71 data_component_interpretations_.begin(),
72 data_component_interpretations_.end());
73
74 const unsigned int n_property_components = data_component_names.size();
75 const unsigned int n_data_components = dataset_names.size();
76
77 patches.resize(particles.n_locally_owned_particles());
78
79 auto particle = particles.begin();
80 for (unsigned int i = 0; particle != particles.end(); ++particle, ++i)
81 {
82 patches[i].vertices[0] = particle->get_location();
83 patches[i].patch_index = i;
84
85 // We have one more data components than dataset_names (the particle id)
86 patches[i].data.reinit(n_data_components, 1);
87
88 patches[i].data(0, 0) = particle->get_id();
89
90 if (n_data_components > 1)
91 {
92 const ArrayView<double> properties = particle->get_properties();
93 for (unsigned int property_index = 0;
94 property_index < n_property_components;
95 ++property_index)
96 patches[i].data(property_index + 1, 0) =
97 properties[property_index];
98 }
99 }
100 }
101
102
103
104 template <int dim, int spacedim>
105 const std::vector<DataOutBase::Patch<0, spacedim>> &
107 {
108 return patches;
109 }
110
111
112
113 template <int dim, int spacedim>
114 std::vector<std::string>
116 {
117 return dataset_names;
118 }
119
120
121
122 template <int dim, int spacedim>
123 std::vector<
124 std::tuple<unsigned int,
125 unsigned int,
126 std::string,
129 {
130 std::vector<
131 std::tuple<unsigned int,
132 unsigned int,
133 std::string,
135 ranges;
136
137 // Make sure the data structures were set up correctly. Since they
138 // can only be filled by build_patches() above, they should have
139 // been checked already.
140 Assert(dataset_names.size() == data_component_interpretations.size(),
142
143 // collect the ranges of particle data
144 const unsigned int n_output_components =
145 data_component_interpretations.size();
146 unsigned int output_component = 0;
147 for (unsigned int i = 0; i < n_output_components; /* i is updated below */)
148 // see what kind of data we have here. note that for the purpose of the
149 // current function all we care about is vector data
150 switch (data_component_interpretations[i])
151 {
153 {
154 // Just move component forward by one
155 ++i;
156 ++output_component;
157
158 break;
159 }
161 {
162 // ensure that there is a continuous number of next space_dim
163 // components that all deal with vectors
164 Assert(
165 i + spacedim <= n_output_components,
167 i, dataset_names[i]));
168 for (unsigned int dd = 1; dd < spacedim; ++dd)
169 Assert(
170 data_component_interpretations[i + dd] ==
173 ExcInvalidVectorDeclaration(i, dataset_names[i]));
174
175 // all seems right, so figure out whether there is a common
176 // name to these components. if not, leave the name empty and
177 // let the output format writer decide what to do here
178 std::string name = dataset_names[i];
179 for (unsigned int dd = 1; dd < spacedim; ++dd)
180 if (name != dataset_names[i + dd])
181 {
182 name = "";
183 break;
184 }
185
186 // Finally add a corresponding range.
187 //
188 // This sort of logic is also explained in some detail in
189 // DataOut::build_one_patch().
190 ranges.emplace_back(std::forward_as_tuple(
191 output_component,
192 output_component + spacedim - 1,
193 name,
195
196 // increase the 'component' counter by the appropriate amount,
197 // same for 'i', since we have already dealt with all these
198 // components
199 output_component += spacedim;
200 i += spacedim;
201
202 break;
203 }
204
206 {
207 const unsigned int size = spacedim * spacedim;
208 // ensure that there is a continuous number of next
209 // spacedim*spacedim components that all deal with tensors
210 Assert(
211 i + size <= n_output_components,
213 i, dataset_names[i]));
214 for (unsigned int dd = 1; dd < size; ++dd)
215 Assert(
216 data_component_interpretations[i + dd] ==
219 ExcInvalidTensorDeclaration(i, dataset_names[i]));
220
221 // all seems right, so figure out whether there is a common
222 // name to these components. if not, leave the name empty and
223 // let the output format writer decide what to do here
224 std::string name = dataset_names[i];
225 for (unsigned int dd = 1; dd < size; ++dd)
226 if (name != dataset_names[i + dd])
227 {
228 name = "";
229 break;
230 }
231
232 // Finally add a corresponding range.
233 ranges.emplace_back(std::forward_as_tuple(
234 output_component,
235 output_component + size - 1,
236 name,
238
239 // increase the 'component' counter by the appropriate amount,
240 // same for 'i', since we have already dealt with all these
241 // components
242 output_component += size;
243 i += size;
244 break;
245 }
246
247 default:
249 }
250
251 return ranges;
252 }
253
254} // namespace Particles
255
256#include "data_out.inst"
257
virtual const std::vector< DataOutBase::Patch< 0, spacedim > > & get_patches() const override
Definition data_out.cc:106
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
Definition data_out.cc:128
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:27
virtual std::vector< std::string > get_dataset_names() const override
Definition data_out.cc:115
particle_iterator begin() const
particle_iterator end() const
types::particle_index n_locally_owned_particles() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#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)
#define DEAL_II_NOT_IMPLEMENTED()