| |
| #include <cmath> /* pow(), ceil() */ |
| #include "igs_motion_wind_table.h" |
| |
| int igs::motion_wind::table_size(const double length_min, |
| const double length_max) { |
| if (length_min < length_max) { |
| return static_cast<int>(ceil(length_max)); |
| } |
| return static_cast<int>(ceil(length_min)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| int igs::motion_wind::make_table( |
| std::vector<double> &table, igs::math::random &length_random, |
| igs::math::random &force_random, igs::math::random &density_random, |
| const double length_min, const double length_max, |
| const double length_bias |
| , |
| const double force_min, const double force_max, |
| const double force_bias |
| , |
| const double density_min, const double density_max, |
| const double density_bias |
| ) { |
| |
| double length = length_min; |
| if (length_min != length_max) { |
| double dif = length_random.next_d(); |
| if (0.0 != length_bias) { |
| dif = pow(dif, 1.0 / length_bias); |
| } |
| length += dif * (length_max - length_min); |
| } |
| |
| |
| |
| double force = force_min; |
| if (force_min != force_max) { |
| double dif = force_random.next_d(); |
| if (0.0 != force_bias) { |
| dif = pow(dif, 1.0 / force_bias); |
| } |
| force += dif * (force_max - force_min); |
| } |
| |
| |
| |
| double density = density_min; |
| if (density_min != density_max) { |
| double dif = density_random.next_d(); |
| if (0.0 != density_bias) { |
| dif = pow(dif, 1.0 / density_bias); |
| } |
| density += dif * (density_max - density_min); |
| } |
| |
| |
| const int table_len = static_cast<int>(ceil(length)); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| for (int ii = 0; ii < table_len; ++ii) { |
| table.at(ii) = (length - ii) / length; |
| } |
| |
| |
| if (1.0 != force) { |
| if (0.0 < force) { |
| for (int ii = 1; ii < table_len; ++ii) { |
| table.at(ii) = pow(table.at(ii), 1.0 / force); |
| } |
| } else { |
| for (int ii = 1; ii < table_len; ++ii) { |
| table.at(ii) = 0.0; |
| } |
| } |
| } |
| |
| |
| for (int ii = 1; ii < table_len; ++ii) { |
| table.at(ii) *= density; |
| } |
| return table_len; |
| } |