Reference documentation for deal.II version GIT d7aca55de5 2022-08-10 12:50: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\}}\)
data_out_resample.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/dofs/dof_tools.h>
17 
18 #include <deal.II/fe/fe_q_iso_q1.h>
19 #include <deal.II/fe/fe_tools.h>
20 
23 
24 #include <deal.II/numerics/data_out_dof_data.templates.h>
27 
28 #include <sstream>
29 
31 
32 
33 template <int dim, int patch_dim, int spacedim>
35  const Triangulation<patch_dim, spacedim> &patch_tria,
36  const Mapping<patch_dim, spacedim> & patch_mapping)
37  : patch_dof_handler(patch_tria)
38  , patch_mapping(&patch_mapping)
39 {}
40 
41 
42 
43 template <int dim, int patch_dim, int spacedim>
44 void
46  const Mapping<dim, spacedim> &mapping,
47  const unsigned int n_subdivisions)
48 {
49  this->mapping = &mapping;
50  this->point_to_local_vector_indices.clear();
51 
53  std::max<unsigned int>(1, n_subdivisions));
54  patch_dof_handler.distribute_dofs(fe);
55 
56  std::vector<std::pair<types::global_dof_index, Point<spacedim>>> points_all;
57 
59 
60  FEValues<patch_dim, spacedim> fe_values(*patch_mapping,
61  fe,
62  quadrature,
64 
65  std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
66 
67  IndexSet active_dofs;
68  DoFTools::extract_locally_active_dofs(patch_dof_handler, active_dofs);
69  partitioner = std::make_shared<Utilities::MPI::Partitioner>(
70  patch_dof_handler.locally_owned_dofs(), active_dofs, MPI_COMM_WORLD);
71 
72  for (const auto &cell : patch_dof_handler.active_cell_iterators() |
74  {
75  fe_values.reinit(cell);
76 
77  cell->get_dof_indices(dof_indices);
78 
79  for (unsigned int i = 0; i < dof_indices.size(); ++i)
80  points_all.emplace_back(partitioner->global_to_local(dof_indices[i]),
81  fe_values.quadrature_point(i));
82  }
83 
84  std::sort(points_all.begin(),
85  points_all.end(),
86  [](const auto &a, const auto &b) { return a.first < b.first; });
87  points_all.erase(std::unique(points_all.begin(),
88  points_all.end(),
89  [](const auto &a, const auto &b) {
90  return a.first == b.first;
91  }),
92  points_all.end());
93 
94  std::vector<Point<spacedim>> points;
95 
96  for (const auto &i : points_all)
97  {
98  point_to_local_vector_indices.push_back(i.first);
99  points.push_back(i.second);
100  }
101 
102  rpe.reinit(points, *this->triangulation, *this->mapping);
103 }
104 
105 
106 
107 template <int dim, int patch_dim, int spacedim>
108 void
110  const Mapping<dim, spacedim> & mapping,
111  const unsigned int n_subdivisions,
112  const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
113 {
114  this->update_mapping(mapping, n_subdivisions);
115  this->build_patches(curved_region);
116 }
117 
118 
119 
120 template <int dim, int patch_dim, int spacedim>
121 void
123  const typename DataOut<patch_dim, spacedim>::CurvedCellRegion curved_region)
124 {
125  patch_data_out.clear();
126 
127  if (rpe.is_ready() == false)
128  {
129  Assert(
130  this->mapping,
131  ExcMessage(
132  "Mapping is not valid anymore! Please register a new mapping via "
133  "update_mapping() or the other build_patches() function."));
134  update_mapping(*this->mapping, patch_dof_handler.get_fe().degree);
135  }
136 
137  std::vector<std::shared_ptr<LinearAlgebra::distributed::Vector<double>>>
138  vectors;
139 
140  patch_data_out.attach_dof_handler(patch_dof_handler);
141 
142  unsigned int counter = 0;
143 
144  for (const auto &data : this->dof_data)
145  {
146  const auto data_ptr = dynamic_cast<
147  internal::DataOutImplementation::DataEntry<dim, spacedim, double> *>(
148  data.get());
149 
150  Assert(data_ptr, ExcNotImplemented());
151 
152  const auto &dh = *data_ptr->dof_handler;
153 
154  // TODO: enable more components
155  AssertDimension(dh.get_fe_collection().n_components(), 1);
156 
157  const auto values =
158  VectorTools::point_values<1>(rpe, dh, data_ptr->vector);
159 
160  vectors.emplace_back(
162  partitioner));
163 
164  for (unsigned int j = 0; j < values.size(); ++j)
165  vectors.back()->local_element(point_to_local_vector_indices[j]) =
166  values[j];
167 
168  vectors.back()->set_ghost_state(true);
169 
170  // we can give the vectors arbitrary names ("temp_*") here, since these
171  // are only used internally (by patch_data_out) but not later on during
172  // the actual output to file
173  patch_data_out.add_data_vector(
174  *vectors.back(),
175  std::string("temp_" + std::to_string(counter)),
177  DataVectorType::type_dof_data);
178 
179  counter++;
180  }
181 
182  patch_data_out.build_patches(*patch_mapping,
183  patch_dof_handler.get_fe().degree,
184  curved_region);
185 }
186 
187 
188 
189 template <int dim, int patch_dim, int spacedim>
190 const std::vector<typename DataOutBase::Patch<patch_dim, spacedim>> &
192 {
193  return patch_data_out.get_patches();
194 }
195 
196 
197 // explicit instantiations
198 #include "data_out_resample.inst"
199 
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)
const Point< spacedim > & quadrature_point(const unsigned int q) 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:311
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcNotImplemented()
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1667
static ::ExceptionBase & ExcMessage(std::string arg1)
@ update_mapping
@ update_quadrature_points
Transformed quadrature points.
IndexSet extract_locally_active_dofs(const DoFHandler< dim, spacedim > &dof_handler)
Definition: dof_tools.cc:1051
std::string to_string(const T &t)
Definition: patterns.h:2393
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation