From 60e6c1f6bd8d71b02689b76f2ef092bda57186f5 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Thu, 3 May 2018 10:49:13 +0200 Subject: [PATCH] Added comments on missing implementation,+test for hanging nodes --- source/non_matching/coupling.cc | 38 ++++---- tests/non_matching/coupling_07.cc | 129 ++++++++++++++++++++++++++ tests/non_matching/coupling_07.output | 36 +++++++ 3 files changed, 187 insertions(+), 16 deletions(-) create mode 100644 tests/non_matching/coupling_07.cc create mode 100644 tests/non_matching/coupling_07.output diff --git a/source/non_matching/coupling.cc b/source/non_matching/coupling.cc index 2ed5670d25..259ed34fb1 100644 --- a/source/non_matching/coupling.cc +++ b/source/non_matching/coupling.cc @@ -121,21 +121,24 @@ namespace NonMatching if (immersed_c[i]) immersed_gtl[i] = j++; - // Construct a dof_mask, used to distribute entries to the sparsity - Table< 2, bool > dof_mask(space_fe.dofs_per_cell, - immersed_fe.dofs_per_cell); - dof_mask.fill(false); - for (unsigned int i=0; i dof_mask(space_fe.dofs_per_cell, + // immersed_fe.dofs_per_cell); + // of_mask.fill(false); + // or (unsigned int i=0; iis_locally_owned()) { ocell->get_dof_indices(odofs); - constraints.add_entries_local_to_global(odofs, dofs, sparsity); + // [TODO]: When the following function will be implemented + // for the case of non-trivial dof_mask, we should + // uncomment the missing part. + constraints.add_entries_local_to_global(odofs, dofs, sparsity); //, true, dof_mask); } } } diff --git a/tests/non_matching/coupling_07.cc b/tests/non_matching/coupling_07.cc new file mode 100644 index 0000000000..901219c0b0 --- /dev/null +++ b/tests/non_matching/coupling_07.cc @@ -0,0 +1,129 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +// Test that a coupling matrix can be constructed for each pair of dimension and +// immersed dimension, and check that constants are projected correctly. +// +// Even when locally refined grids are used. + +template +void test() +{ + deallog << "dim: " << dim << ", spacedim: " + << spacedim << std::endl; + + Triangulation tria; + Triangulation space_tria; + + GridGenerator::hyper_cube(tria,-.4,.3); + GridGenerator::hyper_cube(space_tria,-1,1); + + tria.refine_global(1); + space_tria.refine_global(1); + space_tria.begin_active()->set_refine_flag(); + space_tria.execute_coarsening_and_refinement(); + + FE_Q fe(1); + FE_Q space_fe(1); + + deallog << "FE : " << fe.get_name() << std::endl + << "Space FE: " << space_fe.get_name() << std::endl; + + DoFHandler dh(tria); + DoFHandler space_dh(space_tria); + + dh.distribute_dofs(fe); + space_dh.distribute_dofs(space_fe); + + ConstraintMatrix constraints; + DoFTools::make_hanging_node_constraints(space_dh, constraints); + + constraints.close(); + + deallog << "Dofs : " << dh.n_dofs() << std::endl + << "Space dofs: " << space_dh.n_dofs() << std::endl + << "Constrained dofs: " << constraints.n_constraints() << std::endl; + + QGauss quad(3); // Quadrature for coupling + + + SparsityPattern sparsity; + { + DynamicSparsityPattern dsp(space_dh.n_dofs(), dh.n_dofs()); + NonMatching::create_coupling_sparsity_pattern(space_dh, dh, + quad, dsp, constraints); + sparsity.copy_from(dsp); + } + SparseMatrix coupling(sparsity); + NonMatching::create_coupling_mass_matrix(space_dh, dh, quad, + coupling, constraints); + + SparsityPattern mass_sparsity; + { + DynamicSparsityPattern dsp(dh.n_dofs(), dh.n_dofs()); + DoFTools::make_sparsity_pattern(dh,dsp); + mass_sparsity.copy_from(dsp); + } + SparseMatrix mass_matrix(mass_sparsity); + MatrixTools::create_mass_matrix(dh, quad, mass_matrix); + + SparseDirectUMFPACK mass_matrix_inv; + mass_matrix_inv.factorize(mass_matrix); + + // now take ones in space, project them onto the immersed space, + // get back ones, and check for the error. + Vector space_ones(space_dh.n_dofs()); + Vector ones(dh.n_dofs()); + + space_ones = 1.0; + coupling.Tvmult(ones, space_ones); + mass_matrix_inv.solve(ones); + + Vector real_ones(dh.n_dofs()); + real_ones = 1.0; + ones -= real_ones; + + deallog << "Error on constants: " << ones.l2_norm() << std::endl; +} + + + +int main() +{ + initlog(); + test<1,1>(); + test<1,2>(); + test<2,2>(); + test<2,3>(); + test<3,3>(); +} diff --git a/tests/non_matching/coupling_07.output b/tests/non_matching/coupling_07.output new file mode 100644 index 0000000000..e19c2de3c0 --- /dev/null +++ b/tests/non_matching/coupling_07.output @@ -0,0 +1,36 @@ + +DEAL::dim: 1, spacedim: 1 +DEAL::FE : FE_Q<1>(1) +DEAL::Space FE: FE_Q<1>(1) +DEAL::Dofs : 3 +DEAL::Space dofs: 4 +DEAL::Constrained dofs: 0 +DEAL::Error on constants: 5.20741e-16 +DEAL::dim: 1, spacedim: 2 +DEAL::FE : FE_Q<1,2>(1) +DEAL::Space FE: FE_Q<2>(1) +DEAL::Dofs : 3 +DEAL::Space dofs: 14 +DEAL::Constrained dofs: 2 +DEAL::Error on constants: 4.00297e-16 +DEAL::dim: 2, spacedim: 2 +DEAL::FE : FE_Q<2>(1) +DEAL::Space FE: FE_Q<2>(1) +DEAL::Dofs : 9 +DEAL::Space dofs: 14 +DEAL::Constrained dofs: 2 +DEAL::Error on constants: 1.49365e-15 +DEAL::dim: 2, spacedim: 3 +DEAL::FE : FE_Q<2,3>(1) +DEAL::Space FE: FE_Q<3>(1) +DEAL::Dofs : 9 +DEAL::Space dofs: 46 +DEAL::Constrained dofs: 12 +DEAL::Error on constants: 1.41744e-15 +DEAL::dim: 3, spacedim: 3 +DEAL::FE : FE_Q<3>(1) +DEAL::Space FE: FE_Q<3>(1) +DEAL::Dofs : 27 +DEAL::Space dofs: 46 +DEAL::Constrained dofs: 12 +DEAL::Error on constants: 1.84498e-14 -- 2.39.5