]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Small performance improvement.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 28 Apr 1998 12:30:43 +0000 (12:30 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 28 Apr 1998 12:30:43 +0000 (12:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@212 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_accessor.h
deal.II/deal.II/source/dofs/dof_accessor.cc

index 0e0d39c042d7f88edd627f5260c13489e2e719c0..ea259bf1e46e894f5a8a4ed15395598cc0e654f5 100644 (file)
@@ -180,6 +180,15 @@ class DoFLineAccessor :  public DoFAccessor<dim>, public BaseClass {
                                      */
     void get_dof_indices (vector<int> &dof_indices) const;
 
+                                    /**
+                                     * Return the length of the line. If the
+                                     * line describes part of the boundary
+                                     * and is not a straight one, ask the
+                                     * finite element class for the correct
+                                     * length!
+                                     */
+    double diameter () const;
+                                     
                                     /**
                                      * Return the #i#th child as a DoF line
                                      * iterator. This function is needed since
@@ -266,6 +275,18 @@ class DoFQuadAccessor :  public DoFAccessor<dim>, public BaseClass {
                                      */
     void get_dof_indices (vector<int> &dof_indices) const;
 
+                                    /**
+                                     * Return the diameter of the quad. If the
+                                     * quad describes part of the boundary
+                                     * and is not a plane one, ask the
+                                     * finite element class for the correct
+                                     * length!
+                                     *
+                                     * The diameter of a quad is computed to
+                                     * be the larger of the two diagonals.
+                                     */
+    double diameter () const;
+
                                     /**
                                      *  Return a pointer to the #i#th line
                                      *  bounding this #Quad#.
@@ -453,9 +474,8 @@ class DoFCellAccessor :  public DoFSubstructAccessor<dim> {
                                      * dofs on line 0, dofs on line 1, etc,
                                      * dofs on quad 0, etc.
                                      *
-                                     * The values are appended to the end
-                                     * of the vector. It is assumed that
-                                     * the vector be empty beforehand.
+                                     * It is assumed that the vector already
+                                     * has the right size beforehand.
                                      */
     void get_dof_values (const dVector  &values,
                         vector<double> &dof_values) const;
index 1aee0a8d59f79e38bdf50334e1051a0b9e02b72a..ca220cae1a0388cd48b4f9198224ba329ee38547 100644 (file)
@@ -101,6 +101,14 @@ DoFLineAccessor<dim,BaseClass>::get_dof_indices (vector<int> &dof_indices) const
 
 
 
+template <int dim, class BaseClass>
+double
+DoFLineAccessor<dim,BaseClass>::diameter () const {
+  return sqrt((vertex(1)-vertex(0)).square());
+};
+
+
+
 template <int dim, class BaseClass>
 TriaIterator<dim,DoFLineAccessor<dim,BaseClass> >
 DoFLineAccessor<dim,BaseClass>::child (const unsigned int i) const {
@@ -215,6 +223,15 @@ DoFQuadAccessor<dim,BaseClass>::get_dof_indices (vector<int> &dof_indices) const
 
 
 
+template <int dim, class BaseClass>
+double
+DoFQuadAccessor<dim,BaseClass>::diameter () const {
+  return sqrt(max((vertex(2)-vertex(0)).square(),
+                 (vertex(3)-vertex(1)).square()));
+};
+
+
+
 
 template <int dim, class BaseClass>
 TriaIterator<dim,DoFLineAccessor<dim,LineAccessor<dim> > >
@@ -316,16 +333,17 @@ DoFCellAccessor<1>::get_dof_values (const dVector  &values,
                                    vector<double> &dof_values) const {
   Assert (dof_handler != 0, ExcInvalidObject());
   Assert (&dof_handler->get_selected_fe() != 0, ExcInvalidObject());
-  Assert (dof_values.size() == 0, ExcVectorNotEmpty());
+  Assert (dof_values.size() == dof_handler->get_selected_fe().total_dofs,
+         ExcVectorDoesNotMatch());
   Assert (values.n() == dof_handler->n_dofs(),
          ExcVectorDoesNotMatch());
-  
-  dof_values.reserve (dof_handler->get_selected_fe().total_dofs);
+
+  vector<double>::iterator next_dof_value=dof_values.begin();
   for (unsigned int vertex=0; vertex<2; ++vertex)
     for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_vertex; ++d)
-      dof_values.push_back (values(vertex_dof_index(vertex,d)));
+      *next_dof_value++ = values(vertex_dof_index(vertex,d));
   for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_line; ++d)
-    dof_values.push_back (values(dof_index(d)));
+    *next_dof_value++ = values(dof_index(d));
 };
 
 
@@ -336,19 +354,20 @@ DoFCellAccessor<2>::get_dof_values (const dVector  &values,
                                    vector<double> &dof_values) const {
   Assert (dof_handler != 0, ExcInvalidObject());
   Assert (&dof_handler->get_selected_fe() != 0, ExcInvalidObject());
-  Assert (dof_values.size() == 0, ExcVectorNotEmpty());
+  Assert (dof_values.size() == dof_handler->get_selected_fe().total_dofs,
+         ExcVectorDoesNotMatch());
   Assert (values.n() == dof_handler->n_dofs(),
          ExcVectorDoesNotMatch());
-    
-  dof_values.reserve (dof_handler->get_selected_fe().total_dofs);
+
+  vector<double>::iterator next_dof_value=dof_values.begin();
   for (unsigned int vertex=0; vertex<4; ++vertex)
     for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_vertex; ++d)
-      dof_values.push_back (values(vertex_dof_index(vertex,d)));
+      *next_dof_value++ = values(vertex_dof_index(vertex,d));
   for (unsigned int line=0; line<4; ++line)
     for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_line; ++d)
-      dof_values.push_back (values(this->line(line)->dof_index(d)));
+      *next_dof_value++ = values(this->line(line)->dof_index(d));
   for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_quad; ++d)
-    dof_values.push_back (values(dof_index(d)));
+    *next_dof_value++ = values(dof_index(d));
 };
 
 

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.