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

177 lines
4.9 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_BLACKBODY_HPP
  20. #define ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP
  21. #include "math/constants.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. * @return Radiant intensity of the blackbody, in watt per steradian.
  54. */
  55. template <class T>
  56. T radiant_intensity(T t, T a);
  57. /**
  58. * Calculates the spectral exitance of a blackbody for the given wavelength.
  59. *
  60. * @param t Temperature of the blackbody, in kelvin.
  61. * @param lambda Wavelength of light, in meters.
  62. * @param c Speed of light in medium.
  63. * @return Spectral exitance, in watt per square meter, per meter.
  64. */
  65. template <class T>
  66. T spectral_exitance(T t, T lambda, T c = constants::speed_of_light<T>);
  67. /**
  68. * Calculates the spectral flux of a blackbody for the given wavelength.
  69. *
  70. * @param t Temperature of the blackbody, in kelvin.
  71. * @param a Surface area of the blackbody, in square meters.
  72. * @param lambda Wavelength of light, in meters.
  73. * @param c Speed of light in medium.
  74. * @return Spectral flux of the blackbody, in watt per meter.
  75. */
  76. template <class T>
  77. T spectral_flux(T t, T a, T lambda, T c = constants::speed_of_light<T>);
  78. /**
  79. * Calculates the spectral intensity of a blackbody for the given wavelength.
  80. *
  81. * @param t Temperature of the blackbody, in kelvin.
  82. * @param a Surface area of the blackbody, in square meters.
  83. * @param lambda Wavelength of light, in meters.
  84. * @param c Speed of light in medium.
  85. * @return Spectral intensity of the blackbody for the given wavelength, in watt per steradian per meter.
  86. */
  87. template <class T>
  88. T spectral_intensity(T t, T a, T lambda, T c = constants::speed_of_light<T>);
  89. /**
  90. * Calculates the spectral radiance of a blackbody for the given wavelength.
  91. *
  92. * @param t Temperature of the blackbody, in kelvin.
  93. * @param lambda Wavelength of light, in meters.
  94. * @param c Speed of light in medium.
  95. * @return Spectral radiance, in watt per steradian per square meter per meter.
  96. */
  97. template <class T>
  98. T spectral_radiance(T t, T lambda, T c = constants::speed_of_light<T>);
  99. template <class T>
  100. T radiant_exitance(T t)
  101. {
  102. const T tt = t * t;
  103. return constants::stefan_boltzmann<T> * (tt * tt);
  104. }
  105. template <class T>
  106. T radiant_flux(T t, T a)
  107. {
  108. return a * radiant_exitance(t);
  109. }
  110. template <class T>
  111. T radiant_intensity(T t, T a)
  112. {
  113. return radiant_flux(t, a) / (T(4) * math::pi<T>);
  114. }
  115. template <class T>
  116. T spectral_exitance(T t, T lambda, T c)
  117. {
  118. const T hc = constants::planck<T> * c;
  119. const T lambda2 = lambda * lambda;
  120. // First radiation constant (c1)
  121. const T c1 = T(2) * math::pi<T> * hc * c;
  122. // Second radiation constant (c2)
  123. const T c2 = hc / constants::boltzmann<T>;
  124. return (c1 / (lambda2 * lambda2 * lambda)) / std::expm1(c2 / (lambda * t));
  125. }
  126. template <class T>
  127. T spectral_flux(T t, T a, T lambda, T c)
  128. {
  129. return a * spectral_exitance(t, lambda, c);
  130. }
  131. template <class T>
  132. T spectral_intensity(T t, T a, T lambda, T c)
  133. {
  134. return spectral_flux(t, a, lambda, c) / (T(4) * math::pi<T>);
  135. }
  136. template <class T>
  137. T spectral_radiance(T t, T lambda, T c)
  138. {
  139. const T hc = constants::planck<T> * c;
  140. const T lambda2 = lambda * lambda;
  141. // First radiation constant (c1L)
  142. const T c1l = T(2) * hc * c;
  143. // Second radiation constant (c2)
  144. const T c2 = hc / constants::boltzmann<T>;
  145. return (c1l / (lambda2 * lambda2 * lambda)) / std::expm1(c2 / (lambda * t));
  146. }
  147. } // namespace blackbody
  148. } // namespace light
  149. } // namespace physics
  150. #endif // ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP