Skip to content
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

Add inter-grid transfer operators #10417

Merged
merged 1 commit into from Sep 22, 2020
Merged

Conversation

peterrum
Copy link
Member

No description provided.

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind describing the new classes on a high level? I got lost when looking at the review.

I left some initial comments.

include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved


/**
* Class for repartitioning data living on the same triangulation, which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triangulation or dofhandler? Or is this more generic? Are these vectors the same size?

This is probably unrelated to multigrid and could go somewhere else (vectortools?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably unrelated to multigrid and could go somewhere else (vectortools?).

But for now I would like to keep in this PR since it uses the same infrastructure as the global-coarsening algorithm is using.

include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
@peterrum peterrum mentioned this pull request Aug 24, 2020
@peterrum
Copy link
Member Author

@tjhei Sorry for the late reply! The idea is following.

Let's consider for now two levels (the level with more dofs I will call fine level; the other one is the coarse level). The class MGTwoLevelTransfer is responsible for transfer between these two levels. However, within levels we might need to distinguish how to perform element-wise prolongate/restrict:

  • hp-context: restriction/prolongation between element of different polynomial degrees
  • global coarsening: restriction/prolongation to children or application of identity matrix (if coarse cell is not refined)

This information is encrypted in the class MGTransferScheme. MGTwoLevelTransfer practically loops over all MGTransferSchemes.

The class MGTransferMatrixFreeNew (or however it will be called) is a collection of MGTwoLevelTransfers.

In the namespace MGTransferUtilities, I have collected functions that set up MGTwoLevelTransfer for hp-context and global coarsening.

tests/multigrid-transfer/mg_transfer_a_01.cc Outdated Show resolved Hide resolved
* elements are currently not implemented.
*/
template <typename MatrixType>
class MGTransferMatrixFreeNew
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe MGTransferGlobalCoarsening?

@tjhei
Copy link
Member

tjhei commented Sep 18, 2020

Maybe move VectorRepartitioner into separate PR?
What about custom constraints?

@peterrum
Copy link
Member Author

maybe MGTransferGlobalCoarsening?

Done!

Maybe move VectorRepartitioner into separate PR?

I have removed it. Once this PR is merged, I will open the PR for that.

What about custom constraints?

Could you have a look at the utility functions. There users have the possibility to pass constraint matrices. In what way are these different from custom constraints?

@peterrum
Copy link
Member Author

/rebuild

include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
* MGTransferUtilities to setup the Transfer operators.
*/
template <typename Number>
struct MGTransferScheme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, then this is an implementation detail of TwoLevelTransfer, right? I would make this a member of it or move it into an implementation namespace.

include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_interface.h Outdated Show resolved Hide resolved
* Class for transfer between two multigrid levels.
*/
template <int dim, typename Number>
class MGTwoLevelTransfer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest templating on VectorType and only implementing d:Vector for now.



/**
* Class for transfer between two multigrid levels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extend to say that this can be p or global coarsening?

* elements are currently not implemented.
*/
template <typename MatrixType>
class MGTransferMatrixFreeNew
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming to GlobalCoarsening

: matrices(matrices)
, transfer(transfer)
{
AssertDimension(matrices.max_level() - matrices.min_level(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the documentation of this function talks about l and l-1 entries, but here you assert that they are equal. Fix, please.

bool
run(Fu &fu)
{
return do_run_degree<1>(fu) || do_run_degree<2>(fu) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about degree=0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can think about degree=0. But let's leave that for a follow-up PR.

* 2) bisect, and 3) decrease-by-one is supported.
*/
bool
polynomial_transfer_supported(const unsigned int fe_degree_fine,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just FE_Q or more generic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently FE_Q and FE_DGQ (and I guess FE_DGQArbitraryNodes). I guess it should be the same as in the case MGTransferMatrixFree.

@peterrum
Copy link
Member Author

@tjhei I have made the changes.



/**
* Implementation of the MGTransferBase interface for which the transfer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this documentation is outdated. Please mention p and h global coarsening.


DEAL_II_NAMESPACE_OPEN

namespace MGTransferUtilities
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the namespace. Also, the name is not ideal, is it?

* 2) bisect, and 3) decrease-by-one is supported.
*/
bool
polynomial_transfer_supported(const unsigned int fe_degree_fine,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the documentation, I have no idea what this function does. Would this be more appropriate as a static member of MGTransferTwoLevel? I assume that this is what the function reports on.

*/
template <int dim, typename Number, typename MeshType>
void
setup_global_coarsening_transfer(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a constructor of MGTwoLevelTransfer?

*/
template <int dim, typename Number, typename MeshType>
void
setup_polynomial_transfer(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

MGTwoLevelTransfer<dim, LinearAlgebra::distributed::Vector<Number>>
&transfer);

} // namespace MGTransferUtilities
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With all three functions gone, we could get rid of this namespace and file.

@peterrum
Copy link
Member Author

@tjhei I have following changes:

  • remove utility namspace and add the functions to MGTwoLevelTransfer (with new names reinit_geometric_transfer() and reinit_polynomial_transfer())
  • remove old files
  • remove the template argument MeshType (since hp::DoFHandler is now part of DoFHandler)

Le's not over-think the structure of the internal functions. My guess is once we want to support additional vector types, we can reuse many functions.

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quicj edits. Things look much better now. I have more complaints though, sorry.

* scheme for transfer between children and parent cells, as well as, one
* transfer scheme for cells that are not refined).
*/
struct MGTransferScheme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be public?

// ---------------------------------------------------------------------


// Test ConsensusAlgorithms::AnonymousProcess.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update



/**
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Test MGTwoLevelTransfer with mesh coarsening"

deallog.precision(8);

for (unsigned int i = 1; i < 5; i++)
test<2, double>(i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test output seems to be really large (github doesn't even show it). Can you see if this can be reduced somewhat?



/**
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test MGTwoLevelTransfer with polynomial coarsening

fe_degree_coarse++)
if (MGTwoLevelTransfer<2, LinearAlgebra::distributed::Vector<double>>::
polynomial_transfer_supported(fe_degree_fine, fe_degree_coarse))
test<2, double>(fe_degree_fine, fe_degree_coarse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, the files seem to be quite big?



/**
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, add a one line description

DEAL::1 1 1 1
DEAL::1 1 1 1
DEAL::1 1 1 1
DEAL::1 1 1 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful!

@@ -0,0 +1,167 @@
// ---------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this is a new folder. Don't you need to add a CMakeList.txt? Also, maybe we should name this folder multigrid-global-coarsening ?

@peterrum
Copy link
Member Author

@tjhei I have addressed your comments. Once you are happy, I will squash.

@tjhei
Copy link
Member

tjhei commented Sep 21, 2020

Looks good, please squash.

@peterrum
Copy link
Member Author

@tjhei Done!

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I will let somebody else to take a look. @kronbichler ?

Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from a few comments, this looks good to me.

include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
include/deal.II/multigrid/mg_transfer_global_coarsening.h Outdated Show resolved Hide resolved
Comment on lines +56 to +60
return do_run_degree<1>(fu) || do_run_degree<2>(fu) ||
do_run_degree<3>(fu) || do_run_degree<4>(fu) ||
do_run_degree<5>(fu) || do_run_degree<6>(fu) ||
do_run_degree<7>(fu) || do_run_degree<8>(fu) ||
do_run_degree<9>(fu);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that other cases are supposed to happen later; my question would be if that follow-up code would then go to a generic version with -1 template argument (or 0 in the tensor product evaluators) so we do not bail out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. Let's leave it to a follow-up PR.

Comment on lines +1074 to +1093
AssertDimension(dof_handler_fine.get_fe(0).n_base_elements(), 1);
std::string fe_name =
dof_handler_fine.get_fe(0).base_element(0).get_name();
{
const std::size_t template_starts = fe_name.find_first_of('<');
Assert(fe_name[template_starts + 1] ==
(dim == 1 ? '1' : (dim == 2 ? '2' : '3')),
ExcInternalError());
fe_name[template_starts + 1] = '1';
}
const std::unique_ptr<FiniteElement<1>> fe(
FETools::get_fe_by_name<1, 1>(fe_name));

transfer.schemes[0].prolongation_matrix_1d.resize(fe->dofs_per_cell *
fe->dofs_per_cell);

for (unsigned int i = 0; i < fe->dofs_per_cell; i++)
transfer.schemes[0]
.prolongation_matrix_1d[i + i * fe->dofs_per_cell] = Number(1.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a candidate for #9544.

Comment on lines +1647 to +1652
const auto ierr = cell_transfer.run(cell_prolongator);
(void)ierr;
Assert(ierr,
ExcMessage("Prolongation " +
std::to_string(scheme.degree_coarse) + " -> " +
std::to_string(scheme.degree_fine) +
" not instantiated!"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the place I was referring to in my comment above about the default case degree=-1.

@peterrum
Copy link
Member Author

@kronbichler I have addressed your comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants