-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14868 from vyushut/flux_sparsity_tests
make_flux_sparsity_pattern() revision
- Loading branch information
Showing
3 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* --------------------------------------------------------------------- | ||
* | ||
* Copyright (C) 2021 - 2022 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.md at | ||
* the top level directory of deal.II. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
// @sect3{This test considers two elements which share a common, regular face. | ||
// The logic of make_flux_sparsity_pattern() loops over all faces and filters | ||
// some of them according to a predicate face_has_flux_coupling(). We check | ||
// that the only internal face in the current setup is visited exactly once and | ||
// that the predicate face_has_flux_coupling() is evaluated once for this face.} | ||
|
||
#include <deal.II/dofs/dof_tools.h> | ||
|
||
#include <deal.II/fe/fe_q.h> | ||
|
||
#include <deal.II/grid/grid_generator.h> | ||
|
||
#include <deal.II/lac/dynamic_sparsity_pattern.h> | ||
|
||
#include "../tests.h" | ||
|
||
using namespace dealii; | ||
|
||
template <int dim> | ||
Triangulation<dim> | ||
make_two_elements() | ||
{ | ||
Triangulation<dim> triangulation; | ||
GridGenerator::hyper_cube(triangulation, -2.0, 2.0); | ||
triangulation.begin_active()->set_refine_flag( | ||
RefinementCase<dim>::cut_axis(0)); | ||
triangulation.execute_coarsening_and_refinement(); | ||
return triangulation; | ||
} | ||
|
||
|
||
template <int dim> | ||
bool | ||
is_face_on_OY(const typename DoFHandler<dim>::active_cell_iterator &cell, | ||
const unsigned int face_index) | ||
{ | ||
deallog | ||
<< "This sentence should appear once when the corresponding face is visited only once on cell " | ||
<< cell->index() << std::endl; | ||
return (std::abs(cell->face(face_index)->center()(0)) < 0.01); | ||
} | ||
|
||
template <int dim> | ||
void | ||
create_and_output_flux_sparsity_with_filter( | ||
DoFHandler<dim> & dof_handler, | ||
std::function<bool(const typename DoFHandler<dim>::active_cell_iterator, | ||
const unsigned int)> filter) | ||
{ | ||
DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs()); | ||
DoFTools::make_flux_sparsity_pattern( | ||
dof_handler, | ||
dsp, | ||
AffineConstraints<double>(), | ||
true, | ||
Table<2, DoFTools::Coupling>(1, 1, new auto(DoFTools::always)), | ||
Table<2, DoFTools::Coupling>(1, 1, new auto(DoFTools::always)), | ||
numbers::invalid_subdomain_id, | ||
[&](const auto &cell, const unsigned int face_index) { | ||
return filter(cell, face_index); | ||
}); | ||
dsp.print(deallog.get_file_stream()); | ||
} | ||
|
||
template <int dim> | ||
void | ||
check() | ||
{ | ||
// create a square with two elements | ||
const Triangulation<dim> tria = make_two_elements<dim>(); | ||
// Generate Q1 dofs for the mesh grid | ||
DoFHandler<dim> dof_handler(tria); | ||
dof_handler.distribute_dofs(FE_Q<dim>(1)); | ||
// create and output the sparsity pattern by using a filter | ||
create_and_output_flux_sparsity_with_filter<dim>(dof_handler, | ||
is_face_on_OY<dim>); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
deallog.push("2d"); | ||
check<2>(); | ||
deallog.pop(); | ||
deallog.push("3d"); | ||
check<3>(); | ||
deallog.pop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
DEAL:2d::This sentence should appear once when the corresponding face is visited only once on cell 1 | ||
[0,0,1,2,3,4,5] | ||
[1,0,1,2,3,4,5] | ||
[2,0,1,2,3,4,5] | ||
[3,0,1,2,3,4,5] | ||
[4,0,1,2,3,4,5] | ||
[5,0,1,2,3,4,5] | ||
DEAL:3d::This sentence should appear once when the corresponding face is visited only once on cell 1 | ||
[0,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[1,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[2,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[3,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[4,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[5,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[6,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[7,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[8,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[9,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[10,0,1,2,3,4,5,6,7,8,9,10,11] | ||
[11,0,1,2,3,4,5,6,7,8,9,10,11] |