]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test mixing hanging nodes with Dirichlet boundary conditions.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 16 Sep 2010 14:49:35 +0000 (14:49 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 16 Sep 2010 14:49:35 +0000 (14:49 +0000)
git-svn-id: https://svn.dealii.org/trunk@21993 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 7b36bd8a93aa3312db5a6f3029e76f1caed194ea..5a323d5e13957ed5298ccf8a687873988f197866 100644 (file)
@@ -23,8 +23,7 @@ default: run-tests
 
 tests_x = block_info block_matrices \
        user_data_* \
-       constraints \
-       constraint_graph \
+       constraint* \
        inhomogeneous_constraints \
        inhomogeneous_constraints_nonsymmetric \
        inhomogeneous_constraints_block \
diff --git a/tests/deal.II/constraints_hanging_nodes_bc.cc b/tests/deal.II/constraints_hanging_nodes_bc.cc
new file mode 100644 (file)
index 0000000..b064e8e
--- /dev/null
@@ -0,0 +1,147 @@
+//------------------  constraints_hanging_nodes_bc.cc  ------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010 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.
+//
+//------------------  constraints_hanging_nodes_bc.cc  ------------------------
+
+
+// this function tests the correctness of the implementation of mixing hanging
+// node constraints and Dirichlet boundary constraints. This is trivial in 2D
+// because then hanging nodes never appear on the boundary, but needs to be
+// checked in 3D. To do this, compare a constraint matrix that we fill
+// manually with one that we get from using the library functions
+// make_hanging_node_constraints and interpolate_boundary_values.
+
+#include "../tests.h"
+
+#include <base/function.h>
+#include <base/logstream.h>
+#include <base/utilities.h>
+#include <lac/vector.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <grid/grid_refinement.h>
+#include <dofs/dof_tools.h>
+#include <dofs/dof_handler.h>
+#include <lac/constraint_matrix.h>
+#include <fe/fe_q.h>
+#include <numerics/vectors.h>
+
+#include <fstream>
+#include <iostream>
+#include <complex>
+
+std::ofstream logfile("constraints_hanging_nodes_bc/output");
+
+
+template <int dim>
+void test ()
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube (tria);
+  tria.refine_global(1);
+
+                               // refine some of the cells.
+  typename Triangulation<dim>::active_cell_iterator
+    cell = tria.begin_active(),
+    endc = tria.end();
+  for (unsigned int counter = 0; cell!=endc; ++cell, ++counter)
+    if (counter % 5 == 0)
+      cell->set_refine_flag();
+  tria.execute_coarsening_and_refinement();
+
+  cell = tria.begin_active();
+  endc = tria.end();
+  for (unsigned int counter = 0; cell!=endc; ++cell, ++counter)
+    if (counter % 8 == 0)
+      cell->set_refine_flag();
+  tria.execute_coarsening_and_refinement();
+
+  FE_Q<dim> fe(1);
+  DoFHandler<dim> dof (tria);
+  dof.distribute_dofs (fe);
+
+  ConstraintMatrix correct_constraints, library_constraints;
+
+  DoFTools::make_hanging_node_constraints (dof, correct_constraints);
+  library_constraints.merge (correct_constraints);
+
+  {
+    std::map<unsigned int,double> boundary_values;
+    VectorTools::interpolate_boundary_values (dof,
+                                             0,
+                                             ConstantFunction<dim>(1.),
+                                             boundary_values);
+    std::map<unsigned int,double>::const_iterator boundary_value = 
+      boundary_values.begin();
+    for ( ; boundary_value !=boundary_values.end(); ++boundary_value)
+      {
+       if (!correct_constraints.is_constrained(boundary_value->first))
+         {
+           correct_constraints.add_line(boundary_value->first);
+           correct_constraints.set_inhomogeneity (boundary_value->first,
+                                                  boundary_value->second);
+         }
+      }
+  }
+  correct_constraints.close();
+
+  deallog << "Number of DoFs: " << dof.n_dofs() << std::endl
+         << "Number of hanging nodes: "
+         << library_constraints.n_constraints() << std::endl
+         << "Total number of constraints: "
+         << correct_constraints.n_constraints() << std::endl;
+
+  VectorTools::interpolate_boundary_values (dof, 0, ConstantFunction<dim>(1.),
+                                           library_constraints);
+  library_constraints.close();
+
+                               // the two constraint matrices should look the
+                               // same, so go through them and check
+  deallog << "Check that both constraint matrices are identical... ";
+  for (unsigned int i=0; i<dof.n_dofs(); ++i)
+    {
+      Assert (correct_constraints.is_constrained(i) ==
+             library_constraints.is_constrained(i), ExcInternalError());
+      typedef const std::vector<std::pair<unsigned int, double> >& constraint_format;
+      if (correct_constraints.is_constrained(i))
+       {
+         constraint_format correct = *correct_constraints.get_constraint_entries(i);
+         constraint_format library = *library_constraints.get_constraint_entries(i);
+         Assert (correct.size() == library.size(), ExcInternalError());
+         for (unsigned int q=0; q<correct.size(); ++q)
+           {
+             Assert (correct[q].first == library[q].first, ExcInternalError());
+             Assert (std::fabs(correct[q].second-library[q].second) < 1e-14,
+                     ExcInternalError());
+           }
+         Assert (std::fabs(correct_constraints.get_inhomogeneity(i)-
+                           library_constraints.get_inhomogeneity(i))<1e-14,
+                 ExcInternalError());
+       }
+    }
+  deallog << "OK." << std::endl;
+}
+
+
+int main ()
+{
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+  deallog << std::setprecision (2);
+
+  {
+    deallog.push("3d");
+    test<3>();
+    deallog.pop();
+  }
+}
+
diff --git a/tests/deal.II/constraints_hanging_nodes_bc/cmp/generic b/tests/deal.II/constraints_hanging_nodes_bc/cmp/generic
new file mode 100644 (file)
index 0000000..d86b4b7
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL:3d::Number of DoFs: 163
+DEAL:3d::Number of hanging nodes: 33
+DEAL:3d::Total number of constraints: 134
+DEAL:3d::Check that both constraint matrices are identical... OK.

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.