From 4413b95830d04b4e1f9d02552b70a158356f42e3 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 28 May 2002 16:56:43 +0000 Subject: [PATCH] Add test non_primitive_1 git-svn-id: https://svn.dealii.org/trunk@5910 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/fe/non_primitive_1.cc | 340 ++++++++++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) create mode 100644 tests/fe/non_primitive_1.cc diff --git a/tests/fe/non_primitive_1.cc b/tests/fe/non_primitive_1.cc new file mode 100644 index 0000000000..105c311545 --- /dev/null +++ b/tests/fe/non_primitive_1.cc @@ -0,0 +1,340 @@ +//---------------------------- non_primitive_1.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2001, 2002 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. +// +//---------------------------- non_primitive_1.cc --------------------------- + +// assemble a matrix for the stokes equation in different ways for +// primitive elements. the name of the program is only to indicate +// that we use the way to assemble matrices necessary for +// non-primitive elements, and compare the resulting matrix with what +// we get if we use the usual way which we can take if the FE is +// primitive. then use a third way where we use some optimizations, +// and compare again whether the matrices are the same + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + + // create the matrix in the plain old + // way, which is valid if the finite + // element shape functions are + // primitive +template +void +create_stokes_matrix_1 (const DoFHandler &dof_handler, + SparseMatrix &A) +{ + const FiniteElement &fe = dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + + std::vector local_dof_indices (dofs_per_cell); + FullMatrix local_matrix (dofs_per_cell, dofs_per_cell); + + QGauss quadrature (3); + const unsigned int n_q_points = quadrature.n_quadrature_points; + + FEValues fe_values (fe, quadrature, + update_values | update_gradients | + update_JxW_values); + + const double nu = 3.14159265358e-2; + + for (; cell!=endc; ++cell) + { + local_matrix.clear (); + fe_values.reinit (cell); + + for (unsigned int i=0; iget_dof_indices (local_dof_indices); + for (unsigned int i=0; i +void +create_stokes_matrix_2 (const DoFHandler &dof_handler, + SparseMatrix &A) +{ + const FiniteElement &fe = dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + + std::vector local_dof_indices (dofs_per_cell); + FullMatrix local_matrix (dofs_per_cell, dofs_per_cell); + + QGauss quadrature (3); + const unsigned int n_q_points = quadrature.n_quadrature_points; + + FEValues fe_values (fe, quadrature, + update_values | update_gradients | + update_JxW_values); + + const double nu = 3.14159265358e-2; + + for (; cell!=endc; ++cell) + { + local_matrix.clear (); + fe_values.reinit (cell); + for (unsigned int i=0; iget_dof_indices (local_dof_indices); + for (unsigned int i=0; i +void +create_stokes_matrix_3 (const DoFHandler &dof_handler, + SparseMatrix &A) +{ + const FiniteElement &fe = dof_handler.get_fe(); + const unsigned int dofs_per_cell = fe.dofs_per_cell; + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + + std::vector local_dof_indices (dofs_per_cell); + FullMatrix local_matrix (dofs_per_cell, dofs_per_cell); + + QGauss quadrature (3); + const unsigned int n_q_points = quadrature.n_quadrature_points; + + FEValues fe_values (fe, quadrature, + update_values | update_gradients | + update_JxW_values); + + const double nu = 3.14159265358e-2; + + for (; cell!=endc; ++cell) + { + local_matrix.clear (); + fe_values.reinit (cell); + for (unsigned int i=0; iget_dof_indices (local_dof_indices); + for (unsigned int i=0; i +void +test () +{ + Triangulation triangulation; + if (dim != 2) + GridGenerator::hyper_cube (triangulation); + else + GridGenerator::hyper_cube_slit (triangulation); + triangulation.refine_global (1); + triangulation.begin_active()->set_refine_flag(); + triangulation.execute_coarsening_and_refinement(); + triangulation.last_active()->set_refine_flag (); + triangulation.execute_coarsening_and_refinement(); + triangulation.refine_global (1); + + deallog << "dim=" << dim + << ", n_cells=" << triangulation.n_active_cells() + << std::endl; + + FESystem fe (FE_Q(2), dim, + FE_Q(1), 1); + DoFHandler dof_handler (triangulation); + dof_handler.distribute_dofs (fe); + + SparsityPattern sparsity(dof_handler.n_dofs(), + dof_handler.n_dofs()); + + // have a mask that indicates that + // for the stokes equation the + // pressure does not couple to + // itself + std::vector > mask (dim+1, std::vector (dim+1, true)); + mask[dim][dim] = false; + + DoFTools::make_sparsity_pattern (dof_handler, mask, sparsity); + sparsity.compress (); + + SparseMatrix A1 (sparsity); + SparseMatrix A2 (sparsity); + SparseMatrix A3 (sparsity); + + create_stokes_matrix_1 (dof_handler, A1); + create_stokes_matrix_2 (dof_handler, A2); + create_stokes_matrix_3 (dof_handler, A3); + + // write out the contents of the + // matrix and compare for equality + // with the other matrices + for (unsigned int i=0; i (); + test<2> (); + test<3> (); +}; + + + + -- 2.39.5