18#ifndef rdlm_reduced_coupling_h
19#define rdlm_reduced_coupling_h
66template <
int reduced_dim,
int dim,
int spacedim = dim,
int n_components = 1>
118template <
int reduced_dim,
int dim,
int spacedim = dim,
int n_components = 1>
160 template <
typename MatrixType>
166 template <
typename MatrixType>
197 template <
typename VectorType>
245template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
246template <
typename MatrixType>
256 std::vector<types::global_dof_index> background_dof_indices(
257 fe.n_dofs_per_cell());
260 immersed_fe.n_dofs_per_cell());
263 immersed_fe.n_dofs_per_cell(),
fe.n_dofs_per_cell());
268 const auto &cell = particle->get_surrounding_cell();
271 dh_cell->get_dof_indices(background_dof_indices);
273 const auto pic = this->
get_particles().particles_in_cell(cell);
274 Assert(pic.begin() == particle, ExcInternalError());
278 local_coupling_matrix = 0;
279 for (
const auto &p : pic)
281 const auto [immersed_cell_id, immersed_q, section_q] =
284 const auto &background_p = p.get_reference_location();
286 const auto &JxW = p.get_properties()[0];
287 last_cell_id = immersed_cell_id;
288 if (immersed_cell_id != previous_cell_id &&
292 const auto &immersed_dof_indices =
295 background_dof_indices,
297 immersed_dof_indices,
299 local_coupling_matrix = 0;
300 previous_cell_id = immersed_cell_id;
303 for (
unsigned int i = 0; i <
fe.n_dofs_per_cell(); ++i)
305 const auto comp_i =
fe.system_to_component_index(i).first;
306 if (comp_i < n_components)
308 const auto v_i_comp_i =
fe.shape_value(i, background_p);
310 for (
unsigned int j = 0; j < immersed_fe.n_dofs_per_cell();
314 immersed_fe.system_to_component_index(j).first;
316 const auto phi_comp_j_comp_i =
318 comp_j, section_q, comp_i);
320 const auto w_j_comp_j =
321 immersed_fe.shape_value(j, immersed_p);
323 local_coupling_matrix(i, j) +=
324 v_i_comp_i * phi_comp_j_comp_i * w_j_comp_j * JxW;
329 const auto &immersed_dof_indices = this->
get_dof_indices(last_cell_id);
331 background_dof_indices,
333 immersed_dof_indices,
335 particle = pic.end();
340template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
341template <
typename MatrixType>
353 fe.n_dofs_per_cell());
354 std::vector<types::global_dof_index> dof_indices(
fe.n_dofs_per_cell());
366 const unsigned int thickness_field_index =
368 std::find(this->properties_names.begin(),
369 this->properties_names.end(),
370 par.thickness_field_name));
372 const auto thickness_start =
375 VTKUtils::get_block_indices(properties_fe)
376 .block_start(thickness_field_index);
381 std::vector<double> thickness_values(
383 par.tensor_product_space_parameters.thickness);
385 for (
const auto &cell : this->
get_dof_handler().active_cell_iterators())
386 if (cell->is_locally_owned())
393 properties_fe_values.
reinit(
394 cell->as_dof_handler_iterator(this->properties_dh));
399 local_mass_matrix = 0;
402 const auto section_measure =
413 if (comp_i == comp_j)
414 local_mass_matrix(i, j) += fe_values.
shape_value(i, q) *
416 JxW[q] * section_measure;
420 cell->get_dof_indices(dof_indices);
430template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
431template <
typename VectorType>
434 VectorType &reduced_rhs)
const
443 std::vector<Vector<double>> rhs_values(
446 std::vector<types::global_dof_index> dof_indices(
456 const unsigned int thickness_field_index =
458 std::find(this->properties_names.begin(),
459 this->properties_names.end(),
460 par.thickness_field_name));
462 const auto thickness_start =
465 VTKUtils::get_block_indices(properties_fe)
466 .block_start(thickness_field_index);
472 std::vector<double> thickness_values(
474 par.tensor_product_space_parameters.thickness);
481 for (
const auto &cell : this->
get_dof_handler().active_cell_iterators())
482 if (cell->is_locally_owned())
492 properties_fe_values.
reinit(
493 cell->as_dof_handler_iterator(this->properties_dh));
504 local_rhs(i) += rhs_values[q][comp_i] *
507 thickness_values[q]);
509 cell->get_dof_indices(dof_indices);
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const std::vector< double > & get_JxW_values() const
void get_function_values(const ReadVector< Number > &fe_function, std::vector< Number > &values) const
const std::vector< Point< spacedim > > & get_quadrature_points() const
std_cxx20::ranges::iota_view< unsigned int, unsigned int > dof_indices() const
std_cxx20::ranges::iota_view< unsigned int, unsigned int > quadrature_point_indices() const
const FiniteElement< dim, spacedim > & get_fe() const
const double & shape_value(const unsigned int i, const unsigned int q_point) const
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
ParameterAcceptor(const std::string §ion_name="")
A class implementing a repartitioning policy for immersed triangulations.
SmartPointer< const Mapping< dim > > mapping
Smart pointer to the mapping associated with the triangulation.
const Particles::ParticleHandler< dim > & get_particles() const
ParticleCoupling(const ParticleCouplingParameters< dim > &par)
Constructor.
Stores parameters related to particle coupling in a simulation.
TensorProductSpace(const TensorProductSpaceParameters< reduced_dim, dim, spacedim, n_components > &par, MPI_Comm mpi_communicator=MPI_COMM_WORLD)
DoFHandler< reduced_dim, spacedim > properties_dh
const ReferenceCrossSection< dim - reduced_dim, spacedim, n_components > & get_reference_cross_section() const
auto get_quadrature() const -> const QGauss< reduced_dim > &
const DoFHandler< reduced_dim, spacedim > & get_dof_handler() const
const std::vector< types::global_dof_index > & get_dof_indices(const types::global_cell_index cell_index) const
std::vector< std::string > properties_names
std::tuple< unsigned int, unsigned int, unsigned int > particle_id_to_cell_and_qpoint_indices(const unsigned int qpoint_index) const
LinearAlgebra::distributed::Vector< double > properties
FESystem< reduced_dim, spacedim > fe
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
constexpr unsigned int invalid_unsigned_int
unsigned int global_cell_index
ObserverPointer< T, P > SmartPointer
static MappingQ< dim, spacedim > mapping
void initialize(const Mapping< spacedim > &mapping=StaticMappingQ1< spacedim >::mapping)
Initialize the tensor product space and particle coupling.
ImmersedRepartitioner< reduced_dim, spacedim > immersed_partitioner
void assemble_reduced_rhs(VectorType &reduced_rhs) const
Assemble the right-hand side vector for the reduced space.
void assemble_coupling_mass_matrix(MatrixType &mass_matrix) const
SmartPointer< const parallel::TriangulationBase< spacedim > > background_tria
The triangulation of the background domain.
void assemble_coupling_matrix(MatrixType &coupling_matrix, const DoFHandler< spacedim > &dh, const AffineConstraints< double > &constraints) const
Assemble the coupling matrix between background and reduced spaces.
std::unique_ptr< FunctionParser< spacedim > > coupling_rhs
The right-hand side function for the coupling.
AffineConstraints< double > coupling_constraints
Affine constraints for the coupling.
const ReducedCouplingParameters< reduced_dim, dim, spacedim, n_components > & par
Reference to the parameters used for this coupling.
ReducedCoupling(const parallel::TriangulationBase< spacedim > &background_tria, const ReducedCouplingParameters< reduced_dim, dim, spacedim, n_components > &par)
Constructor that initializes the ReducedCoupling object with background triangulation and parameters.
void assemble_coupling_sparsity(DynamicSparsityPattern &dsp, const DoFHandler< spacedim > &dh, const AffineConstraints< double > &constraints) const
Assemble the sparsity pattern for the coupling matrix.
const MPI_Comm mpi_communicator
The MPI communicator used for parallel operations.
const AffineConstraints< double > & get_coupling_constraints() const
Get the affine constraints associated with the coupling.
Parameter structure for configuring ReducedCoupling objects.
ReducedCouplingParameters()
Constructor that registers parameters with the ParameterAcceptor.
ParticleCouplingParameters< spacedim > particle_coupling_parameters
Parameters for the particle coupling.
std::string thickness_field_name
TensorProductSpaceParameters< reduced_dim, dim, spacedim, n_components > tensor_product_space_parameters
Parameters for the tensor product space.
std::vector< std::string > coupling_rhs_expressions
Right hand side expressions for the reduced coupling.
unsigned int pre_refinement
Number of pre-refinements to apply to the grid before distribution.