]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add a test that verifies what we get from the many MemoryConsumption functions.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Jul 2012 13:04:59 +0000 (13:04 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Jul 2012 13:04:59 +0000 (13:04 +0000)
git-svn-id: https://svn.dealii.org/trunk@25692 0785d39b-7218-0410-832d-ea1e28bc413d

tests/deal.II/memory_consumption_01.cc [new file with mode: 0644]
tests/deal.II/memory_consumption_01/cmp/generic [new file with mode: 0644]

diff --git a/tests/deal.II/memory_consumption_01.cc b/tests/deal.II/memory_consumption_01.cc
new file mode 100644 (file)
index 0000000..d2f3c4e
--- /dev/null
@@ -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 <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/function.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/solver_cg.h>
+#include <deal.II/lac/precondition.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/tria_boundary_lib.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/fe/fe_values.h>
+#include <deal.II/numerics/vectors.h>
+#include <deal.II/numerics/matrices.h>
+#include <deal.II/numerics/data_out.h>
+
+#include <fstream>
+#include <iostream>
+
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/grid/grid_out.h>
+
+
+#include <deal.II/lac/constraint_matrix.h>
+
+#include <deal.II/grid/grid_refinement.h>
+
+#include <deal.II/numerics/error_estimator.h>
+
+using namespace dealii;
+
+
+
+template <int dim>
+class Step6
+{
+  public:
+    Step6 ();
+    ~Step6 ();
+
+    void run ();
+
+  private:
+    void setup_system ();
+    void assemble_system ();
+    void solve ();
+    void refine_grid ();
+
+    Triangulation<dim>   triangulation;
+
+    DoFHandler<dim>      dof_handler;
+    FE_Q<dim>            fe;
+
+    ConstraintMatrix     hanging_node_constraints;
+
+    SparsityPattern      sparsity_pattern;
+    SparseMatrix<double> system_matrix;
+
+    Vector<double>       solution;
+    Vector<double>       system_rhs;
+};
+
+
+
+
+template <int dim>
+class Coefficient : public Function<dim>
+{
+  public:
+    Coefficient () : Function<dim>() {}
+
+    virtual double value (const Point<dim>   &p,
+                          const unsigned int  component = 0) const;
+
+    virtual void value_list (const std::vector<Point<dim> > &points,
+                             std::vector<double>            &values,
+                             const unsigned int              component = 0) const;
+};
+
+
+
+template <int dim>
+double Coefficient<dim>::value (const Point<dim> &p,
+                                const unsigned int) const
+{
+  if (p.square() < 0.5*0.5)
+    return 20;
+  else
+    return 1;
+}
+
+
+
+template <int dim>
+void Coefficient<dim>::value_list (const std::vector<Point<dim> > &points,
+                                   std::vector<double>            &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<n_points; ++i)
+    {
+      if (points[i].square() < 0.5*0.5)
+        values[i] = 20;
+      else
+        values[i] = 1;
+    }
+}
+
+
+
+
+template <int dim>
+Step6<dim>::Step6 ()
+                :
+                dof_handler (triangulation),
+                fe (2)
+{}
+
+
+
+template <int dim>
+Step6<dim>::~Step6 ()
+{
+  dof_handler.clear ();
+}
+
+
+
+template <int dim>
+void Step6<dim>::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 <int dim>
+void Step6<dim>::assemble_system ()
+{
+  const QGauss<dim>  quadrature_formula(3);
+
+  FEValues<dim> 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<double>   cell_matrix (dofs_per_cell, dofs_per_cell);
+  Vector<double>       cell_rhs (dofs_per_cell);
+
+  std::vector<unsigned int> local_dof_indices (dofs_per_cell);
+
+  const Coefficient<dim> coefficient;
+  std::vector<double>    coefficient_values (n_q_points);
+
+  typename DoFHandler<dim>::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_point<n_q_points; ++q_point)
+        for (unsigned int i=0; i<dofs_per_cell; ++i)
+          {
+            for (unsigned int j=0; j<dofs_per_cell; ++j)
+              cell_matrix(i,j) += (coefficient_values[q_point] *
+                                   fe_values.shape_grad(i,q_point) *
+                                   fe_values.shape_grad(j,q_point) *
+                                   fe_values.JxW(q_point));
+
+            cell_rhs(i) += (fe_values.shape_value(i,q_point) *
+                            1.0 *
+                            fe_values.JxW(q_point));
+          }
+
+      cell->get_dof_indices (local_dof_indices);
+      for (unsigned int i=0; i<dofs_per_cell; ++i)
+        {
+          for (unsigned int j=0; j<dofs_per_cell; ++j)
+            system_matrix.add (local_dof_indices[i],
+                               local_dof_indices[j],
+                               cell_matrix(i,j));
+
+          system_rhs(local_dof_indices[i]) += cell_rhs(i);
+        }
+    }
+
+  hanging_node_constraints.condense (system_matrix);
+  hanging_node_constraints.condense (system_rhs);
+
+  std::map<unsigned int,double> boundary_values;
+  VectorTools::interpolate_boundary_values (dof_handler,
+                                            0,
+                                            ZeroFunction<dim>(),
+                                            boundary_values);
+  MatrixTools::apply_boundary_values (boundary_values,
+                                      system_matrix,
+                                      solution,
+                                      system_rhs);
+}
+
+
+
+
+
+template <int dim>
+void Step6<dim>::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 <int dim>
+void Step6<dim>::refine_grid ()
+{
+  Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
+
+  KellyErrorEstimator<dim>::estimate (dof_handler,
+                                      QGauss<dim-1>(3),
+                                      typename FunctionMap<dim>::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 <int dim>
+void Step6<dim>::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<dim> 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<dim> 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 (file)
index 0000000..2022c03
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.