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

Expose RemotePointEvaluation parameters in non-nested multigrid #15899

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion include/deal.II/multigrid/mg_transfer_global_coarsening.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,35 @@ class MGTwoLevelTransferNonNested<dim,
using VectorizedArrayType = VectorizedArray<Number, 1>;

public:
/**
* AdditionalData structure with the arguments needed by
* RemotePointEvaluation. Default values are the same as the ones described in
* the documentation of RemotePointEvaluation. The last boolean parameter, @p enf_all_points_found is true by defaults and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* the documentation of RemotePointEvaluation. The last boolean parameter, @p enf_all_points_found is true by defaults and
* the documentation of RemotePointEvaluation. The last Boolean parameter,
* @p enf_all_points_found is true by defaults and

* checks if RemotePointEvaluation::all_points_found() evaluates to true, i.e.
* all submitted points have been found inside the domain.
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 write the text more general, since we plan to add more parameters.

*/
struct AdditionalData
{
AdditionalData(const double tol = 1e-6,
const bool enf_unique_mapping = false,
Copy link
Member

Choose a reason for hiding this comment

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

Not needed.

const unsigned int rtree_l = 0,
const std::function<std::vector<bool>()> &marked_verts = {},
Copy link
Member

Choose a reason for hiding this comment

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

Not needed.

const bool enf_all_points_found = true)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const bool enf_all_points_found = true)
const bool enforce_all_points_found = true)

: tolerance(tol)
, enforce_unique_mapping(enf_unique_mapping)
, rtree_level(rtree_l)
, marked_vertices(marked_verts)
, enforce_all_points_found(enf_all_points_found)
{}
double tolerance;
bool enforce_unique_mapping;
unsigned int rtree_level;
std::function<std::vector<bool>()> marked_vertices;
bool enforce_all_points_found;
};

MGTwoLevelTransferNonNested(const AdditionalData &data = AdditionalData());

/**
* Set up transfer operator between the given DoFHandler objects (
* @p dof_handler_fine and @p dof_handler_coarse).
Expand Down Expand Up @@ -749,6 +778,7 @@ class MGTwoLevelTransferNonNested<dim,
memory_consumption() const override;

protected:
AdditionalData additional_data;
/**
* Perform prolongation.
*/
Expand Down Expand Up @@ -788,7 +818,7 @@ class MGTwoLevelTransferNonNested<dim,
* Object to evaluate shape functions on one mesh on visited support points of
* the other mesh.
*/
Utilities::MPI::RemotePointEvaluation<dim> rpe;
std::shared_ptr<Utilities::MPI::RemotePointEvaluation<dim>> rpe;
Copy link
Member

Choose a reason for hiding this comment

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

The change to shared_ptr is not needed!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it was a leftover from debugging. Fixed, thanks


/**
* MappingInfo object needed as Mapping argument by FEPointEvaluation.
Expand Down
51 changes: 35 additions & 16 deletions include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -4100,6 +4100,19 @@ namespace internal
} // namespace internal



template <int dim, typename Number>
MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
MGTwoLevelTransferNonNested(const AdditionalData &data)
: additional_data(data)
{
rpe = std::make_shared<Utilities::MPI::RemotePointEvaluation<dim>>(
data.tolerance,
data.enforce_unique_mapping,
data.rtree_level,
data.marked_vertices);
}

template <int dim, typename Number>
void
MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
Expand Down Expand Up @@ -4170,13 +4183,19 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
this->partitioner_fine->global_to_local(global_dof_indices[i]);

// hand points over to RPE
rpe.reinit(points, dof_handler_coarse.get_triangulation(), mapping_coarse);
rpe->reinit(points, dof_handler_coarse.get_triangulation(), mapping_coarse);

if (additional_data.enforce_all_points_found)
AssertThrow(
rpe->all_points_found(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rpe->all_points_found(),
!additional_data.enforce_all_points_found || rpe->all_points_found(),

ExcMessage(
"You requested that all points should be found, but this didn't happen. You can change this option through the AdditionaData struct in the constructor."));

// set up MappingInfo for easier data access
mapping_info = internal::fill_mapping_info<dim, Number>(rpe);
mapping_info = internal::fill_mapping_info<dim, Number>(*rpe);

// set up constraints
const auto &cell_data = rpe.get_cell_data();
const auto &cell_data = rpe->get_cell_data();

constraint_info.reinit(dof_handler_coarse,
cell_data.cells.size(),
Expand All @@ -4185,7 +4204,7 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
for (unsigned int i = 0; i < cell_data.cells.size(); ++i)
{
typename DoFHandler<dim>::active_cell_iterator cell(
&rpe.get_triangulation(),
&rpe->get_triangulation(),
cell_data.cells[i].first,
cell_data.cells[i].second,
&dof_handler_coarse);
Expand Down Expand Up @@ -4295,18 +4314,18 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
}
};

rpe.template evaluate_and_process<value_type>(evaluation_point_results,
buffer,
evaluation_function);
rpe->template evaluate_and_process<value_type>(evaluation_point_results,
buffer,
evaluation_function);

// Weight operator in case some points are owned by multiple cells.
if (rpe.is_map_unique() == false)
if (rpe->is_map_unique() == false)
{
const auto evaluation_point_results_temp = evaluation_point_results;
evaluation_point_results.clear();
evaluation_point_results.reserve(rpe.get_point_ptrs().size() - 1);
evaluation_point_results.reserve(rpe->get_point_ptrs().size() - 1);

const auto &ptr = rpe.get_point_ptrs();
const auto &ptr = rpe->get_point_ptrs();

for (unsigned int i = 0; i < ptr.size() - 1; ++i)
{
Expand Down Expand Up @@ -4388,7 +4407,7 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
std::vector<value_type> evaluation_point_results;
std::vector<value_type> buffer;

evaluation_point_results.resize(rpe.get_point_ptrs().size() - 1);
evaluation_point_results.resize(rpe->get_point_ptrs().size() - 1);

for (unsigned int j = 0; j < evaluation_point_results.size(); ++j)
{
Expand Down Expand Up @@ -4423,9 +4442,9 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
}

// Weight operator in case some points are owned by multiple cells.
if (rpe.is_map_unique() == false)
if (rpe->is_map_unique() == false)
{
const auto &ptr = rpe.get_point_ptrs();
const auto &ptr = rpe->get_point_ptrs();

for (unsigned int i = 0; i < ptr.size() - 1; ++i)
{
Expand Down Expand Up @@ -4470,9 +4489,9 @@ MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>::
}
};

rpe.template process_and_evaluate<value_type>(evaluation_point_results,
buffer,
evaluation_function);
rpe->template process_and_evaluate<value_type>(evaluation_point_results,
buffer,
evaluation_function);
}


Expand Down
4 changes: 3 additions & 1 deletion tests/multigrid-global-coarsening/non_nested_multigrid_03.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ test(const unsigned int n_refinements, const unsigned int fe_degree_fine)
}

// set up transfer operator
typename MGTwoLevelTransferNonNested<dim, VectorType>::AdditionalData data;
data.enforce_all_points_found = false;
for (unsigned int l = min_level; l < max_level; ++l)
{
transfers[l + 1] =
std::make_shared<MGTwoLevelTransferNonNested<dim, VectorType>>();
std::make_shared<MGTwoLevelTransferNonNested<dim, VectorType>>(data);
transfers[l + 1]->reinit(dof_handlers[l + 1],
dof_handlers[l],
mappings[l + 1],
Expand Down
6 changes: 5 additions & 1 deletion tests/multigrid-global-coarsening/non_nested_transfer_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ do_test(const FiniteElement<dim> & fe_fine,
constraint_fine.close();

// setup transfer operator
typename MGTwoLevelTransferNonNested<
dim,
LinearAlgebra::distributed::Vector<Number>>::AdditionalData data;
data.enforce_all_points_found = false;
MGTwoLevelTransferNonNested<dim, LinearAlgebra::distributed::Vector<Number>>
transfer;
transfer(data);
MappingQ1<dim> mapping_fine, mapping_coarse;
transfer.reinit(dof_handler_fine,
dof_handler_coarse,
Expand Down