]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix division by zero that should never happen.
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 10 Jun 2024 17:26:02 +0000 (13:26 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Tue, 18 Jun 2024 23:01:27 +0000 (17:01 -0600)
source/particles/particle_handler.cc

index 7280ba15e2a3684bb4b86368e71d6514236d7c4d..c345341e9d04b5ba80b71f4a81d94003a11b9779 100644 (file)
@@ -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<double>::epsilon())
+            vertex_to_particle /= vertex_to_particle.norm();
 
           const unsigned int closest_vertex_index =
             current_cell->vertex_index(closest_vertex);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.