From: Bruno Turcksin Date: Tue, 10 Jan 2017 23:08:04 +0000 (-0500) Subject: Use shared_ptr to store MatrixFree data in MatrixFreeOperators::Base X-Git-Tag: v8.5.0-rc1~253^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3764%2Fhead;p=dealii.git Use shared_ptr to store MatrixFree data in MatrixFreeOperators::Base --- diff --git a/examples/step-37/step-37.cc b/examples/step-37/step-37.cc index 4360a1f021..9d8d1a0c82 100644 --- a/examples/step-37/step-37.cc +++ b/examples/step-37/step-37.cc @@ -719,7 +719,7 @@ namespace Step37 DoFHandler dof_handler; ConstraintMatrix constraints; - MatrixFree system_mf_storage; + std_cxx11::shared_ptr > system_mf_storage; typedef LaplaceOperator SystemMatrixType; SystemMatrixType system_matrix; @@ -760,6 +760,7 @@ namespace Step37 #endif fe (degree_finite_element), dof_handler (triangulation), + system_mf_storage(new MatrixFree()), pcout (std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0), // The LaplaceProblem class holds an additional output stream that // collects detailed timings about the setup phase. This stream, called @@ -840,8 +841,8 @@ namespace Step37 MatrixFree::AdditionalData::none; additional_data.mapping_update_flags = (update_gradients | update_JxW_values | update_quadrature_points); - system_mf_storage.reinit (dof_handler, constraints, QGauss<1>(fe.degree+1), - additional_data); + system_mf_storage->reinit (dof_handler, constraints, QGauss<1>(fe.degree+1), + additional_data); } system_matrix.initialize (system_mf_storage); @@ -893,7 +894,9 @@ namespace Step37 mg_mf_storage[level].reinit(dof_handler, level_constraints, QGauss<1>(fe.degree+1), additional_data); - mg_matrices[level].initialize(mg_mf_storage[level], mg_constrained_dofs, level); + mg_matrices[level].initialize( + std_cxx11::make_shared>(mg_mf_storage[level]), + mg_constrained_dofs, level); mg_matrices[level].evaluate_coefficient(Coefficient()); } setup_time += time.wall_time(); @@ -918,8 +921,8 @@ namespace Step37 Timer time; system_rhs = 0; - FEEvaluation phi(system_mf_storage); - for (unsigned int cell=0; cell phi(*system_mf_storage); + for (unsigned int cell=0; celln_macro_cells(); ++cell) { phi.reinit(cell); for (unsigned int q=0; q &data); + void initialize (std_cxx11::shared_ptr > data); /** * Initialize operator on a level @p level. */ - void initialize (const MatrixFree &data, + void initialize (std_cxx11::shared_ptr > data, const MGConstrainedDoFs &mg_constrained_dofs, const unsigned int level); @@ -199,7 +199,7 @@ namespace MatrixFreeOperators /** * MatrixFree object to be used with this operator. */ - SmartPointer, Base > data; + std_cxx11::shared_ptr > data; /** * A shared pointer to a diagonal matrix that stores the inverse of @@ -758,9 +758,9 @@ namespace MatrixFreeOperators template void Base:: - initialize (const MatrixFree &data_) + initialize (std_cxx11::shared_ptr > data_) { - data = SmartPointer, Base >(&data_,typeid(*this).name()); + data = data_; edge_constrained_indices.clear(); have_interface_matrices = false; } @@ -770,19 +770,19 @@ namespace MatrixFreeOperators template void Base:: - initialize (const MatrixFree &data_, + initialize (std_cxx11::shared_ptr > data_, const MGConstrainedDoFs &mg_constrained_dofs, const unsigned int level) { AssertThrow (level != numbers::invalid_unsigned_int, ExcMessage("level is not set")); - if (data_.n_macro_cells() > 0) + if (data_->n_macro_cells() > 0) { AssertDimension(static_cast(level), - data_.get_cell_iterator(0,0)->level()); + data_->get_cell_iterator(0,0)->level()); } - data = SmartPointer, Base >(&data_,typeid(*this).name()); + data = data_; // setup edge_constrained indices std::vector interface_indices; @@ -795,7 +795,7 @@ namespace MatrixFreeOperators if (locally_owned.is_element(interface_indices[i])) edge_constrained_indices.push_back(locally_owned.index_within_set(interface_indices[i])); have_interface_matrices = Utilities::MPI::max((unsigned int)edge_constrained_indices.size(), - data_.get_vector_partitioner()->get_mpi_communicator()) > 0; + data->get_vector_partitioner()->get_mpi_communicator()) > 0; } diff --git a/include/deal.II/numerics/vector_tools.h b/include/deal.II/numerics/vector_tools.h index 7e22e5e1c5..802a454ee7 100644 --- a/include/deal.II/numerics/vector_tools.h +++ b/include/deal.II/numerics/vector_tools.h @@ -918,7 +918,7 @@ namespace VectorTools * which stores quadrature point data. */ template - void project (const MatrixFree &data, + void project (std_cxx11::shared_ptr > data, const ConstraintMatrix &constraints, const unsigned int n_q_points_1d, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)> func, @@ -928,7 +928,7 @@ namespace VectorTools * Same as above but for n_q_points_1d = matrix_free.get_dof_handler().get_fe().degree+1. */ template - void project (const MatrixFree &data, + void project (std_cxx11::shared_ptr > data, const ConstraintMatrix &constraints, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)> func, VectorType &vec_result); diff --git a/include/deal.II/numerics/vector_tools.templates.h b/include/deal.II/numerics/vector_tools.templates.h index 0b64ae5dc3..aed2ef802b 100644 --- a/include/deal.II/numerics/vector_tools.templates.h +++ b/include/deal.II/numerics/vector_tools.templates.h @@ -936,9 +936,10 @@ namespace VectorTools additional_data.tasks_parallel_scheme = MatrixFree::AdditionalData::partition_color; additional_data.mapping_update_flags = (update_values | update_JxW_values); - MatrixFree matrix_free; - matrix_free.reinit (mapping, dof, constraints, - QGauss<1>(fe_degree+2), additional_data); + std_cxx11::shared_ptr > matrix_free( + new MatrixFree ()); + matrix_free->reinit (mapping, dof, constraints, + QGauss<1>(fe_degree+2), additional_data); typedef MatrixFreeOperators::MassOperator MatrixType; MatrixType mass_matrix; mass_matrix.initialize(matrix_free); @@ -946,9 +947,9 @@ namespace VectorTools typedef LinearAlgebra::distributed::Vector LocalVectorType; LocalVectorType vec, rhs, inhomogeneities; - matrix_free.initialize_dof_vector(vec); - matrix_free.initialize_dof_vector(rhs); - matrix_free.initialize_dof_vector(inhomogeneities); + matrix_free->initialize_dof_vector(vec); + matrix_free->initialize_dof_vector(rhs); + matrix_free->initialize_dof_vector(inhomogeneities); constraints.distribute(inhomogeneities); inhomogeneities*=-1.; @@ -1163,9 +1164,10 @@ namespace VectorTools additional_data.tasks_parallel_scheme = MatrixFree::AdditionalData::partition_color; additional_data.mapping_update_flags = (update_values | update_JxW_values); - MatrixFree matrix_free; - matrix_free.reinit (mapping, dof, constraints, - QGauss<1>(fe_degree+2), additional_data); + std_cxx11::shared_ptr > matrix_free( + new MatrixFree()); + matrix_free->reinit (mapping, dof, constraints, + QGauss<1>(fe_degree+2), additional_data); typedef MatrixFreeOperators::MassOperator MatrixType; MatrixType mass_matrix; mass_matrix.initialize(matrix_free); @@ -1173,9 +1175,9 @@ namespace VectorTools typedef LinearAlgebra::distributed::Vector LocalVectorType; LocalVectorType vec, rhs, inhomogeneities; - matrix_free.initialize_dof_vector(vec); - matrix_free.initialize_dof_vector(rhs); - matrix_free.initialize_dof_vector(inhomogeneities); + matrix_free->initialize_dof_vector(vec); + matrix_free->initialize_dof_vector(rhs); + matrix_free->initialize_dof_vector(inhomogeneities); constraints.distribute(inhomogeneities); inhomogeneities*=-1.; @@ -1240,12 +1242,12 @@ namespace VectorTools template - void project_parallel (const MatrixFree &matrix_free, + void project_parallel (std_cxx11::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)> func, VectorType &vec_result) { - const DoFHandler &dof = matrix_free.get_dof_handler(); + const DoFHandler &dof = matrix_free->get_dof_handler(); typedef typename VectorType::value_type Number; Assert (dof.get_fe().n_components() == 1, @@ -1263,16 +1265,16 @@ namespace VectorTools typedef LinearAlgebra::distributed::Vector LocalVectorType; LocalVectorType vec, rhs, inhomogeneities; - matrix_free.initialize_dof_vector(vec); - matrix_free.initialize_dof_vector(rhs); - matrix_free.initialize_dof_vector(inhomogeneities); + matrix_free->initialize_dof_vector(vec); + matrix_free->initialize_dof_vector(rhs); + matrix_free->initialize_dof_vector(inhomogeneities); constraints.distribute(inhomogeneities); inhomogeneities*=-1.; // assemble right hand side: { - FEEvaluation fe_eval(matrix_free); - const unsigned int n_cells = matrix_free.n_macro_cells(); + FEEvaluation fe_eval(*matrix_free); + const unsigned int n_cells = matrix_free->n_macro_cells(); const unsigned int n_q_points = fe_eval.n_q_points; for (unsigned int cell=0; cell - void project (const MatrixFree &matrix_free, + void project (std_cxx11::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const unsigned int n_q_points_1d, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)> func, VectorType &vec_result) { (void) n_q_points_1d; - const unsigned int fe_degree = matrix_free.get_dof_handler().get_fe().degree; + const unsigned int fe_degree = matrix_free->get_dof_handler().get_fe().degree; Assert (fe_degree+1 == n_q_points_1d, ExcNotImplemented()); @@ -1402,14 +1404,14 @@ namespace VectorTools template - void project (const MatrixFree &matrix_free, + void project (std_cxx11::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)> func, VectorType &vec_result) { project (matrix_free, constraints, - matrix_free.get_dof_handler().get_fe().degree+1, + matrix_free->get_dof_handler().get_fe().degree+1, func, vec_result); } diff --git a/source/numerics/vector_tools_project_qpmf.inst.in b/source/numerics/vector_tools_project_qpmf.inst.in index 2434af942c..e5fd21666a 100644 --- a/source/numerics/vector_tools_project_qpmf.inst.in +++ b/source/numerics/vector_tools_project_qpmf.inst.in @@ -21,14 +21,14 @@ for (VEC: REAL_NONBLOCK_VECTORS; deal_II_dimension : DIMENSIONS) template void project( - const MatrixFree &matrix_free, + std_cxx11::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)>, VEC &); template void project( - const MatrixFree &matrix_free, + std_cxx11::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const unsigned int, const std_cxx11::function< VectorizedArray (const unsigned int, const unsigned int)>, diff --git a/tests/matrix_free/laplace_operator_01.cc b/tests/matrix_free/laplace_operator_01.cc index 6ca7be6bae..dc46c7b70f 100644 --- a/tests/matrix_free/laplace_operator_01.cc +++ b/tests/matrix_free/laplace_operator_01.cc @@ -97,21 +97,21 @@ void test () //std::cout << "Number of degrees of freedom: " << dof.n_dofs() << std::endl; //std::cout << "Number of constraints: " << constraints.n_constraints() << std::endl; - MatrixFree mf_data; + std_cxx11::shared_ptr > mf_data(new MatrixFree ()); { const QGauss<1> quad (fe_degree+1); typename MatrixFree::AdditionalData data; data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; data.tasks_block_size = 7; - mf_data.reinit (dof, constraints, quad, data); + mf_data->reinit (dof, constraints, quad, data); } MatrixFreeOperators::LaplaceOperator mf; mf.initialize(mf_data); mf.compute_diagonal(); LinearAlgebra::distributed::Vector in, out, ref; - mf_data.initialize_dof_vector (in); + mf_data->initialize_dof_vector (in); out.reinit (in); ref.reinit (in); diff --git a/tests/matrix_free/laplace_operator_02.cc b/tests/matrix_free/laplace_operator_02.cc index 0f95334d89..2bd3657246 100644 --- a/tests/matrix_free/laplace_operator_02.cc +++ b/tests/matrix_free/laplace_operator_02.cc @@ -141,7 +141,7 @@ void test () //std::cout << "Number of degrees of freedom: " << dof.n_dofs() << std::endl; //std::cout << "Number of constraints: " << constraints.n_constraints() << std::endl; - MatrixFree mf_data; + std_cxx11::shared_ptr > mf_data(new MatrixFree ()); { const QGauss<1> quad (fe_degree+1); typename MatrixFree::AdditionalData data; @@ -149,15 +149,15 @@ void test () MatrixFree::AdditionalData::none; data.tasks_block_size = 7; data.mapping_update_flags = update_quadrature_points | update_gradients | update_JxW_values; - mf_data.reinit (dof, constraints, quad, data); + mf_data->reinit (dof, constraints, quad, data); } std_cxx11::shared_ptr > > coefficient; coefficient = std_cxx11::make_shared > >(); { - FEEvaluation fe_eval(mf_data); + FEEvaluation fe_eval(*mf_data); - const unsigned int n_cells = mf_data.n_macro_cells(); + const unsigned int n_cells = mf_data->n_macro_cells(); const unsigned int n_q_points = fe_eval.n_q_points; coefficient->reinit(n_cells, n_q_points); @@ -174,7 +174,7 @@ void test () mf.set_coefficient(coefficient); mf.compute_diagonal(); LinearAlgebra::distributed::Vector in, out, ref; - mf_data.initialize_dof_vector (in); + mf_data->initialize_dof_vector (in); out.reinit (in); ref.reinit (in); diff --git a/tests/matrix_free/mass_operator_01.cc b/tests/matrix_free/mass_operator_01.cc index 43d7d4cd7f..6d8db2a358 100644 --- a/tests/matrix_free/mass_operator_01.cc +++ b/tests/matrix_free/mass_operator_01.cc @@ -105,21 +105,21 @@ void test () //std::cout << "Number of degrees of freedom: " << dof.n_dofs() << std::endl; //std::cout << "Number of constraints: " << constraints.n_constraints() << std::endl; - MatrixFree mf_data; + std_cxx11::shared_ptr > mf_data(new MatrixFree ()); { const QGauss<1> quad (fe_degree+2); typename MatrixFree::AdditionalData data; data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; data.tasks_block_size = 7; - mf_data.reinit (dof, constraints, quad, data); + mf_data->reinit (dof, constraints, quad, data); } MatrixFreeOperators::MassOperator mf; mf.initialize(mf_data); mf.compute_diagonal(); LinearAlgebra::distributed::Vector in, out, ref; - mf_data.initialize_dof_vector (in); + mf_data->initialize_dof_vector (in); out.reinit (in); ref.reinit (in); diff --git a/tests/matrix_free/mass_operator_02.cc b/tests/matrix_free/mass_operator_02.cc index 9d356780a1..4504061770 100644 --- a/tests/matrix_free/mass_operator_02.cc +++ b/tests/matrix_free/mass_operator_02.cc @@ -69,14 +69,14 @@ void test () //std::cout << "Number of degrees of freedom: " << dof.n_dofs() << std::endl; //std::cout << "Number of constraints: " << constraints.n_constraints() << std::endl; - MatrixFree mf_data; + std_cxx11::shared_ptr > mf_data(new MatrixFree ()); { const QGauss<1> quad (fe_degree+2); typename MatrixFree::AdditionalData data; data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; data.tasks_block_size = 7; - mf_data.reinit (dof, constraints, quad, data); + mf_data->reinit (dof, constraints, quad, data); } MatrixFreeOperators::MassOperator mf; @@ -86,7 +86,7 @@ void test () = mf.get_matrix_diagonal_inverse()->get_vector(); LinearAlgebra::distributed::Vector in, out, ref; - mf_data.initialize_dof_vector (in); + mf_data->initialize_dof_vector (in); out.reinit (in); ref.reinit (in); diff --git a/tests/matrix_free/mass_operator_03.cc b/tests/matrix_free/mass_operator_03.cc index bd44120313..3de18fe067 100644 --- a/tests/matrix_free/mass_operator_03.cc +++ b/tests/matrix_free/mass_operator_03.cc @@ -68,14 +68,14 @@ void test () //std::cout << "Number of degrees of freedom: " << dof.n_dofs() << std::endl; //std::cout << "Number of constraints: " << constraints.n_constraints() << std::endl; - MatrixFree mf_data; + std_cxx11::shared_ptr > mf_data(new MatrixFree ()); { const QGauss<1> quad (fe_degree+2); typename MatrixFree::AdditionalData data; data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; data.tasks_block_size = 7; - mf_data.reinit (dof, constraints, quad, data); + mf_data->reinit (dof, constraints, quad, data); } MatrixFreeOperators::MassOperator mf; @@ -85,7 +85,7 @@ void test () = mf.get_matrix_diagonal_inverse()->get_vector(); LinearAlgebra::distributed::Vector in, out, ref; - mf_data.initialize_dof_vector (in); + mf_data->initialize_dof_vector (in); out.reinit (in); ref.reinit (in); diff --git a/tests/matrix_free/parallel_multigrid_02.cc b/tests/matrix_free/parallel_multigrid_02.cc index 4742e0fda6..653fa4918f 100644 --- a/tests/matrix_free/parallel_multigrid_02.cc +++ b/tests/matrix_free/parallel_multigrid_02.cc @@ -114,12 +114,12 @@ void do_test (const DoFHandler &dof) MappingQ mapping(fe_degree+1); LaplaceOperator fine_matrix; - MatrixFree fine_level_data; + std_cxx11::shared_ptr > fine_level_data(new MatrixFree ()); typename MatrixFree::AdditionalData fine_level_additional_data; fine_level_additional_data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; - fine_level_data.reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), - fine_level_additional_data); + fine_level_data->reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), + fine_level_additional_data); fine_matrix.initialize(fine_level_data); fine_matrix.compute_diagonal(); @@ -155,7 +155,8 @@ void do_test (const DoFHandler &dof) mg_level_data[level].reinit (mapping, dof, level_constraints, QGauss<1>(n_q_points_1d), mg_additional_data); - mg_matrices[level].initialize(mg_level_data[level], + mg_matrices[level].initialize(std_cxx11::make_shared >( + mg_level_data[level]), mg_constrained_dofs, level); mg_matrices[level].compute_diagonal(); diff --git a/tests/matrix_free/parallel_multigrid_adaptive_02.cc b/tests/matrix_free/parallel_multigrid_adaptive_02.cc index bebcc0cc79..4105d03a80 100644 --- a/tests/matrix_free/parallel_multigrid_adaptive_02.cc +++ b/tests/matrix_free/parallel_multigrid_adaptive_02.cc @@ -151,13 +151,13 @@ void do_test (const DoFHandler &dof) MappingQ mapping(fe_degree+1); LaplaceOperator fine_matrix; - MatrixFree fine_level_data; + std_cxx11::shared_ptr > fine_level_data(new MatrixFree ()); typename MatrixFree::AdditionalData fine_level_additional_data; fine_level_additional_data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; fine_level_additional_data.tasks_block_size = 3; - fine_level_data.reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), - fine_level_additional_data); + fine_level_data->reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), + fine_level_additional_data); fine_matrix.initialize(fine_level_data); fine_matrix.compute_diagonal(); @@ -204,7 +204,8 @@ void do_test (const DoFHandler &dof) mg_level_data[level].reinit (mapping, dof, level_constraints, QGauss<1>(n_q_points_1d), mg_additional_data); - mg_matrices[level].initialize(mg_level_data[level], + mg_matrices[level].initialize(std_cxx11::make_shared >( + mg_level_data[level]), mg_constrained_dofs, level); mg_matrices[level].compute_diagonal(); diff --git a/tests/matrix_free/parallel_multigrid_adaptive_04.cc b/tests/matrix_free/parallel_multigrid_adaptive_04.cc index e5b9489755..e11ff631db 100644 --- a/tests/matrix_free/parallel_multigrid_adaptive_04.cc +++ b/tests/matrix_free/parallel_multigrid_adaptive_04.cc @@ -151,13 +151,13 @@ void do_test (const DoFHandler &dof) MappingQ mapping(fe_degree+1); LaplaceOperator fine_matrix; - MatrixFree fine_level_data; + std_cxx11::shared_ptr > fine_level_data(new MatrixFree ()); typename MatrixFree::AdditionalData fine_level_additional_data; fine_level_additional_data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; fine_level_additional_data.tasks_block_size = 3; - fine_level_data.reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), - fine_level_additional_data); + fine_level_data->reinit (mapping, dof, constraints, QGauss<1>(n_q_points_1d), + fine_level_additional_data); fine_matrix.initialize(fine_level_data); fine_matrix.compute_diagonal(); @@ -204,7 +204,8 @@ void do_test (const DoFHandler &dof) mg_level_data[level].reinit (mapping, dof, level_constraints, QGauss<1>(n_q_points_1d), mg_additional_data); - mg_matrices[level].initialize(mg_level_data[level], + mg_matrices[level].initialize(std_cxx11::make_shared > ( + mg_level_data[level]), mg_constrained_dofs, level); mg_matrices[level].compute_diagonal();