Skip to content

Commit 418838b

Browse files
committed
INCOMPLETE REFACTORING
1 parent b044e6a commit 418838b

File tree

4 files changed

+168
-45
lines changed

4 files changed

+168
-45
lines changed

include/deal.II/dofs/dof_handler.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,13 @@ class DoFHandler : public Subscriptor
689689
* function set_fe().
690690
*/
691691
void
692-
distribute_dofs(const FiniteElement<dim, spacedim> &fe,
693-
const dealii::types::global_dof_index &virtual_dofs = 0);
692+
distribute_dofs(const FiniteElement<dim, spacedim> &fe);
694693

695694
/**
696695
* Same as above but taking an hp::FECollection object.
697696
*/
698697
void
699-
distribute_dofs(const hp::FECollection<dim, spacedim> &fe,
700-
const dealii::types::global_dof_index &virtual_dofs = 0);
698+
distribute_dofs(const hp::FECollection<dim, spacedim> &fe);
701699

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

708+
/**
709+
* FIXME: documentation
710+
*
711+
* Distribute virtual degrees of freedom. [...]
712+
*
713+
* @pre The locally owned index set must be contiguous.
714+
*/
715+
void
716+
distribute_virtual_dofs(const dealii::types::global_dof_index virtual_dofs);
717+
710718
/**
711719
* Returns whether this DoFHandler has hp-capabilities.
712720
*/
@@ -1190,6 +1198,8 @@ class DoFHandler : public Subscriptor
11901198
locally_owned_dofs() const;
11911199

11921200
/**
1201+
* FIXME: documentation
1202+
*
11931203
* Return an IndexSet describing the subset of locally owned virtual DoFs.
11941204
*/
11951205
const IndexSet &

include/deal.II/dofs/dof_handler_policy.h

+27-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace internal
7373
* argument.
7474
*/
7575
virtual NumberCache
76-
distribute_dofs(const types::global_dof_index virtual_dofs) const = 0;
76+
distribute_dofs() const = 0;
7777

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

86+
/**
87+
* FIXME: documentation
88+
*/
89+
virtual NumberCache
90+
distribute_virtual_dofs(
91+
const types::global_dof_index virtual_dofs) const = 0;
92+
8693
/**
8794
* Renumber degrees of freedom as specified by the first argument.
8895
*
@@ -124,13 +131,16 @@ namespace internal
124131

125132
// documentation is inherited
126133
virtual NumberCache
127-
distribute_dofs(
128-
const types::global_dof_index virtual_dofs) const override;
134+
distribute_dofs() const override;
129135

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

140+
virtual NumberCache
141+
distribute_virtual_dofs(
142+
const types::global_dof_index virtual_dofs) const override;
143+
134144
// documentation is inherited
135145
virtual NumberCache
136146
renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)
@@ -175,15 +185,21 @@ namespace internal
175185
* number_cache.locally_owned_dofs are updated consistently.
176186
*/
177187
virtual NumberCache
178-
distribute_dofs(
179-
const types::global_dof_index virtual_dofs) const override;
188+
distribute_dofs() const override;
180189

181190
/**
182191
* This function is not yet implemented.
183192
*/
184193
virtual std::vector<NumberCache>
185194
distribute_mg_dofs() const override;
186195

196+
/**
197+
* This function is not yet implemented.
198+
*/
199+
virtual NumberCache
200+
distribute_virtual_dofs(
201+
const types::global_dof_index virtual_dofs) const override;
202+
187203
/**
188204
* Renumber degrees of freedom as specified by the first argument.
189205
*
@@ -228,13 +244,17 @@ namespace internal
228244

229245
// documentation is inherited
230246
virtual NumberCache
231-
distribute_dofs(
232-
const types::global_dof_index virtual_dofs) const override;
247+
distribute_dofs() const override;
233248

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

253+
// documentation is inherited
254+
virtual NumberCache
255+
distribute_virtual_dofs(
256+
const types::global_dof_index virtual_dofs) const override;
257+
238258
// documentation is inherited
239259
virtual NumberCache
240260
renumber_dofs(const std::vector<types::global_dof_index> &new_numbers)

source/dofs/dof_handler.cc

+14-6
Original file line numberDiff line numberDiff line change
@@ -2133,19 +2133,17 @@ std::size_t DoFHandler<dim, spacedim>::memory_consumption() const
21332133
template <int dim, int spacedim>
21342134
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
21352135
void DoFHandler<dim, spacedim>::distribute_dofs(
2136-
const FiniteElement<dim, spacedim> &fe,
2137-
const dealii::types::global_dof_index &virtual_dofs)
2136+
const FiniteElement<dim, spacedim> &fe)
21382137
{
2139-
this->distribute_dofs(hp::FECollection<dim, spacedim>(fe), virtual_dofs);
2138+
this->distribute_dofs(hp::FECollection<dim, spacedim>(fe));
21402139
}
21412140

21422141

21432142

21442143
template <int dim, int spacedim>
21452144
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
21462145
void DoFHandler<dim, spacedim>::distribute_dofs(
2147-
const hp::FECollection<dim, spacedim> &ff,
2148-
const dealii::types::global_dof_index &virtual_dofs)
2146+
const hp::FECollection<dim, spacedim> &ff)
21492147
{
21502148
Assert(this->tria != nullptr,
21512149
ExcMessage(
@@ -2256,7 +2254,7 @@ void DoFHandler<dim, spacedim>::distribute_dofs(
22562254
}
22572255

22582256
// hand the actual work over to the policy
2259-
this->number_cache = this->policy->distribute_dofs(virtual_dofs);
2257+
this->number_cache = this->policy->distribute_dofs();
22602258

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

23142312

23152313

2314+
template <int dim, int spacedim>
2315+
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
2316+
void DoFHandler<dim, spacedim>::distribute_virtual_dofs(
2317+
const types::global_dof_index virtual_dofs)
2318+
{
2319+
this->number_cache = this->policy->distribute_virtual_dofs(virtual_dofs);
2320+
}
2321+
2322+
2323+
23162324
template <int dim, int spacedim>
23172325
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
23182326
void DoFHandler<dim, spacedim>::initialize_local_block_info()

source/dofs/dof_handler_policy.cc

+113-28
Original file line numberDiff line numberDiff line change
@@ -2649,8 +2649,7 @@ namespace internal
26492649

26502650
template <int dim, int spacedim>
26512651
NumberCache
2652-
Sequential<dim, spacedim>::distribute_dofs(
2653-
const types::global_dof_index n_virtual_dofs) const
2652+
Sequential<dim, spacedim>::distribute_dofs() const
26542653
{
26552654
const types::global_dof_index n_initial_dofs =
26562655
Implementation::distribute_dofs(numbers::invalid_subdomain_id,
@@ -2661,7 +2660,34 @@ namespace internal
26612660
n_initial_dofs,
26622661
/*check_validity=*/true);
26632662

2663+
return NumberCache(n_dofs);
2664+
}
2665+
2666+
2667+
2668+
template <int dim, int spacedim>
2669+
NumberCache
2670+
Sequential<dim, spacedim>::distribute_virtual_dofs(
2671+
const types::global_dof_index n_virtual_dofs) const
2672+
{
2673+
const auto &old_locally_owned_dofs =
2674+
dof_handler->locally_owned_dofs();
2675+
2676+
Assert(old_locally_owned_dofs.is_contiguous(),
2677+
ExcMessage(
2678+
"Virtual degrees of freedom can only be distributed when the "
2679+
"locally owned index range is contiguous."));
2680+
2681+
const auto &old_locally_owned_virtual_dofs =
2682+
dof_handler->locally_owned_virtual_dofs();
2683+
2684+
Assert(old_locally_owned_virtual_dofs.n_elements() == 0,
2685+
ExcMessage(
2686+
"Can distribute virtual degrees of freedom only once after "
2687+
"distribute_dofs()"));
2688+
26642689
// return a sequential, complete index set
2690+
const auto n_dofs = old_locally_owned_dofs.size();
26652691
NumberCache number_cache(n_dofs + n_virtual_dofs);
26662692

26672693
number_cache.locally_owned_virtual_dofs =
@@ -2920,11 +2946,8 @@ namespace internal
29202946

29212947
template <int dim, int spacedim>
29222948
NumberCache
2923-
ParallelShared<dim, spacedim>::distribute_dofs(
2924-
const types::global_dof_index virtual_dofs [[maybe_unused]]) const
2949+
ParallelShared<dim, spacedim>::distribute_dofs() const
29252950
{
2926-
Assert(virtual_dofs == 0, ExcNotImplemented());
2927-
29282951
const dealii::parallel::shared::Triangulation<dim, spacedim> *tr =
29292952
(dynamic_cast<
29302953
const dealii::parallel::shared::Triangulation<dim, spacedim> *>(
@@ -3066,6 +3089,17 @@ namespace internal
30663089

30673090

30683091

3092+
template <int dim, int spacedim>
3093+
NumberCache
3094+
ParallelShared<dim, spacedim>::distribute_virtual_dofs(
3095+
const types::global_dof_index virtual_dofs) const
3096+
{
3097+
// FIXME: implement me
3098+
AssertThrow(virtual_dofs == 0, ExcNotImplemented());
3099+
}
3100+
3101+
3102+
30693103
template <int dim, int spacedim>
30703104
std::vector<NumberCache>
30713105
ParallelShared<dim, spacedim>::distribute_mg_dofs() const
@@ -3644,8 +3678,7 @@ namespace internal
36443678

36453679
template <int dim, int spacedim>
36463680
NumberCache
3647-
ParallelDistributed<dim, spacedim>::distribute_dofs(
3648-
const types::global_dof_index n_locally_virtual [[maybe_unused]]) const
3681+
ParallelDistributed<dim, spacedim>::distribute_dofs() const
36493682
{
36503683
#ifndef DEAL_II_WITH_MPI
36513684
DEAL_II_NOT_IMPLEMENTED();
@@ -3741,13 +3774,9 @@ namespace internal
37413774
Utilities::MPI::partial_and_total_sum(
37423775
n_locally_owned_dofs, triangulation->get_communicator());
37433776

3744-
const auto [my_shift_virtual, n_global_virtual] =
3745-
Utilities::MPI::partial_and_total_sum(
3746-
n_locally_virtual, triangulation->get_communicator());
3747-
37483777
// make dof indices globally consecutive
37493778
Implementation::enumerate_dof_indices_for_renumbering(
3750-
renumbering, all_constrained_indices, my_shift + my_shift_virtual);
3779+
renumbering, all_constrained_indices, my_shift);
37513780

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

3760-
37613789
NumberCache number_cache;
3762-
number_cache.n_global_dofs = n_global_dofs + n_global_virtual;
3763-
number_cache.n_locally_owned_dofs =
3764-
n_locally_owned_dofs + n_locally_virtual;
3790+
number_cache.n_global_dofs = n_global_dofs;
3791+
number_cache.n_locally_owned_dofs = n_locally_owned_dofs;
37653792

3766-
number_cache.locally_owned_dofs =
3767-
IndexSet(n_global_dofs + n_global_virtual);
3793+
number_cache.locally_owned_dofs = IndexSet(n_global_dofs);
37683794
number_cache.locally_owned_dofs.add_range( //
3769-
my_shift + my_shift_virtual,
3770-
my_shift + my_shift_virtual + n_locally_owned_dofs +
3771-
n_locally_virtual);
3795+
my_shift,
3796+
my_shift + n_locally_owned_dofs);
37723797
number_cache.locally_owned_dofs.compress();
37733798

3774-
number_cache.locally_owned_virtual_dofs =
3775-
IndexSet(n_global_dofs + n_global_virtual);
3776-
number_cache.locally_owned_virtual_dofs.add_range(
3777-
my_shift + my_shift_virtual + n_locally_owned_dofs,
3778-
my_shift + my_shift_virtual + n_locally_owned_dofs +
3779-
n_locally_virtual);
3799+
number_cache.locally_owned_virtual_dofs = IndexSet(n_global_dofs);
37803800
number_cache.locally_owned_virtual_dofs.compress();
37813801

37823802

@@ -3868,6 +3888,71 @@ namespace internal
38683888

38693889

38703890

3891+
template <int dim, int spacedim>
3892+
NumberCache
3893+
ParallelDistributed<dim, spacedim>::distribute_virtual_dofs(
3894+
const types::global_dof_index virtual_dofs) const
3895+
{
3896+
const auto &old_locally_owned_dofs =
3897+
dof_handler->locally_owned_dofs();
3898+
3899+
Assert(old_locally_owned_dofs.is_contiguous(),
3900+
ExcMessage(
3901+
"Virtual degrees of freedom can only be distributed when the "
3902+
"locally owned index range is contiguous."));
3903+
3904+
const auto &old_locally_owned_virtual_dofs =
3905+
dof_handler->locally_owned_virtual_dofs();
3906+
3907+
Assert(old_locally_owned_virtual_dofs.n_elements() == 0,
3908+
ExcMessage(
3909+
"Can distribute virtual degrees of freedom only once after "
3910+
"distribute_dofs()"));
3911+
3912+
dealii::parallel::DistributedTriangulationBase<dim, spacedim>
3913+
*triangulation =
3914+
(dynamic_cast<
3915+
dealii::parallel::DistributedTriangulationBase<dim, spacedim> *>(
3916+
const_cast<dealii::Triangulation<dim, spacedim> *>(
3917+
&dof_handler->get_triangulation())));
3918+
Assert(triangulation != nullptr, ExcInternalError());
3919+
3920+
//
3921+
// Renumber degrees of freedom by adding a global shift to the
3922+
// locally owned index range:
3923+
//
3924+
3925+
const auto [my_shift, n_global_virtual_dofs] =
3926+
Utilities::MPI::partial_and_total_sum(
3927+
virtual_dofs, triangulation->get_communicator());
3928+
3929+
std::vector<dealii::types::global_dof_index> renumbering(
3930+
old_locally_owned_dofs.n_elements());
3931+
std::generate(renumbering.begin(),
3932+
renumbering.end(),
3933+
[my_shift = my_shift,
3934+
n = *old_locally_owned_dofs.begin()]() mutable {
3935+
return my_shift + n++;
3936+
});
3937+
3938+
// FIXME: n_dofs wrong.
3939+
NumberCache number_cache = this->renumber_dofs(renumbering);
3940+
3941+
return number_cache;
3942+
3943+
#if 0
3944+
// FIXME resume here
3945+
number_cache.locally_owned_virtual_dofs =
3946+
number_cache.locally_owned_virtual_dofs.add_range(
3947+
my_shift + my_shift_virtual + n_locally_owned_dofs,
3948+
my_shift + my_shift_virtual + n_locally_owned_dofs +
3949+
n_locally_virtual);
3950+
number_cache.locally_owned_virtual_dofs.compress();
3951+
#endif
3952+
}
3953+
3954+
3955+
38713956
template <int dim, int spacedim>
38723957
std::vector<NumberCache>
38733958
ParallelDistributed<dim, spacedim>::distribute_mg_dofs() const

0 commit comments

Comments
 (0)