]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
The distribute_local_to_global function needs to know which dofs are constrained...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 8 Apr 2005 20:47:44 +0000 (20:47 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 8 Apr 2005 20:47:44 +0000 (20:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@10443 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_constraints.h
deal.II/deal.II/include/dofs/dof_constraints.templates.h
deal.II/deal.II/source/dofs/dof_constraints.cc
tests/bits/dof_constraints_01.cc
tests/bits/dof_constraints_02.cc

index 68d824245caab58b16fb9a1e536455762fc830af..95adfa5b46da00783f33b552cc75ea4ca47ec5d8 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <base/config.h>
 #include <vector>
+#include <map>
 #include <utility>
 #include <base/exceptions.h>
 #include <base/subscriptor.h>
@@ -656,7 +657,7 @@ class ConstraintMatrix : public Subscriptor
                                       * In contrast to the similar function in
                                       * the DoFAccessor class, this function
                                       * also takes care of constraints,
-                                      * i.e. of one of the elements of @p
+                                      * i.e. if one of the elements of @p
                                       * local_dof_indices belongs to a
                                       * constrained node, then rather than
                                       * writing the corresponding element of
@@ -672,11 +673,37 @@ class ConstraintMatrix : public Subscriptor
                                       * the condense function after the
                                       * vectors and matrices are fully
                                       * assembled.
+                                     *
+                                     * In order to do its work
+                                     * properly, this function has to
+                                     * know which degrees of freedom
+                                     * are fixed, for example
+                                     * boundary values. For this, the
+                                     * third argument is a map
+                                     * between the numbers of the
+                                     * DoFs that are fixed and the
+                                     * values they are fixed to. One
+                                     * can pass an empty map in for
+                                     * this argument, but note that
+                                     * you will then have to fix
+                                     * these nodes later on again,
+                                     * for example by using
+                                     * MatrixTools::apply_boundary_values
+                                     * to the resulting
+                                     * matrix. However, since the
+                                     * present function was written
+                                     * for the express purpose of not
+                                     * having to use tools that later
+                                     * modify the matrix, it is
+                                     * advisable to have the list of
+                                     * fixed nodes available when
+                                     * calling the present function.
                                       */
     template <typename VectorType>
     void
     distribute_local_to_global (const Vector<double>            &local_vector,
                                 const std::vector<unsigned int> &local_dof_indices,
+                               const std::map<unsigned int, double> &fixed_dofs,
                                 VectorType                      &global_vector) const;
 
                                      /**
@@ -697,7 +724,7 @@ class ConstraintMatrix : public Subscriptor
                                       * In contrast to the similar function in
                                       * the DoFAccessor class, this function
                                       * also takes care of constraints,
-                                      * i.e. of one of the elements of @p
+                                      * i.e. if one of the elements of @p
                                       * local_dof_indices belongs to a
                                       * constrained node, then rather than
                                       * writing the corresponding element of
@@ -736,11 +763,37 @@ class ConstraintMatrix : public Subscriptor
                                       * the condense function after the
                                       * vectors and matrices are fully
                                       * assembled.
+                                     *
+                                     * In order to do its work
+                                     * properly, this function has to
+                                     * know which degrees of freedom
+                                     * are fixed, for example
+                                     * boundary values. For this, the
+                                     * third argument is a map
+                                     * between the numbers of the
+                                     * DoFs that are fixed and the
+                                     * values they are fixed to. One
+                                     * can pass an empty map in for
+                                     * this argument, but note that
+                                     * you will then have to fix
+                                     * these nodes later on again,
+                                     * for example by using
+                                     * MatrixTools::apply_boundary_values
+                                     * to the resulting
+                                     * matrix. However, since the
+                                     * present function was written
+                                     * for the express purpose of not
+                                     * having to use tools that later
+                                     * modify the matrix, it is
+                                     * advisable to have the list of
+                                     * fixed nodes available when
+                                     * calling the present function.
                                       */
     template <typename MatrixType>
     void
     distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                                 const std::vector<unsigned int> &local_dof_indices,
+                               const std::map<unsigned int, double> &fixed_dofs,
                                 MatrixType                      &global_matrix) const;
     
                                     /**
index 522b54656c1d1fbeee86d14cffbdbb4f52672744..ea249687d09eeefac1cc1ce7fa1ebe2e1d586d44 100644 (file)
@@ -554,11 +554,15 @@ ConstraintMatrix::set_zero (VectorType &vec) const
 
 
 
+#define is_fixed(i) (fixed_dofs.find(i) != fixed_dofs.end())
+//#define is_fixed(i) false
+
 template <typename VectorType>
 void
 ConstraintMatrix::
 distribute_local_to_global (const Vector<double>            &local_vector,
                             const std::vector<unsigned int> &local_dof_indices,
+                           const std::map<unsigned int, double> &fixed_dofs,
                             VectorType                      &global_vector) const
 {
   Assert (local_vector.size() == local_dof_indices.size(),
@@ -589,15 +593,19 @@ distribute_local_to_global (const Vector<double>            &local_vector,
                                          lines.end(),
                                          index_comparison);
 
-                                           // if the line is not constrained,
-                                           // then simply copy the
-                                           // data. otherwise distribute it
+                                           // if the line is not
+                                           // constrained, then simply
+                                           // copy the data. otherwise
+                                           // distribute it, but make
+                                           // sure we don't touch the
+                                           // entries of fixed dofs
           if (position->line != local_dof_indices[i])
             global_vector(local_dof_indices[i]) += local_vector(i);
           else
             for (unsigned int j=0; j<position->entries.size(); ++j)
-              global_vector(position->entries[j].first)
-                += local_vector(i) * position->entries[j].second;
+             if (!is_fixed(position->entries[j].first))
+               global_vector(position->entries[j].first)
+                 += local_vector(i) * position->entries[j].second;
         }
     }
 }
@@ -609,6 +617,7 @@ void
 ConstraintMatrix::
 distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                             const std::vector<unsigned int> &local_dof_indices,
+                           const std::map<unsigned int, double> &fixed_dofs,
                             MatrixType                      &global_matrix) const
 {
   Assert (local_matrix.n() == local_dof_indices.size(),
@@ -693,10 +702,11 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                                                    // ok, row is constrained,
                                                    // but column is not
                   for (unsigned int q=0; q<position_i->entries.size(); ++q)
-                    global_matrix.add (position_i->entries[q].first,
-                                       local_dof_indices[j],
-                                       local_matrix(i,j) *
-                                       position_i->entries[q].second);
+                   if (!is_fixed(position_i->entries[q].first))
+                     global_matrix.add (position_i->entries[q].first,
+                                        local_dof_indices[j],
+                                        local_matrix(i,j) *
+                                        position_i->entries[q].second);
                 }
               else if ((is_constrained_i == false) &&
                        (is_constrained_j == true))
@@ -705,10 +715,11 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                                                    // round: row ok, column is
                                                    // constrained
                   for (unsigned int q=0; q<position_j->entries.size(); ++q)
-                    global_matrix.add (local_dof_indices[i],
-                                       position_j->entries[q].first,
-                                       local_matrix(i,j) *
-                                       position_j->entries[q].second);
+                   if (!is_fixed(position_j->entries[q].first))
+                     global_matrix.add (local_dof_indices[i],
+                                        position_j->entries[q].first,
+                                        local_matrix(i,j) *
+                                        position_j->entries[q].second);
                 }
               else if ((is_constrained_i == true) &&
                        (is_constrained_j == true))
@@ -716,12 +727,14 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                                                    // last case: both row and
                                                    // column are constrained
                   for (unsigned int p=0; p<position_i->entries.size(); ++p)
-                    for (unsigned int q=0; q<position_j->entries.size(); ++q)
-                      global_matrix.add (position_i->entries[p].first,
-                                         position_j->entries[q].first,
-                                         local_matrix(i,j) *
-                                         position_i->entries[p].second *
-                                         position_j->entries[q].second);
+                   if (!is_fixed(position_i->entries[p].first))
+                     for (unsigned int q=0; q<position_j->entries.size(); ++q)
+                       if (!is_fixed(position_j->entries[q].first))
+                         global_matrix.add (position_i->entries[p].first,
+                                            position_j->entries[q].first,
+                                            local_matrix(i,j) *
+                                            position_i->entries[p].second *
+                                            position_j->entries[q].second);
 
                                                    // to make sure that the
                                                    // global matrix remains
index 8a270988ac798f12398c514f3158b7ae72e1b4a4..acaa000c9c443beca6110518ea07f4339be422a9 100644 (file)
@@ -1195,6 +1195,7 @@ ConstraintMatrix::memory_consumption () const
   template void ConstraintMatrix:: \
     distribute_local_to_global<VectorType > (const Vector<double>            &, \
                                              const std::vector<unsigned int> &, \
+                                             const std::map<unsigned int, double> &, \
                                              VectorType                      &) const; \
   template void ConstraintMatrix::distribute<VectorType >(const VectorType &condensed,\
                                                         VectorType       &uncondensed) const;\
@@ -1247,6 +1248,7 @@ ConstraintMatrix::condense<float>(BlockSparseMatrix<float> &uncondensed) const;
 template void ConstraintMatrix:: \
 distribute_local_to_global<MatrixType > (const FullMatrix<double>        &, \
                                          const std::vector<unsigned int> &, \
+                                         const std::map<unsigned int, double> &, \
                                          MatrixType                      &) const
 
 MATRIX_FUNCTIONS(SparseMatrix<double>);
index 0d4a3616d1df0837b8c88326cb9e92aab5b987fa..e16d38035cbf3f81da7f774ea41c6a8afecfd5be 100644 (file)
@@ -99,7 +99,8 @@ void test ()
           A.add (local_dofs[i], local_dofs[j], local_matrix(i,j));
 
                                        // or let other functions do that
-      constraints.distribute_local_to_global (local_matrix, local_dofs, B);
+      constraints.distribute_local_to_global (local_matrix, local_dofs,
+                                             std::map<unsigned int,double>(), B);
     }
 
                                    // now condense away constraints from A
index b70f9168ffd20a2df105f36a2b85276a95d543dc..aac44a4f3cd3dd5d6fa6bf633d76fdc3955e6b5d 100644 (file)
@@ -90,7 +90,8 @@ void test ()
         A(local_dofs[i]) += local_vector(i);
 
                                        // or let other functions do that
-      constraints.distribute_local_to_global (local_vector, local_dofs, B);
+      constraints.distribute_local_to_global (local_vector, local_dofs,
+                                             std::map<unsigned int,double>(), B);
     }
 
                                    // now condense away constraints from A

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.