From a05c2c722e2fc0117bd86b39bbfee6a52718cc34 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 15 Dec 2008 15:43:19 +0000 Subject: [PATCH] In get/set_dof_values, make use of the cache of DoF indices for non-hp DoFHandlers to avoid memory allocation. git-svn-id: https://svn.dealii.org/trunk@17950 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/dofs/dof_accessor.templates.h | 143 ++++++++++++++++++ deal.II/deal.II/source/dofs/dof_accessor.cc | 39 ----- .../deal.II/source/dofs/dof_accessor.inst.in | 35 ----- 3 files changed, 143 insertions(+), 74 deletions(-) diff --git a/deal.II/deal.II/include/dofs/dof_accessor.templates.h b/deal.II/deal.II/include/dofs/dof_accessor.templates.h index dd6b945814..2208aa7873 100644 --- a/deal.II/deal.II/include/dofs/dof_accessor.templates.h +++ b/deal.II/deal.II/include/dofs/dof_accessor.templates.h @@ -2063,6 +2063,125 @@ namespace internal } + /** + * A function that collects the + * values of degrees of freedom. This + * function works for ::DoFHandler + * and all template arguments and + * uses the data from the cache of + * indices that we hold for each + * cell. + */ + template + static + void + get_dof_values (const DoFCellAccessor > &accessor, + const InputVector &values, + Vector &local_values) + { + typedef + dealii::DoFAccessor > + BaseClass; + Assert (local_values.size() == accessor.get_fe().dofs_per_cell, + typename BaseClass::ExcVectorDoesNotMatch()); + Assert (values.size() == accessor.get_dof_handler().n_dofs(), + typename BaseClass::ExcVectorDoesNotMatch()); + + // check as in documentation that + // cell is either active, or dofs + // are only in vertices + Assert (!accessor.has_children() + || + (accessor.get_fe().dofs_per_cell == + accessor.get_fe().dofs_per_vertex * GeometryInfo::vertices_per_cell), + ExcMessage ("Cell must either be active, or all DoFs must be in vertices")); + + unsigned int *cache = &accessor.dof_handler->levels[accessor.level()] + ->cell_dof_indices_cache[accessor.present_index * accessor.get_fe().dofs_per_cell]; + for (unsigned int i=0; i + static + void + get_dof_values (const DoFCellAccessor > &accessor, + const InputVector &values, + Vector &local_values) + { + // no caching for hp::DoFHandler + // implemented + const unsigned int dofs_per_cell = accessor.get_fe().dofs_per_cell; + + std::vector local_dof_indices (dofs_per_cell); + get_dof_indices (accessor, local_dof_indices); + + for (unsigned int i=0; i + static + void + set_dof_values (const DoFCellAccessor > &accessor, + const Vector &local_values, + OutputVector &values) + { + typedef + dealii::DoFAccessor > + BaseClass; + Assert (local_values.size() == accessor.get_fe().dofs_per_cell, + typename BaseClass::ExcVectorDoesNotMatch()); + Assert (values.size() == accessor.get_dof_handler().n_dofs(), + typename BaseClass::ExcVectorDoesNotMatch()); + + // check as in documentation that + // cell is either active, or dofs + // are only in vertices + Assert (!accessor.has_children() + || + (accessor.get_fe().dofs_per_cell == + accessor.get_fe().dofs_per_vertex * GeometryInfo::vertices_per_cell), + ExcMessage ("Cell must either be active, or all DoFs must be in vertices")); + + unsigned int *cache = &accessor.dof_handler->levels[accessor.level()] + ->cell_dof_indices_cache[accessor.present_index * accessor.get_fe().dofs_per_cell]; + for (unsigned int i=0; i + static + void + set_dof_values (const DoFCellAccessor > &accessor, + const Vector &local_values, + OutputVector &values) + { + // no caching for hp::DoFHandler + // implemented + const unsigned int dofs_per_cell = accessor.get_fe().dofs_per_cell; + + std::vector local_dof_indices (dofs_per_cell); + get_dof_indices (accessor, local_dof_indices); + + for (unsigned int i=0; i &dof_indices) const +template +template +void +DoFCellAccessor::get_dof_values (const InputVector &values, + Vector &local_values) const +{ + internal::DoFCellAccessor::Implementation + ::get_dof_values (*this, values, local_values); +} + + + +template +template +void +DoFCellAccessor::set_dof_values (const Vector &local_values, + OutputVector &values) const +{ + internal::DoFCellAccessor::Implementation + ::set_dof_values (*this, local_values, values); +} + + + template inline const FiniteElement & diff --git a/deal.II/deal.II/source/dofs/dof_accessor.cc b/deal.II/deal.II/source/dofs/dof_accessor.cc index 94c888ea20..8fb752fca3 100644 --- a/deal.II/deal.II/source/dofs/dof_accessor.cc +++ b/deal.II/deal.II/source/dofs/dof_accessor.cc @@ -70,45 +70,6 @@ DoFCellAccessor::neighbor_child_on_subface (const unsigned int face, -template -template -void -DoFCellAccessor::get_dof_values (const InputVector &values, - Vector &local_values) const -{ -//TODO[WB]: this function can be made more efficient using the fact that we have cached the result of get_dof_indices; we should therefore be able to get away without having to allocate memory - - const unsigned int dofs_per_cell = this->get_fe().dofs_per_cell; - - std::vector local_dof_indices (dofs_per_cell); - this->get_dof_indices (local_dof_indices); - - for (unsigned int i=0; i -template -void -DoFCellAccessor::set_dof_values (const Vector &local_values, - OutputVector &values) const -{ -//TODO[WB]: this function can be made more efficient using the fact that we have cached the result of get_dof_indices; we should therefore be able to get away without having to allocate memory - - const unsigned int dofs_per_cell = this->get_fe().dofs_per_cell; - - std::vector local_dof_indices (dofs_per_cell); - this->get_dof_indices (local_dof_indices); - - for (unsigned int i=0; i template void diff --git a/deal.II/deal.II/source/dofs/dof_accessor.inst.in b/deal.II/deal.II/source/dofs/dof_accessor.inst.in index e5904074c0..3547e96b9b 100644 --- a/deal.II/deal.II/source/dofs/dof_accessor.inst.in +++ b/deal.II/deal.II/source/dofs/dof_accessor.inst.in @@ -14,15 +14,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS) { - template - void - DoFCellAccessor >::get_dof_values - (const VEC&, Vector&) const; - template - void - DoFCellAccessor >::set_dof_values - (const Vector&, VEC&) const; - template void DoFCellAccessor >::get_interpolated_dof_values @@ -34,15 +25,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS) #if deal_II_dimension != 3 - template - void - DoFCellAccessor >::get_dof_values - (const VEC&, Vector&) const; - template - void - DoFCellAccessor >::set_dof_values - (const Vector&, VEC&) const; - template void DoFCellAccessor >::get_interpolated_dof_values @@ -59,15 +41,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS) for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS) { - template - void - DoFCellAccessor >::get_dof_values - (const VEC&, Vector&) const; - template - void - DoFCellAccessor >::set_dof_values - (const Vector&, VEC&) const; - template void DoFCellAccessor >::get_interpolated_dof_values @@ -78,14 +51,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS) (const Vector&, VEC&) const; #if deal_II_dimension != 3 - template - void - DoFCellAccessor >::get_dof_values - (const VEC&, Vector&) const; - template - void - DoFCellAccessor >::set_dof_values - (const Vector&, VEC&) const; template void -- 2.39.5