18#ifndef rdlm_reduced_coupling_h
19#define rdlm_reduced_coupling_h
67template <
int reduced_dim,
int dim,
int spacedim = dim,
int n_components = 1>
119template <
int reduced_dim,
int dim,
int spacedim = dim,
int n_components = 1>
161 template <
typename MatrixType>
167 template <
typename MatrixType>
198 template <
typename VectorType>
246template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
247template <
typename MatrixType>
257 std::vector<types::global_dof_index> background_dof_indices(
258 fe.n_dofs_per_cell());
261 immersed_fe.n_dofs_per_cell());
264 immersed_fe.n_dofs_per_cell(),
fe.n_dofs_per_cell());
269 const auto &cell = particle->get_surrounding_cell();
272 dh_cell->get_dof_indices(background_dof_indices);
274 const auto pic = this->
get_particles().particles_in_cell(cell);
275 Assert(pic.begin() == particle, ExcInternalError());
279 local_coupling_matrix = 0;
280 for (
const auto &p : pic)
282 const auto [immersed_cell_id, immersed_q, section_q] =
285 const auto &background_p = p.get_reference_location();
287 const auto &JxW = p.get_properties()[0];
288 last_cell_id = immersed_cell_id;
289 if (immersed_cell_id != previous_cell_id &&
293 const auto &immersed_dof_indices =
296 background_dof_indices,
298 immersed_dof_indices,
300 local_coupling_matrix = 0;
301 previous_cell_id = immersed_cell_id;
304 for (
unsigned int i = 0; i <
fe.n_dofs_per_cell(); ++i)
306 const auto comp_i =
fe.system_to_component_index(i).first;
307 if (comp_i < n_components)
309 const auto v_i_comp_i =
fe.shape_value(i, background_p);
311 for (
unsigned int j = 0; j < immersed_fe.n_dofs_per_cell();
315 immersed_fe.system_to_component_index(j).first;
317 const auto phi_comp_j_comp_i =
319 comp_j, section_q, comp_i);
321 const auto w_j_comp_j =
322 immersed_fe.shape_value(j, immersed_p);
324 local_coupling_matrix(i, j) +=
325 v_i_comp_i * phi_comp_j_comp_i * w_j_comp_j * JxW;
330 const auto &immersed_dof_indices = this->
get_dof_indices(last_cell_id);
332 background_dof_indices,
334 immersed_dof_indices,
336 particle = pic.end();
341template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
342template <
typename MatrixType>
354 fe.n_dofs_per_cell());
355 std::vector<types::global_dof_index> dof_indices(
fe.n_dofs_per_cell());
367 const unsigned int thickness_field_index =
369 std::find(this->properties_names.begin(),
370 this->properties_names.end(),
371 par.thickness_field_name));
373 const auto thickness_start =
376 VTKUtils::get_block_indices(properties_fe)
377 .block_start(thickness_field_index);
382 std::vector<double> thickness_values(
384 par.tensor_product_space_parameters.thickness);
386 for (
const auto &cell : this->
get_dof_handler().active_cell_iterators())
387 if (cell->is_locally_owned())
394 properties_fe_values.
reinit(
395 cell->as_dof_handler_iterator(this->properties_dh));
400 local_mass_matrix = 0;
403 const auto section_measure =
414 if (comp_i == comp_j)
415 local_mass_matrix(i, j) += fe_values.
shape_value(i, q) *
417 JxW[q] * section_measure;
421 cell->get_dof_indices(dof_indices);
431template <
int reduced_dim,
int dim,
int spacedim,
int n_components>
432template <
typename VectorType>
435 VectorType &reduced_rhs)
const
444 std::vector<Vector<double>> rhs_values(
447 std::vector<types::global_dof_index> dof_indices(
457 const unsigned int thickness_field_index =
459 std::find(this->properties_names.begin(),
460 this->properties_names.end(),
461 par.thickness_field_name));
463 const auto thickness_start =
466 VTKUtils::get_block_indices(properties_fe)
467 .block_start(thickness_field_index);
473 std::vector<double> thickness_values(
475 par.tensor_product_space_parameters.thickness);
482 for (
const auto &cell : this->
get_dof_handler().active_cell_iterators())
483 if (cell->is_locally_owned())
493 properties_fe_values.
reinit(
494 cell->as_dof_handler_iterator(this->properties_dh));
505 local_rhs(i) += rhs_values[q][comp_i] *
508 thickness_values[q]);
510 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
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.
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.
ReducedCoupling(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.
SmartPointer< parallel::TriangulationBase< spacedim > > background_tria
The triangulation of the background domain.
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
RefinementParameters refinement_parameters
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.