deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00: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_points.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) 2026 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
14
15
17
18template <int dim, int spacedim>
19void
21 const std::vector<Point<spacedim>> &locations,
22 const std::size_t offset,
23 const std::vector<std::vector<double>> &data,
24 const std::vector<std::string> &data_component_names,
25 const std::vector<DataComponentInterpretation::DataComponentInterpretation>
26 &data_component_interpretations_)
27{
28 Assert(
29 data_component_names.size() == data_component_interpretations_.size(),
31 "When calling PointDataOut::build_patches() with data component "
32 "names and interpretations you need to provide as many data component "
33 "names as interpretations. Provide the same name for components that "
34 "belong to a single vector or tensor."));
35
36 Assert(data.size() == 0 || locations.size(),
38 "You need to either provide no data or data for each point."));
39 for (const auto &datum : data)
40 Assert(datum.size() == data_component_names.size(),
42 "The data provided in each point needs to have the same number "
43 "of components as names were provided."));
44
45 // Prepend the "id" to the data fields provided by the user:
46 dataset_names.clear();
47 dataset_names.emplace_back("id");
48 dataset_names.insert(dataset_names.end(),
49 data_component_names.begin(),
50 data_component_names.end());
51
52 data_component_interpretations.clear();
53 data_component_interpretations.emplace_back(
55 data_component_interpretations.insert(data_component_interpretations.end(),
56 data_component_interpretations_.begin(),
57 data_component_interpretations_.end());
58
59 const unsigned int n_property_components = data_component_names.size();
60 const unsigned int n_data_components = dataset_names.size();
61
62 patches.resize(locations.size());
63
64 for (unsigned int i = 0; i < locations.size(); ++i)
65 {
66 patches[i].vertices[0] = locations[i];
67 patches[i].patch_index = i;
68
69 // Store id and properties given by the user:
70 patches[i].data.reinit(n_data_components, 1);
71 patches[i].data(0, 0) = static_cast<float>(offset + i);
72 for (unsigned int property_index = 0;
73 property_index < n_property_components;
74 ++property_index)
75 patches[i].data(property_index + 1, 0) = data[i][property_index];
76 }
77}
78
79
80
81template <int dim, int spacedim>
82const std::vector<DataOutBase::Patch<0, spacedim>> &
84{
85 return patches;
86}
87
88
89
90template <int dim, int spacedim>
91std::vector<std::string>
93{
94 return dataset_names;
95}
96
97
98
99template <int dim, int spacedim>
100std::vector<
101 std::tuple<unsigned int,
102 unsigned int,
103 std::string,
106{
107 std::vector<
108 std::tuple<unsigned int,
109 unsigned int,
110 std::string,
112 ranges;
113
114 // Make sure the data structures were set up correctly. Since they
115 // can only be filled by build_patches() above, they should have
116 // been checked already.
117 Assert(dataset_names.size() == data_component_interpretations.size(),
119
120 const unsigned int n_output_components =
121 data_component_interpretations.size();
122 unsigned int output_component = 0;
123 for (unsigned int i = 0; i < n_output_components; /* i is updated below */)
124 switch (data_component_interpretations[i])
125 {
127 {
128 // OK. Just move component by one:
129 ++i;
130 ++output_component;
131
132 break;
133 }
135 {
136 // Ensure that there is a continuous number of next spacedim
137 // components that all deal with vectors
138 Assert(
139 i + spacedim <= n_output_components,
141 i, dataset_names[i]));
142 for (unsigned int dd = 1; dd < spacedim; ++dd)
143 Assert(
144 data_component_interpretations[i + dd] ==
147 i, dataset_names[i]));
148
149 // All seems right, so figure out whether there is a common
150 // name to these components. if not, leave the name empty and
151 // let the output format writer decide what to do here
152 std::string name = dataset_names[i];
153 for (unsigned int dd = 1; dd < spacedim; ++dd)
154 if (name != dataset_names[i + dd])
155 {
156 name = "";
157 break;
158 }
159
160 // Finally add a corresponding range.
161 //
162 // This sort of logic is also explained in some detail in
163 // DataOut::build_one_patch().
164 ranges.emplace_back(std::forward_as_tuple(
165 output_component,
166 output_component + spacedim - 1,
167 name,
169
170 // Increase the 'component' counter by the appropriate amount,
171 // same for 'i', since we have already dealt with all these
172 // components
173 output_component += spacedim;
174 i += spacedim;
175
176 break;
177 }
178
180 {
181 const unsigned int size = spacedim * spacedim;
182 // Ensure that there is a continuous number of next
183 // spacedim*spacedim components that all deal with tensors
184 Assert(
185 i + size <= n_output_components,
187 i, dataset_names[i]));
188 for (unsigned int dd = 1; dd < size; ++dd)
189 Assert(
190 data_component_interpretations[i + dd] ==
193 i, dataset_names[i]));
194
195 // All seems right, so figure out whether there is a common
196 // name to these components. if not, leave the name empty and
197 // let the output format writer decide what to do here
198 std::string name = dataset_names[i];
199 for (unsigned int dd = 1; dd < size; ++dd)
200 if (name != dataset_names[i + dd])
201 {
202 name = "";
203 break;
204 }
205
206 // Finally add a corresponding range.
207 ranges.emplace_back(std::forward_as_tuple(
208 output_component,
209 output_component + size - 1,
210 name,
212
213 // Increase the 'component' counter by the appropriate amount,
214 // same for 'i', since we have already dealt with all these
215 // components
216 output_component += size;
217 i += size;
218 break;
219 }
220
221 default:
222 Assert(false, ExcNotImplemented());
223 }
224 return ranges;
225}
226
227
228
229// explicit instantiations
230#include "numerics/data_out_points.inst"
231
virtual std::vector< std::string > get_dataset_names() const override
void build_patches(const std::vector< Point< spacedim > > &locations, const std::size_t offset=0, const std::vector< std::vector< double > > &data={}, const std::vector< std::string > &data_component_names={}, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretations={})
virtual const std::vector< DataOutBase::Patch< 0, spacedim > > & get_patches() const override
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcNotImplemented()
#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