deal.II version 9.8.0
\(\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
utilities.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) 2020 - 2026 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_particles_utilities_h
14#define dealii_particles_utilities_h
15
16#include <deal.II/base/config.h>
17
19#include <deal.II/base/point.h>
21
23
25#include <deal.II/fe/fe.h>
26
28
31
33
34
36
37
38
39namespace Particles
40{
45 namespace Utilities
46 {
91 template <int dim, int spacedim, typename number = double>
92 void
94 const DoFHandler<dim, spacedim> &space_dh,
95 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
96 SparsityPatternBase &sparsity,
97 const AffineConstraints<number> &constraints =
99 const ComponentMask &space_comps = {});
100
144 template <int dim, int spacedim, typename MatrixType>
145 void
147 const DoFHandler<dim, spacedim> &space_dh,
148 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
149 MatrixType &matrix,
152 const ComponentMask &space_comps = {});
153
176 template <int dim,
177 int spacedim,
178 typename InputVectorType,
179 typename OutputVectorType>
180 void
182 const DoFHandler<dim, spacedim> &field_dh,
183 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
184 const InputVectorType &field_vector,
185 OutputVectorType &interpolated_field,
186 const ComponentMask &field_comps = {})
187 {
188 if (particle_handler.n_locally_owned_particles() == 0)
189 {
190 interpolated_field.compress(VectorOperation::add);
191 return; // nothing else to do here
192 }
193
194 const auto &fe = field_dh.get_fe();
195 auto particle = particle_handler.begin();
196
197 // Take care of components
198 const ComponentMask comps =
199 (field_comps.size() == 0 ? ComponentMask(fe.n_components(), true) :
200 field_comps);
201 AssertDimension(comps.size(), fe.n_components());
202 const auto n_comps = comps.n_selected_components();
203
204 AssertDimension(field_vector.size(), field_dh.n_dofs());
205 AssertDimension(interpolated_field.size(),
206 particle_handler.get_next_free_particle_index() *
207 n_comps);
208
209 // Global to local indices
210 std::vector<unsigned int> space_gtl(fe.n_components(),
212 for (unsigned int i = 0, j = 0; i < space_gtl.size(); ++i)
213 if (comps[i])
214 space_gtl[i] = j++;
215
216 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
217
218 while (particle != particle_handler.end())
219 {
220 const auto &cell = particle->get_surrounding_cell();
221 const auto &dh_cell =
222 typename DoFHandler<dim, spacedim>::cell_iterator(*cell, &field_dh);
223 dh_cell->get_dof_indices(dof_indices);
224 const auto pic = particle_handler.particles_in_cell(cell);
225
226 Assert(pic.begin() == particle, ExcInternalError());
227 for (unsigned int i = 0; particle != pic.end(); ++particle, ++i)
228 {
229 const Point<dim> reference_location =
230 particle->get_reference_location();
231
232 const auto id = particle->get_id();
233
234 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
235 {
236 const auto comp_j =
237 space_gtl[fe.system_to_component_index(j).first];
238 if (comp_j != numbers::invalid_unsigned_int)
239 interpolated_field[id * n_comps + comp_j] +=
240 fe.shape_value(j, reference_location) *
241 field_vector(dof_indices[j]);
242 }
243 }
244 }
245 interpolated_field.compress(VectorOperation::add);
246 }
247
248 } // namespace Utilities
249} // namespace Particles
251
252#endif
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 types::fe_index index=0) const
types::global_dof_index n_dofs() const
particle_iterator begin() const
particle_iterator end() const
types::particle_index n_locally_owned_particles() const
particle_iterator_range particles_in_cell(const typename Triangulation< dim, spacedim >::active_cell_iterator &cell)
types::particle_index get_next_free_particle_index() const
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
typename ActiveSelector::cell_iterator cell_iterator
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={})
Definition utilities.cc:113
void create_interpolation_sparsity_pattern(const DoFHandler< dim, spacedim > &space_dh, const Particles::ParticleHandler< dim, spacedim > &particle_handler, SparsityPatternBase &sparsity, const AffineConstraints< number > &constraints=AffineConstraints< number >(), const ComponentMask &space_comps={})
Definition utilities.cc:31
void interpolate_field_on_particles(const DoFHandler< dim, spacedim > &field_dh, const Particles::ParticleHandler< dim, spacedim > &particle_handler, const InputVectorType &field_vector, OutputVectorType &interpolated_field, const ComponentMask &field_comps={})
Definition utilities.h:181
constexpr unsigned int invalid_unsigned_int
Definition types.h:236