]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add ability to call ConstraintMatrix::set_zero for parallel vectors.
authorfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Apr 2012 12:35:26 +0000 (12:35 +0000)
committerfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Apr 2012 12:35:26 +0000 (12:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@25355 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/constraint_matrix.templates.h
deal.II/source/lac/constraint_matrix.inst.pl

index a75c6e3cf154520fe1af9f4a352212bc3005e711..cc03ac7f520d57cdd250136e56ff7091ab5c7f14 100644 (file)
@@ -22,6 +22,8 @@
 #include <deal.II/lac/sparse_matrix.h>
 #include <deal.II/lac/block_sparsity_pattern.h>
 #include <deal.II/lac/block_sparse_matrix.h>
+#include <deal.II/lac/parallel_vector.h>
+#include <deal.II/lac/parallel_block_vector.h>
 
 #include <iomanip>
 
@@ -698,19 +700,106 @@ ConstraintMatrix::condense (BlockSparseMatrix<number> &uncondensed,
 
 
 
+// number of functions to select the right implementation for set_zero().
+namespace internal
+{
+  namespace ConstraintMatrix
+  {
+    namespace
+      {
+       // TODO: in general we should iterate over the constraints and not over all DoFs
+       // for performance reasons
+       template<class VEC>
+         void set_zero_parallel(const dealii::ConstraintMatrix &cm, VEC &vec, unsigned int shift = 0)
+         { 
+           Assert(!vec.has_ghost_elements(), ExcInternalError());//ExcGhostsPresent());
+
+           const unsigned int
+             start = vec.local_range().first,
+             end   = vec.local_range().second;
+           for (unsigned int i=start; i<end; ++i)
+             if (cm.is_constrained (shift + i))
+               vec(i) = 0;
+         }
+  
+       template<class VEC>
+         void set_zero_in_parallel(const dealii::ConstraintMatrix &cm, VEC &vec, internal::bool2type<false>)
+         {
+           set_zero_parallel(cm, vec, 0);
+         }
+  
+       // in parallel for BlockVectors
+       template<class VEC>
+         void set_zero_in_parallel(const dealii::ConstraintMatrix &cm, VEC &vec, internal::bool2type<true>)
+         {
+           unsigned int start_shift = 0;
+           for (unsigned int j=0; j<vec.n_blocks(); ++j)
+             {
+               set_zero_parallel(cm, vec.block(j), start_shift);
+               start_shift += vec.block(j).size();
+             }
+         }
+  
+       template<class VEC>
+         void set_zero_serial(const dealii::ConstraintMatrix &cm, VEC &vec)
+         {
+           // TODO would be faster:
+           /* std::vector<dealii::ConstraintMatrix::ConstraintLine>::const_iterator constraint_line = cm.lines.begin();
+              for (; constraint_line!=cm.lines.end(); ++constraint_line)
+              vec(constraint_line->line) = 0.;*/
+           for (unsigned int i=0; i<vec.size(); ++i)
+             if (cm.is_constrained (i))
+               vec(i) = 0;
+         }
+
+       template<class VEC>
+         void set_zero_all(const dealii::ConstraintMatrix &cm, VEC &vec)
+         {
+           set_zero_in_parallel<VEC>(cm, vec, internal::bool2type<IsBlockVector<VEC>::value>());
+         }
+
+
+       template<class T>
+         void set_zero_all(const dealii::ConstraintMatrix &cm, dealii::Vector<T> &vec)
+         {
+           set_zero_serial(cm, vec);
+         }
+
+       template<class T>
+         void set_zero_all(const dealii::ConstraintMatrix &cm, dealii::BlockVector<T> &vec)
+         {
+           set_zero_serial(cm, vec);
+         }
+
+
+       template<class T>
+         void set_zero_all(const dealii::ConstraintMatrix &cm, dealii::parallel::distributed::Vector<T> &vec)
+         {
+           // should use the general template above, but requires that
+           // some member functions are added to parallel::distributed::Vector
+           Assert (false, ExcNotImplemented());
+         }
+
+       template<class T>
+         void set_zero_all(const dealii::ConstraintMatrix &cm, dealii::parallel::distributed::BlockVector<T> &vec)
+         {
+           Assert (false, ExcNotImplemented());
+         }
+      }
+  }
+}
+       
+
 template <class VectorType>
 void
 ConstraintMatrix::set_zero (VectorType &vec) const
 {
-  Assert (sorted == true, ExcMatrixNotClosed());
-
-  std::vector<ConstraintLine>::const_iterator constraint_line = lines.begin();
-  for (; constraint_line!=lines.end(); ++constraint_line)
-    vec(constraint_line->line) = 0.;
+  internal::ConstraintMatrix::set_zero_all(*this, vec);
 }
 
 
 
+
 template <typename VectorType>
 void
 ConstraintMatrix::
index 33b5701226c2ce704c8480a9aded076e4b9d7926..af0f37d0c0702ef80c2365157fe89c9fc6572a7a 100644 (file)
@@ -2,7 +2,7 @@
 # $Id$
 ######################################################################
 #
-# Copyright (C) 2011 by the deal.II authors
+# Copyright (C) 2011, 2012 by the deal.II authors
 #
 # This file is subject to QPL and may not be  distributed
 # without copyright and license information. Please refer
@@ -19,11 +19,17 @@ my $vector_functions = <<'EOT'
 
 template void ConstraintMatrix::condense<V1 >(const V1 &, V1&) const;
 template void ConstraintMatrix::condense<V1 >(V1 &vec) const;
-template void ConstraintMatrix::set_zero<V1 >(V1&) const;
 template void ConstraintMatrix::distribute_local_to_global<V1 > (
     const Vector<double>&, const std::vector<unsigned int> &, V1&, const FullMatrix<double>&) const;
 template void ConstraintMatrix::distribute<V1 >(const V1 &, V1&) const;
 template void ConstraintMatrix::distribute<V1 >(V1 &) const;
+EOT
+    ;
+
+my $vector_functions_also_parallel = <<EOT
+
+template void ConstraintMatrix::set_zero<V1 >(V1&) const;
+
 EOT
     ;
 
@@ -50,5 +56,7 @@ EOT
 ######################################################################
 
 multisubst($vector_functions, ['V1'], \@sequential_vectors);
+multisubst($vector_functions_also_parallel, ['V1'], \@sequential_vectors);
+multisubst($vector_functions_also_parallel, ['V1'], \@parallel_vectors);
 multisubst($scalar_functions, ['S1'], \@real_scalars);
 multisubst($scalar_scalar_functions, ['S1','S2'], \@real_scalars, \@real_scalars);

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.