From d828aca012172d7828b21304cabec7294fb21195 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Tue, 13 Apr 2021 15:38:59 -0600 Subject: [PATCH] Bug in weighting_callback for uninitialized DoFHandlers. --- include/deal.II/distributed/cell_weights.h | 6 +++++- source/distributed/cell_weights.cc | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/deal.II/distributed/cell_weights.h b/include/deal.II/distributed/cell_weights.h index e8c1649178..3ea742ddf1 100644 --- a/include/deal.II/distributed/cell_weights.h +++ b/include/deal.II/distributed/cell_weights.h @@ -40,6 +40,9 @@ namespace parallel * a DoFHandler. One can choose from predefined weighting algorithms provided * by this class or provide a custom one. * + * If the associated DoFHandler has not been initialized yet, i.e., its + * hp::FECollection is empty, all cell weights will be evaluated as zero. + * * This class offers two different ways of connecting the chosen weighting * function to the corresponding signal of the linked * parallel::TriangulationBase. The recommended way involves creating an @@ -282,7 +285,8 @@ namespace parallel * A callback function that will be connected to the cell_weight signal of * the @p triangulation, to which the @p dof_handler is attached. Ultimately * returns the weight for each cell, determined by the @p weighting_function - * provided as a parameter. + * provided as a parameter. Returns zero if @p dof_handler has not been + * initialized yet. */ static unsigned int weighting_callback( diff --git a/source/distributed/cell_weights.cc b/source/distributed/cell_weights.cc index d493728065..a6441a314f 100644 --- a/source/distributed/cell_weights.cc +++ b/source/distributed/cell_weights.cc @@ -176,6 +176,10 @@ namespace parallel "Triangulation associated with the DoFHandler has changed!")); (void)triangulation; + // Skip if the DoFHandler has not been initialized yet. + if (dof_handler.get_fe_collection().size() == 0) + return 0; + // Convert cell type from Triangulation to DoFHandler to be able // to access the information about the degrees of freedom. const typename DoFHandler::cell_iterator cell(*cell_, -- 2.39.5