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

179 lines
5.0 KiB

  1. /*
  2. * Copyright (C) 2023 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_BLACKBODY_HPP
  20. #define ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP
  21. #include "math/numbers.hpp"
  22. #include "physics/constants.hpp"
  23. namespace physics {
  24. namespace light {
  25. /**
  26. * Blackbody radiation functions.
  27. *
  28. * @see https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_law
  29. */
  30. namespace blackbody {
  31. /**
  32. * Calculates the radiant exitance of a blackbody.
  33. *
  34. * @param t Temperature of the blackbody, in kelvin.
  35. * @return Radiant exitance of the blackbody, in watt per square meter.
  36. */
  37. template <class T>
  38. T radiant_exitance(T t);
  39. /**
  40. * Calculates the radiant flux of a blackbody.
  41. *
  42. * @param t Temperature of the blackbody, in kelvin.
  43. * @param a Surface area of the blackbody, in square meters.
  44. * @return Radiant flux of the blackbody, in watt.
  45. */
  46. template <class T>
  47. T radiant_flux(T t, T a);
  48. /**
  49. * Calculates the radiant intensity of a blackbody.
  50. *
  51. * @param t Temperature of the blackbody, in kelvin.
  52. * @param a Surface area of the blackbody, in square meters.
  53. * @param omega Solid angle, in steradians.
  54. * @return Radiant intensity of the blackbody, in watt per steradian.
  55. */
  56. template <class T>
  57. T radiant_intensity(T t, T a, T omega);
  58. /**
  59. * Calculates the spectral exitance of a blackbody for the given wavelength.
  60. *
  61. * @param t Temperature of the blackbody, in kelvin.
  62. * @param lambda Wavelength of light, in meters.
  63. * @param c Speed of light in medium.
  64. * @return Spectral exitance, in watt per square meter, per meter.
  65. */
  66. template <class T>
  67. T spectral_exitance(T t, T lambda, T c = constants::speed_of_light<T>);
  68. /**
  69. * Calculates the spectral flux of a blackbody for the given wavelength.
  70. *
  71. * @param t Temperature of the blackbody, in kelvin.
  72. * @param a Surface area of the blackbody, in square meters.
  73. * @param lambda Wavelength of light, in meters.
  74. * @param c Speed of light in medium.
  75. * @return Spectral flux of the blackbody, in watt per meter.
  76. */
  77. template <class T>
  78. T spectral_flux(T t, T a, T lambda, T c = constants::speed_of_light<T>);
  79. /**
  80. * Calculates the spectral intensity of a blackbody for the given wavelength.
  81. *
  82. * @param t Temperature of the blackbody, in kelvin.
  83. * @param a Surface area of the blackbody, in square meters.
  84. * @param lambda Wavelength of light, in meters.
  85. * @param omega Solid angle, in steradians.
  86. * @param c Speed of light in medium.
  87. * @return Spectral intensity of the blackbody for the given wavelength, in watt per steradian per meter.
  88. */
  89. template <class T>
  90. T spectral_intensity(T t, T a, T lambda, T omega, T c = constants::speed_of_light<T>);
  91. /**
  92. * Calculates the spectral radiance of a blackbody for the given wavelength.
  93. *
  94. * @param t Temperature of the blackbody, in kelvin.
  95. * @param lambda Wavelength of light, in meters.
  96. * @param c Speed of light in medium.
  97. * @return Spectral radiance, in watt per steradian per square meter per meter.
  98. */
  99. template <class T>
  100. T spectral_radiance(T t, T lambda, T c = constants::speed_of_light<T>);
  101. template <class T>
  102. T radiant_exitance(T t)
  103. {
  104. const T tt = t * t;
  105. return constants::stefan_boltzmann<T> * (tt * tt);
  106. }
  107. template <class T>
  108. T radiant_flux(T t, T a)
  109. {
  110. return a * radiant_exitance(t);
  111. }
  112. template <class T>
  113. T radiant_intensity(T t, T a, T omega)
  114. {
  115. return radiant_flux(t, a) / omega;
  116. }
  117. template <class T>
  118. T spectral_exitance(T t, T lambda, T c)
  119. {
  120. const T hc = constants::planck<T> * c;
  121. const T lambda2 = lambda * lambda;
  122. // First radiation constant (c1)
  123. const T c1 = T(2) * math::pi<T> * hc * c;
  124. // Second radiation constant (c2)
  125. const T c2 = hc / constants::boltzmann<T>;
  126. return (c1 / (lambda2 * lambda2 * lambda)) / std::expm1(c2 / (lambda * t));
  127. }
  128. template <class T>
  129. T spectral_flux(T t, T a, T lambda, T c)
  130. {
  131. return a * spectral_exitance(t, lambda, c);
  132. }
  133. template <class T>
  134. T spectral_intensity(T t, T a, T lambda, T omega, T c)
  135. {
  136. return spectral_flux(t, a, lambda, c) / omega;
  137. }
  138. template <class T>
  139. T spectral_radiance(T t, T lambda, T c)
  140. {
  141. const T hc = constants::planck<T> * c;
  142. const T lambda2 = lambda * lambda;
  143. // First radiation constant (c1L)
  144. const T c1l = T(2) * hc * c;
  145. // Second radiation constant (c2)
  146. const T c2 = hc / constants::boltzmann<T>;
  147. return (c1l / (lambda2 * lambda2 * lambda)) / std::expm1(c2 / (lambda * t));
  148. }
  149. } // namespace blackbody
  150. } // namespace light
  151. } // namespace physics
  152. #endif // ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP