Skip to content

Commit

Permalink
INCOMPLETE REFACTORING
Browse files Browse the repository at this point in the history
  • Loading branch information
tamiko committed Aug 16, 2024
1 parent 75f5db5 commit 3b1cff9
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 45 deletions.
18 changes: 14 additions & 4 deletions include/deal.II/dofs/dof_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,13 @@ class DoFHandler : public Subscriptor
* function set_fe().
*/
void
distribute_dofs(const FiniteElement<dim, spacedim> &fe,
const dealii::types::global_dof_index &virtual_dofs = 0);
distribute_dofs(const FiniteElement<dim, spacedim> &fe);

/**
* Same as above but taking an hp::FECollection object.
*/
void
distribute_dofs(const hp::FECollection<dim, spacedim> &fe,
const dealii::types::global_dof_index &virtual_dofs = 0);
distribute_dofs(const hp::FECollection<dim, spacedim> &fe);

/**
* Distribute level degrees of freedom on each level for geometric
Expand All @@ -707,6 +705,16 @@ class DoFHandler : public Subscriptor
void
distribute_mg_dofs();

/**
* FIXME: documentation
*
* Distribute virtual degrees of freedom. [...]
*
* @pre The locally owned index set must be contiguous.
*/
void
distribute_virtual_dofs(const dealii::types::global_dof_index virtual_dofs);

/**
* Returns whether this DoFHandler has hp-capabilities.
*/
Expand Down Expand Up @@ -1190,6 +1198,8 @@ class DoFHandler : public Subscriptor
locally_owned_dofs() const;

/**
* FIXME: documentation
*
* Return an IndexSet describing the subset of locally owned virtual DoFs.
*/
const IndexSet &
Expand Down
34 changes: 27 additions & 7 deletions include/deal.II/dofs/dof_handler_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace internal
* argument.
*/
virtual NumberCache
distribute_dofs(const types::global_dof_index virtual_dofs) const = 0;
distribute_dofs() const = 0;

/**
* Distribute the multigrid dofs on each level of the DoFHandler
Expand All @@ -83,6 +83,13 @@ namespace internal
virtual std::vector<NumberCache>
distribute_mg_dofs() const = 0;

/**
* FIXME: documentation
*/
virtual NumberCache
distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const = 0;

/**
* Renumber degrees of freedom as specified by the first argument.
*
Expand Down Expand Up @@ -124,13 +131,16 @@ namespace internal

// documentation is inherited
virtual NumberCache
distribute_dofs(
const types::global_dof_index virtual_dofs) const override;
distribute_dofs() const override;

// documentation is inherited
virtual std::vector<NumberCache>
distribute_mg_dofs() const override;

virtual NumberCache
distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const override;

// documentation is inherited
virtual NumberCache
renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
Expand Down Expand Up @@ -175,15 +185,21 @@ namespace internal
* number_cache.locally_owned_dofs are updated consistently.
*/
virtual NumberCache
distribute_dofs(
const types::global_dof_index virtual_dofs) const override;
distribute_dofs() const override;

/**
* This function is not yet implemented.
*/
virtual std::vector<NumberCache>
distribute_mg_dofs() const override;

/**
* This function is not yet implemented.
*/
virtual NumberCache
distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const override;

/**
* Renumber degrees of freedom as specified by the first argument.
*
Expand Down Expand Up @@ -228,13 +244,17 @@ namespace internal

// documentation is inherited
virtual NumberCache
distribute_dofs(
const types::global_dof_index virtual_dofs) const override;
distribute_dofs() const override;

// documentation is inherited
virtual std::vector<NumberCache>
distribute_mg_dofs() const override;

// documentation is inherited
virtual NumberCache
distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const override;

// documentation is inherited
virtual NumberCache
renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
Expand Down
20 changes: 14 additions & 6 deletions source/dofs/dof_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2133,19 +2133,17 @@ std::size_t DoFHandler<dim, spacedim>::memory_consumption() const
template <int dim, int spacedim>
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
void DoFHandler<dim, spacedim>::distribute_dofs(
const FiniteElement<dim, spacedim> &fe,
const dealii::types::global_dof_index &virtual_dofs)
const FiniteElement<dim, spacedim> &fe)
{
this->distribute_dofs(hp::FECollection<dim, spacedim>(fe), virtual_dofs);
this->distribute_dofs(hp::FECollection<dim, spacedim>(fe));
}



template <int dim, int spacedim>
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
void DoFHandler<dim, spacedim>::distribute_dofs(
const hp::FECollection<dim, spacedim> &ff,
const dealii::types::global_dof_index &virtual_dofs)
const hp::FECollection<dim, spacedim> &ff)
{
Assert(this->tria != nullptr,
ExcMessage(
Expand Down Expand Up @@ -2256,7 +2254,7 @@ void DoFHandler<dim, spacedim>::distribute_dofs(
}

// hand the actual work over to the policy
this->number_cache = this->policy->distribute_dofs(virtual_dofs);
this->number_cache = this->policy->distribute_dofs();

// do some housekeeping: compress indices
// if(hp_capability_enabled)
Expand Down Expand Up @@ -2313,6 +2311,16 @@ void DoFHandler<dim, spacedim>::distribute_mg_dofs()



template <int dim, int spacedim>
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
void DoFHandler<dim, spacedim>::distribute_virtual_dofs(
const types::global_dof_index virtual_dofs)
{
this->number_cache = this->policy->distribute_virtual_dofs(virtual_dofs);
}



template <int dim, int spacedim>
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
void DoFHandler<dim, spacedim>::initialize_local_block_info()
Expand Down
141 changes: 113 additions & 28 deletions source/dofs/dof_handler_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2649,8 +2649,7 @@ namespace internal

template <int dim, int spacedim>
NumberCache
Sequential<dim, spacedim>::distribute_dofs(
const types::global_dof_index n_virtual_dofs) const
Sequential<dim, spacedim>::distribute_dofs() const
{
const types::global_dof_index n_initial_dofs =
Implementation::distribute_dofs(numbers::invalid_subdomain_id,
Expand All @@ -2661,7 +2660,34 @@ namespace internal
n_initial_dofs,
/*check_validity=*/true);

return NumberCache(n_dofs);
}



template <int dim, int spacedim>
NumberCache
Sequential<dim, spacedim>::distribute_virtual_dofs(
const types::global_dof_index n_virtual_dofs) const
{
const auto &old_locally_owned_dofs =
dof_handler->locally_owned_dofs();

Assert(old_locally_owned_dofs.is_contiguous(),
ExcMessage(
"Virtual degrees of freedom can only be distributed when the "
"locally owned index range is contiguous."));

const auto &old_locally_owned_virtual_dofs =
dof_handler->locally_owned_virtual_dofs();

Assert(old_locally_owned_virtual_dofs.n_elements() == 0,
ExcMessage(
"Can distribute virtual degrees of freedom only once after "
"distribute_dofs()"));

// return a sequential, complete index set
const auto n_dofs = old_locally_owned_dofs.size();
NumberCache number_cache(n_dofs + n_virtual_dofs);

number_cache.locally_owned_virtual_dofs =
Expand Down Expand Up @@ -2920,11 +2946,8 @@ namespace internal

template <int dim, int spacedim>
NumberCache
ParallelShared<dim, spacedim>::distribute_dofs(
const types::global_dof_index virtual_dofs [[maybe_unused]]) const
ParallelShared<dim, spacedim>::distribute_dofs() const
{
Assert(virtual_dofs == 0, ExcNotImplemented());

const dealii::parallel::shared::Triangulation<dim, spacedim> *tr =
(dynamic_cast<
const dealii::parallel::shared::Triangulation<dim, spacedim> *>(
Expand Down Expand Up @@ -3066,6 +3089,17 @@ namespace internal



template <int dim, int spacedim>
NumberCache
ParallelShared<dim, spacedim>::distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const
{
// FIXME: implement me
AssertThrow(virtual_dofs == 0, ExcNotImplemented());
}



template <int dim, int spacedim>
std::vector<NumberCache>
ParallelShared<dim, spacedim>::distribute_mg_dofs() const
Expand Down Expand Up @@ -3644,8 +3678,7 @@ namespace internal

template <int dim, int spacedim>
NumberCache
ParallelDistributed<dim, spacedim>::distribute_dofs(
const types::global_dof_index n_locally_virtual [[maybe_unused]]) const
ParallelDistributed<dim, spacedim>::distribute_dofs() const
{
#ifndef DEAL_II_WITH_MPI
DEAL_II_NOT_IMPLEMENTED();
Expand Down Expand Up @@ -3741,13 +3774,9 @@ namespace internal
Utilities::MPI::partial_and_total_sum(
n_locally_owned_dofs, triangulation->get_communicator());

const auto [my_shift_virtual, n_global_virtual] =
Utilities::MPI::partial_and_total_sum(
n_locally_virtual, triangulation->get_communicator());

// make dof indices globally consecutive
Implementation::enumerate_dof_indices_for_renumbering(
renumbering, all_constrained_indices, my_shift + my_shift_virtual);
renumbering, all_constrained_indices, my_shift);

// now re-enumerate all dofs to this shifted and condensed
// numbering form. we renumber some dofs as invalid, so
Expand All @@ -3757,26 +3786,17 @@ namespace internal
*dof_handler,
/*check_validity=*/false);


NumberCache number_cache;
number_cache.n_global_dofs = n_global_dofs + n_global_virtual;
number_cache.n_locally_owned_dofs =
n_locally_owned_dofs + n_locally_virtual;
number_cache.n_global_dofs = n_global_dofs;
number_cache.n_locally_owned_dofs = n_locally_owned_dofs;

number_cache.locally_owned_dofs =
IndexSet(n_global_dofs + n_global_virtual);
number_cache.locally_owned_dofs = IndexSet(n_global_dofs);
number_cache.locally_owned_dofs.add_range( //
my_shift + my_shift_virtual,
my_shift + my_shift_virtual + n_locally_owned_dofs +
n_locally_virtual);
my_shift,
my_shift + n_locally_owned_dofs);
number_cache.locally_owned_dofs.compress();

number_cache.locally_owned_virtual_dofs =
IndexSet(n_global_dofs + n_global_virtual);
number_cache.locally_owned_virtual_dofs.add_range(
my_shift + my_shift_virtual + n_locally_owned_dofs,
my_shift + my_shift_virtual + n_locally_owned_dofs +
n_locally_virtual);
number_cache.locally_owned_virtual_dofs = IndexSet(n_global_dofs);
number_cache.locally_owned_virtual_dofs.compress();


Expand Down Expand Up @@ -3868,6 +3888,71 @@ namespace internal



template <int dim, int spacedim>
NumberCache
ParallelDistributed<dim, spacedim>::distribute_virtual_dofs(
const types::global_dof_index virtual_dofs) const
{
const auto &old_locally_owned_dofs =
dof_handler->locally_owned_dofs();

Assert(old_locally_owned_dofs.is_contiguous(),
ExcMessage(
"Virtual degrees of freedom can only be distributed when the "
"locally owned index range is contiguous."));

const auto &old_locally_owned_virtual_dofs =
dof_handler->locally_owned_virtual_dofs();

Assert(old_locally_owned_virtual_dofs.n_elements() == 0,
ExcMessage(
"Can distribute virtual degrees of freedom only once after "
"distribute_dofs()"));

dealii::parallel::DistributedTriangulationBase<dim, spacedim>
*triangulation =
(dynamic_cast<
dealii::parallel::DistributedTriangulationBase<dim, spacedim> *>(
const_cast<dealii::Triangulation<dim, spacedim> *>(
&dof_handler->get_triangulation())));
Assert(triangulation != nullptr, ExcInternalError());

//
// Renumber degrees of freedom by adding a global shift to the
// locally owned index range:
//

const auto [my_shift, n_global_virtual_dofs] =
Utilities::MPI::partial_and_total_sum(
virtual_dofs, triangulation->get_communicator());

std::vector<dealii::types::global_dof_index> renumbering(
old_locally_owned_dofs.n_elements());
std::generate(renumbering.begin(),
renumbering.end(),
[my_shift = my_shift,
n = *old_locally_owned_dofs.begin()]() mutable {
return my_shift + n++;
});

// FIXME: n_dofs wrong.
NumberCache number_cache = this->renumber_dofs(renumbering);

return number_cache;

#if 0
// FIXME resume here
number_cache.locally_owned_virtual_dofs =
number_cache.locally_owned_virtual_dofs.add_range(
my_shift + my_shift_virtual + n_locally_owned_dofs,
my_shift + my_shift_virtual + n_locally_owned_dofs +
n_locally_virtual);
number_cache.locally_owned_virtual_dofs.compress();
#endif
}



template <int dim, int spacedim>
std::vector<NumberCache>
ParallelDistributed<dim, spacedim>::distribute_mg_dofs() const
Expand Down

0 comments on commit 3b1cff9

Please sign in to comment.