Reference documentation for deal.II version 9.5.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// Copyright (C) 2020 - 2022 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#ifndef dealii_particles_utilities
17#define dealii_particles_utilities
18
19#include <deal.II/base/config.h>
20
22#include <deal.II/base/point.h>
24
26
28#include <deal.II/fe/fe.h>
29
31
34
36
37
39
40
41
42namespace Particles
43{
48 namespace Utilities
49 {
94 template <int dim, int spacedim, typename number = double>
95 void
97 const DoFHandler<dim, spacedim> & space_dh,
98 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
99 SparsityPatternBase & sparsity,
100 const AffineConstraints<number> & constraints =
102 const ComponentMask &space_comps = ComponentMask());
103
147 template <int dim, int spacedim, typename MatrixType>
148 void
150 const DoFHandler<dim, spacedim> & space_dh,
151 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
152 MatrixType & matrix,
155 const ComponentMask &space_comps = ComponentMask());
156
179 template <int dim,
180 int spacedim,
181 typename InputVectorType,
182 typename OutputVectorType>
183 void
185 const DoFHandler<dim, spacedim> & field_dh,
186 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
187 const InputVectorType & field_vector,
188 OutputVectorType & interpolated_field,
189 const ComponentMask &field_comps = ComponentMask())
190 {
191 if (particle_handler.n_locally_owned_particles() == 0)
192 {
193 interpolated_field.compress(VectorOperation::add);
194 return; // nothing else to do here
195 }
196
197 const auto &fe = field_dh.get_fe();
198 auto particle = particle_handler.begin();
199
200 // Take care of components
201 const ComponentMask comps =
202 (field_comps.size() == 0 ? ComponentMask(fe.n_components(), true) :
203 field_comps);
204 AssertDimension(comps.size(), fe.n_components());
205 const auto n_comps = comps.n_selected_components();
206
207 AssertDimension(field_vector.size(), field_dh.n_dofs());
208 AssertDimension(interpolated_field.size(),
209 particle_handler.get_next_free_particle_index() *
210 n_comps);
211
212 // Global to local indices
213 std::vector<unsigned int> space_gtl(fe.n_components(),
215 for (unsigned int i = 0, j = 0; i < space_gtl.size(); ++i)
216 if (comps[i])
217 space_gtl[i] = j++;
218
219 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
220
221 while (particle != particle_handler.end())
222 {
223 const auto &cell = particle->get_surrounding_cell();
224 const auto &dh_cell =
225 typename DoFHandler<dim, spacedim>::cell_iterator(*cell, &field_dh);
226 dh_cell->get_dof_indices(dof_indices);
227 const auto pic = particle_handler.particles_in_cell(cell);
228
229 Assert(pic.begin() == particle, ExcInternalError());
230 for (unsigned int i = 0; particle != pic.end(); ++particle, ++i)
231 {
232 const Point<dim> reference_location =
233 particle->get_reference_location();
234
235 const auto id = particle->get_id();
236
237 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
238 {
239 const auto comp_j =
240 space_gtl[fe.system_to_component_index(j).first];
241 if (comp_j != numbers::invalid_unsigned_int)
242 interpolated_field[id * n_comps + comp_j] +=
243 fe.shape_value(j, reference_location) *
244 field_vector(dof_indices[j]);
245 }
246 }
247 }
248 interpolated_field.compress(VectorOperation::add);
249 }
250
251 } // namespace Utilities
252} // namespace Particles
254
255#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:112
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
typename ActiveSelector::cell_iterator cell_iterator
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=ComponentMask())
Definition utilities.h:184
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:114
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=ComponentMask())
Definition utilities.cc:32
static const unsigned int invalid_unsigned_int
Definition types.h:213