From: wolf Date: Tue, 11 May 2004 18:15:49 +0000 (+0000) Subject: Rename FullMatrix::clear to FullMatrix::set_zero. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98bb2c57b99a11de8254005e544790f4c7a61290;p=dealii-svn.git Rename FullMatrix::clear to FullMatrix::set_zero. git-svn-id: https://svn.dealii.org/trunk@9237 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 00726f3858..cb52c8387f 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.clear (); + interpolation_matrix.set_zero (); 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 5cf64539cf..196b4c70ea 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.clear(); + matrix.set_zero(); unsigned int n1 = fe1.dofs_per_cell; unsigned int n2 = fe2.dofs_per_cell; diff --git a/deal.II/deal.II/source/numerics/derivative_approximation.cc b/deal.II/deal.II/source/numerics/derivative_approximation.cc index b7e9509d58..d569fcc80d 100644 --- a/deal.II/deal.II/source/numerics/derivative_approximation.cc +++ b/deal.II/deal.II/source/numerics/derivative_approximation.cc @@ -696,14 +696,14 @@ DerivativeApproximation::approximate (const Mapping &mapping, DerivativeDescription::symmetrize (projected_derivative); // compute Y^-1 g - typename DerivativeDescription::Derivative derivative; - Tensor<2,dim> Y_inverse = invert(Y); + const Tensor<2,dim> Y_inverse = invert(Y); + typename DerivativeDescription::Derivative derivative; contract (derivative, Y_inverse, projected_derivative); *derivative_norm_on_this_cell = DerivativeDescription::derivative_norm (derivative); - }; + } } diff --git a/deal.II/deal.II/source/numerics/matrices.cc b/deal.II/deal.II/source/numerics/matrices.cc index a501dbecbf..708d767cbb 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); local_rhs = 0; cell->get_dof_indices (dof_indices); diff --git a/deal.II/examples/step-12/step-12.cc b/deal.II/examples/step-12/step-12.cc index 40b388d51e..5888a8d8e8 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.clear (); + u_v_matrix.set_zero (); 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.clear(); + un_v_matrix.set_zero(); // Now we distinguish the // four different cases in @@ -992,7 +992,7 @@ void DGMethod::assemble_system1 () // different // neighboring // cells. - un_v_matrix.clear(); + un_v_matrix.set_zero(); // As already // mentioned @@ -1270,7 +1270,7 @@ void DGMethod::assemble_system2 () endc = dof_handler.end(); for (;cell!=endc; ++cell) { - u_v_matrix.clear (); + u_v_matrix.set_zero (); 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.clear(); - u_vn_matrix.clear(); - un_vn_matrix.clear(); + un_v_matrix.set_zero(); + u_vn_matrix.set_zero(); + un_vn_matrix.set_zero(); 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.clear(); - u_vn_matrix.clear(); - un_vn_matrix.clear(); + un_v_matrix.set_zero(); + u_vn_matrix.set_zero(); + un_vn_matrix.set_zero(); fe_v_face.reinit (cell, face_no); fe_v_face_neighbor.reinit (neighbor, neighbor2); diff --git a/deal.II/examples/step-13/step-13.cc b/deal.II/examples/step-13/step-13.cc index 4d1c8cc4ca..b37c0e7bde 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.clear (); + cell_matrix.set_zero (); 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 8b31ac182d..cd9906891d 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.clear (); + cell_matrix.set_zero (); 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 fa8a5ed0cc..385cc70586 100644 --- a/deal.II/examples/step-15/step-15.cc +++ b/deal.II/examples/step-15/step-15.cc @@ -100,7 +100,7 @@ double gradient_power (const Tensor<1,dim> &v, Assert ((n/2)*2 == n, ExcMessage ("Value of 'n' must be even")); double p = 1; for (unsigned int k=0; k::assemble_step () // First, clear the objects that hold // the local matrix and right hand side // contributions for this cell: - cell_matrix.clear (); + cell_matrix.set_zero (); cell_rhs = 0; // Then initialize the values and @@ -699,7 +699,7 @@ MinimizationProblem::line_search (const Vector &update) const { // At the present location, which is // ``present_solution+alpha*update'', - // evaluate the energy" + // evaluate the energy tmp = present_solution; tmp.add (alpha, update); const double f_a = energy (dof_handler, tmp); diff --git a/deal.II/examples/step-16/step-16.cc b/deal.II/examples/step-16/step-16.cc index db9efb2377..e868c73722 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); // 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 4eee20ff95..cdae53c9b9 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.clear (); + cell_matrix.set_zero (); 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 0e6152cbde..464f596f8e 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.clear (); + cell_matrix.set_zero (); 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 4f9458703f..6cded3bd7f 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.clear (); + cell_matrix.set_zero (); 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 f83be3f327..fa9d1a2ea6 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.clear (); + cell_matrix.set_zero (); 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 35f1494a30..431370c6d2 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.clear (); + cell_matrix.set_zero (); 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 c577f0b0a8..6362ceb7c2 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.clear (); + cell_matrix.set_zero (); 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 4746120737..5ddb46cfbb 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.clear (); + cell_matrix.set_zero (); 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 c48a953381..75b5257ac7 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.clear (); + cell_matrix.set_zero (); cell_rhs = 0; // ... then initialize diff --git a/deal.II/lac/include/lac/block_matrix_array.h b/deal.II/lac/include/lac/block_matrix_array.h index 829d06af59..7668069b8f 100644 --- a/deal.II/lac/include/lac/block_matrix_array.h +++ b/deal.II/lac/include/lac/block_matrix_array.h @@ -81,7 +81,8 @@ class BlockMatrixArray : public Subscriptor bool transpose = false); /** - * Delete all entries + * Delete all entries, i.e. reset + * the matrix to an empty state. */ void clear(); diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h index 4589cdfc4f..dd44ad0256 100644 --- a/deal.II/lac/include/lac/full_matrix.h +++ b/deal.II/lac/include/lac/full_matrix.h @@ -373,6 +373,13 @@ 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 @@ -976,6 +983,9 @@ class FullMatrix : public Table<2,number> DeclException0 (ExcSourceEqualsDestination); friend class Accessor; + + private: + void clear (); }; /*@}*/ @@ -985,7 +995,8 @@ class FullMatrix : public Table<2,number> template -inline unsigned int +inline +unsigned int FullMatrix::m() const { return this->n_rows(); @@ -994,13 +1005,25 @@ FullMatrix::m() const template -inline unsigned int +inline +unsigned int FullMatrix::n() const { return this->n_cols(); } + +template +void +FullMatrix::set_zero () +{ + if (this->n_elements() != 0) + std::fill_n (this->val, this->n_elements(), number()); +} + + + template template inline @@ -1009,6 +1032,8 @@ void FullMatrix::fill (const number2* src) Table<2,number>::fill(src); } + + template template void diff --git a/deal.II/lac/include/lac/precondition_block.templates.h b/deal.II/lac/include/lac/precondition_block.templates.h index 4f34759200..84e1e734a4 100644 --- a/deal.II/lac/include/lac/precondition_block.templates.h +++ b/deal.II/lac/include/lac/precondition_block.templates.h @@ -207,7 +207,7 @@ void PreconditionBlock::invert_diagblocks() // soon as possible }; - M_cell.clear (); + M_cell.set_zero (); for (unsigned int cell=0; cellget_dof_indices (local_dofs); - local_matrix.clear (); + local_matrix.set_zero (); for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.clear (); + local_matrix.set_zero (); for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.clear (); + local_matrix.set_zero (); for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.clear (); + local_matrix.set_zero (); for (unsigned int i=0; iget_dof_indices (local_dofs); - local_matrix.clear (); + local_matrix.set_zero (); for (unsigned int i=0; i @@ -28,7 +28,7 @@ void test (PETScWrappers::MatrixBase &m) Assert (m.m() == 100, ExcInternalError()); Assert (m.n() == 100, ExcInternalError()); - m.reinit (); + m.set_zero (); 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 6c133ef607..8f364fdd08 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); - cell_laplace_matrix.clear (); + cell_mass_matrix.set_zero (); + cell_laplace_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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.clear (); + cell_matrix.set_zero (); 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 781b740d0e..1bc3c4bb34 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.clear (); + local_matrix.set_zero (); fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.clear (); + local_matrix.set_zero (); fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.clear (); + local_matrix.set_zero (); fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.clear (); + local_matrix.set_zero (); fe_values.reinit (cell); for (unsigned int i=0; i &dof_handler, for (; cell!=endc; ++cell) { - local_matrix.clear (); + local_matrix.set_zero (); fe_values.reinit (cell); for (unsigned int i=0; i