💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
  20. #define ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
  21. #include "math/constants.hpp"
  22. #include "math/quadrature.hpp"
  23. namespace physics {
  24. namespace light {
  25. /// Maximum luminous efficacy of an ideal monochromatic source, in lumen per watt.
  26. template <class T>
  27. constexpr T max_luminous_efficacy = T(683.002);
  28. /**
  29. * Calculates the luminous efficiency of a light source.
  30. *
  31. * @param spd Unary function object that returns spectral radiance given a wavelength.
  32. * @param lef Unary function object that returns luminous efficiency given a wavelength.
  33. * @param first,last Range of sample wavelengths.
  34. * @return Luminous efficiency, on `[0, 1]`.
  35. *
  36. * @see physics::light::blackbody::spectral_radiance
  37. * @see physics::light::luminosity::photopic
  38. */
  39. template <class T, class UnaryOp1, class UnaryOp2, class InputIt>
  40. T luminous_efficiency(UnaryOp1 spd, UnaryOp2 lef, InputIt first, InputIt last)
  41. {
  42. auto spd_lef = [spd, lef](T x) -> T
  43. {
  44. return spd(x) * lef(x);
  45. };
  46. const T num = math::quadrature::simpson(spd_lef, first, last);
  47. const T den = math::quadrature::simpson(spd, first, last);
  48. return num / den;
  49. }
  50. /**
  51. * Calculates luminous efficacy given luminous efficiency.
  52. *
  53. * @param efficiency Luminous efficiency, on `[0, 1]`.
  54. * @return Luminous flux, in lumens.
  55. */
  56. template <class T>
  57. T luminous_efficacy(T efficiency)
  58. {
  59. return max_luminous_efficacy<T> * efficiency;
  60. }
  61. /**
  62. * Converts watts (radiant flux) to lumens (luminous flux).
  63. *
  64. * @param radiant_flux Radiant flux, in watts.
  65. * @param efficiency Luminous efficiency, on `[0, 1]`.
  66. * @return Luminous flux, in lumens.
  67. */
  68. template <class T>
  69. T watts_to_lumens(T radiant_flux, T efficiency)
  70. {
  71. return radiant_flux * luminous_efficacy(efficiency);
  72. }
  73. } // namespace light
  74. } // namespace physics
  75. #endif // ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP