q10.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file q10.h
  3. /// \brief Q10 calculations for photosynthesis
  4. ///
  5. /// Calculations of Q10 values for photosynthesis, formerly
  6. /// placed in canexch.cpp now moved to separate header file
  7. /// because of their application for BVOC calculations as well.
  8. ///
  9. /// \author Guy Schurgers (based on LPJ-GUESS 2.1 / Ben Smith)
  10. /// $Date: 2014-09-09 10:49:13 +0200 (mar, 09 sep 2014) $
  11. ///
  12. ///////////////////////////////////////////////////////////////////////////////////////
  13. // WHAT SHOULD THIS FILE CONTAIN?
  14. // Module header files need normally contain only declarations of functions
  15. // defined in the module that are to be accessible to the calling framework or
  16. // to other modules.
  17. #ifndef LPJ_GUESS_Q10_H
  18. #define LPJ_GUESS_Q10_H
  19. #include "guessmath.h"
  20. #include <vector>
  21. // Constants required for Q10 lookup tables used by photosynthesis
  22. const double Q10_MINTEMP = -70; // minimum temperature ever (deg C)
  23. const double Q10_MAXTEMP = 70; // maximum temperature ever (deg C)
  24. const double Q10_PRECISION = 0.01; // rounding precision for temperature
  25. const int Q10_NDATA = static_cast<int>((Q10_MAXTEMP-Q10_MINTEMP)/Q10_PRECISION + 1.5);
  26. // maximum number of values to store in each lookup table
  27. /// Q10 lookup table class
  28. /** Stores pre-calculated temperature-adjusted values based on Q10 and
  29. * a 25-degree base value.
  30. */
  31. class LookupQ10 {
  32. private:
  33. /// The temperature-adjusted values
  34. std::vector<double> data;
  35. public:
  36. /// Creates a lookup table
  37. /** \param q10 The Q10 to be used for the table
  38. * \param base25 Base value for 25 degrees C
  39. */
  40. LookupQ10(double q10, double base25) : data(Q10_NDATA) {
  41. for (int i=0; i<Q10_NDATA; i++) {
  42. data[i] = base25 * pow(q10, (Q10_MINTEMP + i*Q10_PRECISION - 25.0) / 10.0);
  43. }
  44. }
  45. /// "Array element" operator
  46. /** \param temp Temperature (deg C)
  47. * \returns Temperature-adjusted value based on Q10 and 25-degree base value
  48. */
  49. double& operator[](double& temp) {
  50. // Element number corresponding to a particular temperature
  51. if (temp < Q10_MINTEMP) {
  52. temp = Q10_MINTEMP;
  53. } else if (temp > Q10_MAXTEMP) {
  54. temp = Q10_MAXTEMP;
  55. }
  56. int i = static_cast<int>((temp-Q10_MINTEMP)/Q10_PRECISION+0.5);
  57. return data[i];
  58. }
  59. };
  60. #endif // LPJ_GUESS_Q10_H