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_resample.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) 2021 - 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
14
16#include <deal.II/fe/fe_tools.h>
17
20
21#include <deal.II/numerics/data_out_dof_data.templates.h>
24
25#include <sstream>
26
28
29
30template <int dim, int patch_dim, int spacedim>
32 const Triangulation<patch_dim, spacedim> &patch_tria,
33 const Mapping<patch_dim, spacedim> &patch_mapping)
34 : patch_dof_handler(patch_tria)
35 , patch_mapping(&patch_mapping)
36{}
37
38
39
40template <int dim, int patch_dim, int spacedim>
41void
43 const Mapping<dim, spacedim> &mapping,
44 const unsigned int n_subdivisions)
45{
46 this->mapping = &mapping;
47 this->point_to_local_vector_indices.clear();
48
50 std::max<unsigned int>(1, n_subdivisions));
51 patch_dof_handler.distribute_dofs(fe);
52
53 std::vector<std::pair<types::global_dof_index, Point<spacedim>>> points_all;
54
56
57 FEValues<patch_dim, spacedim> fe_values(*patch_mapping,
58 fe,
59 quadrature,
61
62 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
63
64 partitioner = std::make_shared<Utilities::MPI::Partitioner>(
65 patch_dof_handler.locally_owned_dofs(),
67 patch_dof_handler.get_mpi_communicator());
68
69 for (const auto &cell : patch_dof_handler.active_cell_iterators() |
71 {
72 fe_values.reinit(cell);
73
74 cell->get_dof_indices(dof_indices);
75
76 for (unsigned int i = 0; i < dof_indices.size(); ++i)
77 points_all.emplace_back(partitioner->global_to_local(dof_indices[i]),
78 fe_values.quadrature_point(i));
79 }
80
81 std::sort(points_all.begin(),
82 points_all.end(),
83 [](const auto &a, const auto &b) { return a.first < b.first; });
84 points_all.erase(std::unique(points_all.begin(),
85 points_all.end(),
86 [](const auto &a, const auto &b) {
87 return a.first == b.first;
88 }),
89 points_all.end());
90
91 std::vector<Point<spacedim>> points;
92
93 for (const auto &i : points_all)
94 {
95 point_to_local_vector_indices.push_back(i.first);
96 points.push_back(i.second);
97 }
98
99 rpe.reinit(points, *this->triangulation, *this->mapping);
100}
101
102
103
104template <int dim, int patch_dim, int spacedim>
105void
107 const Mapping<dim, spacedim> &mapping,
108 const unsigned int n_subdivisions,
109 const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
110{
111 this->update_mapping(mapping, n_subdivisions);
112 this->build_patches(curved_region);
113}
114
115
116
117template <int dim, int patch_dim, int spacedim>
118void
120 const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
121{
122 patch_data_out.clear();
123
124 if (rpe.is_ready() == false)
125 {
126 Assert(
127 this->mapping,
129 "Mapping is not valid anymore! Please register a new mapping via "
130 "update_mapping() or the other build_patches() function."));
131 update_mapping(*this->mapping, patch_dof_handler.get_fe().degree);
132 }
133
134 std::vector<std::shared_ptr<LinearAlgebra::distributed::Vector<double>>>
135 vectors;
136
137 patch_data_out.attach_dof_handler(patch_dof_handler);
138
139 unsigned int counter = 0;
140
141 for (const auto &data : this->dof_data)
142 {
143 const auto data_ptr = dynamic_cast<
144 internal::DataOutImplementation::DataEntry<dim, spacedim, double> *>(
145 data.get());
146
147 Assert(data_ptr, ExcNotImplemented());
148
149 const auto &dh = *data_ptr->dof_handler;
150
151 if constexpr (running_in_debug_mode())
152 {
153 for (const auto &fe : dh.get_fe_collection())
154 Assert(
155 fe.n_base_elements() == 1,
157 "This class currently only supports scalar elements and elements "
158 "with a single base element."));
159 }
160
161 for (unsigned int comp = 0; comp < dh.get_fe_collection().n_components();
162 ++comp)
163 {
164 const auto values = VectorTools::point_values<1>(
165 rpe, dh, data_ptr->vector, VectorTools::EvaluationFlags::avg, comp);
166
167 vectors.emplace_back(
169 partitioner));
170
171 for (unsigned int j = 0; j < values.size(); ++j)
172 vectors.back()->local_element(point_to_local_vector_indices[j]) =
173 values[j];
174
175 vectors.back()->set_ghost_state(true);
176
177 // we can give the vectors arbitrary names ("temp_*") here, since
178 // these are only used internally (by patch_data_out) but not later on
179 // during the actual output to file
180 patch_data_out.add_data_vector(
181 *vectors.back(),
182 std::string("temp_" + std::to_string(counter)),
184 DataVectorType::type_dof_data);
185
186 ++counter;
187 }
188 }
189
190 patch_data_out.build_patches(*patch_mapping,
191 patch_dof_handler.get_fe().degree,
192 curved_region);
193}
194
195
196
197template <int dim, int patch_dim, int spacedim>
198const std::vector<typename DataOutBase::Patch<patch_dim, spacedim>> &
200{
201 return patch_data_out.get_patches();
202}
203
204
205// explicit instantiations
206#include "numerics/data_out_resample.inst"
207
virtual const std::vector< typename DataOutBase::Patch< patch_dim, spacedim > > & get_patches() const override
DataOutResample(const Triangulation< patch_dim, spacedim > &patch_tria, const Mapping< patch_dim, spacedim > &patch_mapping)
void build_patches(const Mapping< dim, spacedim > &mapping, const unsigned int n_subdivisions=0, const typename DataOut< patch_dim, spacedim >::CurvedCellRegion curved_region=DataOut< patch_dim, spacedim >::CurvedCellRegion::curved_boundary)
void update_mapping(const Mapping< dim, spacedim > &mapping, const unsigned int n_subdivisions=0)
CurvedCellRegion
Definition data_out.h:183
const Point< spacedim > & quadrature_point(const unsigned int q_point) const
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
unsigned int n_dofs_per_cell() const
const std::vector< Point< dim > > & get_unit_support_points() const
Abstract base class for mapping classes.
Definition mapping.h:318
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
@ update_mapping
@ update_quadrature_points
Transformed quadrature points.
std::vector< index_type > data
Definition mpi.cc:734
IndexSet extract_locally_active_dofs(const DoFHandler< dim, spacedim > &dof_handler)