From c49d8978980a245e512ad5fe95167c1a6ddee5e0 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Wed, 24 Sep 2014 08:52:57 +0200 Subject: [PATCH] [MGT] Handle case where standard deviation of edge lengths is very small. --- MeshGeoToolsLib/HeuristicSearchLength.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/MeshGeoToolsLib/HeuristicSearchLength.cpp b/MeshGeoToolsLib/HeuristicSearchLength.cpp index fad637711b3..3a19fc002bc 100644 --- a/MeshGeoToolsLib/HeuristicSearchLength.cpp +++ b/MeshGeoToolsLib/HeuristicSearchLength.cpp @@ -47,16 +47,20 @@ HeuristicSearchLength::HeuristicSearchLength(MeshLib::Mesh const& mesh) } const double mu (sum/edge_cnt); - const double s (sqrt(1.0/(edge_cnt-1) * (sum_of_sqr - (sum*sum)/edge_cnt) )); - // heuristic to prevent negative search lengths - // in the case of a big standard deviation s - double c(2.0); - while (mu < c * s) { - c *= 0.9; + const double helper (sum_of_sqr - (sum*sum)/edge_cnt); + if (helper < 0.0) { + _search_length = mu/2; + } else { + const double s (sqrt(helper/(edge_cnt-1))); + // heuristic to prevent negative search lengths + // in the case of a big standard deviation s + double c(2.0); + while (mu < c * s) { + c *= 0.9; + } + _search_length = (mu - c * s)/2; } - _search_length = (mu - c * s)/2; - DBUG("[MeshNodeSearcher::MeshNodeSearcher] Calculated search length for mesh \"%s\" is %f.", _mesh.getName().c_str(), _search_length); } -- GitLab