From 9b366e08461a45e1c3687f7212f9c1e62dae0122 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Sat, 2 Nov 2013 20:40:11 +0000 Subject: [PATCH] quicktest: add step-11 in debug and release git-svn-id: https://svn.dealii.org/trunk@31518 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/tests/quick_tests/CMakeLists.txt | 32 ++- deal.II/tests/quick_tests/step.cc | 253 +++++++++++++++++++++++ 2 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 deal.II/tests/quick_tests/step.cc diff --git a/deal.II/tests/quick_tests/CMakeLists.txt b/deal.II/tests/quick_tests/CMakeLists.txt index 4f8a757517..5327d22a9a 100644 --- a/deal.II/tests/quick_tests/CMakeLists.txt +++ b/deal.II/tests/quick_tests/CMakeLists.txt @@ -31,10 +31,40 @@ ELSE() ENDIF() MESSAGE(" we are using build type ${_mybuild}...") + +# simple assembly/solver test +# run this in debug and release mode +FOREACH(_build ${DEAL_II_BUILD_TYPES}) + STRING(TOLOWER ${_build} _build_lowercase) + + SET(_target step.${_build_lowercase}) + + ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL step.cc) + DEAL_II_INSOURCE_SETUP_TARGET(${_target} ${_build}) + + ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK + COMMAND ${_target} > ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK 2>&1 || (rm ${_target}-OK && exit 1) + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + ADD_CUSTOM_TARGET(${_target}.run + DEPENDS ${_target} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_target}-OK + COMMAND echo "${_target}: PASSED.") + + ADD_TEST(NAME ${_target} + COMMAND ${CMAKE_COMMAND} -DTRGT=${_target}.run -DTEST=${_target} + -DDEAL_II_BINARY_DIR=${CMAKE_BINARY_DIR} + -P ${CMAKE_SOURCE_DIR}/cmake/scripts/run_test.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + SET_TESTS_PROPERTIES(${_target} PROPERTIES LABEL "sanity checks") +ENDFOREACH() + + # # Test whether thread affinity is well behaved: # - SET(_target affinity.${_mybuild}) + SET(_target affinity.${_mybuild_lowercase}) ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL affinity.cc) DEAL_II_INSOURCE_SETUP_TARGET(${_target} ${_mybuild}) diff --git a/deal.II/tests/quick_tests/step.cc b/deal.II/tests/quick_tests/step.cc new file mode 100644 index 0000000000..218b90d779 --- /dev/null +++ b/deal.II/tests/quick_tests/step.cc @@ -0,0 +1,253 @@ +// --------------------------------------------------------------------- +// $Id: step-11.cc 31349 2013-10-20 19:07:06Z maier $ +// +// Copyright (C) 2005 - 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. +// +// --------------------------------------------------------------------- + + + +// copied from bits/step-11 with slight modifications to make it run faster + +#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 + +using namespace dealii; + + +template +class LaplaceProblem +{ +public: + LaplaceProblem (const unsigned int mapping_degree); + void run (); + +private: + void setup_system (); + void assemble_and_solve (); + void solve (); + + Triangulation triangulation; + FE_Q fe; + DoFHandler dof_handler; + MappingQ mapping; + + SparsityPattern sparsity_pattern; + SparseMatrix system_matrix; + ConstraintMatrix mean_value_constraints; + + Vector solution; + Vector system_rhs; + + TableHandler output_table; + + double last_error; +}; + + + +template +LaplaceProblem::LaplaceProblem (const unsigned int mapping_degree) : + fe (1), + dof_handler (triangulation), + mapping (mapping_degree) +{ + deallog << "Using mapping with degree " << mapping_degree << ":" + << std::endl + << "============================" + << std::endl; +} + + + +template +void LaplaceProblem::setup_system () +{ + dof_handler.distribute_dofs (fe); + solution.reinit (dof_handler.n_dofs()); + system_rhs.reinit (dof_handler.n_dofs()); + + std::vector boundary_dofs (dof_handler.n_dofs(), false); + DoFTools::extract_boundary_dofs (dof_handler, std::vector(1,true), + boundary_dofs); + + const unsigned int first_boundary_dof + = std::distance (boundary_dofs.begin(), + std::find (boundary_dofs.begin(), + boundary_dofs.end(), + true)); + + mean_value_constraints.clear (); + mean_value_constraints.add_line (first_boundary_dof); + for (unsigned int i=first_boundary_dof+1; i +void LaplaceProblem::assemble_and_solve () +{ + + const unsigned int gauss_degree + = std::max (static_cast(std::ceil(1.*(mapping.get_degree()+1)/2)), + 2U); + MatrixTools::create_laplace_matrix (mapping, dof_handler, + QGauss(gauss_degree), + system_matrix); + VectorTools::create_right_hand_side (mapping, dof_handler, + QGauss(gauss_degree), + ConstantFunction(-2), + system_rhs); + Vector tmp (system_rhs.size()); + VectorTools::create_boundary_right_hand_side (mapping, dof_handler, + QGauss(gauss_degree), + ConstantFunction(1), + tmp); + system_rhs += tmp; + + mean_value_constraints.condense (system_matrix); + mean_value_constraints.condense (system_rhs); + + solve (); + mean_value_constraints.distribute (solution); + + Vector norm_per_cell (triangulation.n_active_cells()); + VectorTools::integrate_difference (mapping, dof_handler, + solution, + ZeroFunction(), + norm_per_cell, + QGauss(gauss_degree+1), + VectorTools::H1_seminorm); + const double norm = norm_per_cell.l2_norm(); + + output_table.add_value ("cells", triangulation.n_active_cells()); + output_table.add_value ("|u|_1", norm); + output_table.add_value ("error", std::fabs(norm-std::sqrt(3.14159265358/2))); + + last_error = std::fabs(norm-std::sqrt(3.14159265358/2)); +} + + + +template +void LaplaceProblem::solve () +{ + SolverControl solver_control (1000, 1e-12); + SolverCG<> cg (solver_control); + + PreconditionSSOR<> preconditioner; + preconditioner.initialize(system_matrix, 1.2); + + cg.solve (system_matrix, solution, system_rhs, + preconditioner); +} + + + +template +void LaplaceProblem::run () +{ + GridGenerator::hyper_ball (triangulation); + static const HyperBallBoundary boundary; + triangulation.set_boundary (0, boundary); + + for (unsigned int cycle=0; cycle<6; ++cycle, triangulation.refine_global(1)) + { + setup_system (); + assemble_and_solve (); + }; + + AssertThrow (last_error<1e-3, ExcMessage("solution is not converging")); + + + + output_table.set_precision("|u|_1", 6); + output_table.set_precision("error", 6); + output_table.write_text (std::cout); + deallog << std::endl; +} + + + +int main () +{ + try + { + LaplaceProblem<2>(1).run (); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return -1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return -1; + }; + + return 0; +} -- 2.39.5