]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move code closer to the C++ standard and small performance changes.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 24 May 1998 21:08:52 +0000 (21:08 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 24 May 1998 21:08:52 +0000 (21:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@342 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/dofs/dof_accessor.cc
deal.II/deal.II/source/numerics/error_estimator.cc
deal.II/deal.II/source/numerics/matrices.cc
deal.II/deal.II/source/numerics/vectors.cc

index 07cbbee0682650c057daffa9c31b42b8f8edde60..d6ea8a91692a6f0271b6a6a89103b9e86639af20 100644 (file)
@@ -93,11 +93,13 @@ DoFLineAccessor<dim,BaseClass>::get_dof_indices (vector<int> &dof_indices) const
                                 dof_handler->get_selected_fe().dofs_per_line),
          ExcVectorDoesNotMatch());
 
+  const unsigned int dofs_per_vertex = dof_handler->get_selected_fe().dofs_per_vertex,
+                    dofs_per_line   = dof_handler->get_selected_fe().dofs_per_line;
   vector<int>::iterator next = dof_indices.begin();
   for (unsigned int vertex=0; vertex<2; ++vertex)
-    for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_vertex; ++d)
+    for (unsigned int d=0; d<dofs_per_vertex; ++d)
       *next++ = vertex_dof_index(vertex,d);
-  for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_line; ++d)
+  for (unsigned int d=0; d<dofs_per_line; ++d)
     *next++ = dof_index(d);
 };
 
@@ -207,14 +209,17 @@ DoFQuadAccessor<dim,BaseClass>::get_dof_indices (vector<int> &dof_indices) const
                                 dof_handler->get_selected_fe().dofs_per_quad),
          ExcVectorDoesNotMatch());
 
+  const unsigned int dofs_per_vertex = dof_handler->get_selected_fe().dofs_per_vertex,
+                    dofs_per_line   = dof_handler->get_selected_fe().dofs_per_line,
+                    dofs_per_quad   = dof_handler->get_selected_fe().dofs_per_quad;
   vector<int>::iterator next = dof_indices.begin();
   for (unsigned int vertex=0; vertex<4; ++vertex)
-    for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_vertex; ++d)
+    for (unsigned int d=0; d<dofs_per_vertex; ++d)
       *next++ = 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)
+    for (unsigned int d=0; d<dofs_per_line; ++d)
       *next++ = this->line(line)->dof_index(d);
-  for (unsigned int d=0; d<dof_handler->get_selected_fe().dofs_per_quad; ++d)
+  for (unsigned int d=0; d<dofs_per_quad; ++d)
     *next++ = dof_index(d);
 };
 
@@ -299,6 +304,7 @@ DoFCellAccessor<dim>::child (const unsigned int i) const {
 
 
 
+template <>
 DoFSubstructAccessor<1>::face_iterator
 DoFCellAccessor<1>::face (const unsigned int) const {
   Assert (false, ExcNotUsefulForThisDimension());
@@ -307,6 +313,7 @@ DoFCellAccessor<1>::face (const unsigned int) const {
 
 
 
+template <>
 DoFSubstructAccessor<2>::face_iterator
 DoFCellAccessor<2>::face (const unsigned int i) const {
   return line(i);
@@ -314,6 +321,7 @@ DoFCellAccessor<2>::face (const unsigned int i) const {
 
 
 
+template <>
 void
 DoFCellAccessor<1>::get_dof_values (const dVector  &values,
                                    vector<double> &dof_values) const {
@@ -324,17 +332,20 @@ DoFCellAccessor<1>::get_dof_values (const dVector  &values,
   Assert (values.size() == dof_handler->n_dofs(),
          ExcVectorDoesNotMatch());
 
+  const unsigned int dofs_per_vertex = dof_handler->get_selected_fe().dofs_per_vertex,
+                    dofs_per_line   = dof_handler->get_selected_fe().dofs_per_line;
   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)
+    for (unsigned int d=0; d<dofs_per_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)
+  for (unsigned int d=0; d<dofs_per_line; ++d)
     *next_dof_value++ = values(dof_index(d));
 };
 
 
 
 
+template <>
 void
 DoFCellAccessor<2>::get_dof_values (const dVector  &values,
                                    vector<double> &dof_values) const {
@@ -345,14 +356,17 @@ DoFCellAccessor<2>::get_dof_values (const dVector  &values,
   Assert (values.size() == dof_handler->n_dofs(),
          ExcVectorDoesNotMatch());
 
+  const unsigned int dofs_per_vertex = dof_handler->get_selected_fe().dofs_per_vertex,
+                    dofs_per_line   = dof_handler->get_selected_fe().dofs_per_line,
+                    dofs_per_quad   = dof_handler->get_selected_fe().dofs_per_quad;
   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)
+    for (unsigned int d=0; d<dofs_per_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)
+    for (unsigned int d=0; d<dofs_per_line; ++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)
+  for (unsigned int d=0; d<dofs_per_quad; ++d)
     *next_dof_value++ = values(dof_index(d));
 };
 
index a4cc86f98924d241432a46c6bb2f7190f3be5d79..5cefcb81f5a236ae0f1574033f9bc585df19be9c 100644 (file)
@@ -23,6 +23,7 @@ inline double sqr (const double x) {
 
 
 
+template <>
 void KellyErrorEstimator<1>::estimate_error (const DoFHandler<1> &,
                                             const Quadrature<0> &,
                                             const FiniteElement<1> &,
@@ -174,6 +175,7 @@ void KellyErrorEstimator<dim>::estimate_error (const DoFHandler<dim>    &dof,
 
 
 
+template <>
 void KellyErrorEstimator<1>::integrate_over_regular_face (const active_cell_iterator &,
                                                          const unsigned int      ,
                                                          const FiniteElement<1> &,
@@ -334,6 +336,7 @@ integrate_over_regular_face (const active_cell_iterator &cell,
 
 
 
+template <>
 void KellyErrorEstimator<1>::
 integrate_over_irregular_face (const active_cell_iterator &,
                               const unsigned int          ,
index 2be140e98f4eb2785a568dbde76c2035a31af5cd..ad1723e1ef3e6049708b287f7d0808c71f5e818a 100644 (file)
@@ -78,6 +78,7 @@ void MatrixCreator<dim>::create_mass_matrix (const DoFHandler<dim>    &dof,
 
 
 
+template <>
 void MatrixCreator<1>::create_boundary_mass_matrix (const DoFHandler<1>    &,
                                                    const FiniteElement<1> &,
                                                    const Quadrature<0>    &,
@@ -322,13 +323,14 @@ void MatrixTools<dim>::apply_boundary_values (const map<int,double> &boundary_va
 
   for (; dof != endd; ++dof)
     {
+      const int dof_number = dof->first;
                                       // for each boundary dof:
-
+      
                                       // set entries of this line
                                       // to zero
-      for (unsigned int j=sparsity_rowstart[dof->first];
-          j<sparsity_rowstart[dof->first+1]; ++j)
-       if (sparsity_colnums[j] != dof->first)
+      const unsigned int last = sparsity_rowstart[dof_number+1];
+      for (unsigned int j=sparsity_rowstart[dof->first]; j<last; ++j)
+       if (sparsity_colnums[j] != dof_number)
                                           // if not main diagonal entry
          matrix.global_entry(j) = 0.;
       
@@ -346,9 +348,9 @@ void MatrixTools<dim>::apply_boundary_values (const map<int,double> &boundary_va
                                       // store the new rhs entry to make
                                       // the gauss step more efficient
       double new_rhs;
-      if (matrix.diag_element(dof->first) != 0.0)
-       new_rhs = right_hand_side(dof->first)
-               = dof->second * matrix.diag_element(dof->first);
+      if (matrix.diag_element(dof_number) != 0.0)
+       new_rhs = right_hand_side(dof_number)
+               = dof->second * matrix.diag_element(dof_number);
       else
        {
          double first_diagonal_entry = 1;
@@ -359,23 +361,23 @@ void MatrixTools<dim>::apply_boundary_values (const map<int,double> &boundary_va
                break;
              };
          
-         matrix.set(dof->first, dof->first,
+         matrix.set(dof_number, dof_number,
                     first_diagonal_entry);
-         new_rhs = right_hand_side(dof->first)
+         new_rhs = right_hand_side(dof_number)
                  = dof->second * first_diagonal_entry;
        };
       
                                       // store the only nonzero entry
                                       // of this line for the Gauss
                                       // elimination step
-      const double diagonal_entry = matrix.diag_element(dof->first);
+      const double diagonal_entry = matrix.diag_element(dof_number);
 
                                       // do the Gauss step
       for (unsigned int row=0; row<n_dofs; ++row) 
        for (unsigned int j=sparsity_rowstart[row];
             j<sparsity_rowstart[row+1]; ++j)
-         if ((sparsity_colnums[j] == (signed int)dof->first) &&
-             ((signed int)row != dof->first))
+         if ((sparsity_colnums[j] == dof_number) &&
+             ((signed int)row != dof_number))
                                             // this line has an entry
                                             // in the regarding column
                                             // but this is not the main
@@ -391,7 +393,7 @@ void MatrixTools<dim>::apply_boundary_values (const map<int,double> &boundary_va
       
       
                                       // preset solution vector
-      solution(dof->first) = dof->second;
+      solution(dof_number) = dof->second;
     };
 };
 
@@ -420,23 +422,26 @@ void MassMatrix<dim>::assemble (dFMatrix            &cell_matrix,
   const dFMatrix       &values    = fe_values.get_shape_values ();
   const vector<double> &weights   = fe_values.get_JxW_values ();
 
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+  
   if (coefficient != 0)
     {
       vector<double> coefficient_values (fe_values.n_quadrature_points);
       coefficient->value_list (fe_values.get_quadrature_points(),
                               coefficient_values);
-      for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-       for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
-         for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+      for (unsigned int i=0; i<total_dofs; ++i) 
+       for (unsigned int j=0; j<total_dofs; ++j)
+         for (unsigned int point=0; point<n_q_points; ++point)
            cell_matrix(i,j) += (values(i,point) *
                                 values(j,point) *
                                 weights[point] *
                                 coefficient_values[point]);
     }
   else
-    for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-      for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
-       for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+    for (unsigned int i=0; i<total_dofs; ++i) 
+      for (unsigned int j=0; j<total_dofs; ++j)
+       for (unsigned int point=0; point<n_q_points; ++point)
          cell_matrix(i,j) += (values(i,point) *
                               values(j,point) *
                               weights[point]);
@@ -456,15 +461,18 @@ void MassMatrix<dim>::assemble (dFMatrix            &cell_matrix,
   vector<double>        rhs_values (fe_values.n_quadrature_points);
   right_hand_side->value_list (fe_values.get_quadrature_points(), rhs_values);
 
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+
   if (coefficient != 0)
     {
-      vector<double> coefficient_values (fe_values.n_quadrature_points);
+      vector<double> coefficient_values (n_q_points);
       coefficient->value_list (fe_values.get_quadrature_points(),
                               coefficient_values);
-      for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-       for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+      for (unsigned int point=0; point<n_q_points; ++point)
+       for (unsigned int i=0; i<total_dofs; ++i) 
          {
-           for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+           for (unsigned int j=0; j<total_dofs; ++j)
              cell_matrix(i,j) += (values(i,point) *
                                   values(j,point) *
                                   weights[point] *
@@ -475,10 +483,10 @@ void MassMatrix<dim>::assemble (dFMatrix            &cell_matrix,
          };
     }
   else
-    for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-      for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+    for (unsigned int point=0; point<n_q_points; ++point)
+      for (unsigned int i=0; i<total_dofs; ++i) 
        {
-         for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+         for (unsigned int j=0; j<total_dofs; ++j)
            cell_matrix(i,j) += (values(i,point) *
                                 values(j,point) *
                                 weights[point]);
@@ -501,8 +509,11 @@ void MassMatrix<dim>::assemble (dVector             &rhs,
   vector<double>        rhs_values(fe_values.n_quadrature_points);
   right_hand_side->value_list (fe_values.get_quadrature_points(), rhs_values);
 
-  for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-    for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+
+  for (unsigned int point=0; point<n_q_points; ++point)
+    for (unsigned int i=0; i<total_dofs; ++i) 
       rhs(i) += values(i,point) *
                rhs_values[point] *
                weights[point];
@@ -533,15 +544,18 @@ void LaplaceMatrix<dim>::assemble (dFMatrix            &cell_matrix,
   const vector<double> &weights   = fe_values.get_JxW_values ();
   right_hand_side->value_list (fe_values.get_quadrature_points(), rhs_values);
 
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+
   if (coefficient != 0)
     {
-      vector<double> coefficient_values(fe_values.n_quadrature_points);
+      vector<double> coefficient_values(n_q_points);
       coefficient->value_list (fe_values.get_quadrature_points(),
                               coefficient_values);
-      for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-       for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+      for (unsigned int point=0; point<n_q_points; ++point)
+       for (unsigned int i=0; i<total_dofs; ++i) 
          {
-           for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+           for (unsigned int j=0; j<total_dofs; ++j)
              cell_matrix(i,j) += (gradients[i][point] *
                                   gradients[j][point]) *
                                  weights[point] *
@@ -552,10 +566,10 @@ void LaplaceMatrix<dim>::assemble (dFMatrix            &cell_matrix,
          };
     }
   else
-    for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-      for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+    for (unsigned int point=0; point<n_q_points; ++point)
+      for (unsigned int i=0; i<total_dofs; ++i) 
        {
-         for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+         for (unsigned int j=0; j<total_dofs; ++j)
            cell_matrix(i,j) += (gradients[i][point] *
                                 gradients[j][point]) *
                                weights[point];
@@ -575,23 +589,26 @@ void LaplaceMatrix<dim>::assemble (dFMatrix            &cell_matrix,
   const vector<vector<Point<dim> > >&gradients = fe_values.get_shape_grads ();
   const vector<double> &weights   = fe_values.get_JxW_values ();
    
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+
   if (coefficient != 0)
     {
-      vector<double> coefficient_values(fe_values.n_quadrature_points);
+      vector<double> coefficient_values(n_q_points);
       coefficient->value_list (fe_values.get_quadrature_points(),
                               coefficient_values);
-      for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-       for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
-         for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+      for (unsigned int point=0; point<n_q_points; ++point)
+       for (unsigned int i=0; i<total_dofs; ++i) 
+         for (unsigned int j=0; j<total_dofs; ++j)
            cell_matrix(i,j) += (gradients[i][point] *
                                 gradients[j][point]) *
                                weights[point] *
                                coefficient_values[point];
     }
   else
-    for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-      for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
-       for (unsigned int j=0; j<fe_values.total_dofs; ++j)
+    for (unsigned int point=0; point<n_q_points; ++point)
+      for (unsigned int i=0; i<total_dofs; ++i) 
+       for (unsigned int j=0; j<total_dofs; ++j)
          cell_matrix(i,j) += (gradients[i][point] *
                               gradients[j][point]) *
                              weights[point];
@@ -610,8 +627,11 @@ void LaplaceMatrix<dim>::assemble (dVector             &rhs,
   vector<double>        rhs_values(fe_values.n_quadrature_points);
   right_hand_side->value_list (fe_values.get_quadrature_points(), rhs_values);
    
-  for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
-    for (unsigned int i=0; i<fe_values.total_dofs; ++i) 
+  const unsigned int total_dofs = fe_values.total_dofs,
+                    n_q_points = fe_values.n_quadrature_points;
+
+  for (unsigned int point=0; point<n_q_points; ++point)
+    for (unsigned int i=0; i<total_dofs; ++i) 
       rhs(i) += values(i,point) *
                rhs_values[point] *
                weights[point];
index 358af5ac37877ced6a33f5a78925b517c66f7aa4..88adaf115c24ed676fbcdf12af196d9f641af8a3 100644 (file)
@@ -71,6 +71,7 @@ void VectorTools<dim>::interpolate (const DoFHandler<dim>    &dof,
 
 
 
+template <>
 void VectorTools<1>::project (const DoFHandler<1>    &,
                              const ConstraintMatrix &,
                              const FiniteElement<1> &,
@@ -173,6 +174,7 @@ void VectorTools<dim>::project (const DoFHandler<dim>    &dof,
 
 
 
+template <>
 void
 VectorTools<1>::interpolate_boundary_values (const DoFHandler<1> &,
                                             const FunctionMap &,
@@ -200,7 +202,7 @@ VectorTools<dim>::interpolate_boundary_values (const DoFHandler<dim> &dof,
   DoFHandler<dim>::active_face_iterator face = dof.begin_active_face(),
                                        endf = dof.end_face();
   
-  FunctionMap::const_iterator function_ptr;
+  typename FunctionMap::const_iterator function_ptr;
 
                                   // field to store the indices of dofs
   vector<int>         face_dofs (fe.dofs_per_face);

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.