deal.II version GIT relicensing-6759-gba22b5843e 2026-09-18 10:10: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
segment_data_out.h
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) 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
13#ifndef dealii_segment_data_out_h
14#define dealii_segment_data_out_h
15
16#include <deal.II/base/config.h>
17
19#include <deal.II/base/point.h>
20
21
23
32template <int spacedim>
33class SegmentDataOut : public DataOutInterface<1, spacedim>
34{
35public:
39 SegmentDataOut() = default;
40
44 ~SegmentDataOut() = default;
45
57 void
59 const std::vector<std::pair<Point<spacedim>, Point<spacedim>>> &segments,
60 const std::vector<std::vector<double>> &datasets = {},
61 const std::vector<std::string> &dataset_names_param = {});
62
63protected:
64 // @copydoc
65 virtual const std::vector<::DataOutBase::Patch<1, spacedim>> &
66 get_patches() const override;
67
68 // @copydoc
69 virtual std::vector<std::string>
70 get_dataset_names() const override;
71
72private:
76 std::vector<DataOutBase::Patch<1, spacedim>> patches;
77
81 std::vector<std::string> dataset_names;
82};
83
84
85// Template and inline functions
86#ifndef DOXYGEN
87template <int spacedim>
88void
90 const std::vector<std::pair<Point<spacedim>, Point<spacedim>>> &segments,
91 const std::vector<std::vector<double>> &datasets,
92 const std::vector<std::string> &dataset_names_param)
93{
94 const unsigned int N = segments.size();
95
96 dataset_names.clear();
97 patches.resize(N);
98
99 for (unsigned int i = 0; i < N; ++i)
100 {
101 // A line segment has 2 vertices
102 patches[i].vertices[0] = segments[i].first;
103 patches[i].vertices[1] = segments[i].second;
104 patches[i].patch_index = i;
105 patches[i].n_subdivisions = 1;
106 patches[i].reference_cell = ReferenceCells::Line;
107 patches[i].points_are_available = false;
108 }
109
110 // If datasets were provided, attach them to the patches. We expect either
111 // both datasets and dataset_names to be empty, or both to be non-empty and
112 // with matching sizes.
113 if (!datasets.empty() || !dataset_names_param.empty())
114 {
115 AssertDimension(datasets.size(), N);
116 AssertDimension(dataset_names_param.size(), datasets[0].size());
117 dataset_names = dataset_names_param; // assign names
118 for (unsigned int i = 0; i < datasets.size(); ++i)
119 {
120 AssertDimension(datasets[i].size(), dataset_names.size());
121 patches[i].data.reinit(dataset_names.size(), 2);
122 for (unsigned int j = 0; j < dataset_names.size(); ++j)
123 for (unsigned int k = 0; k < 2; ++k)
124 patches[i].data(j, k) = datasets[i][j];
125 }
126 }
127}
128
129
130// Note: add_datasets has been merged into build_patches. No separate
131// implementation remains.
132
133
134template <int spacedim>
135const std::vector<DataOutBase::Patch<1, spacedim>> &
137{
138 return patches;
139}
140
141
142
143template <int spacedim>
144std::vector<std::string>
146{
147 return dataset_names;
148}
149
150#endif
151
153
154#endif
Definition point.h:111
~SegmentDataOut()=default
void build_patches(const std::vector< std::pair< Point< spacedim >, Point< spacedim > > > &segments, const std::vector< std::vector< double > > &datasets={}, const std::vector< std::string > &dataset_names_param={})
std::vector< DataOutBase::Patch< 1, spacedim > > patches
SegmentDataOut()=default
std::vector< std::string > dataset_names
virtual const std::vector<::DataOutBase::Patch< 1, spacedim > > & get_patches() const override
virtual std::vector< std::string > get_dataset_names() const override
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertDimension(dim1, dim2)
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733
constexpr ReferenceCell< 1 > Line