From: frohne Date: Tue, 1 Nov 2011 21:35:41 +0000 (+0000) Subject: tests for use_inhomogeneities_for_rhs in ConstraintMatrix::distribute_local_to_global() X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22d1bfcf4d64fc59e3a04522866f9c8652b273e1;p=dealii-svn.git tests for use_inhomogeneities_for_rhs in ConstraintMatrix::distribute_local_to_global() git-svn-id: https://svn.dealii.org/trunk@24716 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/deal.II/inhomogeneous_constraints_02.cc b/tests/deal.II/inhomogeneous_constraints_02.cc new file mode 100644 index 0000000000..cd37d5cedf --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_02.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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 mat(sp); + Vector rhs(5); + + std::vector local_dofs; + for (unsigned int i=0;i<5;++i) + local_dofs.push_back(i); + + FullMatrix local_mat(5,5); + Vector 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 index 0000000000..575f31d31c --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_02/cmp/generic @@ -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 index 0000000000..3b6f8786d1 --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_03.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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 mat(sp); + Vector rhs(8); + + // "assemble": + + std::vector local_dofs1; + for (unsigned int i=0;i<5;++i) + local_dofs1.push_back(i); + + std::vector local_dofs2; + local_dofs2.push_back(1); + for (unsigned int i=1;i<5;++i) + local_dofs2.push_back(3+i); + + FullMatrix local_mat(5,5); + Vector 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 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 index 0000000000..d0fb3fbe68 --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_03/cmp/generic @@ -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 index 0000000000..7ab3ce2a26 --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_04.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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 mat(sp); + Vector rhs(8); + Vector solution(8); + + // "assemble": + + std::vector local_dofs1; + for (unsigned int i=0;i<5;++i) + local_dofs1.push_back(i); + + std::vector local_dofs2; + local_dofs2.push_back(1); + for (unsigned int i=1;i<5;++i) + local_dofs2.push_back(3+i); + + FullMatrix local_mat(5,5); + Vector 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 boundary_values; + boundary_values.insert (std::pair(1, -5.0)); + boundary_values.insert (std::pair(3, 2.0)); + boundary_values.insert (std::pair(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 index 0000000000..4a831c8e78 --- /dev/null +++ b/tests/deal.II/inhomogeneous_constraints_04/cmp/generic @@ -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