From 0d3a7cab063f36c0657db3e192219f494ee50633 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sat, 7 Jul 2012 13:04:59 +0000 Subject: [PATCH] Add a test that verifies what we get from the many MemoryConsumption functions. git-svn-id: https://svn.dealii.org/trunk@25692 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/deal.II/memory_consumption_01.cc | 392 ++++++++++++++++++ .../deal.II/memory_consumption_01/cmp/generic | 163 ++++++++ 2 files changed, 555 insertions(+) create mode 100644 tests/deal.II/memory_consumption_01.cc create mode 100644 tests/deal.II/memory_consumption_01/cmp/generic diff --git a/tests/deal.II/memory_consumption_01.cc b/tests/deal.II/memory_consumption_01.cc new file mode 100644 index 0000000000..d2f3c4e73f --- /dev/null +++ b/tests/deal.II/memory_consumption_01.cc @@ -0,0 +1,392 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007, 2012 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------------------------------------------------- + + +// an only slightly modified version of step-6 in which we compute +// memory consumption data in each iteration + +#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 + +using namespace dealii; + + + +template +class Step6 +{ + public: + Step6 (); + ~Step6 (); + + void run (); + + private: + void setup_system (); + void assemble_system (); + void solve (); + void refine_grid (); + + Triangulation triangulation; + + DoFHandler dof_handler; + FE_Q fe; + + ConstraintMatrix hanging_node_constraints; + + SparsityPattern sparsity_pattern; + SparseMatrix system_matrix; + + Vector solution; + Vector system_rhs; +}; + + + + +template +class Coefficient : public Function +{ + public: + Coefficient () : Function() {} + + virtual double value (const Point &p, + const unsigned int component = 0) const; + + virtual void value_list (const std::vector > &points, + std::vector &values, + const unsigned int component = 0) const; +}; + + + +template +double Coefficient::value (const Point &p, + const unsigned int) const +{ + if (p.square() < 0.5*0.5) + return 20; + else + return 1; +} + + + +template +void Coefficient::value_list (const std::vector > &points, + std::vector &values, + const unsigned int component) const +{ + const unsigned int n_points = points.size(); + + Assert (values.size() == n_points, + ExcDimensionMismatch (values.size(), n_points)); + + Assert (component == 0, + ExcIndexRange (component, 0, 1)); + + for (unsigned int i=0; i +Step6::Step6 () + : + dof_handler (triangulation), + fe (2) +{} + + + +template +Step6::~Step6 () +{ + dof_handler.clear (); +} + + + +template +void Step6::setup_system () +{ + dof_handler.distribute_dofs (fe); + + solution.reinit (dof_handler.n_dofs()); + system_rhs.reinit (dof_handler.n_dofs()); + + + hanging_node_constraints.clear (); + DoFTools::make_hanging_node_constraints (dof_handler, + hanging_node_constraints); + + hanging_node_constraints.close (); + + CompressedSparsityPattern c_sparsity(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, c_sparsity); + + hanging_node_constraints.condense (c_sparsity); + + sparsity_pattern.copy_from(c_sparsity); + + system_matrix.reinit (sparsity_pattern); +} + + +template +void Step6::assemble_system () +{ + const QGauss quadrature_formula(3); + + FEValues fe_values (fe, quadrature_formula, + update_values | update_gradients | + update_quadrature_points | update_JxW_values); + + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int n_q_points = quadrature_formula.size(); + + FullMatrix cell_matrix (dofs_per_cell, dofs_per_cell); + Vector cell_rhs (dofs_per_cell); + + std::vector local_dof_indices (dofs_per_cell); + + const Coefficient coefficient; + std::vector coefficient_values (n_q_points); + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + for (; cell!=endc; ++cell) + { + cell_matrix = 0; + cell_rhs = 0; + + fe_values.reinit (cell); + + coefficient.value_list (fe_values.get_quadrature_points(), + coefficient_values); + + for (unsigned int q_point=0; q_pointget_dof_indices (local_dof_indices); + for (unsigned int i=0; i boundary_values; + VectorTools::interpolate_boundary_values (dof_handler, + 0, + ZeroFunction(), + boundary_values); + MatrixTools::apply_boundary_values (boundary_values, + system_matrix, + solution, + system_rhs); +} + + + + + +template +void Step6::solve () +{ + SolverControl solver_control (1000, 1e-12); + SolverCG<> solver (solver_control); + + PreconditionSSOR<> preconditioner; + preconditioner.initialize(system_matrix, 1.2); + + solver.solve (system_matrix, solution, system_rhs, + preconditioner); + + hanging_node_constraints.distribute (solution); +} + + + +template +void Step6::refine_grid () +{ + Vector estimated_error_per_cell (triangulation.n_active_cells()); + + KellyErrorEstimator::estimate (dof_handler, + QGauss(3), + typename FunctionMap::type(), + solution, + estimated_error_per_cell); + + GridRefinement::refine_and_coarsen_fixed_number (triangulation, + estimated_error_per_cell, + 0.3, 0.03); + + triangulation.execute_coarsening_and_refinement (); +} + + + + + +template +void Step6::run () +{ + deallog << dim << "d" << std::endl; + + for (unsigned int cycle=0; cycle<4; ++cycle) + { + deallog << "Cycle " << cycle << ':' << std::endl; + + if (cycle == 0) + { + if (dim > 1) + { + GridGenerator::hyper_ball (triangulation); + + static const HyperBallBoundary boundary; + triangulation.set_boundary (0, boundary); + + triangulation.refine_global (1); + } + else + { + GridGenerator::hyper_cube (triangulation); + triangulation.refine_global (3); + } + } + else + refine_grid (); + + + deallog << " Number of active cells: " + << triangulation.n_active_cells() + << std::endl; + + setup_system (); + + deallog << " Number of degrees of freedom: " + << dof_handler.n_dofs() + << std::endl; + + assemble_system (); + solve (); + + deallog << "Memory consumption -- Triangulation: " << triangulation.memory_consumption() + << std::endl; + deallog << "Memory consumption -- DoFHandler: " << dof_handler.memory_consumption() + << std::endl; + deallog << "Memory consumption -- FE: " << fe.memory_consumption() + << std::endl; + deallog << "Memory consumption -- Constraints: " << hanging_node_constraints.memory_consumption() + << std::endl; + deallog << "Memory consumption -- Sparsity: " << sparsity_pattern.memory_consumption() + << std::endl; + deallog << "Memory consumption -- Matrix: " << system_matrix.memory_consumption() + << std::endl; + deallog << "Memory consumption -- Solution: " << solution.memory_consumption() + << std::endl; + deallog << "Memory consumption -- Rhs: " << system_rhs.memory_consumption() + << std::endl; + } + + DataOutBase::EpsFlags eps_flags; + eps_flags.z_scaling = 4; + + DataOut data_out; + data_out.set_flags (eps_flags); + + data_out.attach_dof_handler (dof_handler); + data_out.add_data_vector (solution, "solution"); + data_out.build_patches (); + + deallog << "Memory consumption -- DataOut: " << data_out.memory_consumption() + << std::endl; +} + + + + +int main() +{ + deal_II_exceptions::disable_abort_on_exception(); + std::ofstream logfile("memory_consumption_01/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + Step6<1>().run(); + Step6<2>().run(); + Step6<3>().run(); +} diff --git a/tests/deal.II/memory_consumption_01/cmp/generic b/tests/deal.II/memory_consumption_01/cmp/generic new file mode 100644 index 0000000000..2022c037a2 --- /dev/null +++ b/tests/deal.II/memory_consumption_01/cmp/generic @@ -0,0 +1,163 @@ + +DEAL::1d +DEAL::Cycle 0: +DEAL:: Number of active cells: 8 +DEAL:: Number of degrees of freedom: 17 +DEAL:cg::Starting value 0.261041 +DEAL:cg::Convergence step 13 value 0 +DEAL::Memory consumption -- Triangulation: 2622 +DEAL::Memory consumption -- DoFHandler: 952 +DEAL::Memory consumption -- FE: 1680 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 456 +DEAL::Memory consumption -- Matrix: 632 +DEAL::Memory consumption -- Solution: 224 +DEAL::Memory consumption -- Rhs: 224 +DEAL::Cycle 1: +DEAL:: Number of active cells: 11 +DEAL:: Number of degrees of freedom: 23 +DEAL:cg::Starting value 0.235472 +DEAL:cg::Convergence step 16 value 0 +DEAL::Memory consumption -- Triangulation: 3414 +DEAL::Memory consumption -- DoFHandler: 1140 +DEAL::Memory consumption -- FE: 1680 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 576 +DEAL::Memory consumption -- Matrix: 824 +DEAL::Memory consumption -- Solution: 272 +DEAL::Memory consumption -- Rhs: 272 +DEAL::Cycle 2: +DEAL:: Number of active cells: 15 +DEAL:: Number of degrees of freedom: 31 +DEAL:cg::Starting value 0.226008 +DEAL:cg::Convergence step 21 value 0 +DEAL::Memory consumption -- Triangulation: 4166 +DEAL::Memory consumption -- DoFHandler: 1332 +DEAL::Memory consumption -- FE: 1680 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 736 +DEAL::Memory consumption -- Matrix: 1080 +DEAL::Memory consumption -- Solution: 336 +DEAL::Memory consumption -- Rhs: 336 +DEAL::Cycle 3: +DEAL:: Number of active cells: 20 +DEAL:: Number of degrees of freedom: 41 +DEAL:cg::Starting value 0.211804 +DEAL:cg::Convergence step 27 value 0 +DEAL::Memory consumption -- Triangulation: 5118 +DEAL::Memory consumption -- DoFHandler: 1560 +DEAL::Memory consumption -- FE: 1680 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 936 +DEAL::Memory consumption -- Matrix: 1400 +DEAL::Memory consumption -- Solution: 416 +DEAL::Memory consumption -- Rhs: 416 +DEAL::Memory consumption -- DataOut: 3289 +DEAL::2d +DEAL::Cycle 0: +DEAL:: Number of active cells: 20 +DEAL:: Number of degrees of freedom: 89 +DEAL:cg::Starting value 0.351647 +DEAL:cg::Convergence step 22 value 0 +DEAL::Memory consumption -- Triangulation: 4739 +DEAL::Memory consumption -- DoFHandler: 1912 +DEAL::Memory consumption -- FE: 13948 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 5736 +DEAL::Memory consumption -- Matrix: 10616 +DEAL::Memory consumption -- Solution: 800 +DEAL::Memory consumption -- Rhs: 800 +DEAL::Cycle 1: +DEAL:: Number of active cells: 44 +DEAL:: Number of degrees of freedom: 209 +DEAL:cg::Starting value 0.271387 +DEAL:cg::Convergence step 30 value 0 +DEAL::Memory consumption -- Triangulation: 9747 +DEAL::Memory consumption -- DoFHandler: 3704 +DEAL::Memory consumption -- FE: 13948 +DEAL::Memory consumption -- Constraints: 3102 +DEAL::Memory consumption -- Sparsity: 13992 +DEAL::Memory consumption -- Matrix: 26168 +DEAL::Memory consumption -- Solution: 1760 +DEAL::Memory consumption -- Rhs: 1760 +DEAL::Cycle 2: +DEAL:: Number of active cells: 92 +DEAL:: Number of degrees of freedom: 449 +DEAL:cg::Starting value 0.203851 +DEAL:cg::Convergence step 51 value 0 +DEAL::Memory consumption -- Triangulation: 19011 +DEAL::Memory consumption -- DoFHandler: 7160 +DEAL::Memory consumption -- FE: 13948 +DEAL::Memory consumption -- Constraints: 10734 +DEAL::Memory consumption -- Sparsity: 31240 +DEAL::Memory consumption -- Matrix: 58744 +DEAL::Memory consumption -- Solution: 3680 +DEAL::Memory consumption -- Rhs: 3680 +DEAL::Cycle 3: +DEAL:: Number of active cells: 200 +DEAL:: Number of degrees of freedom: 921 +DEAL:cg::Starting value 0.151971 +DEAL:cg::Convergence step 71 value 0 +DEAL::Memory consumption -- Triangulation: 38163 +DEAL::Memory consumption -- DoFHandler: 14648 +DEAL::Memory consumption -- FE: 13948 +DEAL::Memory consumption -- Constraints: 19966 +DEAL::Memory consumption -- Sparsity: 64168 +DEAL::Memory consumption -- Matrix: 120824 +DEAL::Memory consumption -- Solution: 7456 +DEAL::Memory consumption -- Rhs: 7456 +DEAL::Memory consumption -- DataOut: 42749 +DEAL::3d +DEAL::Cycle 0: +DEAL:: Number of active cells: 56 +DEAL:: Number of degrees of freedom: 517 +DEAL:cg::Starting value 0.206362 +DEAL:cg::Convergence step 29 value 0 +DEAL::Memory consumption -- Triangulation: 22643 +DEAL::Memory consumption -- DoFHandler: 9736 +DEAL::Memory consumption -- FE: 314524 +DEAL::Memory consumption -- Constraints: 78 +DEAL::Memory consumption -- Sparsity: 120280 +DEAL::Memory consumption -- Matrix: 236280 +DEAL::Memory consumption -- Solution: 4224 +DEAL::Memory consumption -- Rhs: 4224 +DEAL::Cycle 1: +DEAL:: Number of active cells: 217 +DEAL:: Number of degrees of freedom: 2217 +DEAL:cg::Starting value 0.116541 +DEAL:cg::Convergence step 31 value 0 +DEAL::Memory consumption -- Triangulation: 88881 +DEAL::Memory consumption -- DoFHandler: 37972 +DEAL::Memory consumption -- FE: 314524 +DEAL::Memory consumption -- Constraints: 55262 +DEAL::Memory consumption -- Sparsity: 567152 +DEAL::Memory consumption -- Matrix: 1116424 +DEAL::Memory consumption -- Solution: 17824 +DEAL::Memory consumption -- Rhs: 17824 +DEAL::Cycle 2: +DEAL:: Number of active cells: 896 +DEAL:: Number of degrees of freedom: 9373 +DEAL:cg::Starting value 0.0978429 +DEAL:cg::Convergence step 55 value 0 +DEAL::Memory consumption -- Triangulation: 355923 +DEAL::Memory consumption -- DoFHandler: 151256 +DEAL::Memory consumption -- FE: 314524 +DEAL::Memory consumption -- Constraints: 367086 +DEAL::Memory consumption -- Sparsity: 2517208 +DEAL::Memory consumption -- Matrix: 4959288 +DEAL::Memory consumption -- Solution: 75072 +DEAL::Memory consumption -- Rhs: 75072 +DEAL::Cycle 3: +DEAL:: Number of active cells: 3248 +DEAL:: Number of degrees of freedom: 32433 +DEAL:cg::Starting value 0.0425276 +DEAL:cg::Convergence step 82 value 0 +DEAL::Memory consumption -- Triangulation: 1252759 +DEAL::Memory consumption -- DoFHandler: 541984 +DEAL::Memory consumption -- FE: 314524 +DEAL::Memory consumption -- Constraints: 1307806 +DEAL::Memory consumption -- Sparsity: 8321768 +DEAL::Memory consumption -- Matrix: 16383928 +DEAL::Memory consumption -- Solution: 259552 +DEAL::Memory consumption -- Rhs: 259552 +DEAL::Memory consumption -- DataOut: 1159685 -- 2.39.5