parameters.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file parameters.h
  3. /// \brief The parameters module is responsible for reading in the instruction file
  4. ///
  5. /// This module defines and makes available a lot of the instruction file parameters
  6. /// used by the model, but also lets other modules define their own parameters or
  7. /// access "custom" parameters without defining them.
  8. ///
  9. /// A new parameter can be added by creating a new global variable here (or a new
  10. /// Pft member variable if it's a PFT parameter), and then declaring it in
  11. /// plib_declarations in parameters.cpp. See the many existing examples, and
  12. /// documentation in the PLIB library for further documentation about this.
  13. ///
  14. /// Sometimes, adding a new parameter shouldn't (or can't) be done here however.
  15. /// A parameter specific for a certain input module, should only be declared if
  16. /// that input module is used. In this case the input module should declare its
  17. /// own parameters when it is created. This can also be a good idea simply to
  18. /// make modules more independent. For parameters like this, we can either use
  19. /// the "custom" parameters (\see Paramlist) which don't need to be declared at
  20. /// all, or the parameters can be declared with the declare_parameter family of
  21. /// functions.
  22. ///
  23. /// \author Joe Siltberg
  24. /// $Date: 2018-12-21 08:30:58 +0100 (Fri, 21 Dec 2018) $
  25. ///
  26. ///////////////////////////////////////////////////////////////////////////////////////
  27. #ifndef LPJ_GUESS_PARAMETERS_H
  28. #define LPJ_GUESS_PARAMETERS_H
  29. #include "gutil.h"
  30. #include <string>
  31. ///////////////////////////////////////////////////////////////////////////////////////
  32. // Enums needed by some of the global instruction file parameters defined below
  33. /// Vegetation 'mode', i.e. what each Individual object represents
  34. /** Can be one of:
  35. * 1. The average characteristics of all individuals comprising a PFT
  36. * population over the modelled area (standard LPJ mode)
  37. * 2. A cohort of individuals of a PFT that are roughly the same age
  38. * 3. An individual plant
  39. */
  40. typedef enum {NOVEGMODE, INDIVIDUAL, COHORT, POPULATION} vegmodetype;
  41. /// Land cover type of a stand. NLANDCOVERTYPES keeps count of number of items.
  42. /* NB. set_lc_change_array() must be modified when adding new land cover types
  43. */
  44. typedef enum {URBAN, CROPLAND, PASTURE, FOREST, NATURAL, PEATLAND, BARREN, NLANDCOVERTYPES} landcovertype;
  45. /// CMIP6 Land cover type of a stand. NCMIP6LANDCOVERTYPES keeps count of number of items.
  46. typedef enum { PSL, CRP, PST, URB, NCMIP6LANDCOVERTYPES } cmip6landcovertype;
  47. /// Water uptake parameterisations
  48. /** \see water_uptake in canexch.cpp
  49. */
  50. typedef enum {WR_WCONT, WR_ROOTDIST, WR_SMART, WR_SPECIESSPECIFIC} wateruptaketype;
  51. ///bvoc: define monoterpene species used
  52. typedef enum {APIN, BPIN, LIMO, MYRC, SABI, CAMP, TRIC, TBOC, OTHR, NMTCOMPOUNDTYPES} monoterpenecompoundtype;
  53. ///////////////////////////////////////////////////////////////////////////////////////
  54. // Global instruction file parameters
  55. /// Title for this run
  56. extern xtring title;
  57. /// Vegetation mode (population, cohort or individual)
  58. extern vegmodetype vegmode;
  59. /// Default number of patches in each stand
  60. /** Should always be 1 in population mode,
  61. * cropland stands always have 1 patch.
  62. * Actual patch number for stand objects may differ and
  63. * should always be queried by stand.npatch()
  64. */
  65. extern int npatch;
  66. /// Number of patches in each stand for secondary stands
  67. extern int npatch_secondarystand;
  68. /// Whether to reduce equal percentage of all stands of a stand type at land cover change
  69. extern bool reduce_all_stands;
  70. /// Minimum age of stands to reduce at land cover change
  71. extern int age_limit_reduce;
  72. /// Patch area (m2) (individual and cohort mode only)
  73. extern double patcharea;
  74. /// Whether background establishment enabled (individual, cohort mode)
  75. extern bool ifbgestab;
  76. /// Whether spatial mass effect enabled for establishment (individual, cohort mode)
  77. extern bool ifsme;
  78. /// Whether establishment stochastic (individual, cohort mode)
  79. extern bool ifstochestab;
  80. /// Whether mortality stochastic (individual, cohort mode)
  81. extern bool ifstochmort;
  82. /// Whether fire enabled
  83. extern bool iffire;
  84. /// Whether "generic" patch-destroying disturbance enabled (individual, cohort mode)
  85. extern bool ifdisturb;
  86. /// Generic patch-destroying disturbance interval (individual, cohort mode)
  87. extern double distinterval;
  88. /// Whether SLA calculated from leaf longevity (alt: prescribed)
  89. extern bool ifcalcsla;
  90. /// Whether leaf C:N ratio minimum calculated from leaf longevity (alt: prescribed)
  91. extern bool ifcalccton;
  92. /// Establishment interval in cohort mode (years)
  93. extern int estinterval;
  94. /// Whether C debt (storage between years) permitted
  95. extern bool ifcdebt;
  96. /// Water uptake parameterisation
  97. extern wateruptaketype wateruptake;
  98. /// whether CENTURY SOM dynamics (otherwise uses standard LPJ formalism)
  99. extern bool ifcentury;
  100. /// whether plant growth limited by available N
  101. extern bool ifnlim;
  102. /// number of years to allow spinup without nitrogen limitation
  103. extern int freenyears;
  104. /// fraction of nitrogen relocated by plants from roots and leaves
  105. extern double nrelocfrac;
  106. /// first term in nitrogen fixation eqn (Cleveland et al 1999)
  107. extern double nfix_a;
  108. /// second term in nitrogen fixation eqn (Cleveland et al 1999)
  109. extern double nfix_b;
  110. /// Whether other landcovers than natural vegetation are simulated.
  111. extern bool run_landcover;
  112. /// Whether a specific landcover type is simulated (URBAN, CROPLAND, PASTURE, FOREST, NATURAL, PEATLAND, BARREN).
  113. extern bool run[NLANDCOVERTYPES];
  114. /// Whether landcover fractions are not read from input file.
  115. extern bool lcfrac_fixed;
  116. /// Whether fractions of stand types of a specific land cover are not read from input file.
  117. extern bool frac_fixed[NLANDCOVERTYPES];
  118. /// Set to false by initio( ) if fraction input files have yearly data.
  119. extern bool all_fracs_const;
  120. /// If a slow harvested product pool is included in patchpft.
  121. extern bool ifslowharvestpool;
  122. // If grass is allowed to grow between crop growingseasons
  123. extern bool ifintercropgrass;
  124. // Whether to calculate dynamic potential heat units
  125. extern bool ifcalcdynamic_phu;
  126. // Whether to use gross land transfer: simulate gross lcc (1); read landcover transfer matrix input file (2); read stand type transfer matrix input file (3), or not (0)
  127. extern int gross_land_transfer;
  128. // Whether gross land transfer input read for this gridcell
  129. extern bool gross_input_present;
  130. // Whether to use primary/secondary land transition info in landcover transfer input file (1). or not (0)
  131. extern bool ifprimary_lc_transfer;
  132. // Distinguish between primary and secondary natural stands at area reduction
  133. extern bool use_primary_lc_transfer;
  134. // Whether to use primary-to-secondary land transition info (within land cover type) in landcover transfer input file (1). or not (0)
  135. extern bool ifprimary_to_secondary_transfer;
  136. // Pooling level of land cover transitions; 0: one big pool; 1: land cover-level; 2: stand type-level
  137. extern int transfer_level;
  138. // Whether to create new stands in transfer_to_new_stand() according to the rules in copy_stand_type()
  139. extern bool iftransfer_to_new_stand;
  140. // Whether to limit dynamic phu calculation to a period specified by nyear_dyn_phu
  141. extern bool ifdyn_phu_limit;
  142. // Number of years to calculate dynamic phu if dynamic_phu_limit is true
  143. extern int nyear_dyn_phu;
  144. /// number of spinup years
  145. extern int nyear_spinup;
  146. /// Whether to use sowingdates from input file
  147. extern bool readsowingdates;
  148. /// Whether to use harvestdates from input file
  149. extern bool readharvestdates;
  150. /// Whether to read N fertilization from input file
  151. extern bool readNfert;
  152. /// Whether to read N fertilization (stand type level) from input file
  153. extern bool readNfert_st;
  154. /// Whether to use forest harvested fraction from input file
  155. extern bool readwoodharvest_frac;
  156. /// Whether to use wood harvest volume from input file
  157. extern bool readwoodharvest_vol;
  158. /// Whether to create new stands at clearcut of secondary stands
  159. extern bool harvest_secondary_to_new_stand;
  160. /// Whether to print multiple stands within a land cover type (except cropland) separately
  161. extern bool printseparatestands;
  162. /// Whether to print CRESCENDO output
  163. extern bool printcrescendo;
  164. /// Whether to print * daily * CRESCENDO output
  165. extern bool printcrescendodaily;
  166. /// Whether to print * daily * FACE experiment CRESCENDO output
  167. extern bool printcrescendofacedaily;
  168. /// Whether to print CMIP6 output
  169. extern bool printcmip6;
  170. /// Whether to print * daily * CMIP6 output
  171. extern bool printcmip6daily;
  172. /// Whether to print * daily * IFS input variables as output
  173. extern bool printifsinputdaily;
  174. /// Whether to simulate tillage by increasing soil respiration
  175. extern bool iftillage;
  176. /// Use silt/sand fractions per soiltype
  177. extern bool textured_soil;
  178. /// Whether pastures are affected by disturbance and fire (affects pastures' npatch)
  179. extern bool disturb_pasture;
  180. /// Whether to simulate cropland as pasture
  181. extern bool grassforcrop;
  182. ///////////////////////////////////////////////////////////////////////////////////////
  183. // Settings controlling the saving and loading from state files
  184. /// Location of state files
  185. extern xtring state_path;
  186. /// Name of the state files - ecev3
  187. extern xtring state_name;
  188. /// Whether to restart from state files
  189. extern bool restart;
  190. /// Whether to save state files
  191. extern bool save_state;
  192. /// Save/restart year
  193. extern int state_year;
  194. /// whether to vary mort_greff smoothly with growth efficiency (1) or to use the standard step-function (0)
  195. extern bool ifsmoothgreffmort;
  196. /// whether establishment is limited by growing season drought
  197. extern bool ifdroughtlimitedestab;
  198. /// rain on wet days only (1, true), or a little every day (0, false);
  199. extern bool ifrainonwetdaysonly;
  200. /// whether BVOC calculations are included
  201. extern bool ifbvoc;
  202. /// for LUMIP deforest experiment
  203. /* defines the method of deforestation that is used:
  204. * 0=disabled
  205. * 1=simple establishment turned off/on at start and end year every where
  206. * 2=only in grid points where a "vs" transition occurs is the establishment turned off and on at start and end year, respectively
  207. */
  208. extern int deforest_method_type;
  209. /// year the establishment will be turned off in Trees
  210. extern int deforest_start_year;
  211. /// year the establishment will be turned on again in Trees
  212. extern int deforest_end_year;
  213. ///////////////////////////////////////////////////////////////////////////////////////
  214. // The Paramlist class (and Paramtype)
  215. //
  216. /// Represents one custom "param" item
  217. /** \see Paramlist */
  218. struct Paramtype {
  219. xtring name;
  220. xtring str;
  221. double num;
  222. };
  223. /// List for the "custom" parameters
  224. /** Functionality for storing and retrieving custom "param" items from the instruction
  225. * script. "Custom" parameters can be accessed by other modules without the need to
  226. * define them beforehand. This of course also means there is no help text associated
  227. * with these parameters, so the user can't get any documentation about them from
  228. * the command line.
  229. *
  230. * Custom keywords may be included in the instruction script using syntax similar to
  231. * the following examples:
  232. *
  233. * \code
  234. * param "co2" (num 340)
  235. * param "file_gridlist" (str "gridlist.txt")
  236. * \endcode
  237. *
  238. * To retrieve the values associated with the "param" strings in the above examples,
  239. * use the following function calls (may appear anywhere in this file; instruction
  240. * script must have been read in first):
  241. *
  242. * \code
  243. * param["co2"].num
  244. * param["file_gridlist"].str
  245. * \endcode
  246. *
  247. * Each "param" item can store EITHER a number (int or double) OR a string, but not
  248. * both types of data. Function fail is called to terminate output if a "param" item
  249. * with the specified identifier was not read in.
  250. */
  251. class Paramlist : public ListArray<Paramtype> {
  252. public:
  253. /// Adds a parameter with a numeric value, overwriting if it already existed
  254. void addparam(xtring name,xtring value);
  255. /// Adds a parameter with a string value, overwriting if it already existed
  256. void addparam(xtring name,double value);
  257. /// Fetches a parameter from the list, aborts the program if it didn't exist
  258. Paramtype& operator[](xtring name);
  259. /// Tests if param exists
  260. bool isparam(xtring name);
  261. private:
  262. /// Tries to find the parameter in the list
  263. /** \returns 0 if it wasn't there. */
  264. Paramtype* find(xtring name);
  265. };
  266. /// The global Paramlist object
  267. /** Contains all the custom parameters after reading in the instruction file */
  268. extern Paramlist param;
  269. /// Reads in the instruction file
  270. /** Uses PLIB library functions to read instructions from file specified by
  271. * 'insfilename'.
  272. */
  273. void read_instruction_file(const char* insfilename);
  274. /// Displays documentation about the instruction file parameters to the user
  275. void printhelp();
  276. ///////////////////////////////////////////////////////////////////////////////////////
  277. // Interface for declaring parameters from other modules
  278. /// Declares an xtring parameter
  279. /** \param name The name of the parameter
  280. * \param param Pointer to variable where the value of the parameter is to be placed
  281. * \param maxlen Maximum allowed length of the parameter in the ins file
  282. * \param help Documentation describing the parameter to the user
  283. */
  284. void declare_parameter(const char* name, xtring* param, int maxlen, const char* help = "");
  285. /// Declares a std:string parameter
  286. /** \param name The name of the parameter
  287. * \param param Pointer to variable where the value of the parameter is to be placed
  288. * \param maxlen Maximum allowed length of the parameter in the ins file
  289. * \param help Documentation describing the parameter to the user
  290. */
  291. void declare_parameter(const char* name, std::string* param, int maxlen, const char* help = "");
  292. /// Declares an int parameter
  293. /** \param name The name of the parameter
  294. * \param param Pointer to variable where the value of the parameter is to be placed
  295. * \param min Minimum allowed value of the parameter in the ins file
  296. * \param max Maximum allowed value of the parameter in the ins file
  297. * \param help Documentation describing the parameter to the user
  298. */
  299. void declare_parameter(const char* name, int* param, int min, int max, const char* help = "");
  300. /// Declares a double parameter
  301. /** \param name The name of the parameter
  302. * \param param Pointer to variable where the value of the parameter is to be placed
  303. * \param min Minimum allowed value of the parameter in the ins file
  304. * \param max Maximum allowed value of the parameter in the ins file
  305. * \param help Documentation describing the parameter to the user
  306. */
  307. void declare_parameter(const char* name, double* param, double min, double max, const char* help = "");
  308. /// Declares a bool parameter
  309. /** \param name The name of the parameter
  310. * \param param Pointer to variable where the value of the parameter is to be placed
  311. * \param help Documentation describing the parameter to the user
  312. */
  313. void declare_parameter(const char* name, bool* param, const char* help = "");
  314. #endif // LPJ_GUESS_PARAMETERS_H