Reference documentation for deal.II version 9.3.3
\(\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\}}\)
utilities.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2020 - 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/base/config.h>
17
19
21
22
24
25
26namespace Particles
27{
28 namespace Utilities
29 {
30 template <int dim, int spacedim, typename SparsityType, typename number>
31 void
33 const DoFHandler<dim, spacedim> & space_dh,
34 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
35 SparsityType & sparsity,
36 const AffineConstraints<number> & constraints,
37 const ComponentMask & space_comps)
38 {
39 if (particle_handler.n_locally_owned_particles() == 0)
40 return; // nothing to do here
41
42 const auto &tria = space_dh.get_triangulation();
43 const auto &fe = space_dh.get_fe();
44 const auto max_particles_per_cell =
45 particle_handler.n_global_max_particles_per_cell();
46
47 // Take care of components
48 const ComponentMask comps =
49 (space_comps.size() == 0 ? ComponentMask(fe.n_components(), true) :
50 space_comps);
51 AssertDimension(comps.size(), fe.n_components());
52
53 const auto n_comps = comps.n_selected_components();
54
55 // Global to local indices
56 std::vector<unsigned int> space_gtl(fe.n_components(),
58 for (unsigned int i = 0, j = 0; i < space_gtl.size(); ++i)
59 if (comps[i])
60 space_gtl[i] = j++;
61
62 // [TODO]: when the add_entries_local_to_global below will implement
63 // the version with the dof_mask, this should be uncommented.
64 // // Construct a dof_mask, used to distribute entries to the sparsity
65 // Table<2, bool> dof_mask(max_particles_per_cell * n_comps,
66 // fe.n_dofs_per_cell());
67 // dof_mask.fill(false);
68 // for (unsigned int i = 0; i < space_fe.n_dofs_per_cell(); ++i)
69 // {
70 // const auto comp_i = space_fe.system_to_component_index(i).first;
71 // if (space_gtl[comp_i] != numbers::invalid_unsigned_int)
72 // for (unsigned int j = 0; j < max_particles_per_cell; ++j)
73 // dof_mask(i, j * n_comps + space_gtl[comp_i]) = true;
74 // }
75
76 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
77 std::vector<types::particle_index> particle_indices(
78 max_particles_per_cell * n_comps);
79
80 auto particle = particle_handler.begin();
81 while (particle != particle_handler.end())
82 {
83 const auto &cell = particle->get_surrounding_cell(tria);
84 const auto dh_cell =
85 typename DoFHandler<dim, spacedim>::cell_iterator(*cell, &space_dh);
86 dh_cell->get_dof_indices(dof_indices);
87 const auto pic = particle_handler.particles_in_cell(cell);
88 const auto n_particles = particle_handler.n_particles_in_cell(cell);
89 particle_indices.resize(n_particles * n_comps);
90 Assert(pic.begin() == particle, ExcInternalError());
91 for (unsigned int i = 0; particle != pic.end(); ++particle, ++i)
92 {
93 const auto p_id = particle->get_id();
94 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
95 {
96 const auto comp_j =
97 space_gtl[fe.system_to_component_index(j).first];
100 {p_id * n_comps + comp_j}, {dof_indices[j]}, sparsity);
101 }
102 }
103 // [TODO]: when this works, use this:
104 // constraints.add_entries_local_to_global(particle_indices,
105 // dof_indices,
106 // sparsity,
107 // dof_mask);
108 }
109 }
110
111
112
113 template <int dim, int spacedim, typename MatrixType>
114 void
116 const DoFHandler<dim, spacedim> & space_dh,
117 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
118 MatrixType & matrix,
120 const ComponentMask & space_comps)
121 {
122 if (particle_handler.n_locally_owned_particles() == 0)
123 {
125 return; // nothing else to do here
126 }
127
128 AssertDimension(matrix.n(), space_dh.n_dofs());
129
130 const auto &tria = space_dh.get_triangulation();
131 const auto &fe = space_dh.get_fe();
132 const auto max_particles_per_cell =
133 particle_handler.n_global_max_particles_per_cell();
134
135 // Take care of components
136 const ComponentMask comps =
137 (space_comps.size() == 0 ? ComponentMask(fe.n_components(), true) :
138 space_comps);
139 AssertDimension(comps.size(), fe.n_components());
140 const auto n_comps = comps.n_selected_components();
141
143 particle_handler.n_global_particles() * n_comps);
144
145
146 // Global to local indices
147 std::vector<unsigned int> space_gtl(fe.n_components(),
149 for (unsigned int i = 0, j = 0; i < space_gtl.size(); ++i)
150 if (comps[i])
151 space_gtl[i] = j++;
152
153 // [TODO]: when the add_entries_local_to_global below will implement
154 // the version with the dof_mask, this should be uncommented.
155 // // Construct a dof_mask, used to distribute entries to the sparsity
156 // Table<2, bool> dof_mask(max_particles_per_cell * n_comps,
157 // fe.n_dofs_per_cell());
158 // dof_mask.fill(false);
159 // for (unsigned int i = 0; i < space_fe.n_dofs_per_cell(); ++i)
160 // {
161 // const auto comp_i = space_fe.system_to_component_index(i).first;
162 // if (space_gtl[comp_i] != numbers::invalid_unsigned_int)
163 // for (unsigned int j = 0; j < max_particles_per_cell; ++j)
164 // dof_mask(i, j * n_comps + space_gtl[comp_i]) = true;
165 // }
166
167 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
168 std::vector<types::particle_index> particle_indices(
169 max_particles_per_cell * n_comps);
170
172 max_particles_per_cell * n_comps, fe.n_dofs_per_cell());
173
174 auto particle = particle_handler.begin();
175 while (particle != particle_handler.end())
176 {
177 const auto &cell = particle->get_surrounding_cell(tria);
178 const auto &dh_cell =
179 typename DoFHandler<dim, spacedim>::cell_iterator(*cell, &space_dh);
180 dh_cell->get_dof_indices(dof_indices);
181 const auto pic = particle_handler.particles_in_cell(cell);
182 const auto n_particles = particle_handler.n_particles_in_cell(cell);
183 particle_indices.resize(n_particles * n_comps);
184 local_matrix.reinit({n_particles * n_comps, fe.n_dofs_per_cell()});
185 Assert(pic.begin() == particle, ExcInternalError());
186 for (unsigned int i = 0; particle != pic.end(); ++particle, ++i)
187 {
188 const auto &reference_location =
189 particle->get_reference_location();
190
191 for (unsigned int d = 0; d < n_comps; ++d)
192 particle_indices[i * n_comps + d] =
193 particle->get_id() * n_comps + d;
194
195 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
196 {
197 const auto comp_j =
198 space_gtl[fe.system_to_component_index(j).first];
199 if (comp_j != numbers::invalid_unsigned_int)
200 local_matrix(i * n_comps + comp_j, j) =
201 fe.shape_value(j, reference_location);
202 }
203 }
204 constraints.distribute_local_to_global(local_matrix,
205 particle_indices,
206 dof_indices,
207 matrix);
208 }
210 }
211
212#include "utilities.inst"
213
214 } // namespace Utilities
215} // namespace Particles
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
void add_entries_local_to_global(const std::vector< size_type > &local_dof_indices, SparsityPatternType &sparsity_pattern, const bool keep_constrained_entries=true, const Table< 2, bool > &dof_mask=Table< 2, bool >()) const
unsigned int size() const
unsigned int n_selected_components(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
types::global_dof_index n_dofs() const
types::particle_index n_global_particles() const
particle_iterator begin() const
particle_iterator end() const
types::particle_index n_locally_owned_particles() const
types::particle_index n_particles_in_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell) const
particle_iterator_range particles_in_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell)
types::particle_index n_global_max_particles_per_cell() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
#define Assert(cond, exc)
Definition: exceptions.h:1465
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1622
static ::ExceptionBase & ExcInternalError()
typename ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:466
@ matrix
Contents is actually a matrix.
void create_interpolation_sparsity_pattern(const DoFHandler< dim, spacedim > &space_dh, const Particles::ParticleHandler< dim, spacedim > &particle_handler, SparsityType &sparsity, const AffineConstraints< number > &constraints=AffineConstraints< number >(), const ComponentMask &space_comps=ComponentMask())
Definition: utilities.cc:32
void create_interpolation_matrix(const DoFHandler< dim, spacedim > &space_dh, const Particles::ParticleHandler< dim, spacedim > &particle_handler, MatrixType &matrix, const AffineConstraints< typename MatrixType::value_type > &constraints=AffineConstraints< typename MatrixType::value_type >(), const ComponentMask &space_comps=ComponentMask())
Definition: utilities.cc:115
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static const unsigned int invalid_unsigned_int
Definition: types.h:196