deal.II version GIT relicensing-2289-g1e5549a87a 2024-12-21 21: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
utilities.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2020 - 2023 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
15#ifndef dealii_particles_utilities
16#define dealii_particles_utilities
17
18#include <deal.II/base/config.h>
19
21#include <deal.II/base/point.h>
23
25
27#include <deal.II/fe/fe.h>
28
30
33
35
36
38
39
40
41namespace Particles
42{
47 namespace Utilities
48 {
93 template <int dim, int spacedim, typename number = double>
94 void
96 const DoFHandler<dim, spacedim> &space_dh,
97 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
98 SparsityPatternBase &sparsity,
99 const AffineConstraints<number> &constraints =
101 const ComponentMask &space_comps = {});
102
146 template <int dim, int spacedim, typename MatrixType>
147 void
149 const DoFHandler<dim, spacedim> &space_dh,
150 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
151 MatrixType &matrix,
154 const ComponentMask &space_comps = {});
155
178 template <int dim,
179 int spacedim,
180 typename InputVectorType,
181 typename OutputVectorType>
182 void
184 const DoFHandler<dim, spacedim> &field_dh,
185 const Particles::ParticleHandler<dim, spacedim> &particle_handler,
186 const InputVectorType &field_vector,
187 OutputVectorType &interpolated_field,
188 const ComponentMask &field_comps = {})
189 {
190 if (particle_handler.n_locally_owned_particles() == 0)
191 {
192 interpolated_field.compress(VectorOperation::add);
193 return; // nothing else to do here
194 }
195
196 const auto &fe = field_dh.get_fe();
197 auto particle = particle_handler.begin();
198
199 // Take care of components
200 const ComponentMask comps =
201 (field_comps.size() == 0 ? ComponentMask(fe.n_components(), true) :
202 field_comps);
203 AssertDimension(comps.size(), fe.n_components());
204 const auto n_comps = comps.n_selected_components();
205
206 AssertDimension(field_vector.size(), field_dh.n_dofs());
207 AssertDimension(interpolated_field.size(),
208 particle_handler.get_next_free_particle_index() *
209 n_comps);
210
211 // Global to local indices
212 std::vector<unsigned int> space_gtl(fe.n_components(),
214 for (unsigned int i = 0, j = 0; i < space_gtl.size(); ++i)
215 if (comps[i])
216 space_gtl[i] = j++;
217
218 std::vector<types::global_dof_index> dof_indices(fe.n_dofs_per_cell());
219
220 while (particle != particle_handler.end())
221 {
222 const auto &cell = particle->get_surrounding_cell();
223 const auto &dh_cell =
224 typename DoFHandler<dim, spacedim>::cell_iterator(*cell, &field_dh);
225 dh_cell->get_dof_indices(dof_indices);
226 const auto pic = particle_handler.particles_in_cell(cell);
227
228 Assert(pic.begin() == particle, ExcInternalError());
229 for (unsigned int i = 0; particle != pic.end(); ++particle, ++i)
230 {
231 const Point<dim> reference_location =
232 particle->get_reference_location();
233
234 const auto id = particle->get_id();
235
236 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
237 {
238 const auto comp_j =
239 space_gtl[fe.system_to_component_index(j).first];
240 if (comp_j != numbers::invalid_unsigned_int)
241 interpolated_field[id * n_comps + comp_j] +=
242 fe.shape_value(j, reference_location) *
243 field_vector(dof_indices[j]);
244 }
245 }
246 }
247 interpolated_field.compress(VectorOperation::add);
248 }
249
250 } // namespace Utilities
251} // namespace Particles
253
254#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:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#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:183
static const unsigned int invalid_unsigned_int
Definition types.h:220