From: wolf Date: Sat, 15 May 2004 17:20:22 +0000 (+0000) Subject: Rename set_zero to operator=(double) and only allow zero argument. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80488b2f2f9b0480a975860eb872f7c4c8737f7b;p=dealii-svn.git Rename set_zero to operator=(double) and only allow zero argument. git-svn-id: https://svn.dealii.org/trunk@9242 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/fe/fe_system.cc b/deal.II/deal.II/source/fe/fe_system.cc index cb52c8387f..2f53858306 100644 --- a/deal.II/deal.II/source/fe/fe_system.cc +++ b/deal.II/deal.II/source/fe/fe_system.cc @@ -519,7 +519,7 @@ get_interpolation_matrix (const FiniteElementBase &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; idofs_per_cell; ++i) for (unsigned int j=0; jsystem_to_base_table[i].first == diff --git a/deal.II/deal.II/source/fe/fe_tools.cc b/deal.II/deal.II/source/fe/fe_tools.cc index 196b4c70ea..ff26769d58 100644 --- a/deal.II/deal.II/source/fe/fe_tools.cc +++ b/deal.II/deal.II/source/fe/fe_tools.cc @@ -323,7 +323,7 @@ void FETools::get_projection_matrix (const FiniteElement &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; diff --git a/deal.II/deal.II/source/numerics/matrices.cc b/deal.II/deal.II/source/numerics/matrices.cc index 708d767cbb..e2f46bad3c 100644 --- a/deal.II/deal.II/source/numerics/matrices.cc +++ b/deal.II/deal.II/source/numerics/matrices.cc @@ -137,7 +137,7 @@ void MatrixCreator::create_mass_matrix_1 (const Mapping &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 &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 &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 &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 &mapping, { fe_values.reinit (cell); - cell_matrix.set_zero (); + cell_matrix = 0; local_rhs = 0; cell->get_dof_indices (dof_indices); diff --git a/deal.II/doc/news/c-4-0.html b/deal.II/doc/news/c-4-0.html index 186cb57465..ec126bfe58 100644 --- a/deal.II/doc/news/c-4-0.html +++ b/deal.II/doc/news/c-4-0.html @@ -51,8 +51,8 @@ inconvenience this causes. built has changed, an inherently risky procedure. The no-argument code reinit function has therefore been removed to avoid confusion with the reinit functions - that take arguments. Instead, a set_zero - function has been introduced that simply sets all elements of the + that take arguments. Instead, you should now use matrix=0 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 reinit(SparsityPattern) 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 v=0, while the full matrix class now has - a function FullMatrix::set_zero(). To + class="member">vector=0 and matrix=0. To reset the elements of a table over arbitrary objects, use - Table::reset_values(). + Table<T>::reset_values().
(WB 2004/05/10)

diff --git a/deal.II/examples/step-12/step-12.cc b/deal.II/examples/step-12/step-12.cc index 5888a8d8e8..425c02cdc1 100644 --- a/deal.II/examples/step-12/step-12.cc +++ b/deal.II/examples/step-12/step-12.cc @@ -836,7 +836,7 @@ void DGMethod::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::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::assemble_system1 () // different // neighboring // cells. - un_v_matrix.set_zero(); + un_v_matrix = 0; // As already // mentioned @@ -1270,7 +1270,7 @@ void DGMethod::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::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::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::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(); diff --git a/deal.II/examples/step-13/step-13.cc b/deal.II/examples/step-13/step-13.cc index b37c0e7bde..3ad079e200 100644 --- a/deal.II/examples/step-13/step-13.cc +++ b/deal.II/examples/step-13/step-13.cc @@ -1289,7 +1289,7 @@ namespace LaplaceSolver for (typename DoFHandler::active_cell_iterator cell=begin_cell; cell!=end_cell; ++cell) { - cell_matrix.set_zero (); + cell_matrix = 0; fe_values.reinit (cell); diff --git a/deal.II/examples/step-14/step-14.cc b/deal.II/examples/step-14/step-14.cc index cd9906891d..c06942c9d6 100644 --- a/deal.II/examples/step-14/step-14.cc +++ b/deal.II/examples/step-14/step-14.cc @@ -704,7 +704,7 @@ namespace LaplaceSolver for (typename DoFHandler::active_cell_iterator cell=begin_cell; cell!=end_cell; ++cell) { - cell_matrix.set_zero (); + cell_matrix = 0; fe_values.reinit (cell); diff --git a/deal.II/examples/step-15/step-15.cc b/deal.II/examples/step-15/step-15.cc index 385cc70586..74dc3d7aca 100644 --- a/deal.II/examples/step-15/step-15.cc +++ b/deal.II/examples/step-15/step-15.cc @@ -463,7 +463,7 @@ void MinimizationProblem::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 diff --git a/deal.II/examples/step-16/step-16.cc b/deal.II/examples/step-16/step-16.cc index e868c73722..c701b3c890 100644 --- a/deal.II/examples/step-16/step-16.cc +++ b/deal.II/examples/step-16/step-16.cc @@ -214,7 +214,7 @@ void LaplaceProblem::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::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. diff --git a/deal.II/examples/step-17/step-17.cc b/deal.II/examples/step-17/step-17.cc index cdae53c9b9..cb6527273b 100644 --- a/deal.II/examples/step-17/step-17.cc +++ b/deal.II/examples/step-17/step-17.cc @@ -564,7 +564,7 @@ void ElasticProblem::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); diff --git a/deal.II/examples/step-3/step-3.cc b/deal.II/examples/step-3/step-3.cc index 464f596f8e..fe9469c87e 100644 --- a/deal.II/examples/step-3/step-3.cc +++ b/deal.II/examples/step-3/step-3.cc @@ -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 diff --git a/deal.II/examples/step-4/step-4.cc b/deal.II/examples/step-4/step-4.cc index 6cded3bd7f..5e0b2059d0 100644 --- a/deal.II/examples/step-4/step-4.cc +++ b/deal.II/examples/step-4/step-4.cc @@ -406,7 +406,7 @@ void LaplaceProblem::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 diff --git a/deal.II/examples/step-5/step-5.cc b/deal.II/examples/step-5/step-5.cc index fa9d1a2ea6..de73e2a711 100644 --- a/deal.II/examples/step-5/step-5.cc +++ b/deal.II/examples/step-5/step-5.cc @@ -428,7 +428,7 @@ void LaplaceProblem::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 diff --git a/deal.II/examples/step-6/step-6.cc b/deal.II/examples/step-6/step-6.cc index 431370c6d2..9d10f5b0fb 100644 --- a/deal.II/examples/step-6/step-6.cc +++ b/deal.II/examples/step-6/step-6.cc @@ -509,7 +509,7 @@ void LaplaceProblem::assemble_system () endc = dof_handler.end(); for (; cell!=endc; ++cell) { - cell_matrix.set_zero (); + cell_matrix = 0; cell_rhs = 0; fe_values.reinit (cell); diff --git a/deal.II/examples/step-7/step-7.cc b/deal.II/examples/step-7/step-7.cc index 6362ceb7c2..00620db9c2 100644 --- a/deal.II/examples/step-7/step-7.cc +++ b/deal.II/examples/step-7/step-7.cc @@ -878,7 +878,7 @@ void LaplaceProblem::assemble_system () endc = dof_handler.end(); for (; cell!=endc; ++cell) { - cell_matrix.set_zero (); + cell_matrix = 0; cell_rhs = 0; fe_values.reinit (cell); diff --git a/deal.II/examples/step-8/step-8.cc b/deal.II/examples/step-8/step-8.cc index 5ddb46cfbb..78b955bf5b 100644 --- a/deal.II/examples/step-8/step-8.cc +++ b/deal.II/examples/step-8/step-8.cc @@ -517,7 +517,7 @@ void ElasticProblem::assemble_system () endc = dof_handler.end(); for (; cell!=endc; ++cell) { - cell_matrix.set_zero (); + cell_matrix = 0; cell_rhs = 0; fe_values.reinit (cell); diff --git a/deal.II/examples/step-9/step-9.cc b/deal.II/examples/step-9/step-9.cc index 75b5257ac7..c0dff4e1cc 100644 --- a/deal.II/examples/step-9/step-9.cc +++ b/deal.II/examples/step-9/step-9.cc @@ -1035,7 +1035,7 @@ assemble_system_interval (const typename DoFHandler::active_cell_iterator & { // First clear old contents of // the cell contributions... - cell_matrix.set_zero (); + cell_matrix = 0; cell_rhs = 0; // ... then initialize diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index 3f477e99b2..92f2917c8e 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -339,11 +339,22 @@ class BlockSparseMatrix : public Subscriptor operator = (const BlockSparseMatrix &); /** - * 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 matrix=0, which sets + * all elements of the matrix to zero, + * but keep the sparsity pattern * previously used. */ - void set_zero (); + BlockSparseMatrix & + operator = (const double d); /** * Reinitialize the sparse matrix @@ -885,7 +896,10 @@ class BlockSparseMatrix : public Subscriptor * Exception */ DeclException0 (ExcMatrixNotInitialized); - + /** + * Exception + */ + DeclException0 (ExcScalarAssignmentOnlyForZeroValue); private: /** diff --git a/deal.II/lac/include/lac/block_sparse_matrix.templates.h b/deal.II/lac/include/lac/block_sparse_matrix.templates.h index 50bec5d1aa..e6094ac0cc 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.templates.h @@ -79,12 +79,16 @@ operator = (const BlockSparseMatrix &m) template -void -BlockSparseMatrix::set_zero () +BlockSparseMatrix & +BlockSparseMatrix::operator = (const double d) { + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + for (unsigned int r=0; rv=0. Assigning + * other values is deprecated and may + * be disallowed in the future. */ - BlockVector & operator= (const Number s); + BlockVector & operator = (const Number s); /** * $U = V$: copy all components. diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index 9647287bad..9d0de45e91 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -240,15 +240,33 @@ class FullMatrix : public Table<2,number> /** * Assignment operator. */ - FullMatrix& operator = (const FullMatrix&); + FullMatrix & + operator = (const FullMatrix&); /** * Variable assignment operator. */ template - FullMatrix& operator = (const FullMatrix&); + FullMatrix & + operator = (const FullMatrix&); /** + * 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 matrix=0, which sets + * all elements of the matrix to zero. + */ + FullMatrix & + 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 r. */ 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::n() const template -void -FullMatrix::set_zero () +FullMatrix & +FullMatrix::operator = (const double d) { + Assert (d==0, ExcScalarAssignmentOnlyForZeroValue()); + if (this->n_elements() != 0) std::fill_n (this->val, this->n_elements(), number()); + + return *this; } diff --git a/deal.II/lac/include/lac/petsc_matrix_base.h b/deal.II/lac/include/lac/petsc_matrix_base.h index 51c6ae8cfe..a5ab43a3f3 100644 --- a/deal.II/lac/include/lac/petsc_matrix_base.h +++ b/deal.II/lac/include/lac/petsc_matrix_base.h @@ -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 matrix=0, 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,j) * to @p value. Throws an @@ -648,6 +657,10 @@ namespace PETScWrappers * Exception */ DeclException0 (ExcMatrixNotSquare); + /** + * Exception + */ + DeclException0 (ExcScalarAssignmentOnlyForZeroValue); protected: /** diff --git a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h index e7335ce7f7..33c938db9b 100644 --- a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h @@ -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 + * matrix=0, 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 diff --git a/deal.II/lac/include/lac/petsc_sparse_matrix.h b/deal.II/lac/include/lac/petsc_sparse_matrix.h index 17a5a21b7c..62668e18bb 100644 --- a/deal.II/lac/include/lac/petsc_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_sparse_matrix.h @@ -109,6 +109,24 @@ namespace PETScWrappers const std::vector &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 + * matrix=0, 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 diff --git a/deal.II/lac/include/lac/petsc_vector.h b/deal.II/lac/include/lac/petsc_vector.h index fdf7ea8307..6b6168b9c3 100644 --- a/deal.II/lac/include/lac/petsc_vector.h +++ b/deal.II/lac/include/lac/petsc_vector.h @@ -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 v=0. Assigning + * other values is deprecated and may + * be disallowed in the future. */ Vector & operator = (const PetscScalar s); diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index ab535eac7b..cef84df66e 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -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 v=0. Assigning + * other values is deprecated and may + * be disallowed in the future. */ VectorBase & operator = (const PetscScalar s); diff --git a/deal.II/lac/include/lac/precondition_block.templates.h b/deal.II/lac/include/lac/precondition_block.templates.h index 84e1e734a4..35eebf04ed 100644 --- a/deal.II/lac/include/lac/precondition_block.templates.h +++ b/deal.II/lac/include/lac/precondition_block.templates.h @@ -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::invert_diagblocks() // soon as possible }; - M_cell.set_zero (); + M_cell = 0; for (unsigned int cell=0; cell& operator = (const SparseMatrix &); - /** - * 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 + * matrix=0, 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: /** diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 16203a8cf9..d7a3648b93 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -101,14 +101,18 @@ SparseMatrix::~SparseMatrix () template -void -SparseMatrix::set_zero () +SparseMatrix & +SparseMatrix::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::copy_from (const FullMatrix &matrix) { // first delete previous content - set_zero (); + *this = 0; // then copy old matrix for (unsigned int row=0; row &v); /** - * Set all components of the vector to - * the given number @p s. - */ - Vector & 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 v=0. Assigning + * other values is deprecated and may + * be disallowed in the future. + */ + Vector & operator = (const Number s); /** * Copy the given vector. Resize the diff --git a/deal.II/lac/source/petsc_matrix_base.cc b/deal.II/lac/source/petsc_matrix_base.cc index 82cf58217f..9680e7e421 100644 --- a/deal.II/lac/source/petsc_matrix_base.cc +++ b/deal.II/lac/source/petsc_matrix_base.cc @@ -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; } diff --git a/tests/bits/apply_boundary_values_01.cc b/tests/bits/apply_boundary_values_01.cc index e2f9638751..efcf639e78 100644 --- a/tests/bits/apply_boundary_values_01.cc +++ b/tests/bits/apply_boundary_values_01.cc @@ -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; iget_dof_indices (local_dofs); - local_matrix.set_zero (); + local_matrix = 0; for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.set_zero (); + local_matrix = 0; for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.set_zero (); + local_matrix = 0; for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.set_zero (); + local_matrix = 0; for (unsigned int i=0; i @@ -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()); diff --git a/tests/deal.II/block_matrices.cc b/tests/deal.II/block_matrices.cc index 8f364fdd08..28ce211112 100644 --- a/tests/deal.II/block_matrices.cc +++ b/tests/deal.II/block_matrices.cc @@ -276,7 +276,7 @@ void LaplaceProblem::assemble_system () { fe_values.reinit (cell); - cell_matrix.set_zero (); + cell_matrix = 0; cell_rhs = 0; for (unsigned int i=0; i::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::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 (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::build_rhs (const typename DoFHandler::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 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::collect_from_children (const typename DoFHandler::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 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::collect_from_children (const typename DoFHandler::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 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::distribute_to_children (const typename DoFHandler::cell else { fe_values.reinit (new_child); - cell_matrix.set_zero (); + cell_matrix = 0; std::vector 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::distribute_to_children (const typename DoFHandler::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 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::build_rhs (const typename DoFHandler::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 stiffness_values(fe_values.n_quadrature_points); this->parameters.stiffness->value_list (fe_values.get_quadrature_points(), stiffness_values); @@ -7150,7 +7150,7 @@ FullMatrix 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 density_values(fe_values.n_quadrature_points); this->parameters.density->value_list (fe_values.get_quadrature_points(), density_values); @@ -7165,7 +7165,7 @@ FullMatrix 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 stiffness_values(fe_values.n_quadrature_points); this->parameters.stiffness->value_list (fe_values.get_quadrature_points(), @@ -7248,7 +7248,7 @@ TimeStep_Primal::distribute_to_children (const typename DoFHandler::ce else { fe_values.reinit (new_child); - cell_matrix.set_zero (); + cell_matrix = 0; std::vector 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::distribute_to_children (const typename DoFHandler::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 stiffness_values(fe_values.n_quadrature_points); this->parameters.stiffness->value_list (fe_values.get_quadrature_points(), stiffness_values); diff --git a/tests/fe/non_primitive_1.cc b/tests/fe/non_primitive_1.cc index 1bc3c4bb34..71d8289c33 100644 --- a/tests/fe/non_primitive_1.cc +++ b/tests/fe/non_primitive_1.cc @@ -68,7 +68,7 @@ create_stokes_matrix_1 (const DoFHandler &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.set_zero (); + local_matrix = 0; fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.set_zero (); + local_matrix = 0; fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.set_zero (); + local_matrix = 0; fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.set_zero (); + local_matrix = 0; fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.set_zero (); + local_matrix = 0; fe_values.reinit (cell); for (unsigned int i=0; i