flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
scan.cpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#include "scan.hpp"
20#include "error.hpp"
21#include <algorithm>
22#include <cmath>
23#include <cstddef>
24
30namespace flexiblesusy {
31
42std::vector<double> float_range(double start, double stop,
43 std::size_t number_of_steps)
44{
45 const double step_size = (stop - start) / number_of_steps;
46 std::vector<double> result(number_of_steps);
47
48 for (std::size_t i = 0; i < number_of_steps; ++i) {
49 result[i] = start + i*step_size;
50 }
51
52 return result;
53}
54
67std::vector<double> float_range_log(double start, double stop,
68 std::size_t number_of_steps)
69{
70 if (start <= 0 || stop <= 0) {
71 throw flexiblesusy::OutOfBoundsError("float_range_log: interval boundaries must be > 0.");
72 }
73
74 const double log_start = std::log(start);
75 const double log_stop = std::log(stop);
76 auto result = float_range(log_start, log_stop, number_of_steps);
77
78 std::transform(result.begin(), result.end(), result.begin(),
79 [] (double x) { return std::exp(x); });
80
81 return result;
82}
83
94std::vector<double> subdivide(double start, double stop,
95 std::size_t number_of_divisions)
96{
97 if (number_of_divisions == 0) {
98 throw flexiblesusy::OutOfBoundsError("subdivide: number_of_divisions must be > 0.");
99 }
100
101 auto result = float_range(start, stop, number_of_divisions);
102 result.push_back(stop);
103 result.shrink_to_fit();
104
105 return result;
106}
107
119std::vector<double> subdivide_log(double start, double stop,
120 std::size_t number_of_divisions)
121{
122 if (number_of_divisions == 0) {
123 throw flexiblesusy::OutOfBoundsError("subdivide_log: number_of_divisions must be > 0.");
124 }
125
126 auto result = float_range_log(start, stop, number_of_divisions);
127 result.push_back(stop);
128 result.shrink_to_fit();
129
130 return result;
131}
132
133} // namespace flexiblesusy
LinearRange[start_, stop_, steps_] stop
Out of bounds access.
Definition: error.hpp:208
std::vector< double > subdivide_log(double start, double stop, std::size_t number_of_divisions)
returns range of (number_of_divisions + 1) floating point values between (including) start and (inclu...
Definition: scan.cpp:119
std::vector< double > float_range(double start, double stop, std::size_t number_of_steps)
returns range of floating point values between start (included) and stop (excluded)
Definition: scan.cpp:42
std::vector< double > subdivide(double start, double stop, std::size_t number_of_divisions)
returns range of (number_of_divisions + 1) floating point values between (including) start and (inclu...
Definition: scan.cpp:94
Complex< T > log(const Complex< T > &z) noexcept
Definition: complex.hpp:54
std::vector< double > float_range_log(double start, double stop, std::size_t number_of_steps)
returns range of floating point values between start (included) and stop (excluded) with logarithmic ...
Definition: scan.cpp:67