]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Rename set_zero to operator=(double) and only allow zero argument.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 15 May 2004 17:20:22 +0000 (17:20 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 15 May 2004 17:20:22 +0000 (17:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@9242 0785d39b-7218-0410-832d-ea1e28bc413d

42 files changed:
deal.II/deal.II/source/fe/fe_system.cc
deal.II/deal.II/source/fe/fe_tools.cc
deal.II/deal.II/source/numerics/matrices.cc
deal.II/doc/news/c-4-0.html
deal.II/examples/step-12/step-12.cc
deal.II/examples/step-13/step-13.cc
deal.II/examples/step-14/step-14.cc
deal.II/examples/step-15/step-15.cc
deal.II/examples/step-16/step-16.cc
deal.II/examples/step-17/step-17.cc
deal.II/examples/step-3/step-3.cc
deal.II/examples/step-4/step-4.cc
deal.II/examples/step-5/step-5.cc
deal.II/examples/step-6/step-6.cc
deal.II/examples/step-7/step-7.cc
deal.II/examples/step-8/step-8.cc
deal.II/examples/step-9/step-9.cc
deal.II/lac/include/lac/block_sparse_matrix.h
deal.II/lac/include/lac/block_sparse_matrix.templates.h
deal.II/lac/include/lac/block_vector.h
deal.II/lac/include/lac/full_matrix.h
deal.II/lac/include/lac/petsc_matrix_base.h
deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h
deal.II/lac/include/lac/petsc_sparse_matrix.h
deal.II/lac/include/lac/petsc_vector.h
deal.II/lac/include/lac/petsc_vector_base.h
deal.II/lac/include/lac/precondition_block.templates.h
deal.II/lac/include/lac/sparse_matrix.h
deal.II/lac/include/lac/sparse_matrix.templates.h
deal.II/lac/include/lac/vector.h
deal.II/lac/source/petsc_matrix_base.cc
tests/bits/apply_boundary_values_01.cc
tests/bits/apply_boundary_values_02.cc
tests/bits/dof_constraints_01.cc
tests/bits/dof_constraints_03.cc
tests/bits/dof_constraints_09.cc
tests/bits/petsc_63.cc
tests/deal.II/block_matrices.cc
tests/deal.II/wave-test-3.cc
tests/fe/non_primitive_1.cc
tests/fe/non_primitive_2.cc
tests/lac/full_matrix.cc

index cb52c8387fe8de5cd0959d5ead01e61edf05d5c3..2f53858306ba599c050ef0b27a614c842195d4de 100644 (file)
@@ -519,7 +519,7 @@ get_interpolation_matrix (const FiniteElementBase<dim> &x_source_fe,
                                    // couple different bases (or
                                    // multiplicity indices) are really
                                    // zero. then assign entries
-  interpolation_matrix.set_zero ();
+  interpolation_matrix = 0;
   for (unsigned int i=0; i<this->dofs_per_cell; ++i)
     for (unsigned int j=0; j<source_fe.dofs_per_cell; ++j)
       if (this->system_to_base_table[i].first ==
index 196b4c70ea5c4f3ac449a199f069315a6c282945..ff26769d583f3e05244b744b4ee34a77a503f163 100644 (file)
@@ -323,7 +323,7 @@ void FETools::get_projection_matrix (const FiniteElement<dim> &fe1,
         ExcMatrixDimensionMismatch(matrix.m(), matrix.n(),
                                    fe2.dofs_per_cell,
                                    fe1.dofs_per_cell));
-  matrix.set_zero();
+  matrix = 0;
   
   unsigned int n1 = fe1.dofs_per_cell;
   unsigned int n2 = fe2.dofs_per_cell;
index 708d767cbba7f2811cbaa26e01e3fa1c8c495483..e2f46bad3c0613323479f20a274275a95b40291f 100644 (file)
@@ -137,7 +137,7 @@ void MatrixCreator::create_mass_matrix_1 (const Mapping<dim>       &mapping,
     {
       fe_values.reinit (cell);
       
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell->get_dof_indices (dof_indices);
       
       if (coefficient != 0)
@@ -325,7 +325,7 @@ MatrixCreator::create_mass_matrix_2 (const Mapping<dim>       &mapping,
     {
       fe_values.reinit (cell);
       
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       local_rhs = 0;
       cell->get_dof_indices (dof_indices);
       
@@ -583,7 +583,7 @@ create_boundary_mass_matrix_1 (const Mapping<dim>        &mapping,
       if (boundary_functions.find(cell->face(face)->boundary_indicator()) !=
          boundary_functions.end())
        {
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          cell_vector = 0;
          
          fe_values.reinit (cell, face);
@@ -959,7 +959,7 @@ void MatrixCreator::create_laplace_matrix_1 (const Mapping<dim>       &mapping,
     {
       fe_values.reinit (cell);
       
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell->get_dof_indices (dof_indices);
       
       if (coefficient != 0)
@@ -1150,7 +1150,7 @@ MatrixCreator::create_laplace_matrix_2 (const Mapping<dim>       &mapping,
     {
       fe_values.reinit (cell);
       
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       local_rhs = 0;
       cell->get_dof_indices (dof_indices);
       
index 186cb5746582cef03809bf4e2619d1370aec706f..ec126bfe5810e4b6001a88c50c6ef12a9571ca74 100644 (file)
@@ -51,8 +51,8 @@ inconvenience this causes.
        built has changed, an inherently risky procedure. The no-argument code
        <class="member">reinit</code> function has therefore been removed to
        avoid confusion with the <code class="member">reinit</code> functions
-       that take arguments. Instead, a <code class="member">set_zero</code>
-       function has been introduced that simply sets all elements of the
+       that take arguments. Instead, you should now use <code
+       class="member">matrix=0</code> to simply sets all elements of the
        matrix to zero. If you want to notify a sparse matrix that its sparsity
        pattern has changed, use the <code
        class="member">reinit(SparsityPattern)</code> function.
@@ -81,12 +81,12 @@ inconvenience this causes.
        remaining instances where deal.II classes have a function of
        that name really mean that the object is reset to its virginial
        state. To set all
-       elements of a vector to zero without changing its size, the
+       elements of a matrix or vector to zero without changing its size, the
        recommended way is to use the more obvious notation <code
-       class="member">v=0</code>, while the full matrix class now has
-       a function <code class="member">FullMatrix::set_zero()</code>. To
+       class="member">vector=0</code> and <code
+       class="member">matrix=0</code>. To
        reset the elements of a table over arbitrary objects, use
-       <code class="member">Table<T>::reset_values()</code>.
+       <code class="member">Table&lt;T&gt;::reset_values()</code>.
        <br> 
        (WB 2004/05/10)
        </p>
index 5888a8d8e825b66afa506231c7a1979259ca001a..425c02cdc1998b19b2df670a125df07a8c6ae976 100644 (file)
@@ -836,7 +836,7 @@ void DGMethod<dim>::assemble_system1 ()
                                       // ``u_v_matrix'' and
                                       // ``cell_vector'' to zero,
                                       // before assembling the cell terms.
-      u_v_matrix.set_zero ();
+      u_v_matrix = 0;
       cell_vector = 0;
       
                                       // Now we reinit the ``FEValues''
@@ -869,7 +869,7 @@ void DGMethod<dim>::assemble_system1 ()
                                           // and clear the
                                           // ``un_v_matrix'' on each
                                           // face.
-         un_v_matrix.set_zero();
+         un_v_matrix = 0;
                  
                                           // Now we distinguish the
                                           // four different cases in
@@ -992,7 +992,7 @@ void DGMethod<dim>::assemble_system1 ()
                                                       // different
                                                       // neighboring
                                                       // cells.
-                     un_v_matrix.set_zero();
+                     un_v_matrix = 0;
                      
                                                       // As already
                                                       // mentioned
@@ -1270,7 +1270,7 @@ void DGMethod<dim>::assemble_system2 ()
     endc = dof_handler.end();
   for (;cell!=endc; ++cell) 
     {
-      u_v_matrix.set_zero ();
+      u_v_matrix = 0;
       cell_vector = 0;
 
       fe_v.reinit (cell);
@@ -1317,9 +1317,9 @@ void DGMethod<dim>::assemble_system2 ()
                              ExcInternalError());
                      Assert (!neighbor_child->has_children(), ExcInternalError());
                      
-                     un_v_matrix.set_zero();
-                     u_vn_matrix.set_zero();
-                     un_vn_matrix.set_zero();
+                     un_v_matrix = 0;
+                     u_vn_matrix = 0;
+                     un_vn_matrix = 0;
                      
                      fe_v_subface.reinit (cell, face_no, subface_no);
                      fe_v_face_neighbor.reinit (neighbor_child, neighbor2);
@@ -1355,9 +1355,9 @@ void DGMethod<dim>::assemble_system2 ()
                    {
                      const unsigned int neighbor2=cell->neighbor_of_neighbor(face_no);
                      
-                     un_v_matrix.set_zero();
-                     u_vn_matrix.set_zero();
-                     un_vn_matrix.set_zero();
+                     un_v_matrix = 0;
+                     u_vn_matrix = 0;
+                     un_vn_matrix = 0;
                      
                      fe_v_face.reinit (cell, face_no);
                      fe_v_face_neighbor.reinit (neighbor, neighbor2);
@@ -1624,7 +1624,7 @@ void DGMethod<dim>::run ()
                                       // reinit the system matrix, the
                                       // right hand side vector and
                                       // the Timer object.
-      system_matrix.set_zero();
+      system_matrix = 0;
       right_hand_side = 0;
       assemble_timer.reset();
 
index b37c0e7bde9bcbc0cd8302228c2752671e4a35f2..3ad079e20087615424730f77271917de0e6ce3d3 100644 (file)
@@ -1289,7 +1289,7 @@ namespace LaplaceSolver
     for (typename DoFHandler<dim>::active_cell_iterator cell=begin_cell;
         cell!=end_cell; ++cell)
       {
-       cell_matrix.set_zero ();
+       cell_matrix = 0;
 
        fe_values.reinit (cell);
 
index cd9906891d200ea5862d6f29f9c039e939aaff30..c06942c9d60fe9a19d1c37a8776bc3c566267f75 100644 (file)
@@ -704,7 +704,7 @@ namespace LaplaceSolver
     for (typename DoFHandler<dim>::active_cell_iterator cell=begin_cell;
         cell!=end_cell; ++cell)
       {
-       cell_matrix.set_zero ();
+       cell_matrix = 0;
 
        fe_values.reinit (cell);
 
index 385cc70586b7fc5661495bacd99b82acb7b3b4f2..74dc3d7aca2cb28c1783ff06fca58c79ea42b97f 100644 (file)
@@ -463,7 +463,7 @@ void MinimizationProblem<dim>::assemble_step ()
                                        // First, clear the objects that hold
                                        // the local matrix and right hand side
                                        // contributions for this cell:
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                        // Then initialize the values and
index e868c737227998404ad2da89b9dbdbaac24066b8..c701b3c89090fab2e4eca352305a2adbd503a06b 100644 (file)
@@ -214,7 +214,7 @@ void LaplaceProblem<dim>::assemble_system ()
                                                 endc = mg_dof_handler.end();
   for (; cell!=endc; ++cell)
     {
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                       // As before, we want the
@@ -324,7 +324,7 @@ void LaplaceProblem<dim>::assemble_multigrid ()
                                       // Remember the level of the
                                       // current cell.
       const unsigned int level = cell->level();
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
 
                                       // Compute the values specified
                                       // by update flags above.
index cdae53c9b9559923143b42a6a8bf40416931a214..cb6527273ba3834bea0cc0dd4306a10cde68d6cd 100644 (file)
@@ -564,7 +564,7 @@ void ElasticProblem<dim>::assemble_system ()
   for (; cell!=endc; ++cell)
     if (cell->subdomain_id() == this_mpi_process)
       {
-        cell_matrix.set_zero ();
+        cell_matrix = 0;
         cell_rhs = 0;
 
         fe_values.reinit (cell);
index 464f596f8e7d8ef3c6e880fe9adcd5e42210b90e..fe9469c87ea58624ff95336074f6544f2b304f7b 100644 (file)
@@ -481,7 +481,7 @@ void LaplaceProblem::assemble_system ()
                                       // to global matrix and global
                                       // right hand side to zero,
                                       // before we fill them.
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                       // Assemble the matrix: For the
index 6cded3bd7f85b86d138719d65a36487f058c878d..5e0b2059d0cb41fa33f52e39cffa13e1bbe109ae 100644 (file)
@@ -406,7 +406,7 @@ void LaplaceProblem<dim>::assemble_system ()
   for (; cell!=endc; ++cell)
     {
       fe_values.reinit (cell);
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                       // Now we have to assemble the
index fa9d1a2ea6efe0bed7bfd7eb897e41649ff01a48..de73e2a711539cdcf58b88b366970878c84bbd25 100644 (file)
@@ -428,7 +428,7 @@ void LaplaceProblem<dim>::assemble_system ()
                                                 endc = dof_handler.end();
   for (; cell!=endc; ++cell)
     {
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                       // As before, we want the
index 431370c6d20ef2cadf103594551941fb28b25a78..9d10f5b0fb360ba8c9f2b88910583ca96e96fa8a 100644 (file)
@@ -509,7 +509,7 @@ void LaplaceProblem<dim>::assemble_system ()
                                                 endc = dof_handler.end();
   for (; cell!=endc; ++cell)
     {
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
       fe_values.reinit (cell);
index 6362ceb7c202e3c25b9128e91d176892036e6467..00620db9c25c757406525276d986c01485cf221e 100644 (file)
@@ -878,7 +878,7 @@ void LaplaceProblem<dim>::assemble_system ()
                                                 endc = dof_handler.end();
   for (; cell!=endc; ++cell)
     {
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
       fe_values.reinit (cell);
index 5ddb46cfbbb41efee86c15daaebad931fb897ad6..78b955bf5bb9ee2f222ccf0f51eb7d0e491d6f8f 100644 (file)
@@ -517,7 +517,7 @@ void ElasticProblem<dim>::assemble_system ()
                                                 endc = dof_handler.end();
   for (; cell!=endc; ++cell)
     {
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
       fe_values.reinit (cell);
index 75b5257ac765dedffcafcbc58a98565bda5a61f6..c0dff4e1cc5d70a53c43476c2ef67a13ae6b587b 100644 (file)
@@ -1035,7 +1035,7 @@ assemble_system_interval (const typename DoFHandler<dim>::active_cell_iterator &
     {
                                       // First clear old contents of
                                       // the cell contributions...
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
                                       // ... then initialize
index 3f477e99b2cab9d603a9161654dd094ea93cd688..92f2917c8ebaf8404cbe7c0bdee74ddfa74f3711 100644 (file)
@@ -339,11 +339,22 @@ class BlockSparseMatrix : public Subscriptor
     operator = (const BlockSparseMatrix<number> &);
 
                                     /**
-                                     * Set all elements of the matrix to
-                                     * zero, but keep the sparsity pattern
+                                     * This operator assigns a scalar to a
+                                     * matrix. Since this does usually not
+                                     * make much sense (should we set all
+                                     * matrix entries to this value? Only the
+                                     * nonzero entries of the sparsity
+                                     * pattern?), this operation is only
+                                     * allowed if the actual value to be
+                                     * assigned is zero. This operator only
+                                     * exists to allow for the obvious
+                                     * notation <tt>matrix=0</tt>, which sets
+                                     * all elements of the matrix to zero,
+                                     * but keep the sparsity pattern
                                      * previously used.
                                      */
-    void set_zero ();
+    BlockSparseMatrix<number> &
+    operator = (const double d);
 
                                     /**
                                      * Reinitialize the sparse matrix
@@ -885,7 +896,10 @@ class BlockSparseMatrix : public Subscriptor
                                      * Exception
                                      */
     DeclException0 (ExcMatrixNotInitialized);
-
+                                     /**
+                                      * Exception
+                                      */
+    DeclException0 (ExcScalarAssignmentOnlyForZeroValue);
     
   private:
                                     /**
index 50bec5d1aab5a3ef28be383f447c97bbc47c7a9a..e6094ac0ccde8eabd41243cc23a68b134553e24a 100644 (file)
@@ -79,12 +79,16 @@ operator = (const BlockSparseMatrix<number> &m)
  
 
 template <typename number>
-void
-BlockSparseMatrix<number>::set_zero ()
+BlockSparseMatrix<number> &
+BlockSparseMatrix<number>::operator = (const double d)
 {
+  Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());
+  
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
-      block(r,c).set_zero ();
+      block(r,c) = 0;
+
+  return *this;
 }
 
 
index 557eb0f4a506f292e0885146f114c9e09b3c241f..ca4f4ce557f94ca1ce741b49e0043fe7fe1e8aac 100644 (file)
@@ -884,9 +884,26 @@ class BlockVector
     get_block_indices () const;
     
                                     /**
-                                     * $U(0-N) = s$: fill all components.
+                                      * Set all components of the vector to
+                                      * the given number @p s. Simply pass
+                                      * this down to the individual block
+                                      * objects, but we still need to declare
+                                      * this function to make the example
+                                      * given in the discussion about making
+                                      * the constructor explicit work.
+                                      *
+                                      *
+                                      * Since the semantics of assigning a
+                                      * scalar to a vector are not
+                                      * immediately clear, this operator
+                                      * should really only be used if you
+                                      * want to set the entire vector to
+                                      * zero. This allows the intuitive
+                                      * notation <tt>v=0</tt>. Assigning
+                                      * other values is deprecated and may
+                                      * be disallowed in the future.
                                      */
-    BlockVector<Number> & operator= (const Number s);
+    BlockVector<Number> & operator = (const Number s);
     
                                     /**
                                      *  $U = V$: copy all components.
index 9647287bad05b4f9ade4ef1a254331f3914692ab..9d0de45e918e74a1607f5e954fae79489ae09675 100644 (file)
@@ -240,15 +240,33 @@ class FullMatrix : public Table<2,number>
                                     /**
                                      * Assignment operator.
                                      */
-    FullMatrix<number>& operator = (const FullMatrix<number>&);
+    FullMatrix<number> &
+    operator = (const FullMatrix<number>&);
     
                                     /**
                                      * Variable assignment operator.
                                      */
     template<typename number2>
-    FullMatrix<number>& operator = (const FullMatrix<number2>&);
+    FullMatrix<number> &
+    operator = (const FullMatrix<number2>&);
 
                                     /**
+                                     * This operator assigns a scalar to a
+                                     * matrix. Since this does usually not
+                                     * make much sense (should we set all
+                                     * matrix entries to this value? Only the
+                                     * nonzero entries of the sparsity
+                                     * pattern?), this operation is only
+                                     * allowed if the actual value to be
+                                     * assigned is zero. This operator only
+                                     * exists to allow for the obvious
+                                     * notation <tt>matrix=0</tt>, which sets
+                                     * all elements of the matrix to zero.
+                                     */
+    FullMatrix<number> &
+    operator = (const double d);
+
+                                     /**
                                      * Assignment from different
                                      * matrix classes. This
                                      * assignment operator uses
@@ -373,13 +391,6 @@ class FullMatrix : public Table<2,number>
                                      * Final iterator of row <tt>r</tt>.
                                      */
     const_iterator end (const unsigned int r) const;
-
-                                    /**
-                                     * Set all entries to zero, but
-                                     * do not change the size of the
-                                     * matrix.
-                                     */
-    void set_zero ();
     
                                     /**
                                      * Scale the entire matrix by a
@@ -970,6 +981,10 @@ class FullMatrix : public Table<2,number>
                    << "Target region not in matrix: size in this direction="
                    << arg1 << ", size of new matrix=" << arg2
                    << ", offset=" << arg3);
+                                     /**
+                                      * Exception
+                                      */
+    DeclException0 (ExcScalarAssignmentOnlyForZeroValue);
                                     /**
                                      * Exception
                                      */
@@ -1012,11 +1027,15 @@ FullMatrix<number>::n() const
 
 
 template <typename number>
-void
-FullMatrix<number>::set_zero ()
+FullMatrix<number> &
+FullMatrix<number>::operator = (const double d)
 {
+  Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());
+
   if (this->n_elements() != 0)
     std::fill_n (this->val, this->n_elements(), number());
+
+  return *this;
 }
 
 
index 51c6ae8cfedc7ba8dcfba5d1e91f1c78aee7ab7f..a5ab43a3f34a03391e829b1b415fd68a18a7be6f 100644 (file)
@@ -305,7 +305,23 @@ namespace PETScWrappers
                                         * can use pointers to this class.
                                         */
       virtual ~MatrixBase ();
-      
+                                       /**
+                                        * This operator assigns a scalar to a
+                                        * matrix. Since this does usually not
+                                        * make much sense (should we set all
+                                        * matrix entries to this value? Only
+                                        * the nonzero entries of the sparsity
+                                        * pattern?), this operation is only
+                                        * allowed if the actual value to be
+                                        * assigned is zero. This operator only
+                                        * exists to allow for the obvious
+                                        * notation <tt>matrix=0</tt>, which
+                                        * sets all elements of the matrix to
+                                        * zero, but keeps the sparsity pattern
+                                        * previously used.
+                                        */
+      MatrixBase &
+      operator = (const double d);      
                                        /**
                                         * Release all memory and return
                                         * to a state just like after
@@ -314,13 +330,6 @@ namespace PETScWrappers
                                         */
       void clear ();
 
-                                       /**
-                                        * Set all matrix entries to zero, but
-                                        * retain the sparsity pattern and all
-                                        * the other properties of the matrix.
-                                        */
-      void set_zero ();
-
                                        /**
                                         * Set the element (<i>i,j</i>)
                                         * to @p value. Throws an
@@ -648,6 +657,10 @@ namespace PETScWrappers
                                         * Exception
                                         */
       DeclException0 (ExcMatrixNotSquare);
+                                       /**
+                                        * Exception
+                                        */
+      DeclException0 (ExcScalarAssignmentOnlyForZeroValue);
       
     protected:
                                        /**
index e7335ce7f77e7f78a4c6062e46623f86b9498445..33c938db9be1513fe3d22df68c03585a39969532 100644 (file)
@@ -124,12 +124,22 @@ namespace PETScWrappers
                       const bool                       is_symmetric = false);
 
                                          /**
-                                          * Set all matrix entries to zero, but
-                                          * retain the sparsity pattern. This
-                                          * function simply calls the respective
-                                          * function of the base class.
+                                          * This operator assigns a scalar to
+                                          * a matrix. Since this does usually
+                                          * not make much sense (should we set
+                                          * all matrix entries to this value?
+                                          * Only the nonzero entries of the
+                                          * sparsity pattern?), this operation
+                                          * is only allowed if the actual
+                                          * value to be assigned is zero. This
+                                          * operator only exists to allow for
+                                          * the obvious notation
+                                          * <tt>matrix=0</tt>, which sets all
+                                          * elements of the matrix to zero,
+                                          * but keep the sparsity pattern
+                                          * previously used.
                                           */
-        void set_zero ();
+        SparseMatrix & operator = (const double d);
 
                                          /**
                                           * Throw away the present matrix and
index 17a5a21b7cfe538851b867c832554655492348d6..62668e18bbbed8713160aef625266d23671fc595 100644 (file)
@@ -109,6 +109,24 @@ namespace PETScWrappers
                     const std::vector<unsigned int> &row_lengths,
                     const bool                       is_symmetric = false);
 
+                                       /**
+                                        * This operator assigns a scalar to
+                                        * a matrix. Since this does usually
+                                        * not make much sense (should we set
+                                        * all matrix entries to this value?
+                                        * Only the nonzero entries of the
+                                        * sparsity pattern?), this operation
+                                        * is only allowed if the actual
+                                        * value to be assigned is zero. This
+                                        * operator only exists to allow for
+                                        * the obvious notation
+                                        * <tt>matrix=0</tt>, which sets all
+                                        * elements of the matrix to zero,
+                                        * but keep the sparsity pattern
+                                        * previously used.
+                                        */
+      SparseMatrix & operator = (const double d);
+
                                        /**
                                         * Throw away the present matrix and
                                         * generate one that has the same
index fdf7ea83070f2afe5a51eb66d604aa9dd0f0f62f..6b6168b9c33cf7fc5cc9721870c4b6fd3be3b313 100644 (file)
@@ -114,6 +114,16 @@ namespace PETScWrappers
                                         * to make the example given in the
                                         * discussion about making the
                                         * constructor explicit work.
+                                        *
+                                        * Since the semantics of assigning a
+                                        * scalar to a vector are not
+                                        * immediately clear, this operator
+                                        * should really only be used if you
+                                        * want to set the entire vector to
+                                        * zero. This allows the intuitive
+                                        * notation <tt>v=0</tt>. Assigning
+                                        * other values is deprecated and may
+                                        * be disallowed in the future.
                                         */
       Vector & operator = (const PetscScalar s);
 
index ab535eac7bfe49e51f982fbd73782a912df80115..cef84df66e7feb1b3c7ec9bbc7a89d4335609a28 100644 (file)
@@ -248,7 +248,23 @@ namespace PETScWrappers
 
                                        /**
                                         * Set all components of the vector to
-                                        * the given number @p s.
+                                        * the given number @p s. Simply pass
+                                        * this down to the individual block
+                                        * objects, but we still need to declare
+                                        * this function to make the example
+                                        * given in the discussion about making
+                                        * the constructor explicit work.
+                                        *
+                                        *
+                                        * Since the semantics of assigning a
+                                        * scalar to a vector are not
+                                        * immediately clear, this operator
+                                        * should really only be used if you
+                                        * want to set the entire vector to
+                                        * zero. This allows the intuitive
+                                        * notation <tt>v=0</tt>. Assigning
+                                        * other values is deprecated and may
+                                        * be disallowed in the future.
                                         */
       VectorBase & operator = (const PetscScalar s);    
       
index 84e1e734a4d73ffeb1d8faacd4ab7db5df81ee6e..35eebf04ed0782c0447b83dd4f26279f62baa066 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -207,7 +207,7 @@ void PreconditionBlock<MATRIX,inverse_type>::invert_diagblocks()
                                           // soon as possible
        };
 
-      M_cell.set_zero ();
+      M_cell = 0;
       
       for (unsigned int cell=0; cell<nblocks; ++cell)
        {
index 4c0f979b5af744963669c004c5e58a126216762a..cf7c480450f8be8473bc8e75696ca0d754b59c61 100644 (file)
@@ -491,11 +491,23 @@ class SparseMatrix : public virtual Subscriptor
                                      */
     SparseMatrix<number>& operator = (const SparseMatrix<number> &);
 
-                                    /**
-                                     * Set all elements to zero, but keep to
-                                     * the sparsity pattern of the matrix.
-                                     */
-    virtual void set_zero ();
+                                     /**
+                                      * This operator assigns a scalar to
+                                      * a matrix. Since this does usually
+                                      * not make much sense (should we set
+                                      * all matrix entries to this value?
+                                      * Only the nonzero entries of the
+                                      * sparsity pattern?), this operation
+                                      * is only allowed if the actual
+                                      * value to be assigned is zero. This
+                                      * operator only exists to allow for
+                                      * the obvious notation
+                                      * <tt>matrix=0</tt>, which sets all
+                                      * elements of the matrix to zero,
+                                      * but keep the sparsity pattern
+                                      * previously used.
+                                      */
+    SparseMatrix & operator = (const double d);
 
                                     /**
                                      * Reinitialize the sparse matrix
@@ -1492,6 +1504,10 @@ class SparseMatrix : public virtual Subscriptor
                                       * Exception
                                       */
     DeclException0 (ExcSourceEqualsDestination);
+                                     /**
+                                      * Exception
+                                      */
+    DeclException0 (ExcScalarAssignmentOnlyForZeroValue);
     
   private:
                                     /**
index 16203a8cf986339f267a0d80416e8e0c6908fd0e..d7a3648b93b839849965a5074d5a3e74de8fa0a8 100644 (file)
@@ -101,14 +101,18 @@ SparseMatrix<number>::~SparseMatrix ()
 
 
 template <typename number>
-void
-SparseMatrix<number>::set_zero ()
+SparseMatrix<number> &
+SparseMatrix<number>::operator = (const double d)
 {
+  Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());
+  
   Assert (cols != 0, ExcMatrixNotInitialized());
   Assert (cols->compressed || cols->empty(), ExcNotCompressed());
 
   if (val)
-    std::fill_n (&val[0], cols->n_nonzero_elements(), 0);
+    std::fill_n (&val[0], cols->n_nonzero_elements(), 0.);
+
+  return *this;
 }
 
 
@@ -250,7 +254,7 @@ void
 SparseMatrix<number>::copy_from (const FullMatrix<somenumber> &matrix)
 {
                                   // first delete previous content
-  set_zero ();
+  *this = 0;
 
                                   // then copy old matrix
   for (unsigned int row=0; row<matrix.m(); ++row)
index de05932d3a35ac2e3d8b767327df568a574c0695..680127f737e463a883829a9d1cf60bed00abb861 100644 (file)
@@ -271,10 +271,26 @@ class Vector
     void swap (Vector<Number> &v);
     
                                     /**
-                                     * Set all components of the vector to
-                                     * the given number @p s.
-                                     */
-    Vector<Number> & operator= (const Number s);
+                                      * Set all components of the vector to
+                                      * the given number @p s. Simply pass
+                                      * this down to the individual block
+                                      * objects, but we still need to declare
+                                      * this function to make the example
+                                      * given in the discussion about making
+                                      * the constructor explicit work.
+                                      *
+                                      *
+                                      * Since the semantics of assigning a
+                                      * scalar to a vector are not
+                                      * immediately clear, this operator
+                                      * should really only be used if you
+                                      * want to set the entire vector to
+                                      * zero. This allows the intuitive
+                                      * notation <tt>v=0</tt>. Assigning
+                                      * other values is deprecated and may
+                                      * be disallowed in the future.
+                                     */
+    Vector<Number> & operator = (const Number s);
     
                                     /**
                                      * Copy the given vector. Resize the
index 82cf58217f63b0feca2126dbb14848988859cc2e..9680e7e421b1013f79e885994219eb486674abb3 100644 (file)
@@ -132,11 +132,15 @@ namespace PETScWrappers
   
 
 
-  void
-  MatrixBase::set_zero ()
+  MatrixBase &
+  MatrixBase::operator = (const double d)
   {
+    Assert (d==0, ExcScalarAssignmentOnlyForZeroValue());    
+    
     const int ierr = MatZeroEntries (matrix);
-    AssertThrow (ierr == 0, ExcPETScError(ierr));    
+    AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+    return *this;
   }
     
 
index e2f96387513d8b23fc9e6be256403806f3dda61d..efcf639e7822e966c92cd01f3fac223255e98870 100644 (file)
@@ -94,7 +94,7 @@ void test ()
        cell != dof_handler.end(); ++cell)
     {
       cell->get_dof_indices (local_dofs);
-      local_matrix.set_zero ();
+      local_matrix = 0;
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
         for (unsigned int j=0; j<fe.dofs_per_cell; ++j)
           local_matrix(i,j) = (i+1.)*(j+1.)*(local_dofs[i]+1.)*(local_dofs[j]+1.);
index 63a98f84f336c2b744b5dedcb4e550f5527b9310..71fea211b09541b8a21cd8fe734ec43025366f66 100644 (file)
@@ -94,7 +94,7 @@ void test ()
        cell != dof_handler.end(); ++cell)
     {
       cell->get_dof_indices (local_dofs);
-      local_matrix.set_zero ();
+      local_matrix = 0;
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
         for (unsigned int j=0; j<fe.dofs_per_cell; ++j)
           local_matrix(i,j) = (i+1.)*(j+1.)*(local_dofs[i]+1.)*(local_dofs[j]+1.);
index c9c0a924263ea33001ed5e513befd1eb72c913c0..d74bb5998a51dedd802de3d099099230fdaf05df 100644 (file)
@@ -88,7 +88,7 @@ void test ()
        cell != dof_handler.end(); ++cell)
     {
       cell->get_dof_indices (local_dofs);
-      local_matrix.set_zero ();
+      local_matrix = 0;
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
         for (unsigned int j=0; j<fe.dofs_per_cell; ++j)
           local_matrix(i,j) = (i+1.)*(j+1.)*(local_dofs[i]+1.)*(local_dofs[j]+1.);
index 613f1306d53c4f6753f81e88fb59e85cdabbf55f..b623ed6f6ce810cb0f58430893b68fbd82249961 100644 (file)
@@ -80,7 +80,7 @@ void test ()
        cell != dof_handler.end(); ++cell)
     {
       cell->get_dof_indices (local_dofs);
-      local_matrix.set_zero ();
+      local_matrix = 0;
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
         for (unsigned int j=0; j<fe.dofs_per_cell; ++j)
           local_matrix(i,j) = (i+1.)*(j+1.)*(local_dofs[i]+1.)*(local_dofs[j]+1.);
index 1b94848d144384ad64b7af4d9b25787929966d54..ae6b7a812b274d0f6bdf6f99e82c296e558c6a88 100644 (file)
@@ -88,7 +88,7 @@ void test ()
        cell != dof_handler.end(); ++cell)
     {
       cell->get_dof_indices (local_dofs);
-      local_matrix.set_zero ();
+      local_matrix = 0;
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
         for (unsigned int j=0; j<fe.dofs_per_cell; ++j)
           local_matrix(i,j) = (i+1.)*(j+1.)*(local_dofs[i]+1.)*(local_dofs[j]+1.);
index 9d07e3e11d149f8555638c832e303e8afd36f317..cc86b554bc136808488eff2b8a09d331c4aa5c00 100644 (file)
@@ -12,7 +12,8 @@
 //----------------------------  petsc_63.cc  ---------------------------
 
 
-// PETScWrappers::SparseMatrix::set_zero () was declared but not defined
+// PETScWrappers::SparseMatrix::operator = (double) was declared but not
+// defined
 
 #include "../tests.h"
 #include <lac/petsc_sparse_matrix.h>
@@ -28,7 +29,7 @@ void test (PETScWrappers::MatrixBase &m)
   Assert (m.m() == 100, ExcInternalError());
   Assert (m.n() == 100, ExcInternalError());
 
-  m.set_zero ();
+  m = 0;
   
   Assert (m.m() == 100, ExcInternalError());
   Assert (m.n() == 100, ExcInternalError());
index 8f364fdd08322753b3c0bfad7ba2032506cbbdde..28ce211112d28ee7192a01a11b66faa1da3462f7 100644 (file)
@@ -276,7 +276,7 @@ void LaplaceProblem<Vector,Matrix,Sparsity>::assemble_system ()
     {
       fe_values.reinit (cell);
 
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       cell_rhs = 0;
 
       for (unsigned int i=0; i<dofs_per_cell; ++i)
index f0402986e3479fd1e4f1f68d0aa8acfc841521c6..6a40ce1925a4766ca6fc73d2e75caa4d1902a709 100644 (file)
@@ -2413,7 +2413,7 @@ double EvaluateEnergyContent<dim>::compute_energy (const PartOfDomain pod) const
       cell->get_dof_values (*this->u, local_u);
       cell->get_dof_values (*this->v, local_v);
 
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       this->density->value_list (fe_values.get_quadrature_points(),
                           density_values);
       for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
@@ -2426,7 +2426,7 @@ double EvaluateEnergyContent<dim>::compute_energy (const PartOfDomain pod) const
 
       total_energy += 1./2. * cell_matrix.matrix_norm_square (local_v);
 
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       this->stiffness->value_list (fe_values.get_quadrature_points(),
                             stiffness_values);
       for (unsigned int point=0; point<fe_values.n_quadrature_points; ++point)
@@ -4772,8 +4772,8 @@ FEValues<dim>  fe_values (fe, quadrature,
        cell != dof_handler->end(); ++cell)
     {
       fe_values.reinit (cell);
-      cell_mass_matrix.set_zero ();
-      cell_laplace_matrix.set_zero ();
+      cell_mass_matrix = 0;
+      cell_laplace_matrix = 0;
       cell->get_dof_indices (dof_indices_on_cell);
 
       if (!density_constant || !stiffness_constant)
@@ -5280,7 +5280,7 @@ TimeStep_Dual<dim>::build_rhs (const typename DoFHandler<dim>::cell_iterator &ol
       old_cell->get_dof_values (previous_time_level.u, tmp);
       cell_matrix.vmult (local_M_u, tmp);
 
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       std::vector<double> stiffness_values(fe_values.n_quadrature_points);
       this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
                                        stiffness_values);
@@ -5396,7 +5396,7 @@ TimeStep_Dual<dim>::collect_from_children (const typename DoFHandler<dim>::cell_
          old_child->get_dof_values (previous_time_level.u, local_old_dof_values_u);
          old_child->get_dof_values (previous_time_level.v, local_old_dof_values_v);
 
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> density_values(fe_values.n_quadrature_points);
          this->parameters.density->value_list (fe_values.get_quadrature_points(),
                                          density_values);
@@ -5411,7 +5411,7 @@ TimeStep_Dual<dim>::collect_from_children (const typename DoFHandler<dim>::cell_
          cell_matrix.vmult (local_M_u, local_old_dof_values_u);
          cell_matrix.vmult (local_M_v, local_old_dof_values_v);
 
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> stiffness_values(fe_values.n_quadrature_points);
          this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
                                                stiffness_values);
@@ -5493,7 +5493,7 @@ TimeStep_Dual<dim>::distribute_to_children (const typename DoFHandler<dim>::cell
       else
        {
          fe_values.reinit (new_child);
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> density_values(fe_values.n_quadrature_points);
          this->parameters.density->value_list (fe_values.get_quadrature_points(),
                                          density_values);
@@ -5508,7 +5508,7 @@ TimeStep_Dual<dim>::distribute_to_children (const typename DoFHandler<dim>::cell
          cell_matrix.vmult (local_M_u, local_old_dof_values_u);
          cell_matrix.vmult (local_M_v, local_old_dof_values_v);
 
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> stiffness_values(fe_values.n_quadrature_points);
          this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
                                            stiffness_values);
@@ -7030,7 +7030,7 @@ TimeStep_Primal<dim>::build_rhs (const typename DoFHandler<dim>::cell_iterator &
       old_cell->get_dof_values (previous_time_level.v, tmp);
       cell_matrix.vmult (local_M_v, tmp);
 
-      cell_matrix.set_zero ();
+      cell_matrix = 0;
       std::vector<double> stiffness_values(fe_values.n_quadrature_points);
       this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
                                            stiffness_values);
@@ -7150,7 +7150,7 @@ FullMatrix<double>   cell_matrix (dofs_per_cell, dofs_per_cell);
          old_child->get_dof_values (previous_time_level.u, local_old_dof_values_u);
          old_child->get_dof_values (previous_time_level.v, local_old_dof_values_v);
       
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> density_values(fe_values.n_quadrature_points);
          this->parameters.density->value_list (fe_values.get_quadrature_points(),
                                          density_values);
@@ -7165,7 +7165,7 @@ FullMatrix<double>   cell_matrix (dofs_per_cell, dofs_per_cell);
          cell_matrix.vmult (local_M_u, local_old_dof_values_u);
          cell_matrix.vmult (local_M_v, local_old_dof_values_v);
       
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
 
          std::vector<double> stiffness_values(fe_values.n_quadrature_points);
          this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
@@ -7248,7 +7248,7 @@ TimeStep_Primal<dim>::distribute_to_children (const typename DoFHandler<dim>::ce
       else
        {
          fe_values.reinit (new_child);
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> density_values(fe_values.n_quadrature_points);
          this->parameters.density->value_list (fe_values.get_quadrature_points(),
                                              density_values);
@@ -7263,7 +7263,7 @@ TimeStep_Primal<dim>::distribute_to_children (const typename DoFHandler<dim>::ce
          cell_matrix.vmult (local_M_u, local_old_dof_values_u);
          cell_matrix.vmult (local_M_v, local_old_dof_values_v);
 
-         cell_matrix.set_zero ();
+         cell_matrix = 0;
          std::vector<double> stiffness_values(fe_values.n_quadrature_points);
          this->parameters.stiffness->value_list (fe_values.get_quadrature_points(),
                                                stiffness_values);
index 1bc3c4bb343986766502bba394cf7306c1224d3a..71d8289c33f423428dee9c8cfcd4dab9fe299a9d 100644 (file)
@@ -68,7 +68,7 @@ create_stokes_matrix_1 (const DoFHandler<dim> &dof_handler,
   
   for (; cell!=endc; ++cell)
     {
-      local_matrix.set_zero ();
+      local_matrix = 0;
       fe_values.reinit (cell);
 
       for (unsigned int i=0; i<dofs_per_cell; ++i)
@@ -141,7 +141,7 @@ create_stokes_matrix_2 (const DoFHandler<dim> &dof_handler,
   
   for (; cell!=endc; ++cell)
     {
-      local_matrix.set_zero ();
+      local_matrix = 0;
       fe_values.reinit (cell);
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
        for (unsigned int comp_i=0; comp_i<fe.n_components(); ++comp_i)
@@ -217,7 +217,7 @@ create_stokes_matrix_3 (const DoFHandler<dim> &dof_handler,
   
   for (; cell!=endc; ++cell)
     {
-      local_matrix.set_zero ();
+      local_matrix = 0;
       fe_values.reinit (cell);
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
        for (unsigned int comp_i=0; comp_i<fe.n_components(); ++comp_i)
index c75282dc1e02a8a862b66d7dda3256d9f76ccc5e..a5575956e60b99fb501abcd39574a70ad311c9d5 100644 (file)
@@ -70,7 +70,7 @@ create_stokes_matrix_2 (const DoFHandler<dim> &dof_handler,
   
   for (; cell!=endc; ++cell)
     {
-      local_matrix.set_zero ();
+      local_matrix = 0;
       fe_values.reinit (cell);
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
        for (unsigned int comp_i=0; comp_i<fe.n_components(); ++comp_i)
@@ -146,7 +146,7 @@ create_stokes_matrix_3 (const DoFHandler<dim> &dof_handler,
   
   for (; cell!=endc; ++cell)
     {
-      local_matrix.set_zero ();
+      local_matrix = 0;
       fe_values.reinit (cell);
       for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
        for (unsigned int comp_i=0; comp_i<fe.n_components(); ++comp_i)
index 6cceef2e2a94809d19ef79c5fe83c06b03b40d8f..47a0e65f73c926afb735b5df1f4617489b8f37a6 100644 (file)
@@ -113,7 +113,7 @@ main ()
       for (unsigned int i=0;i<4;++i)
        {
                                           // Setup rotation matrix
-         C.set_zero();
+         C = 0;
          C.diagadd(1.);
          C(i,i) = C(i+1,i+1) = std::cos(i+1.);
          C(i+1,i) = std::sin(i+1.);

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.