]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
In get/set_dof_values, make use of the cache of DoF indices for non-hp DoFHandlers...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 15 Dec 2008 15:43:19 +0000 (15:43 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 15 Dec 2008 15:43:19 +0000 (15:43 +0000)
git-svn-id: https://svn.dealii.org/trunk@17950 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_accessor.templates.h
deal.II/deal.II/source/dofs/dof_accessor.cc
deal.II/deal.II/source/dofs/dof_accessor.inst.in

index dd6b9458145b118eb577a5d8539fc3b9907c7f1d..2208aa78732176f1d5292307f16f287b75437248 100644 (file)
@@ -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 <int dim, int spacedim, class InputVector, typename number>
+       static
+       void
+       get_dof_values (const DoFCellAccessor<DoFHandler<dim,spacedim> > &accessor,
+                       const InputVector &values,
+                       Vector<number>    &local_values)
+         {
+           typedef
+             dealii::DoFAccessor<dim,DoFHandler<dim,spacedim> >
+             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<dim>::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<accessor.get_fe().dofs_per_cell; ++i, ++cache)
+             local_values(i) = values(*cache);
+         }      
+
+                                        /**
+                                         * Same function as above except
+                                         * that it works for
+                                         * hp::DoFHandler objects that do
+                                         * not have a cache for the local
+                                         * DoF indices.
+                                         */
+       template <int dim, int spacedim, class InputVector, typename number>
+       static
+       void
+       get_dof_values (const DoFCellAccessor<dealii::hp::DoFHandler<dim,spacedim> > &accessor,
+                       const InputVector &values,
+                       Vector<number>    &local_values)
+         {
+                                            // no caching for hp::DoFHandler
+                                            // implemented
+           const unsigned int dofs_per_cell = accessor.get_fe().dofs_per_cell;
+  
+           std::vector<unsigned int> local_dof_indices (dofs_per_cell);
+           get_dof_indices (accessor, local_dof_indices);
+
+           for (unsigned int i=0; i<dofs_per_cell; ++i)
+             local_values(i) = values(local_dof_indices[i]);
+         }
+
+
+                                        /**
+                                         * Same set of functions as above
+                                         * except that it sets rather than
+                                         * gets values
+                                         */
+       template <int dim, int spacedim, class OutputVector, typename number>
+       static
+       void
+       set_dof_values (const DoFCellAccessor<DoFHandler<dim,spacedim> > &accessor,
+                       const Vector<number> &local_values,
+                       OutputVector &values)
+         {
+           typedef
+             dealii::DoFAccessor<dim,DoFHandler<dim,spacedim> >
+             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<dim>::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<accessor.get_fe().dofs_per_cell; ++i, ++cache)
+             values(*cache) = local_values(i);
+         }      
+
+       template <int dim, int spacedim, class OutputVector, typename number>
+       static
+       void
+       set_dof_values (const DoFCellAccessor<dealii::hp::DoFHandler<dim,spacedim> > &accessor,
+                       const Vector<number> &local_values,
+                       OutputVector &values)
+         {
+                                            // no caching for hp::DoFHandler
+                                            // implemented
+           const unsigned int dofs_per_cell = accessor.get_fe().dofs_per_cell;
+  
+           std::vector<unsigned int> local_dof_indices (dofs_per_cell);
+           get_dof_indices (accessor, local_dof_indices);
+
+           for (unsigned int i=0; i<dofs_per_cell; ++i)
+             values(local_dof_indices[i]) = local_values(i);
+         }
+       
+
                                         /**
                                          * Do what the active_fe_index
                                          * function in the parent class
@@ -2268,6 +2387,30 @@ get_dof_indices (std::vector<unsigned int> &dof_indices) const
 
 
 
+template <class DH>
+template <class InputVector, typename number>
+void
+DoFCellAccessor<DH>::get_dof_values (const InputVector &values,
+                                    Vector<number>    &local_values) const
+{
+  internal::DoFCellAccessor::Implementation
+    ::get_dof_values (*this, values, local_values);
+}
+
+
+
+template <class DH>
+template <class OutputVector, typename number>
+void
+DoFCellAccessor<DH>::set_dof_values (const Vector<number> &local_values,
+                                    OutputVector         &values) const
+{
+  internal::DoFCellAccessor::Implementation
+    ::set_dof_values (*this, local_values, values);
+}
+
+
+
 template <class DH>
 inline
 const FiniteElement<DH::dimension,DH::space_dimension> &
index 94c888ea20c18e65040eb768dd85dbb82ed73a53..8fb752fca3bf5067c1f6555b6fbbb6ebb9b22239 100644 (file)
@@ -70,45 +70,6 @@ DoFCellAccessor<DH>::neighbor_child_on_subface (const unsigned int face,
 
 
 
-template <class DH>
-template <class InputVector, typename number>
-void
-DoFCellAccessor<DH>::get_dof_values (const InputVector &values,
-                                    Vector<number>    &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<unsigned int> local_dof_indices (dofs_per_cell);
-  this->get_dof_indices (local_dof_indices);
-
-  for (unsigned int i=0; i<dofs_per_cell; ++i)
-    local_values(i) = values(local_dof_indices[i]);
-}
-
-
-
-template <class DH>
-template <class OutputVector, typename number>
-void
-DoFCellAccessor<DH>::set_dof_values (const Vector<number> &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<unsigned int> local_dof_indices (dofs_per_cell);
-  this->get_dof_indices (local_dof_indices);
-
-  for (unsigned int i=0; i<dofs_per_cell; ++i)
-    values(local_dof_indices[i]) = local_values(i);
-}
-
-
-
-
 template <class DH>
 template <class InputVector, typename number>
 void
index e5904074c04ab24b94e2dcc6a687754c72bac262..3547e96b9bc55a0081f07e91a923b329dcc5f8c1 100644 (file)
 
 for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS)
   {  
-    template
-      void
-      DoFCellAccessor<DoFHandler<deal_II_dimension> >::get_dof_values
-      (const VEC&, Vector<SCALAR>&) const;
-    template
-      void
-      DoFCellAccessor<DoFHandler<deal_II_dimension> >::set_dof_values
-      (const Vector<SCALAR>&, VEC&) const;
-
     template
       void
       DoFCellAccessor<DoFHandler<deal_II_dimension> >::get_interpolated_dof_values
@@ -34,15 +25,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS)
 
 #if deal_II_dimension != 3
 
-    template
-      void
-      DoFCellAccessor<DoFHandler<deal_II_dimension,deal_II_dimension+1> >::get_dof_values
-      (const VEC&, Vector<SCALAR>&) const;
-    template
-      void
-      DoFCellAccessor<DoFHandler<deal_II_dimension,deal_II_dimension+1> >::set_dof_values
-      (const Vector<SCALAR>&, VEC&) const;
-
     template
       void
       DoFCellAccessor<DoFHandler<deal_II_dimension,deal_II_dimension+1> >::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<hp::DoFHandler<deal_II_dimension> >::get_dof_values
-      (const VEC&, Vector<SCALAR>&) const;
-    template
-      void
-      DoFCellAccessor<hp::DoFHandler<deal_II_dimension> >::set_dof_values
-      (const Vector<SCALAR>&, VEC&) const;
-
     template
       void
       DoFCellAccessor<hp::DoFHandler<deal_II_dimension> >::get_interpolated_dof_values
@@ -78,14 +51,6 @@ for (VEC : SERIAL_VECTORS; SCALAR : REAL_SCALARS)
       (const Vector<SCALAR>&, VEC&) const;
 
 #if deal_II_dimension != 3
-    template
-      void
-      DoFCellAccessor<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> >::get_dof_values
-      (const VEC&, Vector<SCALAR>&) const;
-    template
-      void
-      DoFCellAccessor<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> >::set_dof_values
-      (const Vector<SCALAR>&, VEC&) const;
 
     template
       void

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.