deal.II version GIT relicensing-2291-g668cd86249 2024-12-24 11:30:00+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: LGPL-2.1-or-later
4// Copyright (C) 2021 - 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
16
18#include <deal.II/fe/fe_tools.h>
19
22
23#include <deal.II/numerics/data_out_dof_data.templates.h>
26
27#include <sstream>
28
30
31
32template <int dim, int patch_dim, int spacedim>
34 const Triangulation<patch_dim, spacedim> &patch_tria,
35 const Mapping<patch_dim, spacedim> &patch_mapping)
36 : patch_dof_handler(patch_tria)
37 , patch_mapping(&patch_mapping)
38{}
39
40
41
42template <int dim, int patch_dim, int spacedim>
43void
45 const Mapping<dim, spacedim> &mapping,
46 const unsigned int n_subdivisions)
47{
48 this->mapping = &mapping;
49 this->point_to_local_vector_indices.clear();
50
52 std::max<unsigned int>(1, n_subdivisions));
53 patch_dof_handler.distribute_dofs(fe);
54
55 std::vector<std::pair<types::global_dof_index, Point<spacedim>>> points_all;
56
58
59 FEValues<patch_dim, spacedim> fe_values(*patch_mapping,
60 fe,
61 quadrature,
63
64 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
65
66 const IndexSet active_dofs =
68 partitioner = std::make_shared<Utilities::MPI::Partitioner>(
69 patch_dof_handler.locally_owned_dofs(), active_dofs, MPI_COMM_WORLD);
70
71 for (const auto &cell : patch_dof_handler.active_cell_iterators() |
73 {
74 fe_values.reinit(cell);
75
76 cell->get_dof_indices(dof_indices);
77
78 for (unsigned int i = 0; i < dof_indices.size(); ++i)
79 points_all.emplace_back(partitioner->global_to_local(dof_indices[i]),
80 fe_values.quadrature_point(i));
81 }
82
83 std::sort(points_all.begin(),
84 points_all.end(),
85 [](const auto &a, const auto &b) { return a.first < b.first; });
86 points_all.erase(std::unique(points_all.begin(),
87 points_all.end(),
88 [](const auto &a, const auto &b) {
89 return a.first == b.first;
90 }),
91 points_all.end());
92
93 std::vector<Point<spacedim>> points;
94
95 for (const auto &i : points_all)
96 {
97 point_to_local_vector_indices.push_back(i.first);
98 points.push_back(i.second);
99 }
100
101 rpe.reinit(points, *this->triangulation, *this->mapping);
102}
103
104
105
106template <int dim, int patch_dim, int spacedim>
107void
109 const Mapping<dim, spacedim> &mapping,
110 const unsigned int n_subdivisions,
111 const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
112{
113 this->update_mapping(mapping, n_subdivisions);
114 this->build_patches(curved_region);
115}
116
117
118
119template <int dim, int patch_dim, int spacedim>
120void
122 const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
123{
124 patch_data_out.clear();
125
126 if (rpe.is_ready() == false)
127 {
128 Assert(
129 this->mapping,
131 "Mapping is not valid anymore! Please register a new mapping via "
132 "update_mapping() or the other build_patches() function."));
133 update_mapping(*this->mapping, patch_dof_handler.get_fe().degree);
134 }
135
136 std::vector<std::shared_ptr<LinearAlgebra::distributed::Vector<double>>>
137 vectors;
138
139 patch_data_out.attach_dof_handler(patch_dof_handler);
140
141 unsigned int counter = 0;
142
143 for (const auto &data : this->dof_data)
144 {
145 const auto data_ptr = dynamic_cast<
146 internal::DataOutImplementation::DataEntry<dim, spacedim, double> *>(
147 data.get());
148
149 Assert(data_ptr, ExcNotImplemented());
150
151 const auto &dh = *data_ptr->dof_handler;
152
153#ifdef DEBUG
154 for (const auto &fe : dh.get_fe_collection())
155 Assert(
156 fe.n_base_elements() == 1,
158 "This class currently only supports scalar elements and elements "
159 "with a single base element."));
160#endif
161
162 for (unsigned int comp = 0; comp < dh.get_fe_collection().n_components();
163 ++comp)
164 {
165 const auto values = VectorTools::point_values<1>(
166 rpe, dh, data_ptr->vector, VectorTools::EvaluationFlags::avg, comp);
167
168 vectors.emplace_back(
170 partitioner));
171
172 for (unsigned int j = 0; j < values.size(); ++j)
173 vectors.back()->local_element(point_to_local_vector_indices[j]) =
174 values[j];
175
176 vectors.back()->set_ghost_state(true);
177
178 // we can give the vectors arbitrary names ("temp_*") here, since
179 // these are only used internally (by patch_data_out) but not later on
180 // during the actual output to file
181 patch_data_out.add_data_vector(
182 *vectors.back(),
183 std::string("temp_" + std::to_string(counter)),
185 DataVectorType::type_dof_data);
186
187 ++counter;
188 }
189 }
190
191 patch_data_out.build_patches(*patch_mapping,
192 patch_dof_handler.get_fe().degree,
193 curved_region);
194}
195
196
197
198template <int dim, int patch_dim, int spacedim>
199const std::vector<typename DataOutBase::Patch<patch_dim, spacedim>> &
201{
202 return patch_data_out.get_patches();
203}
204
205
206// explicit instantiations
207#include "data_out_resample.inst"
208
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:185
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:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
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:735
IndexSet extract_locally_active_dofs(const DoFHandler< dim, spacedim > &dof_handler)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation