💿🐜 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.

82 lines
2.4 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. /**
  26. * Calculates the luminous efficiency of a light source.
  27. *
  28. * @param spd Unary function object that returns spectral radiance given a wavelength.
  29. * @param lef Unary function object that returns luminous efficiency given a wavelength.
  30. * @param first,last Range of sample wavelengths.
  31. * @return Luminous efficiency, on `[0, 1]`.
  32. *
  33. * @see physics::light::blackbody::spectral_radiance
  34. * @see physics::light::luminosity::photopic
  35. */
  36. template <class T, class UnaryOp1, class UnaryOp2, class InputIt>
  37. T luminous_efficiency(UnaryOp1 spd, UnaryOp2 lef, InputIt first, InputIt last)
  38. {
  39. auto spd_lef = [spd, lef](T x) -> T
  40. {
  41. return spd(x) * lef(x);
  42. };
  43. const T num = math::quadrature::trapezoid(spd_lef, first, last);
  44. const T den = math::quadrature::trapezoid(spd, first, last);
  45. return num / den;
  46. }
  47. /**
  48. * Calculates luminous efficacy given luminous efficiency.
  49. *
  50. * @param efficiency Luminous efficiency, on `[0, 1]`.
  51. * @return Luminous flux, in lumens.
  52. */
  53. template <class T>
  54. T luminous_efficacy(T efficiency)
  55. {
  56. return T(683.002) * efficiency;
  57. }
  58. /**
  59. * Converts watts (radiant flux) to lumens (luminous flux).
  60. *
  61. * @param radient_flux Radiance flux, in watts.
  62. * @param efficiency Luminous efficiency, on `[0, 1]`.
  63. * @return Luminous flux, in lumens.
  64. */
  65. template <class T>
  66. T watts_to_lumens(T radient_flux, T efficiency)
  67. {
  68. return radient_flux * luminous_efficacy(efficiency);
  69. }
  70. } // namespace light
  71. } // namespace physics
  72. #endif // ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP