parameters.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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: 2020-06-12 17:25:52 +0200 (ven, 12 jun 2020) $
  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. /// Whether to drop leaves and root litter PFT specific (1) or once a year (0)
  97. extern bool ifpftlitterfall;
  98. /// Whether to recalculate phenology directly after restarting from a saved state (1, default for EC-Earth-Veg) or not (0)
  99. extern bool calc_phen_after_restart;
  100. /// Water uptake parameterisation
  101. extern wateruptaketype wateruptake;
  102. /// whether CENTURY SOM dynamics (otherwise uses standard LPJ formalism)
  103. extern bool ifcentury;
  104. /// whether plant growth limited by available N
  105. extern bool ifnlim;
  106. /// number of years to allow spinup without nitrogen limitation
  107. extern int freenyears;
  108. /// fraction of nitrogen relocated by plants from roots and leaves
  109. extern double nrelocfrac;
  110. /// first term in nitrogen fixation eqn (Cleveland et al 1999)
  111. extern double nfix_a;
  112. /// second term in nitrogen fixation eqn (Cleveland et al 1999)
  113. extern double nfix_b;
  114. /// Whether other landcovers than natural vegetation are simulated.
  115. extern bool run_landcover;
  116. /// Whether a specific landcover type is simulated (URBAN, CROPLAND, PASTURE, FOREST, NATURAL, PEATLAND, BARREN).
  117. extern bool run[NLANDCOVERTYPES];
  118. /// Whether landcover fractions are not read from input file.
  119. extern bool lcfrac_fixed;
  120. /// Whether fractions of stand types of a specific land cover are not read from input file.
  121. extern bool frac_fixed[NLANDCOVERTYPES];
  122. /// Set to false by initio( ) if fraction input files have yearly data.
  123. extern bool all_fracs_const;
  124. /// If a slow harvested product pool is included in patchpft.
  125. extern bool ifslowharvestpool;
  126. // If grass is allowed to grow between crop growingseasons
  127. extern bool ifintercropgrass;
  128. // Whether to calculate dynamic potential heat units
  129. extern bool ifcalcdynamic_phu;
  130. // 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)
  131. extern int gross_land_transfer;
  132. // Whether gross land transfer input read for this gridcell
  133. extern bool gross_input_present;
  134. // Whether to use primary/secondary land transition info in landcover transfer input file (1). or not (0)
  135. extern bool ifprimary_lc_transfer;
  136. // Distinguish between primary and secondary natural stands at area reduction
  137. extern bool use_primary_lc_transfer;
  138. // Whether to use primary-to-secondary land transition info (within land cover type) in landcover transfer input file (1). or not (0)
  139. extern bool ifprimary_to_secondary_transfer;
  140. // Pooling level of land cover transitions; 0: one big pool; 1: land cover-level; 2: stand type-level
  141. extern int transfer_level;
  142. // Whether to create new stands in transfer_to_new_stand() according to the rules in copy_stand_type()
  143. extern bool iftransfer_to_new_stand;
  144. // Whether to limit dynamic phu calculation to a period specified by nyear_dyn_phu
  145. extern bool ifdyn_phu_limit;
  146. // Number of years to calculate dynamic phu if dynamic_phu_limit is true
  147. extern int nyear_dyn_phu;
  148. /// number of spinup years
  149. extern int nyear_spinup;
  150. /// Whether to use sowingdates from input file
  151. extern bool readsowingdates;
  152. /// Whether to use harvestdates from input file
  153. extern bool readharvestdates;
  154. /// Whether to read N fertilization from input file
  155. extern bool readNfert;
  156. /// Whether to read N fertilization (stand type level) from input file
  157. extern bool readNfert_st;
  158. /// Whether to use forest harvested fraction from input file
  159. extern bool readwoodharvest_frac;
  160. /// Whether to use wood harvest volume from input file
  161. extern bool readwoodharvest_vol;
  162. /// Whether to create new stands at clearcut of secondary stands
  163. extern bool harvest_secondary_to_new_stand;
  164. /// Whether to print multiple stands within a land cover type (except cropland) separately
  165. extern bool printseparatestands;
  166. /// Whether to print CRESCENDO output
  167. extern bool printcrescendo;
  168. /// Whether to print * daily * CRESCENDO output
  169. extern bool printcrescendodaily;
  170. /// Whether to print * daily * FACE experiment CRESCENDO output
  171. extern bool printcrescendofacedaily;
  172. /// Whether to print CMIP6 output
  173. extern bool printcmip6;
  174. /// Whether to print * daily * CMIP6 output
  175. extern bool printcmip6daily;
  176. /// Whether to print * daily * IFS input variables as output
  177. extern bool printifsinputdaily;
  178. /// Whether to simulate tillage by increasing soil respiration
  179. extern bool iftillage;
  180. /// Use silt/sand fractions per soiltype
  181. extern bool textured_soil;
  182. /// Whether pastures are affected by disturbance and fire (affects pastures' npatch)
  183. extern bool disturb_pasture;
  184. /// Whether to simulate cropland as pasture
  185. extern bool grassforcrop;
  186. ///////////////////////////////////////////////////////////////////////////////////////
  187. // Settings controlling the saving and loading from state files
  188. /// Location of state files
  189. extern xtring state_path;
  190. /// Name of the state files - ecev3
  191. extern xtring state_name;
  192. /// Whether to restart from state files
  193. extern bool restart;
  194. /// Whether to save state files
  195. extern bool save_state;
  196. /// Save/restart year
  197. extern int state_year;
  198. /// whether to vary mort_greff smoothly with growth efficiency (1) or to use the standard step-function (0)
  199. extern bool ifsmoothgreffmort;
  200. /// whether establishment is limited by growing season drought
  201. extern bool ifdroughtlimitedestab;
  202. /// rain on wet days only (1, true), or a little every day (0, false);
  203. extern bool ifrainonwetdaysonly;
  204. /// whether BVOC calculations are included
  205. extern bool ifbvoc;
  206. /// for LUMIP deforest experiment
  207. /* defines the method of deforestation that is used:
  208. * 0=disabled
  209. * 1=simple establishment turned off/on at start and end year every where
  210. * 2=only in grid points where a "vs" transition occurs is the establishment turned off and on at start and end year, respectively
  211. */
  212. extern int deforest_method_type;
  213. /// year the establishment will be turned off in Trees
  214. extern int deforest_start_year;
  215. /// year the establishment will be turned on again in Trees
  216. extern int deforest_end_year;
  217. ///////////////////////////////////////////////////////////////////////////////////////
  218. // The Paramlist class (and Paramtype)
  219. //
  220. /// Represents one custom "param" item
  221. /** \see Paramlist */
  222. struct Paramtype {
  223. xtring name;
  224. xtring str;
  225. double num;
  226. };
  227. /// List for the "custom" parameters
  228. /** Functionality for storing and retrieving custom "param" items from the instruction
  229. * script. "Custom" parameters can be accessed by other modules without the need to
  230. * define them beforehand. This of course also means there is no help text associated
  231. * with these parameters, so the user can't get any documentation about them from
  232. * the command line.
  233. *
  234. * Custom keywords may be included in the instruction script using syntax similar to
  235. * the following examples:
  236. *
  237. * \code
  238. * param "co2" (num 340)
  239. * param "file_gridlist" (str "gridlist.txt")
  240. * \endcode
  241. *
  242. * To retrieve the values associated with the "param" strings in the above examples,
  243. * use the following function calls (may appear anywhere in this file; instruction
  244. * script must have been read in first):
  245. *
  246. * \code
  247. * param["co2"].num
  248. * param["file_gridlist"].str
  249. * \endcode
  250. *
  251. * Each "param" item can store EITHER a number (int or double) OR a string, but not
  252. * both types of data. Function fail is called to terminate output if a "param" item
  253. * with the specified identifier was not read in.
  254. */
  255. class Paramlist : public ListArray<Paramtype> {
  256. public:
  257. /// Adds a parameter with a numeric value, overwriting if it already existed
  258. void addparam(xtring name,xtring value);
  259. /// Adds a parameter with a string value, overwriting if it already existed
  260. void addparam(xtring name,double value);
  261. /// Fetches a parameter from the list, aborts the program if it didn't exist
  262. Paramtype& operator[](xtring name);
  263. /// Tests if param exists
  264. bool isparam(xtring name);
  265. private:
  266. /// Tries to find the parameter in the list
  267. /** \returns 0 if it wasn't there. */
  268. Paramtype* find(xtring name);
  269. };
  270. /// The global Paramlist object
  271. /** Contains all the custom parameters after reading in the instruction file */
  272. extern Paramlist param;
  273. /// Reads in the instruction file
  274. /** Uses PLIB library functions to read instructions from file specified by
  275. * 'insfilename'.
  276. */
  277. void read_instruction_file(const char* insfilename);
  278. /// Displays documentation about the instruction file parameters to the user
  279. void printhelp();
  280. ///////////////////////////////////////////////////////////////////////////////////////
  281. // Interface for declaring parameters from other modules
  282. /// Declares an xtring parameter
  283. /** \param name The name of the parameter
  284. * \param param Pointer to variable where the value of the parameter is to be placed
  285. * \param maxlen Maximum allowed length of the parameter in the ins file
  286. * \param help Documentation describing the parameter to the user
  287. */
  288. void declare_parameter(const char* name, xtring* param, int maxlen, const char* help = "");
  289. /// Declares a std:string parameter
  290. /** \param name The name of the parameter
  291. * \param param Pointer to variable where the value of the parameter is to be placed
  292. * \param maxlen Maximum allowed length of the parameter in the ins file
  293. * \param help Documentation describing the parameter to the user
  294. */
  295. void declare_parameter(const char* name, std::string* param, int maxlen, const char* help = "");
  296. /// Declares an int parameter
  297. /** \param name The name of the parameter
  298. * \param param Pointer to variable where the value of the parameter is to be placed
  299. * \param min Minimum allowed value of the parameter in the ins file
  300. * \param max Maximum allowed value of the parameter in the ins file
  301. * \param help Documentation describing the parameter to the user
  302. */
  303. void declare_parameter(const char* name, int* param, int min, int max, const char* help = "");
  304. /// Declares a double parameter
  305. /** \param name The name of the parameter
  306. * \param param Pointer to variable where the value of the parameter is to be placed
  307. * \param min Minimum allowed value of the parameter in the ins file
  308. * \param max Maximum allowed value of the parameter in the ins file
  309. * \param help Documentation describing the parameter to the user
  310. */
  311. void declare_parameter(const char* name, double* param, double min, double max, const char* help = "");
  312. /// Declares a bool parameter
  313. /** \param name The name of the parameter
  314. * \param param Pointer to variable where the value of the parameter is to be placed
  315. * \param help Documentation describing the parameter to the user
  316. */
  317. void declare_parameter(const char* name, bool* param, const char* help = "");
  318. #endif // LPJ_GUESS_PARAMETERS_H