-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MGTwoLevelTransfer: enable FE_Nothing #12891
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,201 @@ | ||||||
// --------------------------------------------------------------------- | ||||||
// | ||||||
// Copyright (C) 2021 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. | ||||||
// | ||||||
// --------------------------------------------------------------------- | ||||||
|
||||||
|
||||||
/** | ||||||
* Test MGTwoLevelTransfer::interpolate() for DoFHandlers with `FE_Nothing`. | ||||||
*/ | ||||||
|
||||||
#include <deal.II/base/conditional_ostream.h> | ||||||
#include <deal.II/base/function_lib.h> | ||||||
#include <deal.II/base/logstream.h> | ||||||
#include <deal.II/base/mpi.h> | ||||||
#include <deal.II/base/quadrature_lib.h> | ||||||
|
||||||
#include <deal.II/distributed/tria.h> | ||||||
|
||||||
#include <deal.II/dofs/dof_handler.h> | ||||||
|
||||||
#include <deal.II/fe/fe_dgq.h> | ||||||
#include <deal.II/fe/fe_nothing.h> | ||||||
#include <deal.II/fe/fe_q.h> | ||||||
#include <deal.II/fe/fe_system.h> | ||||||
#include <deal.II/fe/fe_tools.h> | ||||||
#include <deal.II/fe/mapping_q.h> | ||||||
|
||||||
#include <deal.II/grid/grid_generator.h> | ||||||
#include <deal.II/grid/grid_out.h> | ||||||
|
||||||
#include <deal.II/matrix_free/fe_evaluation.h> | ||||||
#include <deal.II/matrix_free/matrix_free.h> | ||||||
|
||||||
#include <deal.II/multigrid/mg_constrained_dofs.h> | ||||||
#include <deal.II/multigrid/mg_transfer_global_coarsening.h> | ||||||
|
||||||
#include <deal.II/numerics/data_out.h> | ||||||
#include <deal.II/numerics/vector_tools.h> | ||||||
|
||||||
#include "mg_transfer_util.h" | ||||||
|
||||||
using namespace dealii; | ||||||
|
||||||
template <int dim> | ||||||
class AnalyticalSolution : public Function<dim> | ||||||
{ | ||||||
public: | ||||||
AnalyticalSolution() | ||||||
{} | ||||||
|
||||||
virtual double | ||||||
value(const Point<dim> &p, const unsigned int component = 0) const override | ||||||
{ | ||||||
(void)component; | ||||||
|
||||||
return p[0]; | ||||||
} | ||||||
|
||||||
private: | ||||||
}; | ||||||
Comment on lines
+54
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using dealii/include/deal.II/base/function_lib.h Lines 1329 to 1330 in 21e7779
exponents = {1, 0, 0} ?
|
||||||
|
||||||
template <int dim, typename Number = double> | ||||||
void | ||||||
do_test(const hp::FECollection<dim> &fe_fine, | ||||||
const hp::FECollection<dim> &fe_coarse) | ||||||
{ | ||||||
parallel::distributed::Triangulation<dim> tria(MPI_COMM_WORLD); | ||||||
|
||||||
// create grid | ||||||
GridGenerator::hyper_cube(tria); | ||||||
tria.refine_global(2); | ||||||
|
||||||
// setup dof-handlers | ||||||
DoFHandler<dim> dof_handler_fine(tria); | ||||||
|
||||||
if (fe_fine.size() > 1) | ||||||
{ | ||||||
for (const auto &cell : dof_handler_fine.active_cell_iterators()) | ||||||
if (cell->center()[0] < 0.5) | ||||||
cell->set_active_fe_index(0); | ||||||
else | ||||||
cell->set_active_fe_index(1); | ||||||
} | ||||||
|
||||||
dof_handler_fine.distribute_dofs(fe_fine); | ||||||
|
||||||
DoFHandler<dim> dof_handler_coarse(tria); | ||||||
|
||||||
if (fe_coarse.size() > 1) | ||||||
{ | ||||||
for (const auto &cell : dof_handler_coarse.active_cell_iterators()) | ||||||
if (cell->center()[0] < 0.5) | ||||||
cell->set_active_fe_index(0); | ||||||
else | ||||||
cell->set_active_fe_index(1); | ||||||
} | ||||||
dof_handler_coarse.distribute_dofs(fe_coarse); | ||||||
|
||||||
AffineConstraints<Number> dummy; | ||||||
dummy.close(); | ||||||
|
||||||
// setup transfer operator | ||||||
MGTwoLevelTransfer<dim, LinearAlgebra::distributed::Vector<Number>> transfer; | ||||||
transfer.reinit_polynomial_transfer(dof_handler_fine, | ||||||
dof_handler_coarse, | ||||||
dummy, | ||||||
dummy); | ||||||
|
||||||
LinearAlgebra::distributed::Vector<Number> vec_fine( | ||||||
dof_handler_fine.n_dofs()); | ||||||
LinearAlgebra::distributed::Vector<Number> vec_coarse( | ||||||
dof_handler_coarse.n_dofs()); | ||||||
|
||||||
Tensor<1, dim, Number> exp; | ||||||
exp[0] = 1.0; | ||||||
|
||||||
VectorTools::interpolate(dof_handler_fine, | ||||||
Functions::Monomial<dim>(exp), | ||||||
vec_fine); | ||||||
|
||||||
transfer.interpolate(vec_coarse, vec_fine); | ||||||
|
||||||
DataOut<dim> data_out; | ||||||
|
||||||
data_out.add_data_vector(dof_handler_coarse, vec_coarse, "solution_coarse"); | ||||||
data_out.add_data_vector(dof_handler_fine, vec_fine, "solution_fine"); | ||||||
|
||||||
data_out.build_patches(); | ||||||
|
||||||
static unsigned int counter = 0; | ||||||
|
||||||
#if 0 | ||||||
data_out.write_vtu_with_pvtu_record( | ||||||
"./", "result", counter++, tria.get_communicator(), 3, 1); | ||||||
#else | ||||||
deallog << std::endl; | ||||||
data_out.write_vtk(deallog.get_file_stream()); | ||||||
#endif | ||||||
} | ||||||
|
||||||
template <int dim, typename Number> | ||||||
void | ||||||
test(const FiniteElement<dim> &fe_fine, const FiniteElement<dim> &fe_coarse) | ||||||
{ | ||||||
deallog.push("0"); | ||||||
do_test(hp::FECollection<dim>(fe_fine), hp::FECollection<dim>(fe_coarse)); | ||||||
deallog.pop(); | ||||||
deallog.push("1"); | ||||||
do_test(hp::FECollection<dim>(fe_fine, FE_Nothing<dim>()), | ||||||
hp::FECollection<dim>(fe_coarse)); | ||||||
deallog.pop(); | ||||||
deallog.push("2"); | ||||||
do_test(hp::FECollection<dim>(fe_fine), | ||||||
hp::FECollection<dim>(fe_coarse, FE_Nothing<dim>())); | ||||||
deallog.pop(); | ||||||
deallog.push("3"); | ||||||
do_test(hp::FECollection<dim>(fe_fine, FE_Nothing<dim>()), | ||||||
hp::FECollection<dim>(fe_coarse, FE_Nothing<dim>())); | ||||||
deallog.pop(); | ||||||
} | ||||||
|
||||||
template <int dim, typename Number> | ||||||
void | ||||||
test() | ||||||
{ | ||||||
const unsigned int fe_degree = 2; | ||||||
|
||||||
deallog.push("CG<->CG"); | ||||||
test<dim, Number>(FE_Q<dim>(fe_degree), FE_Q<dim>(fe_degree)); | ||||||
deallog.pop(); | ||||||
deallog.push("DG<->CG"); | ||||||
test<dim, Number>(FE_DGQ<dim>(fe_degree), FE_Q<dim>(fe_degree)); | ||||||
deallog.pop(); | ||||||
deallog.push("CG<->DG"); | ||||||
test<dim, Number>(FE_Q<dim>(fe_degree), FE_DGQ<dim>(fe_degree)); | ||||||
deallog.pop(); | ||||||
deallog.push("DG<->DG"); | ||||||
test<dim, Number>(FE_DGQ<dim>(fe_degree), FE_DGQ<dim>(fe_degree)); | ||||||
deallog.pop(); | ||||||
} | ||||||
|
||||||
int | ||||||
main(int argc, char **argv) | ||||||
{ | ||||||
Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); | ||||||
MPILogInitAll all; | ||||||
|
||||||
deallog.precision(8); | ||||||
|
||||||
test<2, double>(); | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was a bug before, but we never actually triggered the alternative element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It was "just" an assert ;)