Skip to content

Commit

Permalink
Remove the cell dof indices cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kronbichler committed Jun 28, 2022
1 parent 472adc6 commit 25e8925
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 252 deletions.
6 changes: 0 additions & 6 deletions include/deal.II/dofs/dof_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2033,12 +2033,6 @@ class DoFCellAccessor : public DoFAccessor<dimension_,
void
set_mg_dof_indices(const std::vector<types::global_dof_index> &dof_indices);

/**
* Update the cache in which we store the dof indices of this cell.
*/
void
update_cell_dof_indices_cache() const;

/**
* @name Dealing with refinement indicators
*/
Expand Down
134 changes: 42 additions & 92 deletions include/deal.II/dofs/dof_accessor.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -2247,46 +2247,6 @@ namespace internal
*/
struct Implementation
{
/**
* Implement the updating of the cache.
*/
template <int dim, int spacedim, bool level_dof_access>
static void
update_cell_dof_indices_cache(
const DoFCellAccessor<dim, spacedim, level_dof_access> &accessor)
{
// caches are only for cells with DoFs, i.e., for active ones and not
// FE_Nothing
if (accessor.has_children())
return;
const unsigned int dofs_per_cell = accessor.get_fe().n_dofs_per_cell();
if (dofs_per_cell == 0)
return;

// call the get_dof_indices() function of DoFAccessor, which goes
// through all the parts of the cell to get the indices by hand. the
// corresponding function of DoFCellAccessor can then later use the
// cache
std::vector<types::global_dof_index> dof_indices(dofs_per_cell);
static_cast<
const dealii::DoFAccessor<dim, dim, spacedim, level_dof_access> &>(
accessor)
.get_dof_indices(dof_indices, accessor.active_fe_index());

types::global_dof_index *next_dof_index =
const_cast<types::global_dof_index *>(
dealii::internal::DoFAccessorImplementation::Implementation::
get_cache_ptr(accessor.dof_handler,
accessor.present_level,
accessor.present_index,
dofs_per_cell));

for (unsigned int i = 0; i < dofs_per_cell; ++i, ++next_dof_index)
*next_dof_index = dof_indices[i];
}



/**
* Do what the active_fe_index function in the parent class is supposed to
* do.
Expand Down Expand Up @@ -2675,15 +2635,8 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::
ExcMessage("Can't ask for DoF indices on artificial cells."));
AssertDimension(dof_indices.size(), this->get_fe().n_dofs_per_cell());

const auto dofs_per_cell = this->get_fe().n_dofs_per_cell();
if (dofs_per_cell > 0)
{
const types::global_dof_index *cache = dealii::internal::
DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler, this->present_level, this->index(), dofs_per_cell);
for (unsigned int i = 0; i < dofs_per_cell; ++i, ++cache)
dof_indices[i] = *cache;
}
dealii::internal::DoFAccessorImplementation::Implementation::get_dof_indices(
*this, dof_indices, this->active_fe_index());
}


Expand Down Expand Up @@ -2762,16 +2715,13 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::get_dof_values(
Assert(values.size() == this->get_dof_handler().n_dofs(),
typename DoFCellAccessor::ExcVectorDoesNotMatch());

const types::global_dof_index *cache =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler,
this->present_level,
this->index(),
this->get_fe().n_dofs_per_cell());
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);
dealii::internal::DoFAccessorImplementation::Implementation::
extract_subvector_to(values,
cache,
cache + this->get_fe().n_dofs_per_cell(),
dof_indices.data(),
dof_indices.data() + dof_indices.size(),
local_values_begin);
}

Expand All @@ -2797,15 +2747,12 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::get_dof_values(
typename DoFCellAccessor::ExcVectorDoesNotMatch());


const types::global_dof_index *cache =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler,
this->present_level,
this->index(),
this->get_fe().n_dofs_per_cell());
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

constraints.get_dof_values(values,
*cache,
*dof_indices.begin(),
local_values_begin,
local_values_end);
}
Expand All @@ -2831,15 +2778,14 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::set_dof_values(


Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());
const types::global_dof_index *cache =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler,
this->present_level,
this->index(),
this->get_fe().n_dofs_per_cell());
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

for (unsigned int i = 0; i < this->get_fe().n_dofs_per_cell(); ++i, ++cache)
internal::ElementAccess<OutputVector>::set(local_values(i), *cache, values);
for (unsigned int i = 0; i < this->get_fe().n_dofs_per_cell(); ++i)
internal::ElementAccess<OutputVector>::set(local_values(i),
dof_indices[i],
values);
}


Expand Down Expand Up @@ -3060,12 +3006,12 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::

const unsigned int n_dofs = local_source_end - local_source_begin;

const types::global_dof_index *dofs =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler, this->level(), this->index(), n_dofs);
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

// distribute cell vector
global_destination.add(n_dofs, dofs, local_source_begin);
global_destination.add(n_dofs, dof_indices.begin(), local_source_begin);
}


Expand All @@ -3090,16 +3036,14 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::

Assert(!this->has_children(), ExcMessage("Cell must be active."));

const unsigned int n_dofs = local_source_end - local_source_begin;

const types::global_dof_index *dofs =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler, this->level(), this->index(), n_dofs);
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

// distribute cell vector
constraints.distribute_local_to_global(local_source_begin,
local_source_end,
dofs,
dof_indices.begin(),
global_destination);
}

Expand Down Expand Up @@ -3127,13 +3071,16 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::

const unsigned int n_dofs = local_source.m();

const types::global_dof_index *dofs =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler, this->level(), this->index(), n_dofs);
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

// distribute cell matrix
for (unsigned int i = 0; i < n_dofs; ++i)
global_destination.add(dofs[i], n_dofs, dofs, &local_source(i, 0));
global_destination.add(dof_indices[i],
n_dofs,
dof_indices.begin(),
&local_source(i, 0));
}


Expand Down Expand Up @@ -3164,16 +3111,19 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::

Assert(!this->has_children(), ExcMessage("Cell must be active."));

const unsigned int n_dofs = this->get_fe().n_dofs_per_cell();
const types::global_dof_index *dofs =
dealii::internal::DoFAccessorImplementation::Implementation::get_cache_ptr(
this->dof_handler, this->level(), this->index(), n_dofs);
const unsigned int n_dofs = this->get_fe().n_dofs_per_cell();
std::vector<types::global_dof_index> dof_indices(
this->get_fe().n_dofs_per_cell());
get_dof_indices(dof_indices);

// distribute cell matrices
for (unsigned int i = 0; i < n_dofs; ++i)
{
global_matrix.add(dofs[i], n_dofs, dofs, &local_matrix(i, 0));
global_vector(dofs[i]) += local_vector(i);
global_matrix.add(dof_indices[i],
n_dofs,
dof_indices.begin(),
&local_matrix(i, 0));
global_vector(dof_indices[i]) += local_vector(i);
}
}

Expand Down
14 changes: 0 additions & 14 deletions include/deal.II/dofs/dof_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1453,20 +1453,6 @@ class DoFHandler : public Subscriptor
std::vector<dealii::internal::DoFHandlerImplementation::NumberCache>
mg_number_cache;

/**
* Cached indices of the degrees of freedom of all active cell. Identification
* of the appropriate position of a cell in the vectors is done via
* cell_dof_cache_ptr (CRS scheme).
*/
mutable std::vector<std::vector<types::global_dof_index>>
cell_dof_cache_indices;

/**
* Pointer to the first cached degree of freedom of an active cell
* (identified by level and level index) within cell_dof_cache_indices.
*/
mutable std::vector<std::vector<offset_type>> cell_dof_cache_ptr;

/**
* Indices of degree of freedom of each d+1 geometric object (3D: vertex,
* line, quad, hex) for all relevant active finite elements. Identification
Expand Down
16 changes: 0 additions & 16 deletions source/dofs/dof_accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ DoFInvalidAccessor<structdim, dim, spacedim>::set_dof_index(



template <int dim, int spacedim, bool lda>
void
DoFCellAccessor<dim, spacedim, lda>::update_cell_dof_indices_cache() const
{
Assert(static_cast<unsigned int>(this->present_level) <
this->dof_handler->object_dof_indices.size(),
ExcMessage("DoFHandler not initialized"));

Assert(this->dof_handler != nullptr, typename BaseClass::ExcInvalidObject());

internal::DoFCellAccessorImplementation::Implementation::
update_cell_dof_indices_cache(*this);
}



template <int dim, int spacedim, bool lda>
void
DoFCellAccessor<dim, spacedim, lda>::set_dof_indices(
Expand Down
49 changes: 1 addition & 48 deletions source/dofs/dof_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,6 @@ namespace internal
dof_handler.object_dof_ptr.clear();
dof_handler.object_dof_ptr.resize(dof_handler.tria->n_levels());
dof_handler.object_dof_ptr.shrink_to_fit();

dof_handler.cell_dof_cache_indices.clear();
dof_handler.cell_dof_cache_indices.resize(dof_handler.tria->n_levels());
dof_handler.cell_dof_cache_indices.shrink_to_fit();

dof_handler.cell_dof_cache_ptr.clear();
dof_handler.cell_dof_cache_ptr.resize(dof_handler.tria->n_levels());
dof_handler.cell_dof_cache_ptr.shrink_to_fit();
}

/**
Expand All @@ -293,7 +285,6 @@ namespace internal
{
for (unsigned int i = 0; i < dof_handler.tria->n_levels(); ++i)
{
// 1) object_dof_indices
dof_handler.object_dof_ptr[i][dim].assign(
dof_handler.tria->n_raw_cells(i) + 1, 0);

Expand All @@ -310,24 +301,6 @@ namespace internal
dof_handler.object_dof_indices[i][dim].resize(
dof_handler.object_dof_ptr[i][dim].back(),
numbers::invalid_dof_index);

// 2) cell_dof_cache_indices
dof_handler.cell_dof_cache_ptr[i].assign(
dof_handler.tria->n_raw_cells(i) + 1, 0);

for (const auto &cell :
dof_handler.tria->cell_iterators_on_level(i))
if (cell->is_active() && !cell->is_artificial())
dof_handler.cell_dof_cache_ptr[i][cell->index() + 1] =
dof_handler.get_fe().n_dofs_per_cell();

for (unsigned int j = 0; j < dof_handler.tria->n_raw_cells(i); ++j)
dof_handler.cell_dof_cache_ptr[i][j + 1] +=
dof_handler.cell_dof_cache_ptr[i][j];

dof_handler.cell_dof_cache_indices[i].resize(
dof_handler.cell_dof_cache_ptr[i].back(),
numbers::invalid_dof_index);
}
}

Expand Down Expand Up @@ -867,15 +840,8 @@ namespace internal
dof_handler.tria->n_raw_cells(level),
static_cast<typename DoFHandler<dim, spacedim>::offset_type>(
-1));
dof_handler.cell_dof_cache_ptr[level] =
std::vector<typename DoFHandler<dim, spacedim>::offset_type>(
dof_handler.tria->n_raw_cells(level),
static_cast<typename DoFHandler<dim, spacedim>::offset_type>(
-1));

types::global_dof_index next_free_dof = 0;
types::global_dof_index cache_size = 0;

for (auto cell :
dof_handler.active_cell_iterators_on_level(level))
if (cell->is_active() && !cell->is_artificial())
Expand All @@ -884,18 +850,11 @@ namespace internal
next_free_dof;
next_free_dof +=
cell->get_fe().template n_dofs_per_object<dim>();

dof_handler.cell_dof_cache_ptr[level][cell->index()] =
cache_size;
cache_size += cell->get_fe().n_dofs_per_cell();
}

dof_handler.object_dof_indices[level][dim] =
std::vector<types::global_dof_index>(
next_free_dof, numbers::invalid_dof_index);
dof_handler.cell_dof_cache_indices[level] =
std::vector<types::global_dof_index>(
cache_size, numbers::invalid_dof_index);
}
}

Expand Down Expand Up @@ -2130,9 +2089,7 @@ DoFHandler<dim, spacedim>::memory_consumption() const
MemoryConsumption::memory_consumption(this->fe_collection) +
MemoryConsumption::memory_consumption(this->number_cache);

mem += MemoryConsumption::memory_consumption(cell_dof_cache_indices) +
MemoryConsumption::memory_consumption(cell_dof_cache_ptr) +
MemoryConsumption::memory_consumption(object_dof_indices) +
mem += MemoryConsumption::memory_consumption(object_dof_indices) +
MemoryConsumption::memory_consumption(object_dof_ptr) +
MemoryConsumption::memory_consumption(hp_object_fe_indices) +
MemoryConsumption::memory_consumption(hp_object_fe_ptr) +
Expand Down Expand Up @@ -2390,10 +2347,6 @@ template <int dim, int spacedim>
void
DoFHandler<dim, spacedim>::clear_space()
{
cell_dof_cache_indices.clear();

cell_dof_cache_ptr.clear();

object_dof_indices.clear();

object_dof_ptr.clear();
Expand Down

0 comments on commit 25e8925

Please sign in to comment.