Hi,
30-40% of the runtime for this operation seems a bit excessive to me. Maybe you should try using the FEValuesExtractors in conjunction with FEValues in order to get the solution at the quadrature points. If you want the solution at the support points, then you can just create a quadrature rule that has the quadrature points at the support points and initialise your FEValues object with it.
So this bit of pseudo-code illustrates roughly how it could be done:
const Quadrature<dim> q_cell_support_points (fe.unit_support_points()); // Assumes that your FE has unit support points; could also use the unit cell vertex positions, something else...
const FEValues<dim> fe_values(fe, q_cell_support_points, update_values);
const FEValuesExtractors::Scalar surface_A(0);
Vector<double> solution_vector = …; // If this is an MPI vector, then still use the same basic approach
double max_value = std::numeric_limits<double>::min();
for (auto cell : dof_handler.active_cell_iterators())
{
if (!cell->locally_owned()) continue;
fe_values.reinit(cell);
std::vector<double> q_point_solution_values (fe_values.n_quadrature_points);
fe_values[surface_A].get_function_values(solution_vector , q_point_solution_values);
// This will get you the maximum of the solution at the queried points
// for the local process.
for (auto entry : q_point_solution_values)
max_value = std::max(max_value, entry);
// Since you’re doing the work with a cell loop, if appropriate then you could also
// retrieve the max for the other fields at the same time.
}
// If the solution is distributed, then you still need the max over all processes:
max_value = Utilities::MPI::max(max_value, mpi_communicator);
I think that’s more or less how you could do it using the established classes and methodology. Hopefully it would yield you better performance,
since you don’t have to fetch a huge index set mask. The other benefit is that what I’ve written here makes no assumptions about how the coefficients of the solution vector relate to the physical solution.
I hope that this helps you out. It would be great to hear whether or not this sort of approach yields a performance benefit.
Best,
Jean-Paul