]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add first assembler test
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Mon, 12 Oct 2009 17:27:12 +0000 (17:27 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Mon, 12 Oct 2009 17:27:12 +0000 (17:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@19826 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 4e19b4e2709a89b52432dbd46d20e8f6ed61a0c3..6d2d3b7ac2ee25d6aa95ad399ecfae75dac9a72d 100644 (file)
@@ -75,6 +75,7 @@ tests_x = block_info block_matrices \
        iterators* \
        mesh_smoothing_* \
        create_* \
+       mesh_worker_* \
        line_coarsening_3d \
        no_flux_* \
        fe_values_view_* \
diff --git a/tests/deal.II/mesh_worker_01.cc b/tests/deal.II/mesh_worker_01.cc
new file mode 100644 (file)
index 0000000..a8101c9
--- /dev/null
@@ -0,0 +1,225 @@
+//----------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2000, 2001, 2003, 2004, 2007, 2008, 2009 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.
+//
+//----------------------------------------------------------------------
+
+// Test whether the various assember classes put the right data in the
+// right place.
+
+#include "../tests.h"
+#include <numerics/mesh_worker.h>
+#include <numerics/mesh_worker_assembler.h>
+#include <numerics/mesh_worker_loop.h>
+
+#include <base/logstream.h>
+#include <lac/sparsity_pattern.h>
+#include <lac/sparse_matrix.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_tools.h>
+#include <fe/mapping_q1.h>
+#include <fe/fe_q.h>
+#include <fe/fe_dgp.h>
+
+#include <fstream>
+#include <iomanip>
+
+using namespace dealii;
+
+
+// Define a class that fills all available entries in the info objects
+// with recognizable numbers. 
+template <int dim>
+class Local : public Subscriptor
+{
+  public:
+    typedef typename MeshWorker::IntegrationWorker<dim>::CellInfo CellInfo;
+    typedef typename MeshWorker::IntegrationWorker<dim>::FaceInfo FaceInfo;
+    
+    void cell(CellInfo& info) const;
+    void bdry(FaceInfo& info) const;
+    void face(FaceInfo& info1, FaceInfo& info2) const;
+
+    bool cells;
+    bool faces;
+};
+
+// Fill local structures with the following format:
+// 1. Residuals: CC.DDD
+// 2. Matrices:  CC.DDDEEE
+
+//   CC : 2 digits number of cell
+//
+//   DDD: degree of freedom of test function in cell, 1 digit block, 2
+//        digits number in block
+//   EEE: degree of freedom of trial function in cell, same format as
+//        DDD
+
+template <int dim>
+void
+Local<dim>::cell(CellInfo& info) const
+{
+  if (!cells) return;
+  const unsigned int cell = info.cell->user_index();
+
+  deallog << "Cell " << std::setw(2) << cell << ':';
+  for (unsigned int i=0;i<info.indices.size();++i)
+    deallog << ' ' << info.indices[i];
+  deallog << std::endl;
+  
+                                  // Fill local residuals
+  for (unsigned int k=0;k<info.R.size();++k)
+    for (unsigned int b=0;b<info.R[k].n_blocks();++b)
+      for (unsigned int i=0;i<info.R[k].block(b).size();++i)
+       {
+         const double x = cell + 0.1 * b + 0.001 * i;
+         info.R[k].block(b)(i) = x;
+       }
+  
+  for (unsigned int k=0;k<info.M1.size();++k)
+    {
+      const unsigned int block_row = info.M1[k].row;
+      const unsigned int block_col = info.M1[k].column;
+      FullMatrix<double>& M1 = info.M1[k].matrix;
+      for (unsigned int i=0;i<M1.m();++i)
+       for (unsigned int j=0;j<M1.n();++j)
+         {
+           double x = .1 * block_row + .001 * i;
+           x = .1 * block_col + .001 * j + .001 * x;
+           M1(i,j) = cell + x;
+         }
+    }
+}
+
+
+template <int dim>
+void
+Local<dim>::bdry(FaceInfo& info) const
+{
+  const unsigned int cell = info.cell->user_index();
+  deallog << "Bdry " << std::setw(2) << cell;
+  deallog << std::endl;
+}
+
+
+template <int dim>
+void
+Local<dim>::face(FaceInfo& info1, FaceInfo& info2) const
+{
+  const unsigned int cell1 = info1.cell->user_index();
+  const unsigned int cell2 = info2.cell->user_index();
+  deallog << "Face " << cell1 << '|' << cell2;
+  deallog << std::endl;
+}
+
+
+template <int dim, class WORKER>
+void
+assemble(const DoFHandler<dim>& dof_handler, WORKER& worker)
+{
+  const FiniteElement<dim>& fe = dof_handler.get_fe();
+  MappingQ1<dim> mapping;
+  
+  MeshWorker::IntegrationInfoBox<dim> info_box(dof_handler);
+  info_box.initialize(worker, fe, mapping);
+  
+  MeshWorker::integration_loop(dof_handler.begin_active(), dof_handler.end(), info_box, worker);
+}
+
+
+template <int dim>
+void
+test_simple(MGDoFHandler<dim>& mgdofs)
+{
+  SparsityPattern pattern;
+  SparseMatrix<double> matrix;
+  Vector<double> v;
+
+  const DoFHandler<dim>& dofs = mgdofs;
+  const FiniteElement<dim>& fe = dofs.get_fe();
+  pattern.reinit (dofs.n_dofs(), dofs.n_dofs(),
+                 (GeometryInfo<dim>::faces_per_cell
+                  *GeometryInfo<dim>::max_children_per_face+1)*fe.dofs_per_cell);
+  DoFTools::make_flux_sparsity_pattern (dofs, pattern);
+  pattern.compress();
+  matrix.reinit (pattern);
+  v.reinit (dofs.n_dofs());
+  
+  Local<dim> local;
+  local.cells = true;
+  local.faces = false;
+  
+  MeshWorker::AssemblingIntegrator<dim, MeshWorker::Assembler::SystemSimple<SparseMatrix<double>, Vector<double> >, Local<dim> >
+    integrator(local);
+  integrator.initialize_gauss_quadrature(1, 1, 1);
+  integrator.initialize(matrix, v);
+  integrator.boundary_fluxes = local.faces;
+  integrator.interior_fluxes = local.faces;  
+
+  assemble(dofs, integrator);
+  for (unsigned int i=0;i<v.size();++i)
+    deallog << ' ' << std::setprecision(3) << v(i);
+  deallog << std::endl;
+
+  deallog << std::setprecision(6);
+  matrix.print(deallog, true);
+}
+
+
+template<int dim>
+void
+test(const FiniteElement<dim>& fe)
+{
+  Triangulation<dim> tr;
+  GridGenerator::hyper_cube(tr);
+  tr.refine_global(1);
+  tr.begin(1)->set_refine_flag();
+  tr.execute_coarsening_and_refinement();
+  tr.begin(2)->set_refine_flag();
+  tr.execute_coarsening_and_refinement();
+//  tr.refine_global(1);
+  deallog << "Triangulation levels";
+  for (unsigned int l=0;l<tr.n_levels();++l)
+    deallog << ' ' << l << ':' << tr.n_cells(l);
+  deallog << std::endl;
+  
+  unsigned int cn = 0;
+  for (typename Triangulation<dim>::cell_iterator cell = tr.begin();
+       cell != tr.end(); ++cell, ++cn)
+    cell->set_user_index(cn);
+
+  MGDoFHandler<dim> dofs(tr);
+  dofs.distribute_dofs(fe);
+  deallog << "DoFHandler " << dofs.n_dofs() << " levels";
+  for (unsigned int l=0;l<tr.n_levels();++l)
+    deallog << ' ' << l << ':' << dofs.n_dofs(l);
+  deallog << std::endl;
+  
+  test_simple(dofs);
+}
+
+
+int main ()
+{
+  std::ofstream logfile ("mesh_worker_01/output");
+  logfile << std::setprecision (2);
+  logfile << std::fixed;  
+  deallog << std::setprecision (2);
+  deallog << std::fixed;  
+  deallog.attach(logfile);
+//  deallog.depth_console (0);
+
+  std::vector<boost::shared_ptr<FiniteElement<2> > > fe2;
+  fe2.push_back(boost::shared_ptr<FiniteElement<2> >(new  FE_DGP<2>(1)));
+  fe2.push_back(boost::shared_ptr<FiniteElement<2> >(new  FE_Q<2>(1)));
+  
+  for (unsigned int i=0;i<fe2.size();++i)
+    test(*fe2[i]);
+}
diff --git a/tests/deal.II/mesh_worker_01/cmp/generic b/tests/deal.II/mesh_worker_01/cmp/generic
new file mode 100644 (file)
index 0000000..3190f4b
--- /dev/null
@@ -0,0 +1,29 @@
+
+DEAL::Triangulation levels 0:1 1:4 2:4 3:4
+DEAL::DoFHandler 30 levels 0:3 1:12 2:12 3:12
+DEAL::Cell 2 : 0 1 2
+DEAL::Cell 3 : 3 4 5
+DEAL::Cell 4 : 6 7 8
+DEAL::Cell 6 : 9 10 11
+DEAL::Cell 7 : 12 13 14
+DEAL::Cell 8 : 15 16 17
+DEAL::Cell 9 : 18 19 20
+DEAL::Cell 10: 21 22 23
+DEAL::Cell 11: 24 25 26
+DEAL::Cell 12: 27 28 29
+DEAL:: 2.000 2.001 2.002 3.000 3.001 3.002 4.000 4.001 4.002 6.000 6.001 6.002 7.000 7.001 7.002 8.000 8.001 8.002 9.000 9.001 9.002 10.000 10.001 10.002 11.000 11.001 11.002 12.000 12.001 12.002
+DEAL:: 0,0:2.000000 0,1:2.001000 0,2:2.002000 0,6:0 0,7:0 0,8:0 0,9:0 0,10:0 0,11:0 0,15:0 0,16:0 0,17:0 1,1:2.001001 1,0:2.000001 1,2:2.002001 1,6:0 1,7:0 1,8:0 1,9:0 1,10:0 1,11:0 1,15:0 1,16:0 1,17:0 2,2:2.002002 2,0:2.000002 2,1:2.001002 2,6:0 2,7:0 2,8:0 2,9:0 2,10:0 2,11:0 2,15:0 2,16:0 2,17:0 3,3:3.000000 3,4:3.001000 3,5:3.002000 3,6:0 3,7:0 3,8:0 3,12:0 3,13:0 3,14:0 3,15:0 3,16:0 3,17:0 4,4:3.001001 4,3:3.000001 4,5:3.002001 4,6:0 4,7:0 4,8:0 4,12:0 4,13:0 4,14:0 4,15:0 4,16:0 4,17:0 5,5:3.002002 5,3:3.000002 5,4:3.001002 5,6:0 5,7:0 5,8:0 5,12:0 5,13:0 5,14:0 5,15:0 5,16:0 5,17:0 6,6:4.000000 6,0:0 6,1:0 6,2:0 6,3:0 6,4:0 6,5:0 6,7:4.001000 6,8:4.002000 7,7:4.001001 7,0:0 7,1:0 7,2:0 7,3:0 7,4:0 7,5:0 7,6:4.000001 7,8:4.002001 8,8:4.002002 8,0:0 8,1:0 8,2:0 8,3:0 8,4:0 8,5:0 8,6:4.000002 8,7:4.001002 9,9:6.000000 9,0:0 9,1:0 9,2:0 9,10:6.001000 9,11:6.002000 9,15:0 9,16:0 9,17:0 9,21:0 9,22:0 9,23:0 9,27:0 9,28:0 9,29:0 10,10:6.001001 10,0:0 10,1:0 10,2:0 10,9:6.000001 10,11:6.002001 10,15:0 10,16:0 10,17:0 10,21:0 10,22:0 10,23:0 10,27:0 10,28:0 10,29:0 11,11:6.002002 11,0:0 11,1:0 11,2:0 11,9:6.000002 11,10:6.001002 11,15:0 11,16:0 11,17:0 11,21:0 11,22:0 11,23:0 11,27:0 11,28:0 11,29:0 12,12:7.000000 12,3:0 12,4:0 12,5:0 12,13:7.001000 12,14:7.002000 12,15:0 12,16:0 12,17:0 12,24:0 12,25:0 12,26:0 12,27:0 12,28:0 12,29:0 13,13:7.001001 13,3:0 13,4:0 13,5:0 13,12:7.000001 13,14:7.002001 13,15:0 13,16:0 13,17:0 13,24:0 13,25:0 13,26:0 13,27:0 13,28:0 13,29:0 14,14:7.002002 14,3:0 14,4:0 14,5:0 14,12:7.000002 14,13:7.001002 14,15:0 14,16:0 14,17:0 14,24:0 14,25:0 14,26:0 14,27:0 14,28:0 14,29:0 15,15:8.000000 15,0:0 15,1:0 15,2:0 15,3:0 15,4:0 15,5:0 15,9:0 15,10:0 15,11:0 15,12:0 15,13:0 15,14:0 15,16:8.001000 15,17:8.002000 16,16:8.001001 16,0:0 16,1:0 16,2:0 16,3:0 16,4:0 16,5:0 16,9:0 16,10:0 16,11:0 16,12:0 16,13:0 16,14:0 16,15:8.000001 16,17:8.002001 17,17:8.002002 17,0:0 17,1:0 17,2:0 17,3:0 17,4:0 17,5:0 17,9:0 17,10:0 17,11:0 17,12:0 17,13:0 17,14:0 17,15:8.000002 17,16:8.001002 18,18:9.000000 18,19:9.001000 18,20:9.002000 18,21:0 18,22:0 18,23:0 18,24:0 18,25:0 18,26:0 19,19:9.001001 19,18:9.000001 19,20:9.002001 19,21:0 19,22:0 19,23:0 19,24:0 19,25:0 19,26:0 20,20:9.002002 20,18:9.000002 20,19:9.001002 20,21:0 20,22:0 20,23:0 20,24:0 20,25:0 20,26:0 21,21:10.000000 21,9:0 21,10:0 21,11:0 21,18:0 21,19:0 21,20:0 21,22:10.001000 21,23:10.002000 21,27:0 21,28:0 21,29:0 22,22:10.001001 22,9:0 22,10:0 22,11:0 22,18:0 22,19:0 22,20:0 22,21:10.000001 22,23:10.002001 22,27:0 22,28:0 22,29:0 23,23:10.002002 23,9:0 23,10:0 23,11:0 23,18:0 23,19:0 23,20:0 23,21:10.000002 23,22:10.001002 23,27:0 23,28:0 23,29:0 24,24:11.000000 24,12:0 24,13:0 24,14:0 24,18:0 24,19:0 24,20:0 24,25:11.001000 24,26:11.002000 24,27:0 24,28:0 24,29:0 25,25:11.001001 25,12:0 25,13:0 25,14:0 25,18:0 25,19:0 25,20:0 25,24:11.000001 25,26:11.002001 25,27:0 25,28:0 25,29:0 26,26:11.002002 26,12:0 26,13:0 26,14:0 26,18:0 26,19:0 26,20:0 26,24:11.000002 26,25:11.001002 26,27:0 26,28:0 26,29:0 27,27:12.000000 27,9:0 27,10:0 27,11:0 27,12:0 27,13:0 27,14:0 27,21:0 27,22:0 27,23:0 27,24:0 27,25:0 27,26:0 27,28:12.001000 27,29:12.002000 28,28:12.001001 28,9:0 28,10:0 28,11:0 28,12:0 28,13:0 28,14:0 28,21:0 28,22:0 28,23:0 28,24:0 28,25:0 28,26:0 28,27:12.000001 28,29:12.002001 29,29:12.002002 29,9:0 29,10:0 29,11:0 29,12:0 29,13:0 29,14:0 29,21:0 29,22:0 29,23:0 29,24:0 29,25:0 29,26:0 29,27:12.000002 29,28:12.001002
+DEAL::Triangulation levels 0:1 1:4 2:4 3:4
+DEAL::DoFHandler 19 levels 0:4 1:9 2:9 3:9
+DEAL::Cell 2 : 0 1 2 3
+DEAL::Cell 3 : 4 2 5 6
+DEAL::Cell 4 : 2 3 6 7
+DEAL::Cell 6 : 8 0 9 10
+DEAL::Cell 7 : 11 9 4 12
+DEAL::Cell 8 : 9 10 12 2
+DEAL::Cell 9 : 13 14 15 16
+DEAL::Cell 10: 14 8 16 17
+DEAL::Cell 11: 15 16 11 18
+DEAL::Cell 12: 16 17 18 9
+DEAL:: 8.001 2.001 17.006 6.004 10.002 3.002 7.005 4.003 16.001 33.006 14.004 18.002 15.005 9.000 19.001 20.002 42.006 22.004 23.005
+DEAL:: 0,0:8.001001 0,1:2.001000 0,2:2.002000 0,3:2.003000 0,6:0 0,7:0 0,8:6.000001 0,9:6.002001 0,10:6.003001 0,12:0 0,14:0 0,16:0 0,17:0 0,18:0 1,1:2.001001 1,0:2.000001 1,2:2.002001 1,3:2.003001 1,6:0 1,7:0 1,8:0 1,9:0 1,10:0 1,12:0 2,2:17.006006 2,0:2.000002 2,1:2.001002 2,3:6.004002 2,4:3.000001 2,5:3.002001 2,6:7.005001 2,7:4.003000 2,8:0 2,9:8.000003 2,10:8.001003 2,11:0 2,12:8.002003 3,3:6.004004 3,0:2.000003 3,1:2.001003 3,2:6.002004 3,4:0 3,5:0 3,6:4.002001 3,7:4.003001 3,8:0 3,9:0 3,10:0 3,12:0 4,4:10.002002 4,2:3.001000 4,3:0 4,5:3.002000 4,6:3.003000 4,7:0 4,9:7.001002 4,10:0 4,11:7.000002 4,12:7.003002 4,15:0 4,16:0 4,17:0 4,18:0 5,5:3.002002 5,2:3.001002 5,3:0 5,4:3.000002 5,6:3.003002 5,7:0 5,9:0 5,10:0 5,11:0 5,12:0 6,6:7.005005 6,0:0 6,1:0 6,2:7.001005 6,3:4.001002 6,4:3.000003 6,5:3.002003 6,7:4.003002 6,9:0 6,10:0 6,11:0 6,12:0 7,7:4.003003 7,0:0 7,1:0 7,2:4.000003 7,3:4.001003 7,4:0 7,5:0 7,6:4.002003 8,8:16.001001 8,0:6.001000 8,1:0 8,2:0 8,3:0 8,9:6.002000 8,10:6.003000 8,12:0 8,13:0 8,14:10.000001 8,15:0 8,16:10.002001 8,17:10.003001 8,18:0 9,9:33.006006 9,0:6.001002 9,1:0 9,2:8.003000 9,3:0 9,4:7.002001 9,5:0 9,6:0 9,8:6.000002 9,10:14.004002 9,11:7.000001 9,12:15.005001 9,14:0 9,15:0 9,16:12.000003 9,17:12.001003 9,18:12.002003 10,10:14.004004 10,0:6.001003 10,1:0 10,2:8.003001 10,3:0 10,4:0 10,5:0 10,6:0 10,8:6.000003 10,9:14.002004 10,11:0 10,12:8.002001 10,14:0 10,16:0 10,17:0 10,18:0 11,11:18.002002 11,2:0 11,4:7.002000 11,5:0 11,6:0 11,9:7.001000 11,10:0 11,12:7.003000 11,13:0 11,14:0 11,15:11.000002 11,16:11.001002 11,17:0 11,18:11.003002 12,12:15.005005 12,0:0 12,1:0 12,2:8.003002 12,3:0 12,4:7.002003 12,5:0 12,6:0 12,8:0 12,9:15.001005 12,10:8.001002 12,11:7.000003 12,15:0 12,16:0 12,17:0 12,18:0 13,13:9.000000 13,8:0 13,11:0 13,14:9.001000 13,15:9.002000 13,16:9.003000 13,17:0 13,18:0 14,14:19.001001 14,0:0 14,8:10.001000 14,9:0 14,10:0 14,11:0 14,13:9.000001 14,15:9.002001 14,16:19.005001 14,17:10.003000 14,18:0 15,15:20.002002 15,4:0 15,8:0 15,9:0 15,11:11.002000 15,12:0 15,13:9.000002 15,14:9.001002 15,16:20.004002 15,17:0 15,18:11.003000 16,16:42.006006 16,0:0 16,4:0 16,8:10.001002 16,9:12.003000 16,10:0 16,11:11.002001 16,12:0 16,13:9.000003 16,14:19.001005 16,15:20.002004 16,17:22.004002 16,18:23.005001 17,17:22.004004 17,0:0 17,4:0 17,8:10.001003 17,9:12.003001 17,10:0 17,11:0 17,12:0 17,13:0 17,14:10.000003 17,15:0 17,16:22.002004 17,18:12.002001 18,18:23.005005 18,0:0 18,4:0 18,8:0 18,9:12.003002 18,10:0 18,11:11.002003 18,12:0 18,13:0 18,14:0 18,15:11.000003 18,16:23.001005 18,17:12.001002

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.