From: Rene Gassmoeller Date: Mon, 10 Jun 2024 17:26:02 +0000 (-0400) Subject: Fix division by zero that should never happen. X-Git-Tag: v9.6.0-rc1~179^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0d65191fb07ba10b2fd5466a4bf38aacbb7c9e2;p=dealii.git Fix division by zero that should never happen. --- diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 7280ba15e2..c345341e9d 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -1348,7 +1348,12 @@ namespace Particles current_cell, out_particle->get_location(), *mapping); Tensor<1, spacedim> vertex_to_particle = out_particle->get_location() - current_cell->vertex(closest_vertex); - vertex_to_particle /= vertex_to_particle.norm(); + + // Only normalize if vector is larger than zero, the algorithm below + // works fine for zero vectors. + if (vertex_to_particle.norm() > + 100. * std::numeric_limits::epsilon()) + vertex_to_particle /= vertex_to_particle.norm(); const unsigned int closest_vertex_index = current_cell->vertex_index(closest_vertex);