From: Marc Fehling Date: Tue, 13 Apr 2021 21:38:59 +0000 (-0600) Subject: Bug in weighting_callback for uninitialized DoFHandlers. X-Git-Tag: v9.3.0-rc1~227^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12041%2Fhead;p=dealii.git Bug in weighting_callback for uninitialized DoFHandlers. --- 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_,