]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
tests for use_inhomogeneities_for_rhs in ConstraintMatrix::distribute_local_to_global()
authorfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 1 Nov 2011 21:35:41 +0000 (21:35 +0000)
committerfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 1 Nov 2011 21:35:41 +0000 (21:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@24716 0785d39b-7218-0410-832d-ea1e28bc413d

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

diff --git a/tests/deal.II/inhomogeneous_constraints_02.cc b/tests/deal.II/inhomogeneous_constraints_02.cc
new file mode 100644 (file)
index 0000000..cd37d5c
--- /dev/null
@@ -0,0 +1,115 @@
+//------------------  inhomogeneous_constraints.cc  ------------------------
+//    $Id: inhomogeneous_constraints.cc 23710 2011-05-17 04:50:10Z bangerth $
+//    Version: $Name$ 
+//
+//    Copyright (C) 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.
+//
+//------------------  inhomogeneous_constraints.cc  ------------------------
+
+
+// We take one cell and create the system_matrix and the
+// right-hand-side-vector.  But we have a few inhomogeneous
+// constraints and want to test if the
+// distribute_local_to_global-function supplies the correct
+// right-hand-side-vector if the use_inhomogeneities_for_rhs-parameter
+// is set to true or false.
+
+#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/base/utilities.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/solver_cg.h>
+#include <deal.II/lac/precondition.h>
+#include <deal.II/grid/tria.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/grid_refinement.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/lac/constraint_matrix.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/numerics/vectors.h>
+#include <deal.II/numerics/matrices.h>
+#include <deal.II/numerics/error_estimator.h>
+#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+
+#include <fstream>
+#include <iostream>
+#include <complex>
+
+std::ofstream logfile("inhomogeneous_constraints_02/output");
+
+using namespace dealii;
+
+void test(bool use_inhomogeneity_for_rhs)
+{
+  ConstraintMatrix cm;
+
+  cm.add_line(2);
+  cm.set_inhomogeneity(2, 3.0);
+  cm.add_line(3);
+  cm.set_inhomogeneity(3, 0.0);
+  cm.add_line(4);
+  cm.add_entry(4, 2, 2.0);
+
+  cm.close();
+  cm.print(logfile);
+
+  
+  CompressedSimpleSparsityPattern csp(5,5);
+  for (unsigned int i=0;i<5;++i)
+    csp.add(i,i);
+    
+  SparsityPattern sp;
+  sp.copy_from(csp);
+  SparseMatrix<double> mat(sp);
+  Vector<double> rhs(5);
+
+  std::vector<unsigned int> local_dofs;
+  for (unsigned int i=0;i<5;++i)
+    local_dofs.push_back(i);
+
+  FullMatrix<double> local_mat(5,5);
+  Vector<double> local_vec(5);
+  for (unsigned int i=0;i<5;++i)
+    local_mat(i,i)=2.0;
+  
+  local_vec = 0;
+
+  cm.distribute_local_to_global(local_mat, local_vec, local_dofs, mat, rhs, use_inhomogeneity_for_rhs);
+
+  mat.print(logfile);
+  rhs.print(logfile);
+  
+}
+
+
+int main () 
+{
+  deallog << std::setprecision (2);
+  logfile << std::setprecision (2);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  // Use the constraints for the right-hand-side
+  {
+    test(true);        
+  }
+
+  // Don not use the constraints for the right-hand-side
+  {
+    test(false);
+  }
+}
diff --git a/tests/deal.II/inhomogeneous_constraints_02/cmp/generic b/tests/deal.II/inhomogeneous_constraints_02/cmp/generic
new file mode 100644 (file)
index 0000000..575f31d
--- /dev/null
@@ -0,0 +1,19 @@
+
+    2 = 3.0
+    3 = 0
+    4 = 6.0
+(0,0) 2.0
+(1,1) 2.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 2.0
+0.000e+00 0.000e+00 6.000e+00 0.000e+00 1.200e+01 
+    2 = 3.0
+    3 = 0
+    4 = 6.0
+(0,0) 2.0
+(1,1) 2.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 2.0
+0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
diff --git a/tests/deal.II/inhomogeneous_constraints_03.cc b/tests/deal.II/inhomogeneous_constraints_03.cc
new file mode 100644 (file)
index 0000000..3b6f878
--- /dev/null
@@ -0,0 +1,136 @@
+//------------------  inhomogeneous_constraints.cc  ------------------------
+//    $Id: inhomogeneous_constraints.cc 23710 2011-05-17 04:50:10Z bangerth $
+//    Version: $Name$ 
+//
+//    Copyright (C) 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.
+//
+//------------------  inhomogeneous_constraints.cc  ------------------------
+
+
+// We take two cells with two common dofs and create the system_matrix
+// and the right-hand-side-vector for this system.  But we have the following
+// two inhomogeneous constraints:
+//       x_1 = -5   and   x_4 = 2*x_0 + 1
+// And we want to test if the distribute_local_to_global function supplies the correct
+// right-hand-side-vector if the use_inhomogeneities_for_rhs-parameter
+// is set to true or false. The problem is that for the 4th component of the rhs-vector
+// it is not possible to compute the correct value because of the unknown x_0. So
+// for the 4th component of the rhs-vector distribute_local_to_global fill in
+// 1*4 ( mat(4,4)*inhomogeneity(4) ).
+
+#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/base/utilities.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/solver_cg.h>
+#include <deal.II/lac/precondition.h>
+#include <deal.II/grid/tria.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/grid_refinement.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/lac/constraint_matrix.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/numerics/vectors.h>
+#include <deal.II/numerics/matrices.h>
+#include <deal.II/numerics/error_estimator.h>
+#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+
+#include <fstream>
+#include <iostream>
+#include <complex>
+
+std::ofstream logfile("inhomogeneous_constraints_03/output");
+
+using namespace dealii;
+
+void test(bool use_inhomogeneity_for_rhs)
+{
+  ConstraintMatrix cm;
+
+  cm.add_line(1);
+  cm.set_inhomogeneity(1, -5.0);
+  cm.add_line(4);
+  cm.add_entry(4, 0, 2.0);
+  cm.set_inhomogeneity(4, 1.0);
+
+  cm.close();
+  cm.print(logfile);
+
+  
+  CompressedSimpleSparsityPattern csp(8,8);
+  for (unsigned int i=0;i<8;++i)
+    csp.add(i,i);
+    
+  SparsityPattern sp;
+  sp.copy_from(csp);
+  SparseMatrix<double> mat(sp);
+  Vector<double> rhs(8);
+
+  // "assemble":
+
+  std::vector<unsigned int> local_dofs1;
+  for (unsigned int i=0;i<5;++i)
+    local_dofs1.push_back(i);
+
+  std::vector<unsigned int> local_dofs2;
+  local_dofs2.push_back(1);
+  for (unsigned int i=1;i<5;++i)
+    local_dofs2.push_back(3+i);
+
+  FullMatrix<double> local_mat(5,5);
+  Vector<double> local_vec(5);
+  for (unsigned int i=0;i<5;++i)
+    local_mat(i,i)=2.0;
+  
+  local_vec = 1;
+
+  cm.distribute_local_to_global(local_mat, local_vec, local_dofs1, mat, rhs, use_inhomogeneity_for_rhs);
+  cm.distribute_local_to_global(local_mat, local_vec, local_dofs2, mat, rhs, use_inhomogeneity_for_rhs);
+
+
+  mat.print(logfile);
+  rhs.print(logfile);
+
+  Vector<double> solution(8);
+  for (unsigned int i=0;i<8;++i)
+    {
+      solution(i)=rhs(i)/mat(i,i);
+    }
+
+  solution.print(logfile);
+  cm.distribute(solution);
+  solution.print(logfile);  
+}
+
+
+int main () 
+{
+  deallog << std::setprecision (2);
+  logfile << std::setprecision (2);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  // Use the constraints for the right-hand-side
+  {
+    test(true);        
+  }
+
+  // Don not use the constraints for the right-hand-side
+  {
+    test(false);
+  }
+}
diff --git a/tests/deal.II/inhomogeneous_constraints_03/cmp/generic b/tests/deal.II/inhomogeneous_constraints_03/cmp/generic
new file mode 100644 (file)
index 0000000..d0fb3fb
--- /dev/null
@@ -0,0 +1,29 @@
+
+    1 = -5.0
+    4 0:  2.0
+    4: 1.0
+(0,0) 18.
+(1,1) 4.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 4.0
+(5,5) 2.0
+(6,6) 2.0
+(7,7) 2.0
+-3.000e+00 -2.000e+01 1.000e+00 1.000e+00 4.000e+00 1.000e+00 1.000e+00 1.000e+00 
+-1.667e-01 -5.000e+00 5.000e-01 5.000e-01 1.000e+00 5.000e-01 5.000e-01 5.000e-01 
+-1.667e-01 -5.000e+00 5.000e-01 5.000e-01 6.667e-01 5.000e-01 5.000e-01 5.000e-01 
+    1 = -5.0
+    4 0:  2.0
+    4: 1.0
+(0,0) 18.
+(1,1) 4.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 4.0
+(5,5) 2.0
+(6,6) 2.0
+(7,7) 2.0
+-3.000e+00 0.000e+00 1.000e+00 1.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 
+-1.667e-01 0.000e+00 5.000e-01 5.000e-01 0.000e+00 5.000e-01 5.000e-01 5.000e-01 
+-1.667e-01 -5.000e+00 5.000e-01 5.000e-01 6.667e-01 5.000e-01 5.000e-01 5.000e-01 
diff --git a/tests/deal.II/inhomogeneous_constraints_04.cc b/tests/deal.II/inhomogeneous_constraints_04.cc
new file mode 100644 (file)
index 0000000..7ab3ce2
--- /dev/null
@@ -0,0 +1,156 @@
+//------------------  inhomogeneous_constraints.cc  ------------------------
+//    $Id: inhomogeneous_constraints.cc 23710 2011-05-17 04:50:10Z bangerth $
+//    Version: $Name$ 
+//
+//    Copyright (C) 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.
+//
+//------------------  inhomogeneous_constraints.cc  ------------------------
+
+
+// We take two cells with two common dofs and create the system_matrix
+// and the right-hand-side-vector for this system.  But we have the following
+// two inhomogeneous constraints:
+//       x_1 = -5, x_3 = 2.0  and  x_4 = 0.0
+// And we want to test if the distribute_local_to_global function supplies the same
+// system_matrix, right-hand-side-vector and solution as we obtain by using the
+// MatrixTools::apply_boundary_values function.
+
+#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/base/utilities.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/solver_cg.h>
+#include <deal.II/lac/precondition.h>
+#include <deal.II/grid/tria.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/grid_refinement.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/lac/constraint_matrix.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/numerics/vectors.h>
+#include <deal.II/numerics/matrices.h>
+#include <deal.II/numerics/error_estimator.h>
+#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+
+#include <fstream>
+#include <iostream>
+#include <complex>
+
+std::ofstream logfile("inhomogeneous_constraints_04/output");
+
+using namespace dealii;
+
+void test(bool use_constraint_matrix)
+{
+  CompressedSimpleSparsityPattern csp(8,8);
+  for (unsigned int i=0;i<8;++i)
+    csp.add(i,i);
+    
+  SparsityPattern sp;
+  sp.copy_from(csp);
+  SparseMatrix<double> mat(sp);
+  Vector<double> rhs(8);
+  Vector<double> solution(8);
+
+  // "assemble":
+
+  std::vector<unsigned int> local_dofs1;
+  for (unsigned int i=0;i<5;++i)
+    local_dofs1.push_back(i);
+
+  std::vector<unsigned int> local_dofs2;
+  local_dofs2.push_back(1);
+  for (unsigned int i=1;i<5;++i)
+    local_dofs2.push_back(3+i);
+
+  FullMatrix<double> local_mat(5,5);
+  Vector<double> local_vec(5);
+  for (unsigned int i=0;i<5;++i)
+    local_mat(i,i)=2.0;
+  
+  local_vec = 1;
+
+  if (use_constraint_matrix == true)
+    {
+      ConstraintMatrix cm;
+      
+      cm.add_line(1);
+      cm.set_inhomogeneity(1, -5.0);
+      cm.add_line(3);
+      cm.set_inhomogeneity(3, 2.0);
+      cm.add_line(4);
+      cm.set_inhomogeneity(4, 0.0);
+
+      cm.close();
+      cm.print(logfile);
+
+      cm.distribute_local_to_global(local_mat, local_vec, local_dofs1, mat, rhs, true);
+      cm.distribute_local_to_global(local_mat, local_vec, local_dofs2, mat, rhs, true);
+    }
+  else
+    {
+      for (unsigned int i=0; i<5; i++)
+       {
+         mat.add (local_dofs1[i], local_dofs1[i], local_mat (i,i));
+         rhs (local_dofs1[i]) += local_vec (i);
+       }
+
+      for (unsigned int i=0; i<5; i++)
+       {
+         mat.add (local_dofs2[i], local_dofs2[i], local_mat (i,i));
+         rhs (local_dofs2[i]) += local_vec (i);
+       }
+
+      std::map<unsigned int, double>     boundary_values;
+      boundary_values.insert (std::pair<unsigned int,double>(1, -5.0));
+      boundary_values.insert (std::pair<unsigned int,double>(3, 2.0));
+      boundary_values.insert (std::pair<unsigned int,double>(4, 0.0));
+      MatrixTools::apply_boundary_values (boundary_values,
+                                         mat,
+                                         solution,
+                                         rhs);
+    }
+
+  mat.print(logfile);
+  rhs.print(logfile);
+
+  for (unsigned int i=0;i<8;++i)
+    {
+      solution(i)=rhs(i)/mat(i,i);
+    }
+
+  solution.print(logfile);  
+}
+
+
+int main () 
+{
+  deallog << std::setprecision (2);
+  logfile << std::setprecision (2);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  // Use the constraints for the right-hand-side
+  {
+    test(true);        
+  }
+
+  // Don not use the constraints for the right-hand-side
+  {
+    test(false);
+  }
+}
diff --git a/tests/deal.II/inhomogeneous_constraints_04/cmp/generic b/tests/deal.II/inhomogeneous_constraints_04/cmp/generic
new file mode 100644 (file)
index 0000000..4a831c8
--- /dev/null
@@ -0,0 +1,24 @@
+
+    1 = -5.0
+    3 = 2.0
+    4 = 0
+(0,0) 2.0
+(1,1) 4.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 4.0
+(5,5) 2.0
+(6,6) 2.0
+(7,7) 2.0
+1.000e+00 -2.000e+01 1.000e+00 4.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 
+5.000e-01 -5.000e+00 5.000e-01 2.000e+00 0.000e+00 5.000e-01 5.000e-01 5.000e-01 
+(0,0) 2.0
+(1,1) 4.0
+(2,2) 2.0
+(3,3) 2.0
+(4,4) 4.0
+(5,5) 2.0
+(6,6) 2.0
+(7,7) 2.0
+1.000e+00 -2.000e+01 1.000e+00 4.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 
+5.000e-01 -5.000e+00 5.000e-01 2.000e+00 0.000e+00 5.000e-01 5.000e-01 5.000e-01 

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.