From 80890215df5494b67767152cf40ff01c3db20814 Mon Sep 17 00:00:00 2001 From: kronbichler Date: Wed, 4 Dec 2013 17:21:32 +0000 Subject: [PATCH] Two more test cases. Use common naming scheme for parallel assembly tests git-svn-id: https://svn.dealii.org/trunk@31882 0785d39b-7218-0410-832d-ea1e28bc413d --- ...llel.cc => assemble_matrix_parallel_01.cc} | 0 ...put => assemble_matrix_parallel_01.output} | 0 tests/deal.II/assemble_matrix_parallel_02.cc | 520 +++++++++++++++++ .../assemble_matrix_parallel_02.output | 13 + ...llel.cc => assemble_matrix_parallel_03.cc} | 2 +- ...put => assemble_matrix_parallel_03.output} | 0 tests/deal.II/assemble_matrix_parallel_04.cc | 525 ++++++++++++++++++ .../assemble_matrix_parallel_04.output | 13 + 8 files changed, 1072 insertions(+), 1 deletion(-) rename tests/deal.II/{assemble_matrix_parallel.cc => assemble_matrix_parallel_01.cc} (100%) rename tests/deal.II/{assemble_block_matrix_parallel.output => assemble_matrix_parallel_01.output} (100%) create mode 100644 tests/deal.II/assemble_matrix_parallel_02.cc create mode 100644 tests/deal.II/assemble_matrix_parallel_02.output rename tests/deal.II/{assemble_block_matrix_parallel.cc => assemble_matrix_parallel_03.cc} (99%) rename tests/deal.II/{assemble_matrix_parallel.output => assemble_matrix_parallel_03.output} (100%) create mode 100644 tests/deal.II/assemble_matrix_parallel_04.cc create mode 100644 tests/deal.II/assemble_matrix_parallel_04.output diff --git a/tests/deal.II/assemble_matrix_parallel.cc b/tests/deal.II/assemble_matrix_parallel_01.cc similarity index 100% rename from tests/deal.II/assemble_matrix_parallel.cc rename to tests/deal.II/assemble_matrix_parallel_01.cc diff --git a/tests/deal.II/assemble_block_matrix_parallel.output b/tests/deal.II/assemble_matrix_parallel_01.output similarity index 100% rename from tests/deal.II/assemble_block_matrix_parallel.output rename to tests/deal.II/assemble_matrix_parallel_01.output diff --git a/tests/deal.II/assemble_matrix_parallel_02.cc b/tests/deal.II/assemble_matrix_parallel_02.cc new file mode 100644 index 0000000000..a2cd47d8dc --- /dev/null +++ b/tests/deal.II/assemble_matrix_parallel_02.cc @@ -0,0 +1,520 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2009 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// tests that assembly in parallel works properly even when using two separate +// loops on the same constraint matrix, otherwise similar to +// assemble_matrix_parallel_01 + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +std::ofstream logfile("output"); + +using namespace dealii; + + +namespace Assembly +{ + namespace Scratch + { + template + struct Data + { + Data (const hp::FECollection &fe, + const hp::QCollection &quadrature) + : + hp_fe_values(fe, + quadrature, + update_values | update_gradients | + update_quadrature_points | update_JxW_values) + {} + + Data (const Data &data) + : + hp_fe_values(data.hp_fe_values.get_mapping_collection(), + data.hp_fe_values.get_fe_collection(), + data.hp_fe_values.get_quadrature_collection(), + data.hp_fe_values.get_update_flags()) + {} + + hp::FEValues hp_fe_values; + }; + } + + namespace Copy + { + struct Data + { + Data (bool second_test = false) + : + second_test (second_test) + {} + + Data (const Data &data) + : + second_test (data.second_test) + {} + + std::vector local_dof_indices; + FullMatrix local_matrix; + Vector local_rhs; + const bool second_test; + }; + } +} + +template +class LaplaceProblem +{ +public: + LaplaceProblem (); + ~LaplaceProblem (); + + void run (); + +private: + void setup_system (); + void test_equality (); + void assemble_reference (); + void assemble_test (); + void assemble_test_1(); + void assemble_test_2(); + void solve (); + void create_coarse_grid (); + void postprocess (); + + void local_assemble (const typename hp::DoFHandler::active_cell_iterator &cell, + Assembly::Scratch::Data &scratch, + Assembly::Copy::Data &data); + void copy_local_to_global (const Assembly::Copy::Data &data); + + std::vector + get_conflict_indices (typename hp::DoFHandler::active_cell_iterator const &cell) const; + + Triangulation triangulation; + + hp::DoFHandler dof_handler; + hp::FECollection fe_collection; + hp::QCollection quadrature_collection; + hp::QCollection face_quadrature_collection; + + ConstraintMatrix constraints; + + SparsityPattern sparsity_pattern; + SparseMatrix reference_matrix; + SparseMatrix test_matrix; + SparseMatrix test_matrix_2; + + Vector solution; + Vector reference_rhs; + Vector test_rhs; + Vector test_rhs_2; + + std::vector::active_cell_iterator> > graph; + + const unsigned int max_degree; +}; + + + +template +class BoundaryValues : public Function +{ +public: + BoundaryValues () : Function () {} + + virtual double value (const Point &p, + const unsigned int component) const; +}; + + +template +double +BoundaryValues::value (const Point &p, + const unsigned int /*component*/) const +{ + double sum = 0; + for (unsigned int d=0; d +class RightHandSide : public Function +{ +public: + RightHandSide () : Function () {} + + virtual double value (const Point &p, + const unsigned int component) const; +}; + + +template +double +RightHandSide::value (const Point &p, + const unsigned int /*component*/) const +{ + double product = 1; + for (unsigned int d=0; d +LaplaceProblem::LaplaceProblem () + : + dof_handler (triangulation), + max_degree (5) +{ + if (dim == 2) + for (unsigned int degree=2; degree<=max_degree; ++degree) + { + fe_collection.push_back (FE_Q(degree)); + quadrature_collection.push_back (QGauss(degree+1)); + face_quadrature_collection.push_back (QGauss(degree+1)); + } + else + for (unsigned int degree=1; degree(degree)); + quadrature_collection.push_back (QGauss(degree+1)); + face_quadrature_collection.push_back (QGauss(degree+1)); + } +} + + +template +LaplaceProblem::~LaplaceProblem () +{ + dof_handler.clear (); +} + + + +template +std::vector +LaplaceProblem:: +get_conflict_indices (typename hp::DoFHandler::active_cell_iterator const &cell) const +{ + std::vector local_dof_indices(cell->get_fe().dofs_per_cell); + cell->get_dof_indices(local_dof_indices); + + constraints.resolve_indices(local_dof_indices); + return local_dof_indices; +} + +template +void LaplaceProblem::setup_system () +{ + reference_matrix.clear(); + test_matrix.clear(); + dof_handler.distribute_dofs (fe_collection); + + solution.reinit (dof_handler.n_dofs()); + reference_rhs.reinit (dof_handler.n_dofs()); + test_rhs.reinit (dof_handler.n_dofs()); + test_rhs_2.reinit (dof_handler.n_dofs()); + + constraints.clear (); + + DoFTools::make_hanging_node_constraints (dof_handler, constraints); + + // add boundary conditions as inhomogeneous constraints here, do it after + // having added the hanging node constraints in order to be consistent and + // skip dofs that are already constrained (i.e., are hanging nodes on the + // boundary in 3D). In contrast to step-27, we choose a sine function. + VectorTools::interpolate_boundary_values (dof_handler, + 0, + BoundaryValues(), + constraints); + constraints.close (); + + graph = GraphColoring::make_graph_coloring(dof_handler.begin_active(),dof_handler.end(), + static_cast + (typename hp::DoFHandler::active_cell_iterator const &)> > + (std_cxx1x::bind(&LaplaceProblem::get_conflict_indices, this,std_cxx1x::_1))); + + + CompressedSimpleSparsityPattern csp (dof_handler.n_dofs(), + dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, csp, + constraints, false); + sparsity_pattern.copy_from (csp); + + reference_matrix.reinit (sparsity_pattern); + test_matrix.reinit (sparsity_pattern); + test_matrix_2.reinit (sparsity_pattern); +} + + + +template +void +LaplaceProblem::local_assemble (const typename hp::DoFHandler::active_cell_iterator &cell, + Assembly::Scratch::Data &scratch, + Assembly::Copy::Data &data) +{ + const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell; + + data.local_matrix.reinit (dofs_per_cell, dofs_per_cell); + data.local_matrix = 0; + + data.local_rhs.reinit (dofs_per_cell); + data.local_rhs = 0; + + scratch.hp_fe_values.reinit (cell); + + const FEValues &fe_values = scratch.hp_fe_values.get_present_fe_values (); + + const RightHandSide rhs_function; + + for (unsigned int q_point=0; + q_pointget_dof_indices (data.local_dof_indices); +} + + + +template +void +LaplaceProblem::copy_local_to_global (const Assembly::Copy::Data &data) +{ + if (data.second_test) + constraints.distribute_local_to_global(data.local_matrix, data.local_rhs, + data.local_dof_indices, + test_matrix_2, test_rhs_2); + else + constraints.distribute_local_to_global(data.local_matrix, data.local_rhs, + data.local_dof_indices, + test_matrix, test_rhs); +} + + + +template +void LaplaceProblem::assemble_reference () +{ + test_matrix = 0; + test_rhs = 0; + + Assembly::Copy::Data copy_data; + Assembly::Scratch::Data assembly_data(fe_collection, quadrature_collection); + + for (unsigned int color=0; color::active_cell_iterator>::const_iterator p = graph[color].begin(); + p != graph[color].end(); ++p) + { + local_assemble(*p, assembly_data, copy_data); + copy_local_to_global(copy_data); + } + + reference_matrix.add(1., test_matrix); + reference_rhs = test_rhs; +} + + + +template +void LaplaceProblem::assemble_test_1 () +{ + test_matrix = 0; + test_rhs = 0; + + WorkStream:: + run (graph, + std_cxx1x::bind (&LaplaceProblem:: + local_assemble, + this, + std_cxx1x::_1, + std_cxx1x::_2, + std_cxx1x::_3), + std_cxx1x::bind (&LaplaceProblem:: + copy_local_to_global, + this, + std_cxx1x::_1), + Assembly::Scratch::Data(fe_collection, quadrature_collection), + Assembly::Copy::Data (), + 1); +} + + +template +void LaplaceProblem::assemble_test_2 () +{ + test_matrix_2 = 0; + test_rhs_2 = 0; + + WorkStream:: + run (graph, + std_cxx1x::bind (&LaplaceProblem:: + local_assemble, + this, + std_cxx1x::_1, + std_cxx1x::_2, + std_cxx1x::_3), + std_cxx1x::bind (&LaplaceProblem:: + copy_local_to_global, + this, + std_cxx1x::_1), + Assembly::Scratch::Data(fe_collection, quadrature_collection), + Assembly::Copy::Data (true), + 1); +} + +template +void LaplaceProblem::assemble_test() +{ + // start two tasks that each run an assembly + Threads::TaskGroup tasks; + tasks += Threads::new_task (&LaplaceProblem::assemble_test_1, + *this); + tasks += Threads::new_task (&LaplaceProblem::assemble_test_2, + *this); + tasks.join_all(); + + test_matrix.add(-1, reference_matrix); + const double frobenius_norm = test_matrix.frobenius_norm(); + + // the data should add up exactly (unfortunately, there is some roundoff due + // to the cell similarity detection, but there should not be any similarity + // for the hypershell geometry) + deallog << "log error in matrix norm: " << std::log(frobenius_norm) << std::endl; + test_rhs.add(-1., reference_rhs); + deallog << "log error in vector norm: " << std::log(test_rhs.l2_norm()) << std::endl; + + test_matrix_2.add(-numbers::PI, reference_matrix); + deallog << "absolute error matrix assembly 2: " << test_matrix_2.frobenius_norm() << std::endl; + test_rhs_2.add(-numbers::PI, reference_rhs); + deallog << "absolute error vector assembly 2: " << test_rhs_2.l2_norm() << std::endl; +} + + + +template +void LaplaceProblem::postprocess () +{ + Vector estimated_error_per_cell (triangulation.n_active_cells()); + for (unsigned int i=0; i::active_cell_iterator cell = dof_handler.begin_active(); + cell != dof_handler.end(); ++cell) + cell->set_active_fe_index (rand() % fe_collection.size()); +} + + + + +template +void LaplaceProblem::run () +{ + for (unsigned int cycle=0; cycle<3; ++cycle) + { + if (cycle == 0) + { + GridGenerator::hyper_shell(triangulation, + Point(), + 0.5, 1., (dim==3) ? 96 : 12, false); + triangulation.refine_global(2); + } + + setup_system (); + + assemble_reference (); + assemble_test (); + + if (cycle < 2) + postprocess (); + } +} + + + +int main () +{ + deallog << std::setprecision (2); + logfile << std::setprecision (2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-8); + + { + deallog.push("2d"); + LaplaceProblem<2> laplace_problem; + laplace_problem.run (); + deallog.pop(); + } +} + diff --git a/tests/deal.II/assemble_matrix_parallel_02.output b/tests/deal.II/assemble_matrix_parallel_02.output new file mode 100644 index 0000000000..627a39f770 --- /dev/null +++ b/tests/deal.II/assemble_matrix_parallel_02.output @@ -0,0 +1,13 @@ + +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 diff --git a/tests/deal.II/assemble_block_matrix_parallel.cc b/tests/deal.II/assemble_matrix_parallel_03.cc similarity index 99% rename from tests/deal.II/assemble_block_matrix_parallel.cc rename to tests/deal.II/assemble_matrix_parallel_03.cc index 2e20166c55..a0e1c59be0 100644 --- a/tests/deal.II/assemble_block_matrix_parallel.cc +++ b/tests/deal.II/assemble_matrix_parallel_03.cc @@ -16,7 +16,7 @@ -// same as assemble_matrix_parallel, but now for a BlockSparseMatrix +// same as assemble_matrix_parallel_01, but now for a BlockSparseMatrix #include "../tests.h" diff --git a/tests/deal.II/assemble_matrix_parallel.output b/tests/deal.II/assemble_matrix_parallel_03.output similarity index 100% rename from tests/deal.II/assemble_matrix_parallel.output rename to tests/deal.II/assemble_matrix_parallel_03.output diff --git a/tests/deal.II/assemble_matrix_parallel_04.cc b/tests/deal.II/assemble_matrix_parallel_04.cc new file mode 100644 index 0000000000..148cdc137a --- /dev/null +++ b/tests/deal.II/assemble_matrix_parallel_04.cc @@ -0,0 +1,525 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2009 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// same as assemble_matrix_parallel_02, but using a constraint that should +// create conflicts on most cells (similar to mean value constraint) + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +std::ofstream logfile("output"); + +using namespace dealii; + + +namespace Assembly +{ + namespace Scratch + { + template + struct Data + { + Data (const hp::FECollection &fe, + const hp::QCollection &quadrature) + : + hp_fe_values(fe, + quadrature, + update_values | update_gradients | + update_quadrature_points | update_JxW_values) + {} + + Data (const Data &data) + : + hp_fe_values(data.hp_fe_values.get_mapping_collection(), + data.hp_fe_values.get_fe_collection(), + data.hp_fe_values.get_quadrature_collection(), + data.hp_fe_values.get_update_flags()) + {} + + hp::FEValues hp_fe_values; + }; + } + + namespace Copy + { + struct Data + { + Data (bool second_test = false) + : + second_test (second_test) + {} + + Data (const Data &data) + : + second_test (data.second_test) + {} + + std::vector local_dof_indices; + FullMatrix local_matrix; + Vector local_rhs; + const bool second_test; + }; + } +} + +template +class LaplaceProblem +{ +public: + LaplaceProblem (); + ~LaplaceProblem (); + + void run (); + +private: + void setup_system (); + void test_equality (); + void assemble_reference (); + void assemble_test (); + void assemble_test_1(); + void assemble_test_2(); + void solve (); + void create_coarse_grid (); + void postprocess (); + + void local_assemble (const typename hp::DoFHandler::active_cell_iterator &cell, + Assembly::Scratch::Data &scratch, + Assembly::Copy::Data &data); + void copy_local_to_global (const Assembly::Copy::Data &data); + + std::vector + get_conflict_indices (typename hp::DoFHandler::active_cell_iterator const &cell) const; + + Triangulation triangulation; + + hp::DoFHandler dof_handler; + hp::FECollection fe_collection; + hp::QCollection quadrature_collection; + hp::QCollection face_quadrature_collection; + + ConstraintMatrix constraints; + + SparsityPattern sparsity_pattern; + SparseMatrix reference_matrix; + SparseMatrix test_matrix; + SparseMatrix test_matrix_2; + + Vector solution; + Vector reference_rhs; + Vector test_rhs; + Vector test_rhs_2; + + std::vector::active_cell_iterator> > graph; + + const unsigned int max_degree; +}; + + + +template +class BoundaryValues : public Function +{ +public: + BoundaryValues () : Function () {} + + virtual double value (const Point &p, + const unsigned int component) const; +}; + + +template +double +BoundaryValues::value (const Point &p, + const unsigned int /*component*/) const +{ + double sum = 0; + for (unsigned int d=0; d +class RightHandSide : public Function +{ +public: + RightHandSide () : Function () {} + + virtual double value (const Point &p, + const unsigned int component) const; +}; + + +template +double +RightHandSide::value (const Point &p, + const unsigned int /*component*/) const +{ + double product = 1; + for (unsigned int d=0; d +LaplaceProblem::LaplaceProblem () + : + dof_handler (triangulation), + max_degree (5) +{ + if (dim == 2) + for (unsigned int degree=2; degree<=max_degree; ++degree) + { + fe_collection.push_back (FE_Q(degree)); + quadrature_collection.push_back (QGauss(degree+1)); + face_quadrature_collection.push_back (QGauss(degree+1)); + } + else + for (unsigned int degree=1; degree(degree)); + quadrature_collection.push_back (QGauss(degree+1)); + face_quadrature_collection.push_back (QGauss(degree+1)); + } +} + + +template +LaplaceProblem::~LaplaceProblem () +{ + dof_handler.clear (); +} + + + +template +std::vector +LaplaceProblem:: +get_conflict_indices (typename hp::DoFHandler::active_cell_iterator const &cell) const +{ + std::vector local_dof_indices(cell->get_fe().dofs_per_cell); + cell->get_dof_indices(local_dof_indices); + + constraints.resolve_indices(local_dof_indices); + return local_dof_indices; +} + +template +void LaplaceProblem::setup_system () +{ + reference_matrix.clear(); + test_matrix.clear(); + dof_handler.distribute_dofs (fe_collection); + + solution.reinit (dof_handler.n_dofs()); + reference_rhs.reinit (dof_handler.n_dofs()); + test_rhs.reinit (dof_handler.n_dofs()); + test_rhs_2.reinit (dof_handler.n_dofs()); + + constraints.clear (); + + // add a constraint that expands over most of the domain, which should + // create many conflicts + constraints.add_line(3); + for (unsigned int i=5; i(), + constraints); + constraints.close (); + + graph = GraphColoring::make_graph_coloring(dof_handler.begin_active(),dof_handler.end(), + static_cast + (typename hp::DoFHandler::active_cell_iterator const &)> > + (std_cxx1x::bind(&LaplaceProblem::get_conflict_indices, this,std_cxx1x::_1))); + + + CompressedSimpleSparsityPattern csp (dof_handler.n_dofs(), + dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, csp, + constraints, false); + sparsity_pattern.copy_from (csp); + + reference_matrix.reinit (sparsity_pattern); + test_matrix.reinit (sparsity_pattern); + test_matrix_2.reinit (sparsity_pattern); +} + + + +template +void +LaplaceProblem::local_assemble (const typename hp::DoFHandler::active_cell_iterator &cell, + Assembly::Scratch::Data &scratch, + Assembly::Copy::Data &data) +{ + const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell; + + data.local_matrix.reinit (dofs_per_cell, dofs_per_cell); + data.local_matrix = 0; + + data.local_rhs.reinit (dofs_per_cell); + data.local_rhs = 0; + + scratch.hp_fe_values.reinit (cell); + + const FEValues &fe_values = scratch.hp_fe_values.get_present_fe_values (); + + const RightHandSide rhs_function; + + for (unsigned int q_point=0; + q_pointget_dof_indices (data.local_dof_indices); +} + + + +template +void +LaplaceProblem::copy_local_to_global (const Assembly::Copy::Data &data) +{ + if (data.second_test) + constraints.distribute_local_to_global(data.local_matrix, data.local_rhs, + data.local_dof_indices, + test_matrix_2, test_rhs_2); + else + constraints.distribute_local_to_global(data.local_matrix, data.local_rhs, + data.local_dof_indices, + test_matrix, test_rhs); +} + + + +template +void LaplaceProblem::assemble_reference () +{ + test_matrix = 0; + test_rhs = 0; + + Assembly::Copy::Data copy_data; + Assembly::Scratch::Data assembly_data(fe_collection, quadrature_collection); + + for (unsigned int color=0; color::active_cell_iterator>::const_iterator p = graph[color].begin(); + p != graph[color].end(); ++p) + { + local_assemble(*p, assembly_data, copy_data); + copy_local_to_global(copy_data); + } + + reference_matrix.add(1., test_matrix); + reference_rhs = test_rhs; +} + + + +template +void LaplaceProblem::assemble_test_1 () +{ + test_matrix = 0; + test_rhs = 0; + + WorkStream:: + run (graph, + std_cxx1x::bind (&LaplaceProblem:: + local_assemble, + this, + std_cxx1x::_1, + std_cxx1x::_2, + std_cxx1x::_3), + std_cxx1x::bind (&LaplaceProblem:: + copy_local_to_global, + this, + std_cxx1x::_1), + Assembly::Scratch::Data(fe_collection, quadrature_collection), + Assembly::Copy::Data (), + 1); +} + + +template +void LaplaceProblem::assemble_test_2 () +{ + test_matrix_2 = 0; + test_rhs_2 = 0; + + WorkStream:: + run (graph, + std_cxx1x::bind (&LaplaceProblem:: + local_assemble, + this, + std_cxx1x::_1, + std_cxx1x::_2, + std_cxx1x::_3), + std_cxx1x::bind (&LaplaceProblem:: + copy_local_to_global, + this, + std_cxx1x::_1), + Assembly::Scratch::Data(fe_collection, quadrature_collection), + Assembly::Copy::Data (true), + 1); +} + +template +void LaplaceProblem::assemble_test() +{ + // start two tasks that each run an assembly + Threads::TaskGroup tasks; + tasks += Threads::new_task (&LaplaceProblem::assemble_test_1, + *this); + tasks += Threads::new_task (&LaplaceProblem::assemble_test_2, + *this); + tasks.join_all(); + + test_matrix.add(-1, reference_matrix); + const double frobenius_norm = test_matrix.frobenius_norm(); + + // the data should add up exactly (unfortunately, there is some roundoff due + // to the cell similarity detection, but there should not be any similarity + // for the hypershell geometry) + deallog << "log error in matrix norm: " << std::log(frobenius_norm) << std::endl; + test_rhs.add(-1., reference_rhs); + deallog << "log error in vector norm: " << std::log(test_rhs.l2_norm()) << std::endl; + + test_matrix_2.add(-numbers::PI, reference_matrix); + deallog << "absolute error matrix assembly 2: " << test_matrix_2.frobenius_norm() << std::endl; + test_rhs_2.add(-numbers::PI, reference_rhs); + deallog << "absolute error vector assembly 2: " << test_rhs_2.l2_norm() << std::endl; +} + + + +template +void LaplaceProblem::postprocess () +{ + Vector estimated_error_per_cell (triangulation.n_active_cells()); + for (unsigned int i=0; i::active_cell_iterator cell = dof_handler.begin_active(); + cell != dof_handler.end(); ++cell) + cell->set_active_fe_index (rand() % fe_collection.size()); +} + + + + +template +void LaplaceProblem::run () +{ + for (unsigned int cycle=0; cycle<3; ++cycle) + { + if (cycle == 0) + { + GridGenerator::hyper_shell(triangulation, + Point(), + 0.5, 1., (dim==3) ? 96 : 12, false); + triangulation.refine_global(2); + } + + setup_system (); + + assemble_reference (); + assemble_test (); + + if (cycle < 2) + postprocess (); + } +} + + + +int main () +{ + deallog << std::setprecision (2); + logfile << std::setprecision (2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-8); + + { + deallog.push("2d"); + LaplaceProblem<2> laplace_problem; + laplace_problem.run (); + deallog.pop(); + } +} + diff --git a/tests/deal.II/assemble_matrix_parallel_04.output b/tests/deal.II/assemble_matrix_parallel_04.output new file mode 100644 index 0000000000..627a39f770 --- /dev/null +++ b/tests/deal.II/assemble_matrix_parallel_04.output @@ -0,0 +1,13 @@ + +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 +DEAL:2d::log error in matrix norm: -inf +DEAL:2d::log error in vector norm: -inf +DEAL:2d::absolute error matrix assembly 2: 0 +DEAL:2d::absolute error vector assembly 2: 0 -- 2.39.5