From 736c5c61fe9101acf42ab856143b00e91c31d034 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 1 Mar 2021 09:50:29 -0600 Subject: [PATCH 1/3] Change how temperatures are selected when temperature_range is given --- src/nuclide.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/nuclide.cpp b/src/nuclide.cpp index b0d3439743..7c1396e0f2 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -90,9 +90,17 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) double T_min = n > 0 ? settings::temperature_range[0] : 0.0; double T_max = n > 0 ? settings::temperature_range[1] : INFTY; if (T_max > 0.0) { - for (auto T : temps_available) { - if (T_min <= T && T <= T_max) { - temps_to_read.push_back(std::round(T)); + for (int j = 0; j < temps_available.size() - 1; ++j) { + if ((T_min <= temps_available[j] && temps_available[j] < T_max) || + (T_min <= temps_available[j+1] && temps_available[j+1] < T_max)) { + int T_j = std::round(temps_available[j]); + int T_j1 = std::round(temps_available[j+1]); + if (!contains(temps_to_read, T_j)) { + temps_to_read.push_back(T_j); + } + if (!contains(temps_to_read, T_j1)) { + temps_to_read.push_back(T_j1); + } } } } From 1bad13d5f6e5b7877050183e28ba8c74adba98c9 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 2 Mar 2021 09:40:13 -0600 Subject: [PATCH 2/3] Make sure one-temperature case is handled correctly for temperature range --- src/nuclide.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 7c1396e0f2..47f380aac8 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -90,14 +90,18 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) double T_min = n > 0 ? settings::temperature_range[0] : 0.0; double T_max = n > 0 ? settings::temperature_range[1] : INFTY; if (T_max > 0.0) { - for (int j = 0; j < temps_available.size() - 1; ++j) { - if ((T_min <= temps_available[j] && temps_available[j] < T_max) || - (T_min <= temps_available[j+1] && temps_available[j+1] < T_max)) { + // For each interval (T_j, T_j+1), if either T_j or T_j+1 are within the + // temperature range, load data for *both* T_j and T_j+1 + int n = temps_available.size(); + for (int j = 0; j < n; ++j) { + if ((T_min <= temps_available[j] && temps_available[j] < T_max)) { int T_j = std::round(temps_available[j]); - int T_j1 = std::round(temps_available[j+1]); if (!contains(temps_to_read, T_j)) { temps_to_read.push_back(T_j); } + } + if (j < n - 1 && T_min <= temps_available[j+1] && temps_available[j+1] < T_max) { + int T_j1 = std::round(temps_available[j+1]); if (!contains(temps_to_read, T_j1)) { temps_to_read.push_back(T_j1); } From 9933b7f0f83085785febd12dad44cafe01bbd780 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 9 Mar 2021 13:03:34 -0600 Subject: [PATCH 3/3] Update determination of temperatures to load given temperature range --- src/nuclide.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 47f380aac8..17508fa190 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -83,29 +83,25 @@ Nuclide::Nuclide(hid_t group, const std::vector& temperature) } // Determine actual temperatures to read -- start by checking whether a - // temperature range was given, in which case all temperatures in the range - // are loaded irrespective of what temperatures actually appear in the model + // temperature range was given (indicated by T_max > 0), in which case all + // temperatures in the range are loaded irrespective of what temperatures + // actually appear in the model std::vector temps_to_read; int n = temperature.size(); double T_min = n > 0 ? settings::temperature_range[0] : 0.0; double T_max = n > 0 ? settings::temperature_range[1] : INFTY; if (T_max > 0.0) { - // For each interval (T_j, T_j+1), if either T_j or T_j+1 are within the - // temperature range, load data for *both* T_j and T_j+1 - int n = temps_available.size(); - for (int j = 0; j < n; ++j) { - if ((T_min <= temps_available[j] && temps_available[j] < T_max)) { - int T_j = std::round(temps_available[j]); - if (!contains(temps_to_read, T_j)) { - temps_to_read.push_back(T_j); - } - } - if (j < n - 1 && T_min <= temps_available[j+1] && temps_available[j+1] < T_max) { - int T_j1 = std::round(temps_available[j+1]); - if (!contains(temps_to_read, T_j1)) { - temps_to_read.push_back(T_j1); - } - } + // Determine first available temperature below or equal to T_min + auto T_min_it = std::upper_bound(temps_available.begin(), temps_available.end(), T_min); + if (T_min_it != temps_available.begin()) --T_min_it; + + // Determine first available temperature above or equal to T_max + auto T_max_it = std::lower_bound(temps_available.begin(), temps_available.end(), T_max); + if (T_max_it != temps_available.end()) ++T_max_it; + + // Add corresponding temperatures to vector + for (auto it = T_min_it; it != T_max_it; ++it) { + temps_to_read.push_back(std::round(*it)); } }