From: Wolfgang Bangerth Date: Mon, 8 Jul 2013 04:24:31 +0000 (+0000) Subject: The testcase is getting shorter and shorter... X-Git-Tag: v8.0.0~170 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f62e129d4daa57ba49ddebb0cced38a2b7963e7;p=dealii.git The testcase is getting shorter and shorter... git-svn-id: https://svn.dealii.org/trunk@29950 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/base/work_stream_03.cc b/tests/base/work_stream_03.cc index e9f324ea0b..61c094d4ef 100644 --- a/tests/base/work_stream_03.cc +++ b/tests/base/work_stream_03.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include #include #include @@ -56,6 +58,7 @@ char logname[] = "work_stream_03/output"; + template class F : public Function { @@ -73,44 +76,150 @@ class F : public Function } }; +namespace +{ + template + struct Scratch + { + Scratch (const ::dealii::hp::FECollection &fe, + const UpdateFlags update_flags, + const ::dealii::hp::QCollection &quadrature) + : + fe_collection (fe), + quadrature_collection (quadrature), + x_fe_values (fe_collection, + quadrature_collection, + update_flags), + rhs_values(quadrature_collection.max_n_quadrature_points()), + update_flags (update_flags) + {} + + Scratch (const Scratch &data) + : + fe_collection (data.fe_collection), + quadrature_collection (data.quadrature_collection), + x_fe_values (fe_collection, + quadrature_collection, + data.update_flags), + rhs_values (data.rhs_values), + update_flags (data.update_flags) + {} + + const ::dealii::hp::FECollection &fe_collection; + const ::dealii::hp::QCollection &quadrature_collection; + + ::dealii::hp::FEValues x_fe_values; + + std::vector rhs_values; + + const UpdateFlags update_flags; + }; + + + struct CopyData + { + Vector cell_rhs; + }; +} + +template + void + mass_assembler(const CellIterator &cell, Scratch &data, + CopyData ©_data) + { + data.x_fe_values.reinit(cell); + const FEValues &fe_values = + data.x_fe_values.get_present_fe_values(); + + const unsigned int dofs_per_cell = fe_values.dofs_per_cell, n_q_points = + fe_values.n_quadrature_points; + const FiniteElement &fe = fe_values.get_fe(); + const unsigned int n_components = fe.n_components(); + + { + copy_data.cell_rhs.reinit(dofs_per_cell); + } + + data.rhs_values.resize(n_q_points); + F().value_list(fe_values.get_quadrature_points(), + data.rhs_values); + + for (unsigned int i = 0; i < dofs_per_cell; ++i) + { + const unsigned int component_i = fe.system_to_component_index(i).first; + const double *phi_i = &fe_values.shape_value(i, 0); + + double add_data = 0; + for (unsigned int point = 0; point < n_q_points; ++point) + add_data += phi_i[point] * fe_values.JxW(point) + * data.rhs_values[point]; + copy_data.cell_rhs(i) = add_data; + } + } + + +template +void copy_local_to_global (const CopyData &data, + VectorType *right_hand_side) +{ +// std::cout << data.cell_rhs.l2_norm() << ' '; + right_hand_side->push_back (data.cell_rhs.l2_norm()); +} + + + +template +void create_mass_matrix (const DoFHandler &dof, + const Quadrature &q, + std::vector &rhs_vector) +{ + hp::FECollection fe_collection (dof.get_fe()); + hp::QCollection q_collection (q); + Scratch + assembler_data (fe_collection, + update_values | + update_JxW_values | update_quadrature_points, + q_collection); + CopyData copy_data; + copy_data.cell_rhs.reinit (assembler_data.fe_collection.max_dofs_per_cell()); + + dealii::WorkStream::run (dof.begin_active(), + static_cast::active_cell_iterator>(dof.end()), + &mass_assembler::active_cell_iterator>, + std_cxx1x::bind(& + copy_local_to_global >, + std_cxx1x::_1, &rhs_vector), + assembler_data, + copy_data, + 2*multithread_info.n_default_threads, + 1); +} + template void do_project (const FiniteElement &fe) { Triangulation triangulation; GridGenerator::hyper_cube (triangulation); - triangulation.refine_global (3); + triangulation.refine_global (2); DoFHandler dof_handler(triangulation); dof_handler.distribute_dofs (fe); - ConstraintMatrix constraints; - constraints.close (); - - SparsityPattern sparsity (dof_handler.n_dofs(), dof_handler.n_dofs(), 30); - DoFTools::make_sparsity_pattern (dof_handler, sparsity); - sparsity.compress(); - - SparseMatrix mass_matrix (sparsity); - Vector tmp (mass_matrix.n()); + std::vector tmp; - const Function* dummy = 0; - MatrixCreator::create_mass_matrix (dof_handler, QGauss(3), - mass_matrix, F(), tmp, - dummy, constraints); + create_mass_matrix (dof_handler, QGauss(3), + tmp); double sum=0; - for (unsigned int i=0; i void test_no_hanging_nodes (const FiniteElement &fe) {