guess.h 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file guess.h
  3. /// \brief Framework header file, LPJ-GUESS Combined Modular Framework
  4. ///
  5. /// This header file contains:
  6. /// (1) definitions of all main classes used by the framework and modules. Modules may
  7. /// require classes to contain certain member variables and functions (see module
  8. /// source files for details).
  9. /// (2) other type, constant and function definitions to be accessible throughout the
  10. /// model code.
  11. /// (3) a forward declaration of the framework function if this is not the main
  12. /// function.
  13. ///
  14. /// \author Ben Smith
  15. /// $Date: 2020-06-23 10:44:28 +0200 (mar, 23 jun 2020) $
  16. ///
  17. ///////////////////////////////////////////////////////////////////////////////////////
  18. #ifndef LPJ_GUESS_GUESS_H
  19. #define LPJ_GUESS_GUESS_H
  20. #define CRESCENDO_FACE
  21. #undef CRESCENDO_FACE
  22. ///////////////////////////////////////////////////////////////////////////////////////
  23. // #INCLUDES FOR LIBRARY HEADER FILES
  24. // C/C++ libraries required for member functions of classes defined in this file.
  25. // These libraries will also be available globally (so omit these #includes from source
  26. // files). In addition to various standard C/C++ runtime libraries, the framework
  27. // requires the following libraries (individual modules may use additional libraries)
  28. //
  29. // GUTIL
  30. // Includes class xtring, providing functionality for pointer-free dynamic handling
  31. // of character strings; wherever possible in LPJ-GUESS, strings are represented as
  32. // objects of type xtring rather than simple arrays of type char. GUTIL also provides
  33. // templates for dynamic collection classes (list arrays of various types), argument
  34. // processing for printf-style functions, timing functions and other utilities.
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <time.h>
  39. #include "gutil.h"
  40. #include <vector>
  41. #include <algorithm>
  42. #include "shell.h"
  43. #include "guessmath.h"
  44. #include "archive.h"
  45. #include "parameters.h"
  46. #include "guesscontainer.h"
  47. #include "lamarquendep.h"
  48. ///////////////////////////////////////////////////////////////////////////////////////
  49. // GLOBAL ENUMERATED TYPE DEFINITIONS
  50. /// Life form class for PFTs (trees, grasses)
  51. typedef enum {NOLIFEFORM, TREE, GRASS} lifeformtype;
  52. /// Phenology class for PFTs
  53. typedef enum {NOPHENOLOGY, EVERGREEN, RAINGREEN, SUMMERGREEN, CROPGREEN, ANY} phenologytype;
  54. /// Biochemical pathway for photosynthesis (C3 or C4)
  55. typedef enum {NOPATHWAY, C3, C4} pathwaytype;
  56. /// Leaf physiognomy types for PFTs
  57. typedef enum {NOLEAFTYPE, NEEDLELEAF, BROADLEAF} leafphysiognomytype;
  58. /// Units for insolation driving data
  59. /** Insolation can be expressed as:
  60. *
  61. * - Percentage sunshine
  62. * - Net instantaneous downward shortwave radiation flux (W/m2)
  63. * - Total (i.e. with no correction for surface albedo) instantaneous downward
  64. * shortwave radiation flux (W/m2)
  65. *
  66. * Radiation flux can be interpreted as W/m2 during daylight hours, or averaged
  67. * over the whole time step which it represents (24 hours in daily mode). For
  68. * this reason there are two enumerators for these insolation types (e.g. SWRAD
  69. * and SWRAD_TS).
  70. */
  71. typedef enum {
  72. /// No insolation type chosen
  73. NOINSOL,
  74. /// Percentage sunshine
  75. SUNSHINE,
  76. /// Net shortwave radiation flux during daylight hours (W/m2)
  77. NETSWRAD,
  78. /// Total shortwave radiation flux during daylight hours (W/m2)
  79. SWRAD,
  80. /// Net shortwave radiation flux during whole time step (W/m2)
  81. NETSWRAD_TS,
  82. /// Total shortwave radiation flux during whole time step (W/m2)
  83. SWRAD_TS
  84. } insoltype;
  85. /// CENTURY pool names, NSOMPOOL number of SOM pools
  86. typedef enum {SURFSTRUCT, SOILSTRUCT, SOILMICRO, SURFHUMUS, SURFMICRO, SURFMETA, SURFFWD, SURFCWD,
  87. SOILMETA, SLOWSOM, PASSIVESOM, LEACHED, NSOMPOOL} pooltype;
  88. /// Irrigation type for PFTs
  89. typedef enum {RAINFED, IRRIGATED} hydrologytype;
  90. /// Intercrop type for PFTs
  91. typedef enum {NOINTERCROP, NATURALGRASS} intercroptype;
  92. /// Seasonality type of gridcell
  93. /** 0:SEASONALITY_NO No seasonality
  94. * 1:SEASONALITY_PREC Precipitation seasonality only
  95. * 2:SEASONALITY_PRECTEMP Both temperature and precipitation seasonality, but "weak" temperature seasonality (coldest month > 10degC)
  96. * 3:SEASONALITY_TEMP Temperature seasonality only
  97. * 4:SEASONALITY_TEMPPREC Both temperature and precipitation seasonality, but temperature most important (coldest month < 10degC)
  98. * 5:SEASONALITY_TEMPWARM Temperature seasonality, always above 10 degrees (currently not used)
  99. */
  100. typedef enum {SEASONALITY_NO, SEASONALITY_PREC, SEASONALITY_PRECTEMP, SEASONALITY_TEMP, SEASONALITY_TEMPPREC} seasonality_type;
  101. /// Precipitation seasonality type of gridcell
  102. /** 0:DRY (minprec_pet20<=0.5 && maxprec_pet20<=0.5)
  103. * 1:DRY_INTERMEDIATE (minprec_pet20<=0.5 && maxprec_pet20>0.5 && maxprec_pet20<=1.0)
  104. * 2:DRY_WET (minprec_pet20<=0.5 && maxprec_pet20>1.0)
  105. * 3:INTERMEDIATE (minprec_pet20>0.5 && minprec_pet20<=1.0 && maxprec_pet20>0.5 && maxprec_pet20<=1.0)
  106. * 4:INTERMEDIATE_WET (minprec_pet20>0.5 && minprec_pet20<=1.0 && maxprec_pet20>1.0)
  107. * 5:WET (minprec_pet20>1.0 && maxprec_pet20>1.0)
  108. */
  109. typedef enum {DRY, DRY_INTERMEDIATE, DRY_WET, INTERMEDIATE, INTERMEDIATE_WET, WET} prec_seasonality_type;
  110. /// Temperature seasonality type of gridcell
  111. /** 0:COLD (mtemp_max20<=10)
  112. * 1:COLD_WARM (mtemp_min20<=10 && mtemp_max20>10 && mtemp_max20<=30)
  113. * 2:COLD_HOT (mtemp_min20<=10 && mtemp_max20>30)
  114. * 3:WARM (mtemp_min20>10 && mtemp_max20<=30)
  115. * 4:WARM_HOT (mtemp_min20>10 && mtemp_max20>30)
  116. * 5:HOT (mtemp_min20>30)
  117. */
  118. typedef enum {COLD, COLD_WARM, COLD_HOT, WARM, WARM_HOT, HOT} temp_seasonality_type;
  119. ///////////////////////////////////////////////////////////////////////////////////////
  120. // GLOBAL CONSTANTS
  121. /// number of soil layers modelled
  122. const int NSOILLAYER = 2;
  123. /// bvoc: number of monoterpene species used
  124. const int NMTCOMPOUNDS = NMTCOMPOUNDTYPES;
  125. // SOIL DEPTH VALUES
  126. /// soil upper layer depth (mm)
  127. const double SOILDEPTH_UPPER = 500.0;
  128. /// soil lower layer depth (mm)
  129. const double SOILDEPTH_LOWER = 1000.0;
  130. /// Year at which to calculate equilibrium soil carbon
  131. const int SOLVESOM_END=400;
  132. /// Year at which to begin documenting means for calculation of equilibrium soil carbon
  133. const int SOLVESOM_BEGIN = 350;
  134. /// Number of years to average growth efficiency over in function mortality
  135. const int NYEARGREFF = 5;
  136. /// Coldest day in N hemisphere (January 15)
  137. /** Used to decide when to start counting GDD's and leaf-on days
  138. * for summergreen phenology.
  139. */
  140. const int COLDEST_DAY_NHEMISPHERE = 14;
  141. /// Coldest day in S hemisphere (July 15)
  142. /** Used to decide when to start counting GDD's and leaf-on days
  143. * for summergreen phenology.
  144. */
  145. const int COLDEST_DAY_SHEMISPHERE = 195;
  146. /// Warmest day in N hemisphere (same as COLDEST_DAY_SHEMISPHERE)
  147. const int WARMEST_DAY_NHEMISPHERE = COLDEST_DAY_SHEMISPHERE;
  148. /// Warmest day in S hemisphere (same as COLDEST_DAY_NHEMISPHERE)
  149. const int WARMEST_DAY_SHEMISPHERE = COLDEST_DAY_NHEMISPHERE;
  150. /// number of years to average aaet over in function soilnadd
  151. const int NYEARAAET = 5;
  152. /// Priestley-Taylor coefficient (conversion factor from equilibrium evapotranspiration to PET)
  153. const double PRIESTLEY_TAYLOR = 1.32;
  154. // Solving Century SOM pools
  155. /// fraction of nyear_spinup minus freenyears at which to begin documenting for calculation of Century equilibrium
  156. const double SOLVESOMCENT_SPINBEGIN = 0.1;
  157. /// fraction of nyear_spinup minus freenyears at which to end documentation and start calculation of Century equilibrium
  158. const double SOLVESOMCENT_SPINEND = 0.3;
  159. /// Kelvin to deg c conversion
  160. const double K2degC = 273.15;
  161. /// Maximum number of crop rotation items
  162. const int NROTATIONPERIODS_MAX = 3;
  163. /// Conversion factor for CO2 from ppmv to mole fraction
  164. const double CO2_CONV = 1.0e-6;
  165. /// Initial carbon allocated to crop organs at sowing, kg m-2
  166. const double CMASS_SEED = 0.01;
  167. /// Precision in land cover fraction input
  168. const double INPUT_PRECISION = 1.0e-14;
  169. const double INPUT_ERROR = 0.5e-6;
  170. const double INPUT_RESOLUTION = INPUT_PRECISION - INPUT_PRECISION * INPUT_ERROR;
  171. ///////////////////////////////////////////////////////////////////////////////////////
  172. // FORWARD DECLARATIONS OF CLASSES DEFINED IN THIS FILE
  173. // Forward declarations of classes used as types (e.g. for reference variables in some
  174. // classes) before they are actually defined
  175. class Date;
  176. class Stand;
  177. class Patch;
  178. class Vegetation;
  179. class Individual;
  180. class Gridcell;
  181. class Patchpft;
  182. ///////////////////////////////////////////////////////////////////////////////////////
  183. // GLOBAL VARIABLES WITH EXTERNAL LINKAGE
  184. // These variables are defined in the framework source code file, and are accessible
  185. // throughout the code
  186. /// Object describing timing stage of simulation
  187. extern Date date;
  188. /// Number of possible PFTs
  189. extern int npft;
  190. /// Number of stand types in stlist
  191. extern int nst;
  192. /// Number of stand types per land cover
  193. extern int nst_lc[NLANDCOVERTYPES];
  194. /// Number of management types in stlist
  195. extern int nmt;
  196. /// General purpose object for handling simulation timing.
  197. /** In general, frameworks should use a single Date object for all simulation
  198. * timing.
  199. *
  200. * Member variables of the class (see below) provide various kinds of calender
  201. * and timing information, assuming init has been called to initialise the
  202. * object, and next() has been called at the end of each simulation day.
  203. */
  204. class Date {
  205. // MEMBER VARIABLES
  206. public:
  207. /// Maximum number of days in an LPJ-GUESS simulation year
  208. /** The standard version doesn't yet support leap years. */
  209. static const int MAX_YEAR_LENGTH = 366; // ecev3
  210. /// number of days in each month (0=January - 11=December)
  211. int ndaymonth[12];
  212. /// julian day of year (0-364; 0=Jan 1)
  213. int day;
  214. /// day of current month (0=first day)
  215. int dayofmonth;
  216. /// month number (0=January - 11=December)
  217. int month;
  218. /// year since start of simulation (0=first simulation year)
  219. int year;
  220. /// number of subdaily periods in a day (to be set in IO module)
  221. int subdaily;
  222. /// julian day for middle day of each month
  223. int middaymonth[12];
  224. /// true if last year of simulation, false otherwise
  225. bool islastyear;
  226. /// true if last month of year, false otherwise
  227. bool islastmonth;
  228. /// true if last day of month, false otherwise
  229. bool islastday;
  230. /// true if middle day of month, false otherwise
  231. bool ismidday;
  232. /// The calendar year corresponding to simulation year 0
  233. int first_calendar_year;
  234. /// ecev3
  235. int hour, minute, second;
  236. private:
  237. int nyear;
  238. // MEMBER FUNCTIONS
  239. public:
  240. /// Constructor function called automatically when Date object is created
  241. /** Do not call explicitly. Initialises some member variables. */
  242. Date() {
  243. const int data[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  244. int month;
  245. int dayct = 0;
  246. for (month=0; month<12; month++) {
  247. ndaymonth[month] = data[month];
  248. middaymonth[month] = dayct + data[month] / 2;
  249. dayct += data[month];
  250. }
  251. subdaily = 1;
  252. first_calendar_year = 0;
  253. }
  254. /// Initialises date to day 0 of year 0 and sets intended number of simulation years
  255. /** Intended number of simulation years is only used to set islastyear flag,
  256. * actual simulation may be longer or shorter.
  257. *
  258. * \param nyearsim Intended number of simulation years
  259. */
  260. void init(int nyearsim) {
  261. nyear = nyearsim;
  262. day = month=year = dayofmonth = 0;
  263. islastmonth = islastday = ismidday = false;
  264. if (nyear == 1) islastyear = true;
  265. else islastyear = false;
  266. hour=minute=second=0; // ecev3
  267. }
  268. Date(int y,int m,int d,int h,int n,int s) {
  269. // Constructor with initialisation to given date and time
  270. init(1);
  271. set(y,m,d,h,n,s);
  272. }
  273. // ecev3
  274. void set(int y,int m,int d,int h,int n,int s) {
  275. int i;
  276. if (y != year || m != month || d != dayofmonth) {
  277. //timestep = 0;
  278. }
  279. year = y;
  280. // ecev3 - leap year?
  281. if (is_leap(year))
  282. ndaymonth[1] = 29;
  283. else
  284. ndaymonth[1] = 28;
  285. month = m;
  286. dayofmonth = d;
  287. day = d;
  288. hour = h;
  289. minute = n;
  290. second = s;
  291. for (i = 0; i < m; i++) {
  292. day += ndaymonth[i];
  293. }
  294. if (dayofmonth == ndaymonth[m] - 1)
  295. islastday = true;
  296. else
  297. islastday = false;
  298. if (m == 11)
  299. islastmonth = true;
  300. else
  301. islastmonth = false;
  302. if (y == nyear - 1)
  303. islastyear = true;
  304. else
  305. islastyear = false;
  306. if (dayofmonth == ndaymonth[m] / 2)
  307. ismidday = true;
  308. else
  309. ismidday = false;
  310. }
  311. /// Call at end of every simulation day to update member variables.
  312. void next() {
  313. if (islastday) {
  314. if (islastmonth) {
  315. dayofmonth = 0;
  316. day = 0;
  317. month = 0;
  318. year++;
  319. if (year == nyear - 1) islastyear = true;
  320. islastmonth = false;
  321. }
  322. else {
  323. day++;
  324. dayofmonth = 0;
  325. month++;
  326. if (month == 11) islastmonth = true;
  327. }
  328. islastday = false;
  329. }
  330. else {
  331. day++;
  332. dayofmonth++;
  333. if (dayofmonth == ndaymonth[month] / 2) ismidday = true;
  334. else {
  335. ismidday = false;
  336. if (dayofmonth == ndaymonth[month] - 1) islastday = true;
  337. }
  338. }
  339. }
  340. // \returns index (0-11) of previous month (11 if currently month 0).
  341. int prevmonth() {
  342. if (month > 0) return month - 1;
  343. return 11;
  344. }
  345. /// \returns index of next month (0 if currently month 11)
  346. int nextmonth() {
  347. if (month < 11) return month+1;
  348. return 0;
  349. }
  350. /// Check if the year is leap
  351. /** \param year Calendar year
  352. * The algorith is as follows: only year that are divisible by 4 could
  353. * potentially be leap (e.g., 1904), however, not if they're divisible by
  354. * 100 (e.g., 1900 is not leap), unless they're divisible by 400 (e.g., 2000
  355. * is still leap).
  356. */
  357. static bool is_leap(int year);// {
  358. // return (!(year % 4) && (year % 100 | !(year % 400)));
  359. //}
  360. /// Whether the current mode is diurnal
  361. bool diurnal() const { return subdaily > 1; }
  362. /// Sets calendar year for simulation year 0
  363. /** Astronomical year numbering is used, so year 1 BC is represented by 0,
  364. * 2 BC = -1 etc. See ISO 8601.
  365. */
  366. void set_first_calendar_year(int calendar_year) {
  367. first_calendar_year = calendar_year;
  368. }
  369. /// Returns the calendar year corresponding to the current simulation year
  370. /** Astronomical year numbering is used, so year 1 BC is represented by 0,
  371. * 2 BC = -1 etc. See ISO 8601.
  372. */
  373. int get_calendar_year() const {
  374. return year + first_calendar_year;
  375. }
  376. /// \returns the number of days in the current simulation year
  377. /** For this function to work properly in simulations with varying number
  378. * of days per year, the set_first_calendar_year must have been called first.
  379. *
  380. * Currently there is no support for leap years, so this function
  381. * always returns 365. */
  382. int year_length() const {
  383. if (is_leap(year)) // ecev3 - added leap year check
  384. return 366;
  385. else
  386. return 365;
  387. }
  388. /// Step n days from a date.
  389. /** Current implementation does not consider leap days, and the same
  390. * apply for the current use of the function through-out the model.
  391. */
  392. static int stepfromdate(int day, int step) {
  393. if(day < 0) // a negative value should not be a valid day
  394. return -1;
  395. else if(day + step > 0)
  396. return (day + step) % MAX_YEAR_LENGTH;
  397. else if(day + step < 0)
  398. return day + step + MAX_YEAR_LENGTH;
  399. else
  400. return 0;
  401. }
  402. /// \returns the number of days in a month in the current simulation year
  403. /** This function returns the number of days in a month
  404. */
  405. int month_length(int mth) {
  406. if (is_leap(year) && mth == 1) // ecev3 - leap year and February
  407. return 29;
  408. else
  409. return ndaymonth[mth];
  410. }
  411. };
  412. /// Object describing sub-daily periods
  413. class Day {
  414. public:
  415. /// Whether sub-daily period first/last within day (both true in daily mode)
  416. bool isstart, isend;
  417. /// Ordinal number of the sub-daily period [0, date.subdaily)
  418. int period;
  419. /// Constructs beginning of the day period (the only one in daily mode)
  420. Day() {
  421. isstart = true;
  422. isend = !date.diurnal();
  423. period = 0;
  424. }
  425. /// Advances to the next sub-daily period
  426. void next() {
  427. period++;
  428. isstart = false;
  429. isend = period == date.subdaily - 1;
  430. }
  431. };
  432. /// Object updating gridcell mass balance; currently used in framework()
  433. class MassBalance : public Serializable {
  434. int start_year;
  435. double ccont;
  436. double ccont_zero;
  437. double ccont_zero_scaled;
  438. double cflux;
  439. double cflux_zero;
  440. double ncont;
  441. double ncont_zero;
  442. double ncont_zero_scaled;
  443. double nflux;
  444. double nflux_zero;
  445. public:
  446. MassBalance() {
  447. start_year = nyear_spinup;
  448. ccont = 0.0;
  449. ccont_zero = 0.0;
  450. ccont_zero_scaled = 0.0;
  451. cflux = 0.0;
  452. cflux_zero = 0.0;
  453. ncont = 0.0;
  454. ncont_zero = 0.0;
  455. ncont_zero_scaled = 0.0;
  456. nflux = 0.0;
  457. nflux_zero = 0.0;
  458. }
  459. MassBalance(int start_yearX) {
  460. start_year = start_yearX;
  461. ccont = 0.0;
  462. ccont_zero = 0.0;
  463. ccont_zero_scaled = 0.0;
  464. cflux = 0.0;
  465. cflux_zero = 0.0;
  466. ncont = 0.0;
  467. ncont_zero = 0.0;
  468. ncont_zero_scaled = 0.0;
  469. nflux = 0.0;
  470. nflux_zero = 0.0;
  471. }
  472. void init(Gridcell& gridcell);
  473. void check(Gridcell& gridcell);
  474. // indiv and patch-level functions are for use with true crop stands only
  475. void init_indiv(Individual& indiv);
  476. bool check_indiv(Individual& indiv, bool check_harvest = false);
  477. bool check_indiv_C(Individual& indiv, bool check_harvest = false);
  478. bool check_indiv_N(Individual& indiv, bool check_harvest = false);
  479. void init_patch(Patch& patch);
  480. bool check_patch(Patch& patch, bool check_harvest = false);
  481. bool check_patch_C(Patch& patch, bool check_harvest = false);
  482. bool check_patch_N(Patch& patch, bool check_harvest = false);
  483. void check_year(Gridcell& gridcell);
  484. void check_period(Gridcell& gridcell);
  485. void serialize(ArchiveStream& arch);
  486. };
  487. /// Struct containing wood harvest information
  488. struct Wood_harvest_struct {
  489. double prim_frac;
  490. double prim_vol;
  491. double sec_mature_frac;
  492. double sec_mature_vol;
  493. double sec_young_frac;
  494. double sec_young_vol;
  495. void zero() {
  496. prim_frac = 0.0;
  497. prim_vol = 0.0;
  498. sec_mature_frac = 0.0;
  499. sec_mature_vol = 0.0;
  500. sec_young_frac = 0.0;
  501. sec_young_vol = 0.0;
  502. }
  503. };
  504. /// This struct contains the result of a photosynthesis calculation.
  505. /** \see photosynthesis */
  506. struct PhotosynthesisResult {// : public Serializable {
  507. /// Constructs an empty result
  508. PhotosynthesisResult() {
  509. clear();
  510. }
  511. /// Clears all members
  512. /** This is returned by the photosynthesis function when no photosynthesis
  513. * takes place.
  514. */
  515. void clear() {
  516. agd_g = 0;
  517. adtmm = 0;
  518. rd_g = 0;
  519. vm = 0;
  520. je = 0;
  521. nactive_opt = 0.0;
  522. vmaxnlim = 1.0;
  523. }
  524. /// RuBisCO capacity (gC/m2/day)
  525. double vm;
  526. /// gross daily photosynthesis (gC/m2/day)
  527. double agd_g;
  528. /// leaf-level net daytime photosynthesis
  529. /** expressed in CO2 diffusion units (mm/m2/day) */
  530. double adtmm;
  531. /// leaf respiration (gC/m2/day)
  532. double rd_g;
  533. /// PAR-limited photosynthesis rate (gC/m2/h)
  534. double je;
  535. /// optimal leaf nitrogen associated with photosynthesis (kgN/m2)
  536. double nactive_opt;
  537. /// nitrogen limitation on vm
  538. double vmaxnlim;
  539. /// net C-assimilation (gross photosynthesis minus leaf respiration) (kgC/m2/day)
  540. double net_assimilation() const {
  541. return (agd_g - rd_g) * 1e-3;
  542. }
  543. //void serialize(ArchiveStream& arch);
  544. };
  545. /// The Climate for a grid cell
  546. /** Stores all static and variable data relating to climate parameters, as well as
  547. * latitude, atmospheric CO2 concentration and daylength for a grid cell. Includes
  548. * a reference to the parent Gridcell object (defined below). Initialised by a
  549. * call to initdrivers.
  550. */
  551. class Climate : public Serializable {
  552. // MEMBER VARIABLES
  553. public:
  554. /// reference to parent Gridcell object
  555. Gridcell& gridcell;
  556. /// mean air temperature today (deg C)
  557. double temp;
  558. /// total daily net downward shortwave solar radiation today (J/m2/day)
  559. double rad;
  560. /// total daily photosynthetically-active radiation today (J/m2/day)
  561. double par;
  562. /// precipitation today (mm)
  563. double prec;
  564. /// day length today (h)
  565. double daylength;
  566. /// atmospheric ambient CO2 concentration today (ppmv)
  567. double co2;
  568. /// monthly atmospheric ambient CO2 concentration (ppmv)
  569. double mco2[12];
  570. /// latitude (degrees; +=north, -=south)
  571. double lat;
  572. /// Insolation today, see also instype
  573. double insol;
  574. /// Type of insolation
  575. /** This decides how to interpret the variable insol,
  576. * see also documentation for the insoltype enum.
  577. */
  578. insoltype instype;
  579. /// net LW today. Used to calculate eet
  580. double netlw;
  581. /// equilibrium evapotranspiration today (mm/day)
  582. double eet;
  583. /// mean temperature for the last 31 days (deg C)
  584. double mtemp;
  585. /// mean of lowest mean monthly temperature for the last 20 years (deg C)
  586. double mtemp_min20;
  587. /// mean of highest mean monthly temperature for the last 20 years (deg C)
  588. double mtemp_max20;
  589. /// highest mean monthly temperature for the last 12 months (deg C)
  590. double mtemp_max;
  591. /// accumulated growing degree day sum on 5 degree base
  592. /** reset when temperatures fall below 5 deg C */
  593. double gdd5;
  594. /// total gdd5 (accumulated) for this year (reset 1 January)
  595. double agdd5;
  596. /// total gdd5 for this year for each of the last five simulation years
  597. Historic<double, 5> agdd5_5;
  598. /// number of days with temperatures <5 deg C
  599. /** reset when temperatures fall below 5 deg C;
  600. * maximum value is number of days in the year */
  601. int chilldays;
  602. /// true if chill day count may be reset by temperature fall below 5 deg C
  603. bool ifsensechill;
  604. /** Respiration response to today's air temperature incorporating damping of Q10
  605. * due to temperature acclimation (Lloyd & Taylor 1994)
  606. */
  607. double gtemp;
  608. /// daily temperatures for the last 31 days (deg C)
  609. Historic<double, 31> dtemp_31;
  610. /// daily precipitation for the last 31 days (deg C)
  611. Historic<double, 31> dprec_31;
  612. /// daily eet for the last 31 days (deg C)
  613. Historic<double, 31> deet_31;
  614. /// minimum monthly temperatures for the last 20 years (deg C)
  615. double mtemp_min_20[20];
  616. /// maximum monthly temperatures for the last 20 years (deg C)
  617. double mtemp_max_20[20];
  618. /// minimum monthly temperature for the last 12 months (deg C)
  619. double mtemp_min;
  620. /// mean of monthly temperatures for the last 12 months (deg C)
  621. double atemp_mean;
  622. /// annual nitrogen deposition (kgN/m2/year)
  623. double andep;
  624. /// daily nitrogen deposition (kgN/m2)
  625. double dndep;
  626. // ecev3 - needed if we're forcing with IFS soil properties:
  627. double ifssoiltemp;
  628. double ifsw_surf;
  629. double ifsw_deep;
  630. // Saved parameters used by function daylengthinsoleet
  631. double sinelat;
  632. double cosinelat;
  633. double qo[Date::MAX_YEAR_LENGTH];
  634. double u[Date::MAX_YEAR_LENGTH];
  635. double v[Date::MAX_YEAR_LENGTH];
  636. double hh[Date::MAX_YEAR_LENGTH];
  637. double sinehh[Date::MAX_YEAR_LENGTH];
  638. double daylength_save[Date::MAX_YEAR_LENGTH];
  639. /// indicates whether saved values exist for this day
  640. bool doneday[Date::MAX_YEAR_LENGTH];
  641. /// diurnal temperature range, used in daily/monthly BVOC (deg C)
  642. double dtr;
  643. // containers for sub-daily values of temperature, short-wave downward
  644. // radiation, par, rad and gtemp (equivalent to temp, insol, par, rad and gtemp)
  645. // NB: units of these variable are the same as their daily counterparts,
  646. // i.e. representing daily averages (e.g. pars [J/m2/day])
  647. /// Sub-daily temperature (deg C) (\see temp)
  648. std::vector<double> temps;
  649. /// Sub-daily insolation (\see insol)
  650. std::vector<double> insols;
  651. /// Sub-daily PAR (\see par)
  652. std::vector<double> pars;
  653. /// Sub-daily net downward shortwave solar radiation (\see rad)
  654. std::vector<double> rads;
  655. /// Sub-daily respiration response (\see gtemp)
  656. std::vector<double> gtemps;
  657. /// Variables used for crop sowing date or seasonality calculation
  658. /// daily precipitations for the last 10 days (mm)
  659. double dprec_10[10];
  660. /// daily 10 day-sums of precipitations for today and yesterday (mm)
  661. double sprec_2[2];
  662. /// max temperature during the last test period
  663. double maxtemp;
  664. /// summer day when we test last year's crossing of sowing temperature limits; NH:June 30(day 180), SH:Dec.31(day 364), set in getgridcell()
  665. int testday_temp;
  666. /// last day of dry month when we test last year's crossing of sowing precipitation limits; NH:Dec.31(day 364), SH:June 30(day 180), set in getgridcell()
  667. int testday_prec;
  668. /// date used for sowing if no frost or spring occured during the year between the testmonths; NH:14, SH:195, set in getgridcell()
  669. int coldestday;
  670. /// used to adapt equations to hemisphere, set in getgridcell()
  671. int adjustlat;
  672. /// accumulated monthly pet values for this year
  673. double mpet_year[12];
  674. /// past 20 years monthly temperature values
  675. double mtemp_20[20][12];
  676. /// past 20 years monthly precipitation values
  677. double mprec_20[20][12];
  678. /// past 20 years monthly PET values
  679. double mpet_20[20][12];
  680. /// past 20 years monthly precipitation to PET ratios
  681. double mprec_pet_20[20][12];
  682. /// past 20 years minimum of monthly precipitation to PET ratios
  683. double mprec_petmin_20[20];
  684. /// past 20 years maximum of monthly precipitation to PET ratios
  685. double mprec_petmax_20[20];
  686. /// 20-year running average monthly temperature values
  687. double mtemp20[12];
  688. /// 20-year running average monthly precipitation values
  689. double mprec20[12];
  690. /// 20-year running average monthly PET values
  691. double mpet20[12];
  692. /// 20-year running average monthly precipitation to PET ratios
  693. double mprec_pet20[12];
  694. /// 20-year running average of minimum monthly precipitation to PET ratios
  695. double mprec_petmin20;
  696. /// 20-year running average of maximum monthly precipitation to PET ratios
  697. double mprec_petmax20;
  698. Historic<double, 20> hmtemp_20[12];
  699. Historic<double, 20> hmprec_20[12];
  700. Historic<double, 20> hmeet_20[12];
  701. /// seasonality type (SEASONALITY_NO, SEASONALITY_PREC, SEASONALITY_PRECTEMP, SEASONALITY_TEMP, SEASONALITY_TEMPPREC)
  702. seasonality_type seasonality;
  703. seasonality_type seasonality_lastyear;
  704. /// precipitation seasonality type (DRY, DRY_INTERMEDIATE, DRY_WET, INTERMEDIATE, INTERMEDIATE_WET, WET)
  705. /** based on the extremes of the 20-year monthly means
  706. */
  707. prec_seasonality_type prec_seasonality;
  708. prec_seasonality_type prec_seasonality_lastyear;
  709. /// precipitation range (DRY, DRY_INTERMEDIATE, DRY_WET, INTERMEDIATE, INTERMEDIATE_WET, WET)
  710. /** based on the average of the 20-year monthly extremes
  711. */
  712. prec_seasonality_type prec_range;
  713. prec_seasonality_type prec_range_lastyear;
  714. /// temperature seasonality (COLD, COLD_WARM, COLD_HOT, WARM, WARM_HOT, HOT)
  715. temp_seasonality_type temp_seasonality;
  716. temp_seasonality_type temp_seasonality_lastyear;
  717. /// whether several months with precipitation maxima exists (remains to be implemented)
  718. bool biseasonal;
  719. /// variation coefficient of 20-year mean monthly temperatures
  720. double var_prec;
  721. /// variation coefficient of 20-year mean monthly precipitation to PET ratios
  722. double var_temp;
  723. /// annual precipitation sum
  724. double aprec;
  725. /// CRESCENDO physical variables output
  726. /// Near Surface Air Temperature [K]
  727. double mtemp_K[12];
  728. /// Precipitation [kg m-2 s-1]
  729. double mprec[12];
  730. /// Daily precipitation [kg m-2 s-1]
  731. double dprec[366];
  732. /// Surface Downwelling Shortwave Radiation [W m-2]
  733. double mrsds[12];
  734. #ifdef CRESCENDO_FACE
  735. /// Daily CO2 (mean ppm)
  736. double co2_daily[366];
  737. /// Daily PAR (mol day-1)
  738. double par_daily[366];
  739. /// Daily Air Temperature (mean oC)
  740. double at_daily[366];
  741. /// Daily N deposition (gN m-2 day-1)
  742. double ndep_daily[366];
  743. #endif
  744. public:
  745. /// constructor function: initialises gridcell member
  746. Climate(Gridcell& gc):gridcell(gc) {
  747. for(int m=0;m<12;m++) {
  748. mtemp20[m] = 0.0;
  749. mprec20[m] = 0.0;
  750. mpet20[m] = 0.0;
  751. mpet_year[m] = 0.0;
  752. mprec_pet20[m] = 0.0;
  753. for(int y=0;y<20;y++) {
  754. mtemp_20[y][m] = 0.0;
  755. mprec_20[y][m] = 0.0;
  756. mpet_20[y][m] = 0.0;
  757. mprec_pet_20[y][m] = 0.0;
  758. }
  759. }
  760. for(int y=0;y<20;y++) {
  761. mprec_petmin_20[y] = 0.0;
  762. mprec_petmax_20[y] = 0.0;
  763. }
  764. mprec_petmin20=0.0;
  765. mprec_petmax20=0.0;
  766. seasonality=SEASONALITY_NO;
  767. seasonality_lastyear=SEASONALITY_NO;
  768. prec_seasonality=DRY;
  769. prec_seasonality_lastyear=DRY;
  770. prec_range=DRY;
  771. prec_range_lastyear=DRY;
  772. temp_seasonality=COLD;
  773. temp_seasonality_lastyear=COLD;
  774. biseasonal=false;
  775. eet=0.0;
  776. };
  777. /// Initialises certain member variables
  778. /** Should be called before Climate object is applied to a new grid cell */
  779. void initdrivers(double latitude) {
  780. std::fill_n(mtemp_min_20, 20, 0.0);
  781. std::fill_n(mtemp_max_20, 20, 0.0);
  782. mtemp_min20 = 0.0;
  783. mtemp_max20 = 0.0;
  784. mtemp = 0.0;
  785. maxtemp = 0.0;
  786. gdd5 = 0.0;
  787. chilldays = 0;
  788. ifsensechill = true;
  789. atemp_mean = 0.0;
  790. lat = latitude;
  791. std::fill_n(doneday, Date::MAX_YEAR_LENGTH, false);
  792. sinelat = sin(lat * DEGTORAD);
  793. cosinelat = cos(lat * DEGTORAD);
  794. // Set crop-specific members
  795. if (latitude >= 0) {
  796. testday_temp = 180; //June 30(day 180)
  797. testday_prec = 364; //Dec.31(day 364)
  798. coldestday = COLDEST_DAY_NHEMISPHERE;
  799. adjustlat = 0;
  800. }
  801. else {
  802. testday_temp = 364; //Dec.31(day 364)
  803. testday_prec = 180; //June 30(day 180)
  804. coldestday = COLDEST_DAY_SHEMISPHERE;
  805. adjustlat = 181;
  806. }
  807. // ecev3 - needed if we're forcing with IFS soil properties:
  808. ifssoiltemp = 0.0;
  809. ifsw_surf = 0.0;
  810. ifsw_deep = 0.0;
  811. }
  812. /// ecev3 - transfer today's drivers from IFS to Climate
  813. void setdrivers(double ifstemp, double ifsprec, double ifsrad, double ifslw, double tm5co2, double ifstemp_soil, double ifssoilw_surf, double ifssoilw_deep,
  814. double dailyndep, double dailynfert);
  815. void serialize(ArchiveStream& arch);
  816. };
  817. /// Stores accumulated monthly and annual fluxes.
  818. /** This class handles the storage and accounting of fluxes for a single patch.
  819. * Different fluxes can be stored in different ways, depending on what kind of
  820. * flux it is and what kind of output we want. The details of whether fluxes
  821. * are stored per PFT or just as a patch total, or per day, month or only a
  822. * yearly sum, is hidden from the 'scientific' code, which merely reports the
  823. * fluxes generated.
  824. */
  825. class Fluxes : public Serializable {
  826. public:
  827. /// Daily fluxes stored as totals for the whole patch
  828. enum DailyPerPatchFluxType {
  829. /// Carbon flux to atmosphere from soil respiration (kgC/m2)
  830. SOILC,
  831. /// Carbon flux to atmosphere from burnt vegetation and litter (kgC/m2)
  832. FIREC,
  833. /// Flux from atmosphere to vegetation associated with sowing (kgC/m2)
  834. SEEDC,
  835. /// Flux to atmosphere from consumed harvested products (kgC/m2)
  836. HARVESTC,
  837. /// Number of types, must be last
  838. NDAILYPERPATCHFLUXTYPES
  839. };
  840. /// Fluxes stored as totals for the whole patch
  841. enum PerPatchFluxType {
  842. /// Carbon flux to atmosphere from burnt vegetation (kgC/m2)
  843. FIREVEGC,
  844. /// Carbon flux to atmosphere from burnt litter (kgC/m2)
  845. FIRELITTERC,
  846. /// Carbon flux to atmosphere from litter respiration (kgC/m2)
  847. LITTERC,
  848. /// Flux from atmosphere to vegetation associated with establishment (kgC/m2)
  849. ESTC,
  850. /// Flux to atmosphere from consumed grazing harvested products (kgC/m2)
  851. HARVGRAZC,
  852. /// Flux to slow product pool from grazing (kgC/m2)
  853. HARVGRAZSLOWC,
  854. /// Flux to atmosphere from consumed cropping harvested products (kgC/m2)
  855. HARVCROPC,
  856. /// Flux to litter from harvested crops (kgC/m2)
  857. HARVCROPRESC,
  858. /// Flux to slow product pool from harvested crop (kgC/m2)
  859. HARVCROPSLOWC,
  860. /// Reproduction costs
  861. REPRC,
  862. /// Carbon leached
  863. LEACHC,
  864. /// Total Carbon Flux from Vegetation to Litter
  865. VEGLITTERC,
  866. /// Total Carbon Flux from Litter to Soil
  867. LITTERSOILC,
  868. /// Total Carbon Flux from excess and debt to atmosphere
  869. DEBEXCC,
  870. /// Total Carbon Flux from natural sources to atmosphere (flux seen by TM5)
  871. CO2NAT,
  872. /// Total Carbon Flux from anthropogenic sources to atmosphere (flux seen by TM5)
  873. CO2ANTT,
  874. /// Nitrogen flux from atmosphere to vegetation associated with sowing (kgC/m2)
  875. SEEDN,
  876. /// NH3 flux to atmosphere from fire
  877. NH3_FIRE,
  878. /// NOx flux to atmosphere from fire
  879. NOx_FIRE,
  880. /// N2O flux to atmosphere from fire
  881. N2O_FIRE,
  882. /// N2 flux to atmosphere from fire
  883. N2_FIRE,
  884. /// N flux from soil
  885. N_SOIL,
  886. /// N deposition
  887. NDEP,
  888. /// Biological N fixation
  889. NFIX,
  890. /// N fertilisation
  891. NFERT,
  892. /// Plant N Uptake
  893. NUP,
  894. /// Net N mineralisation
  895. NMIN,
  896. /// N leached
  897. LEACHN,
  898. /// Total nitrogen Flux from vegetation to litter
  899. VEGLITTERN,
  900. /// Total nitrogen Flux from litter to soil
  901. LITTERSOILN,
  902. /// Nitrogen flux to atmosphere from consumed harvested products (kgN/m2)
  903. HARVESTN,
  904. /// Autotrophic respiration from leaf (kgC/m2)
  905. RALEAF,
  906. /// Autotrophic respiration from stem (kgC/m2)
  907. RASTEM,
  908. /// Autotrophic respiration from roots (kgC/m2)
  909. RAROOT,
  910. /// Autotrophic respiration from growth (kgC/m2)
  911. RAGROWTH,
  912. /// Gross primary production for grass (kgC/m2)
  913. GPPGRASS,
  914. /// Gross primary production for tree (kgC/m2)
  915. GPPTREE,
  916. /// Autotrophic respiration from grass (kgC/m2)
  917. RAGRASS,
  918. /// Autotrophic respiration from tree (kgC/m2)
  919. RATREE,
  920. /// Number of types, must be last
  921. NPERPATCHFLUXTYPES
  922. };
  923. /// Fluxes stored per pft
  924. enum PerPFTFluxType {
  925. /// NPP (kgC/m2)
  926. NPP,
  927. /// GPP (kgC/m2)
  928. GPP,
  929. /// Autotrophic respiration (kgC/m2)
  930. RA,
  931. /// Isoprene (mgC/m2)
  932. ISO,
  933. /// Monoterpene (mgC/m2)
  934. MT1, // MT_APIN, MT_LIMO, MT_TRIC
  935. MT2, // MT_BPIN, MT_MYRC, MT_SABI, MT_CAMP, MT_TBOC, MT_OTHR
  936. /// Number of types, must be last
  937. NPERPFTFLUXTYPES
  938. };
  939. #ifdef CRESCENDO_FACE
  940. /// Daily FACE fluxes stored as totals for the whole patch
  941. enum DailyPerPatchFACEFluxType {
  942. /// Reproduction costs
  943. DREPRC,
  944. /// Flux from atmosphere to vegetation associated with establishment (kgC/m2)
  945. DESTC,
  946. /// Autotrophic respiration from leaf (kgC/m2)
  947. DRALEAF,
  948. /// Autotrophic respiration from stem (kgC/m2)
  949. DRASTEM,
  950. /// Autotrophic respiration from roots (kgC/m2)
  951. DRAROOT,
  952. /// Autotrophic respiration from growth (kgC/m2)
  953. DRAGROWTH,
  954. /// Plant leaf N growth
  955. DNGL,
  956. /// Plant sapwood N growth
  957. DNGW,
  958. /// Plant root N growth
  959. DNGR,
  960. /// Leaf nitrogen Flux from vegetation to litter
  961. DLEAFLITN,
  962. /// Wood nitrogen Flux from vegetation to litter
  963. DWOODLITN,
  964. /// Root nitrogen Flux from vegetation to litter
  965. DROOTLITN,
  966. /// Biological N fixation
  967. DNFIX,
  968. /// Plant N Uptake
  969. DNUP,
  970. /// Gross N mineralisation
  971. DGNMIN,
  972. /// Net N mineralisation
  973. DNMIN,
  974. /// N leached
  975. DLEACHN,
  976. /// N flux from soil
  977. DN_SOIL,
  978. /// Leaf Carbon Flux from Vegetation to Litter
  979. DLEAFLITC,
  980. /// Wood Carbon Flux from Vegetation to Litter
  981. DWOODLITC,
  982. /// Root Carbon Flux from Vegetation to Litter
  983. DROOTLITC,
  984. /// Number of types, must be last
  985. NDAILYPERPATCHFACEFLUXTYPE
  986. };
  987. #endif
  988. // emission ratios from fire (NH3, NOx, N2O, N2) Delmas et al. 1995
  989. // values in .cpp file
  990. static const double NH3_FIRERATIO;
  991. static const double NOx_FIRERATIO;
  992. static const double N2O_FIRERATIO;
  993. static const double N2_FIRERATIO;
  994. /// Reference to patch to which this Fluxes object belongs
  995. Patch& patch;
  996. // MEMBER FUNCTIONS
  997. public:
  998. /// constructor: initialises members
  999. Fluxes(Patch& p);
  1000. /// Sets all fluxes to zero (call at the beginning of each year)
  1001. void reset();
  1002. void serialize(ArchiveStream& arch);
  1003. /// Report flux for a certain flux type
  1004. void report_flux(PerPFTFluxType flux_type, int pft_id, double value);
  1005. /// Report flux for a certain flux type
  1006. void report_flux(PerPatchFluxType flux_type, double value);
  1007. /// Report flux for a certain flux type
  1008. void report_flux(DailyPerPatchFluxType flux_type, double value);
  1009. /// \returns flux for a given month and flux type (for all PFTs)
  1010. double get_monthly_flux(PerPFTFluxType flux_type, int month) const;
  1011. /// \returns flux for a given month and flux type
  1012. double get_monthly_flux(PerPatchFluxType flux_type, int month) const;
  1013. /// \returns flux for a given month and flux type
  1014. double get_monthly_flux(DailyPerPatchFluxType flux_type, int month) const;
  1015. /// \returns annual flux for a given PFT and flux type
  1016. double get_annual_flux(PerPFTFluxType flux_type, int pft_id) const;
  1017. /// \returns annual flux for a given flux type (for all PFTs)
  1018. double get_annual_flux(PerPFTFluxType flux_type) const;
  1019. /// \returns annual flux for a given flux type
  1020. double get_annual_flux(PerPatchFluxType flux_type) const;
  1021. /// \returns annual flux for a given flux type
  1022. double get_annual_flux(DailyPerPatchFluxType flux_type) const;
  1023. // ecev3
  1024. /// \returns flux for a given day and flux type (for all PFTs)
  1025. double get_daily_flux(PerPFTFluxType flux_type, int day) const;
  1026. /// \returns flux for a given day and flux type
  1027. double get_daily_flux(DailyPerPatchFluxType flux_type, int day) const;
  1028. #ifdef CRESCENDO_FACE
  1029. /// Report flux for a certain flux type
  1030. void report_flux(DailyPerPatchFACEFluxType flux_type, double value);
  1031. /// \returns flux for a given day and flux type
  1032. double get_daily_flux(DailyPerPatchFACEFluxType flux_type, int day) const;
  1033. #endif
  1034. private:
  1035. /// Stores one flux value per PFT and flux type
  1036. std::vector<std::vector<float> > annual_fluxes_per_pft;
  1037. /// Stores one flux value per month and flux type
  1038. /** For the fluxes only stored as totals for the whole patch */
  1039. float monthly_fluxes_patch[12][NPERPATCHFLUXTYPES];
  1040. /// Stores one flux value per month and flux type
  1041. /** For the fluxes stored per pft for annual values */
  1042. float monthly_fluxes_pft[12][NPERPFTFLUXTYPES];
  1043. // ecev3 also in LPJ-GUESS trunk but 365 instead of 366
  1044. /// Stores one flux value per day for GPP and NPP only
  1045. /** For the fluxes stored per pft for annual values */
  1046. float daily_fluxes_pft[366][NPERPFTFLUXTYPES];
  1047. // ecev3
  1048. /// Stores one flux value per day
  1049. /** For the fluxes only stored as totals for the whole patch */
  1050. float daily_fluxes_patch[366][NDAILYPERPATCHFLUXTYPES];
  1051. #ifdef CRESCENDO_FACE
  1052. /// Stores one flux value per day
  1053. /** For the fluxes only stored as totals for the whole patch */
  1054. float daily_fluxes_patch_FACE[366][NDAILYPERPATCHFACEFLUXTYPE];
  1055. #endif
  1056. };
  1057. /// Storage class of crop management information for one rotation period for a stand type, read from the instruction file.
  1058. class ManagementType {
  1059. public:
  1060. /// id code (should be zero based and sequential, 0...nst-1)
  1061. int id;
  1062. /// name of management type
  1063. xtring name;
  1064. /// type of planting system ("", "MONOCULTURE", "SELECTION", etc.)
  1065. xtring planting_system;
  1066. /// type of harvest system ("", "CLEARCUT", "CONTINUOUS")
  1067. xtring harvest_system;
  1068. /// name of crop pft
  1069. xtring pftname;
  1070. /// identifier of pft selection
  1071. xtring selection;
  1072. /// Rotation period in years
  1073. double nyears;
  1074. /// hydrology (RAINFED,IRRIGATED)
  1075. hydrologytype hydrology;
  1076. /// irrigation efficiency
  1077. // double firr;
  1078. /// forced sowing date, unless sdate_force read from file
  1079. int sdate;
  1080. /// forced harvest date, unless hdate_force read from file
  1081. int hdate;
  1082. /// Harvested forest area fraction, unless woodharv_frac read from file
  1083. double woodharv_frac;
  1084. /// Wood harvest volume, unless woodharv_volume read from file
  1085. double woodharv_vol;
  1086. /// Nitrogen fertilisation amount, unless Nfert_read read from file
  1087. double nfert;
  1088. /// Whether grass is grown in fallow
  1089. bool fallow;
  1090. /// Double cropping of one crop (e.g. rice)
  1091. bool multicrop;
  1092. ManagementType() {
  1093. planting_system = "";
  1094. harvest_system = "";
  1095. pftname = "";
  1096. selection = "";
  1097. nyears = 1.0;
  1098. hydrology = RAINFED;
  1099. // firr = 0.0;
  1100. sdate = -1;
  1101. hdate = -1;
  1102. nfert = -1.0;
  1103. woodharv_frac = -1.0;
  1104. woodharv_vol = -1.0;
  1105. fallow = false;
  1106. multicrop = false;
  1107. }
  1108. // Copy constructor
  1109. ManagementType(const ManagementType& from) {
  1110. name = from.name;
  1111. pftname = from.pftname;
  1112. hydrology = from.hydrology;
  1113. sdate = from.sdate;
  1114. hdate = from.hdate;
  1115. nfert = from.nfert;
  1116. fallow = from.fallow;
  1117. }
  1118. bool is_managed() {
  1119. // Add new management parameters here
  1120. if(pftname != "" || planting_system != "" || selection != ""|| harvest_system != "" || hydrology == IRRIGATED || fallow || nfert > -1.0)
  1121. return true;
  1122. else
  1123. return false;
  1124. }
  1125. /// Returns true if pft is in pftselection.
  1126. int pftinselection(const char* name) {
  1127. bool found = false;
  1128. char *p = NULL, string_copy[200] = {0};
  1129. strcpy(string_copy, selection);
  1130. p = strtok(string_copy, "\t\n ");
  1131. if(p) {
  1132. if(!strcmp(name, p)) {
  1133. found = true;
  1134. }
  1135. }
  1136. do {
  1137. p = strtok(NULL, "\t\n ");
  1138. if(p) {
  1139. if(!strcmp(name, p)) {
  1140. found = true;
  1141. }
  1142. }
  1143. }
  1144. while(p && !found);
  1145. return found;
  1146. }
  1147. };
  1148. /// A list of management types
  1149. /** Functionality for building, maintaining, referencing and destroying a list array of
  1150. * management types objects.
  1151. *
  1152. * Functionality is inherited from the ListArray_id template type in the GUTIL
  1153. * Library. Sequential management type objects can be referenced as array elements by id:
  1154. *
  1155. * ManagementTypelist mtlist;
  1156. * ...
  1157. * for (i=0; i<nst; i++) {
  1158. * ManagementType& thismt=stlist[i];
  1159. * // query or modify object thismt here
  1160. * }
  1161. *
  1162. * or by iteration through the linked list:
  1163. *
  1164. * mtlist.firstobj();
  1165. * while (mtlist.isobj) {
  1166. * ManagementType& thismt=mtlist.getobj();
  1167. * // query or modify object thismt here
  1168. * mtlist.nextobj();
  1169. * }
  1170. */
  1171. class ManagementTypelist : public ListArray_id<ManagementType> {
  1172. public:
  1173. int getmtid(xtring mtname) {
  1174. int id = -1;
  1175. for(unsigned int i=0; i< this->nobj; i++) {
  1176. ManagementType& mt = (*this)[i];
  1177. if(mt.name == mtname) {
  1178. id = mt.id;
  1179. break;
  1180. }
  1181. }
  1182. return id;
  1183. }
  1184. };
  1185. /// The one and only linked list of ManagementType objects
  1186. extern ManagementTypelist mtlist;
  1187. /// Storage class of crop rotation information for a stand type, read from the instruction file.
  1188. struct CropRotation {
  1189. /// Number of crops in rotation
  1190. int ncrops;
  1191. /// First rotation year
  1192. int firstrotyear;
  1193. CropRotation() {
  1194. ncrops = 0;
  1195. firstrotyear = 0;
  1196. }
  1197. };
  1198. /// Stand type class for storing both static parameters, read from the instruction file,
  1199. /* and dynamic variables, updated in landcover_change()
  1200. * Active stand types are stored in the stlist analogous to the pftlist.
  1201. */
  1202. class StandType {
  1203. public:
  1204. /// id code (should be zero based and sequential, 0...nst-1)
  1205. int id;
  1206. /// name of stand type
  1207. xtring name;
  1208. /// specifies type of landcover
  1209. /** \see landcovertype */
  1210. landcovertype landcover; // specifies type of landcover (0 = URBAN, 1 = CROP, 2 = PASTURE, 3 = FOREST, 4 = NATURAL, 5 = PEATLAND)
  1211. /// Rotation information, read from the instruction file
  1212. CropRotation rotation;
  1213. /// Management struct (static)
  1214. ManagementType management;
  1215. /// Management types in a rotation cycle
  1216. xtring mtnames[NROTATIONPERIODS_MAX];
  1217. /// First management year: sets time when common features for managed stands begin, e.g. relaxed establishment rules and absence of disturbance before harvest begins
  1218. /** \this currently only applies for stands with wood havest */
  1219. int firstmanageyear;
  1220. /// intercrop (NOINTERCROP,NATURALGRASS)
  1221. intercroptype intercrop;
  1222. /// whether natural pft:s are allowed to grow in stand type
  1223. xtring naturalveg; // "", "GRASSONLY", "ALL"
  1224. // whether only pft:s defined in management are allowed (plus intercrop or naturalveg/grass)
  1225. bool restrictpfts;
  1226. /// whether planted pft:s or all active pft:s are allowed to established after planting in a forest stand ("", "RESTRICTED", "ALL")
  1227. xtring reestab;
  1228. StandType() {
  1229. intercrop = NOINTERCROP;
  1230. naturalveg = "";
  1231. restrictpfts = false;
  1232. reestab = "ALL";
  1233. firstmanageyear = 100000;
  1234. }
  1235. ManagementType& get_management(int rot = 0) {
  1236. if(rotation.ncrops > 1) {
  1237. return mtlist[mtlist.getmtid(mtnames[rot])];
  1238. }
  1239. else {
  1240. return management;
  1241. }
  1242. }
  1243. /// Returns position of management in rotation list if present. Returns -1 if not.
  1244. int mtinrotation(xtring name) {
  1245. int mtno = -1;
  1246. for(int i=0; i<rotation.ncrops; i++) {
  1247. if(name == mtnames[i])
  1248. mtno = i;
  1249. }
  1250. return mtno;
  1251. }
  1252. /// Returns position of crop in rotation list if present. Returns -1 if not.
  1253. int pftinrotation(xtring name) {
  1254. int cropno = -1;
  1255. for(int i=0; i<rotation.ncrops; i++) {
  1256. if(name == get_management(i).pftname)
  1257. cropno = i;
  1258. }
  1259. return cropno;
  1260. }
  1261. };
  1262. /// A list of stand types
  1263. /** Functionality for building, maintaining, referencing and destroying a list array of
  1264. * stand types objects.
  1265. *
  1266. * Functionality is inherited from the ListArray_id template type in the GUTIL
  1267. * Library. Sequential stand type objects can be referenced as array elements by id:
  1268. *
  1269. * StandTypelist stlist;
  1270. * ...
  1271. * for (i=0; i<nst; i++) {
  1272. * StandType& thisst=stlist[i];
  1273. * // query or modify object thisst here
  1274. * }
  1275. *
  1276. * or by iteration through the linked list:
  1277. *
  1278. * stlist.firstobj();
  1279. * while (stlist.isobj) {
  1280. * StandType& thisst=stlist.getobj();
  1281. * // query or modify object thisst here
  1282. * stlist.nextobj();
  1283. * }
  1284. */
  1285. class StandTypelist : public ListArray_id<StandType> {
  1286. };
  1287. /// The one and only linked list of StandType objects
  1288. extern StandTypelist stlist;
  1289. /// Holds static functional parameters for a plant functional type (PFT).
  1290. /** There should be one Pft object for each potentially occurring PFT. The same Pft object
  1291. * may be referenced (via the pft member of the Individual object; see below) by different
  1292. * average individuals. Member functions are included for initialising SLA given leaf
  1293. * longevity, and for initialising sapling/regen characteristics (required for
  1294. * population mode).
  1295. */
  1296. class Pft {
  1297. // MEMBER VARIABLES
  1298. public:
  1299. /// id code (should be zero based and sequential, 0...npft-1)
  1300. int id;
  1301. /// name of PFT
  1302. xtring name;
  1303. /// life form (tree or grass)
  1304. lifeformtype lifeform;
  1305. /// leaf phenology (raingreen, summergreen, evergreen, rain+summergreen, cropgreen)
  1306. phenologytype phenology;
  1307. /// leaf physiognomy (needleleaf, broadleaf)
  1308. leafphysiognomytype leafphysiognomy;
  1309. /// growing degree sum on 5 degree base required for full leaf cover
  1310. double phengdd5ramp;
  1311. /// water stress threshold for leaf abscission (range 0-1; raingreen PFTs)
  1312. double wscal_min;
  1313. /// biochemical pathway for photosynthesis (C3 or C4)
  1314. pathwaytype pathway;
  1315. /// approximate low temperature limit for photosynthesis (deg C)
  1316. double pstemp_min;
  1317. /// approximate lower range of temperature optimum for photosynthesis (deg C)
  1318. double pstemp_low;
  1319. /// approximate upper range of temperature optimum for photosynthesis (deg C)
  1320. double pstemp_high;
  1321. /// maximum temperature limit for photosynthesis (deg C)
  1322. double pstemp_max;
  1323. /// non-water-stressed ratio of intercellular to ambient CO2 partial pressure
  1324. double lambda_max;
  1325. /// vegetation root profile
  1326. /** array containing fraction of roots in each soil layer, [0=upper layer] */
  1327. double rootdist[NSOILLAYER];
  1328. /// canopy conductance component not associated with photosynthesis (mm/s)
  1329. double gmin;
  1330. /// maximum evapotranspiration rate (mm/day)
  1331. double emax;
  1332. /// maintenance respiration coefficient (0-1)
  1333. double respcoeff;
  1334. /// minimum leaf C:N mass ratio allowed when nitrogen demand is determined
  1335. double cton_leaf_min;
  1336. /// maximum leaf C:N mass ratio allowed when nitrogen demand is determined
  1337. double cton_leaf_max;
  1338. /// average leaf C:N mass ratio (between min and max)
  1339. double cton_leaf_avr;
  1340. /// average fine root C:N mass ratio (connected cton_leaf_avr)
  1341. double cton_root_avr;
  1342. /// maximum fine root C:N mass ratio (used when mass is negligible)
  1343. double cton_root_max;
  1344. /// average sapwood C:N mass ratio (connected cton_leaf_avr)
  1345. double cton_sap_avr;
  1346. /// maximum sapwood C:N mass ratio (used when mass is negligible)
  1347. double cton_sap_max;
  1348. /// reference fine root C:N mass ratio
  1349. double cton_root;
  1350. /// reference sapwood C:N mass ratio
  1351. double cton_sap;
  1352. /// Maximum nitrogen (NH4+ and NO3- seperatly) uptake per fine root [kgN kgC-1 day-1]
  1353. double nuptoroot;
  1354. /// coefficient to compensate for vertical distribution of fine root on nitrogen uptake
  1355. double nupscoeff;
  1356. /// fraction of sapwood (root for herbaceous pfts) that can be used as a nitrogen longterm storage scalar
  1357. double fnstorage;
  1358. /// Michaelis-Menten kinetic parameters
  1359. /** Half saturation concentration for N uptake [kgN l-1] (Rothstein 2000) */
  1360. double km_volume;
  1361. /// fraction of NPP allocated to reproduction
  1362. double reprfrac;
  1363. /// annual leaf turnover as a proportion of leaf C biomass
  1364. double turnover_leaf;
  1365. /// annual fine root turnover as a proportion of fine root C biomass
  1366. double turnover_root;
  1367. /// annual sapwood turnover as a proportion of sapwood C biomass
  1368. double turnover_sap;
  1369. /// sapwood and heartwood density (kgC/m3)
  1370. double wooddens;
  1371. /// maximum tree crown area (m2)
  1372. double crownarea_max;
  1373. /// constant in allometry equations
  1374. double k_allom1;
  1375. /// constant in allometry equations
  1376. double k_allom2;
  1377. /// constant in allometry equations
  1378. double k_allom3;
  1379. /// constant in allometry equations
  1380. double k_rp;
  1381. /// tree leaf to sapwood area ratio
  1382. double k_latosa;
  1383. /// specific leaf area (m2/kgC)
  1384. double sla;
  1385. /// leaf longevity (years)
  1386. double leaflong;
  1387. /// leaf to root mass ratio under non-water-stressed conditions
  1388. double ltor_max;
  1389. /// litter moisture flammability threshold (fraction of AWC)
  1390. double litterme;
  1391. /// fire resistance (0-1)
  1392. double fireresist;
  1393. /// minimum forest-floor PAR level for growth (grasses) or establishment (trees)
  1394. /** J/m2/day, individual and cohort modes */
  1395. double parff_min;
  1396. /** parameter capturing non-linearity in recruitment rate relative to
  1397. * understorey growing conditions for trees (Fulton 1991) (individual and
  1398. * cohort modes)
  1399. */
  1400. double alphar;
  1401. /// maximum sapling establishment rate (saplings/m2/year) (individual and cohort modes)
  1402. double est_max;
  1403. /** constant used in calculation of sapling establishment rate when spatial
  1404. * mass effect enabled (individual and cohort modes)
  1405. */
  1406. double kest_repr;
  1407. /// constant affecting amount of background establishment
  1408. /** \see ifbgestab */
  1409. double kest_bg;
  1410. /** constant used in calculation of sapling establishment rate when spatial
  1411. * mass effect disabled (individual and cohort modes)
  1412. */
  1413. double kest_pres;
  1414. /// expected longevity under non-stressed conditions (individual and cohort modes)
  1415. double longevity;
  1416. /// threshold growth efficiency for imposition of growth suppression mortality
  1417. /** kgC/m2 leaf/year, individual and cohort modes */
  1418. double greff_min;
  1419. // Bioclimatic limits (all temperatures deg C)
  1420. /// minimum 20-year coldest month mean temperature for survival
  1421. double tcmin_surv;
  1422. /// maximum 20-year coldest month mean temperature for establishment
  1423. double tcmax_est;
  1424. /// minimum degree day sum on 5 deg C base for establishment
  1425. double gdd5min_est;
  1426. /// minimum 20-year coldest month mean temperature for establishment
  1427. double tcmin_est;
  1428. /// minimum warmest month mean temperature for establishment
  1429. double twmin_est;
  1430. /// continentality parameter for boreal summergreen trees
  1431. double twminusc;
  1432. /// constant in equation for budburst chilling time requirement (Sykes et al 1996)
  1433. double k_chilla;
  1434. /// coefficient in equation for budburst chilling time requirement
  1435. double k_chillb;
  1436. /// exponent in equation for budburst chilling time requirement
  1437. double k_chillk;
  1438. /// array containing values for GDD0(c) given c=number of chill days
  1439. /** Sykes et al 1996, Eqn 1
  1440. * gdd0 has one element for each possible value for number of chill days
  1441. */
  1442. double gdd0[Date::MAX_YEAR_LENGTH + 1];
  1443. /// interception coefficient (unitless)
  1444. double intc;
  1445. /// the amount of N that is applied (kg N m-2)
  1446. double N_appfert;
  1447. /// 0 - 1 how much of the fertiliser is applied the first date, default 1.
  1448. double fertrate[2];
  1449. /// dates relative to sowing date
  1450. int fertdates[2];
  1451. double fert_stages[2];
  1452. bool fertilised[2];
  1453. double T_vn_min;
  1454. double T_vn_opt;
  1455. double T_vn_max;
  1456. double T_veg_min;
  1457. double T_veg_opt;
  1458. double T_veg_max;
  1459. double T_rep_min;
  1460. double T_rep_opt;
  1461. double T_rep_max;
  1462. double photo[3];
  1463. double dev_rate_veg;
  1464. double dev_rate_rep;
  1465. double a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3;
  1466. double cton_stem_avr;
  1467. double cton_stem_max;
  1468. /// Drought tolerance level (0 = very -> 1 = not at all) (unitless)
  1469. /** Used to implement drought-limited establishment */
  1470. double drought_tolerance;
  1471. // bvoc
  1472. /// aerodynamic conductance (m s-1)
  1473. double ga;
  1474. /// isoprene emission capacity (ug C g-1 h-1)
  1475. double eps_iso;
  1476. /// whether (1) or not (1) isoprene emissions show a seasonality
  1477. bool seas_iso;
  1478. /// monoterpene emission capacity (ug C g-1 h-1) per monoterpene species
  1479. double eps_mon[NMTCOMPOUNDS];
  1480. /// fraction of monoterpene production that goes into storage pool (-) per monoterpene species
  1481. double storfrac_mon[NMTCOMPOUNDS];
  1482. /// Sapling/regeneration characteristics (used only in population mode)
  1483. /** For trees, on sapling individual basis (kgC); for grasses, on stand area basis,
  1484. * kgC/m2 */
  1485. struct {
  1486. /// leaf C biomass
  1487. double cmass_leaf;
  1488. /// fine root C biomass
  1489. double cmass_root;
  1490. /// sapwood C biomass
  1491. double cmass_sap;
  1492. /// heartwood C biomass
  1493. double cmass_heart;
  1494. } regen;
  1495. /// specifies type of landcover pft is allowed to grow in (0 = URBAN, 1 = CROP, 2 = PASTURE, 3 = FOREST, 4 = NATURAL, 5 = PEATLAND)
  1496. landcovertype landcover;
  1497. /// pft selection
  1498. xtring selection;
  1499. /// fraction of residue outtake at harvest
  1500. double res_outtake;
  1501. /// harvest efficiency
  1502. double harv_eff;
  1503. /// harvest efficiency of intercrop grass
  1504. double harv_eff_ic;
  1505. /// fraction of harvested products that goes into patchpft.harvested_products_slow
  1506. double harvest_slow_frac;
  1507. /// yearly turnover fraction of patchpft.harvested_products_slow (goes to gridcell.acflux_harvest_slow)
  1508. double turnover_harv_prod;
  1509. /// whether pft may grow as cover crop
  1510. bool isintercropgrass;
  1511. /// whether autumn temperature dependent sowing date is calculated
  1512. bool ifsdautumn;
  1513. /// upper temperature limit for autumn sowing
  1514. double tempautumn;
  1515. /// lower temperature limit for spring sowing
  1516. double tempspring;
  1517. /// default length of growing period
  1518. int lgp_def;
  1519. /// upper minimum temperature limit for crop sowing
  1520. double maxtemp_sowing;
  1521. /// default sowing date in the northern hemisphere (julian day)
  1522. int sdatenh;
  1523. /// default sowing date in the southern hemisphere
  1524. int sdatesh;
  1525. /// whether sowing date adjusting equation is used
  1526. bool sd_adjust;
  1527. /// parameter 1 in sowing date adjusting equation
  1528. double sd_adjust_par1;
  1529. /// parameter 2 in sowing date adjusting equation
  1530. double sd_adjust_par2;
  1531. /// parameter 3 in sowing date adjusting equation
  1532. double sd_adjust_par3;
  1533. /// latest date for harvesting in the northern hemisphere
  1534. int hlimitdatenh;
  1535. /// latest date for harvesting in the southern hemisphere
  1536. int hlimitdatesh;
  1537. /// default base temperature (°C) for heat unit (hu) calculation
  1538. double tb;
  1539. /// temperature under which vernalisation is possible (°C)
  1540. double trg;
  1541. /// default number of vernalising days required
  1542. int pvd;
  1543. /// sensitivity to the photoperiod effect [0-1]
  1544. double psens;
  1545. /// basal photoperiod (h) (pb<ps for longer days plants)
  1546. double pb;
  1547. /// lag in days after sowing before vernalization starts
  1548. int vern_lag;
  1549. /// saturating photoperiod (h) (ps<pb for shorter days plants)
  1550. double ps;
  1551. /// default potential heat units required for crop maturity (degree-days)
  1552. double phu;
  1553. /// whether quadratic equation used for calculating potential heat units (Bondeau method)
  1554. bool phu_calc_quad;
  1555. /// whether linear equation used for calculating potential heat units (Bondeau method)
  1556. bool phu_calc_lin;
  1557. /// minimum potential heat units required for crop maturity (Bondeau method) (degree-days)
  1558. double phu_min;
  1559. /// maximum potential heat units required for crop maturity (Bondeau method) (degree-days)
  1560. double phu_max;
  1561. /// reduction factor of potential heat units in spring crops (Bondeau method) (degree-days)
  1562. double phu_red_spring_sow;
  1563. /// number of days of phu decrease in the linear phu equation (Bondeau method)
  1564. double ndays_ramp_phu;
  1565. /// intercept for the linear phu equation (Bondeau method)
  1566. double phu_interc;
  1567. /// fraction of growing season (phu) at which senescence starts [0-1]
  1568. double fphusen;
  1569. /// type of senescence curve (see Bondeau et al. 2007)
  1570. bool shapesenescencenorm;
  1571. /// fraction of maximal LAI still present at harvest [0-1]
  1572. double flaimaxharvest;
  1573. /// default maximum LAI (only used for intercrop grass in the case where no pasture is present in any stand)
  1574. double laimax;
  1575. /// whether harvestable organs are above ground
  1576. bool aboveground_ho;
  1577. /// optimum harvest index
  1578. double hiopt;
  1579. /// minimum harvest index
  1580. double himin;
  1581. /// initial fraction of growing season's npp allocated to roots
  1582. double frootstart;
  1583. /// final fraction of growing season's npp allocated to roots
  1584. double frootend;
  1585. /// autumn/spring sowing of pft:s with tempautumn = 1
  1586. int forceautumnsowing; //0 = NOFORCING, 1 = AUTUMNSOWING, 2 = SPRINGSOWING
  1587. /// N limited version of pft
  1588. bool nlim;
  1589. double avg_cton(const double& min, const double& max) {
  1590. return 2.0 / (1. / min + 1. / max);
  1591. }
  1592. // MEMBER FUNCTIONS
  1593. public:
  1594. /// Constructor (initialises array gdd0)
  1595. Pft() {
  1596. std::fill_n(gdd0, Date::MAX_YEAR_LENGTH + 1, -1.0); // value<0 signifies "unknown"; see function phenology()
  1597. // guess2008 - DLE
  1598. drought_tolerance = 0.0; // Default, means that the PFT will never be limited by drought.
  1599. res_outtake = 0.0;
  1600. harv_eff = 0.0;
  1601. harv_eff_ic = 0.0;
  1602. turnover_harv_prod = 1.0; // default 1 year turnover time
  1603. harvest_slow_frac = 0.0; // ecev3
  1604. isintercropgrass = false;
  1605. ifsdautumn = false;
  1606. maxtemp_sowing = 60;
  1607. sdatenh = -1;
  1608. sdatesh = -1;
  1609. sd_adjust = 0; // ecev3 - prevent SIGFPE for PFT CC4G_ic in set_sdatecalc_temp(), sd_adjust_par.. are set to bogus values
  1610. lgp_def = 190;
  1611. hlimitdatenh = -1;
  1612. hlimitdatesh = -1;
  1613. tb = -999.9;
  1614. trg = -999.9;
  1615. pvd = -1;
  1616. psens = -1.0;
  1617. pb = -1.0;
  1618. vern_lag=0;
  1619. ps = -1.0;
  1620. phu = -1.0;
  1621. phu_red_spring_sow = 1.0;
  1622. fphusen = -1.0;
  1623. shapesenescencenorm = 0;
  1624. flaimaxharvest = -1.0;
  1625. laimax = 0.0;
  1626. aboveground_ho = true;
  1627. frootstart = 0.0;
  1628. frootend = 0.0;
  1629. forceautumnsowing = 0;
  1630. nlim = false;
  1631. fertrate[0] = 0.0;
  1632. fertrate[1] = 1.0;
  1633. fertdates[0] = 0;
  1634. fertdates[1] = 30;
  1635. fert_stages[0] = 0.5;
  1636. fert_stages[1] = 0.9;
  1637. fertilised[0] = false;
  1638. fertilised[1] = false;
  1639. N_appfert = 0.0;
  1640. T_vn_min=0.0;
  1641. T_vn_opt=0.0;
  1642. T_vn_max=0.0;
  1643. T_veg_min=0.0;
  1644. T_veg_opt=0.0;
  1645. T_veg_max=0.0;
  1646. T_rep_min=0.0;
  1647. T_rep_opt=0.0;
  1648. T_rep_max=0.0;
  1649. a1=0.0;
  1650. b1=0.0;
  1651. c1=0.0;
  1652. d1=0.0;
  1653. a2=0.0;
  1654. b2=0.0;
  1655. c2=0.0;
  1656. d2=0.0;
  1657. a3=0.0;
  1658. b3=0.0;
  1659. c3=0.0;
  1660. d3=0.0;
  1661. // ecev3 - extra initialisation
  1662. harvest_slow_frac = 0.0;
  1663. for (int i=0; i<3; i++)
  1664. photo[i]=0.0;
  1665. }
  1666. /// Calculates SLA given leaf longevity
  1667. void initsla() {
  1668. // SLA has to be supplied in the insfile for crops with N limitation
  1669. if (!(phenology == CROPGREEN && ifnlim)) {
  1670. // Reich et al 1992, Table 1 (includes conversion x2.0 from m2/kg_dry_weight to
  1671. // m2/kgC)
  1672. if (leafphysiognomy == BROADLEAF) {
  1673. if (phenology == RAINGREEN) {
  1674. sla = 0.2 * pow(10.0, 2.51 - 0.36 * log10(12.0 * leaflong));
  1675. }
  1676. else {
  1677. sla = 0.2 * pow(10.0, 2.41 - 0.38 * log10(12.0 * leaflong));
  1678. }
  1679. }
  1680. else if (leafphysiognomy == NEEDLELEAF) {
  1681. sla = 0.2 * pow(10.0, 2.32 - 0.4 * log10(12.0 * leaflong));
  1682. }
  1683. }
  1684. }
  1685. /// Calculates minimum leaf C:N ratio given leaf longevity
  1686. void init_cton_min() {
  1687. // cton_leaf_min has to be supplied in the insfile for crops with N limitation
  1688. if (!(phenology == CROPGREEN && ifnlim)) {
  1689. // Reich et al 1992, Table 1 (includes conversion x500 from mg/g_dry_weight to
  1690. // kgN/kgC)
  1691. if (leafphysiognomy == BROADLEAF) {
  1692. if (phenology == RAINGREEN) {
  1693. cton_leaf_min = 500.0 / pow(10.0, 1.93 - 0.3 * log10(12.0 * leaflong));
  1694. }
  1695. else {
  1696. cton_leaf_min = 500.0 / pow(10.0, 1.75 - 0.33 * log10(12.0 * leaflong));
  1697. }
  1698. }
  1699. else if (leafphysiognomy == NEEDLELEAF) {
  1700. cton_leaf_min = 500.0 / pow(10.0, 1.57 - 0.27 * log10(12.0 * leaflong));
  1701. }
  1702. }
  1703. }
  1704. void init_cton_limits() {
  1705. // Fraction between min and max C:N ratio White et al. 2000
  1706. double frac_mintomax = (phenology == CROPGREEN && ifnlim) ? 5.0 : 2.78; // Use value also without nlim ?
  1707. // Fraction between leaf and root C:N ratio
  1708. double frac_leaftoroot = 1.16; // Friend et al. 1997
  1709. // Fraction between leaf and sap wood C:N ratio
  1710. double frac_leaftosap = 6.9; // Friend et al. 1997
  1711. // Max leaf C:N ratio
  1712. cton_leaf_max = cton_leaf_min * frac_mintomax;
  1713. // Average leaf C:N ratio
  1714. cton_leaf_avr = avg_cton(cton_leaf_min, cton_leaf_max);
  1715. // Tighter C:N ratio range for roots and sapwood: picked out thin air
  1716. double frac_maxtomin = .9;
  1717. // Maximum fine root C:N ratio
  1718. cton_root_max = cton_leaf_max * frac_leaftoroot;
  1719. double cton_root_min = cton_root_max * frac_maxtomin;
  1720. // Average fine root C:N ratio
  1721. cton_root_avr = avg_cton(cton_root_min, cton_root_max);
  1722. // Maximum sap C:N ratio
  1723. cton_sap_max = cton_leaf_max * frac_leaftosap;
  1724. double cton_sap_min = cton_sap_max * frac_maxtomin;
  1725. // Average sap C:N ratio
  1726. cton_sap_avr = avg_cton(cton_sap_min, cton_sap_max);
  1727. if (lifeform == GRASS) {
  1728. respcoeff /= 2.0 * cton_root / (cton_root_avr + cton_root_min);
  1729. } else {
  1730. respcoeff /= cton_root / (cton_root_avr + cton_root_min) +
  1731. cton_sap / (cton_sap_avr + cton_sap_min);
  1732. }
  1733. cton_stem_max = 1.0/(2.0*0.0034); //Maize params
  1734. cton_stem_avr = 1.0/(2.0*0.0068);
  1735. }
  1736. /// Calculates coefficient to compensate for different vertical distribution of fine root on nitrogen uptake
  1737. void init_nupscoeff() {
  1738. // Fraction fine root in upper soil layer should have higher possibility for mineralized nitrogen uptake
  1739. // Soil nitrogen profile is considered to have a exponential decline (Franzluebbers et al. 2009) giving
  1740. // an approximate advantage of 2 of having more roots in the upper soil layer
  1741. const double upper_adv = 2.0;
  1742. nupscoeff = rootdist[0] * upper_adv + rootdist[1];
  1743. }
  1744. /// Initialises sapling/regen characteristics in population mode following LPJF formulation
  1745. void initregen() {
  1746. // see function allometry in growth module.
  1747. // Note: primary PFT parameters, including SLA, must be set before this
  1748. // function is called
  1749. const double REGENLAI_TREE = 1.5;
  1750. const double REGENLAI_GRASS = 0.001;
  1751. const double SAPLINGHW = 0.2;
  1752. if (lifeform == TREE) {
  1753. // Tree sapling characteristics
  1754. regen.cmass_leaf = pow(REGENLAI_TREE * k_allom1 * pow(1.0 + SAPLINGHW, k_rp) *
  1755. pow(4.0 * sla / PI / k_latosa, k_rp * 0.5) / sla, 2.0 / (2.0 - k_rp));
  1756. regen.cmass_sap = wooddens * k_allom2 * pow((1.0 + SAPLINGHW) *
  1757. sqrt(4.0 * regen.cmass_leaf * sla / PI / k_latosa), k_allom3) *
  1758. regen.cmass_leaf * sla / k_latosa;
  1759. regen.cmass_heart = SAPLINGHW * regen.cmass_sap;
  1760. }
  1761. else if (lifeform == GRASS) {
  1762. // Grass regeneration characteristics
  1763. regen.cmass_leaf = REGENLAI_GRASS / sla;
  1764. }
  1765. regen.cmass_root = 1.0 / ltor_max * regen.cmass_leaf;
  1766. }
  1767. };
  1768. /// A list of PFTs
  1769. /** Functionality for building, maintaining, referencing and destroying a list array of
  1770. * Pft objects. In general, there should be a single Pftlist object containing
  1771. * a single list of PFTs. Pft objects within the list are then referenced by the pft
  1772. * member of each Individual object.
  1773. *
  1774. * Functionality is inherited from the ListArray_id template type in the GUTIL
  1775. * Library. Sequential Pft objects can be referenced as array elements by id:
  1776. *
  1777. * Pftlist pftlist;
  1778. * ...
  1779. * for (i=0; i<npft; i++) {
  1780. * Pft& thispft=pftlist[i];
  1781. * // query or modify object thispft here
  1782. * }
  1783. *
  1784. * or by iteration through the linked list:
  1785. *
  1786. * pftlist.firstobj();
  1787. * while (pftlist.isobj) {
  1788. * Pft& thispft=pftlist.getobj();
  1789. * // query or modify object thispft here
  1790. * pftlist.nextobj();
  1791. * }
  1792. */
  1793. class Pftlist : public ListArray_id<Pft> {
  1794. public:
  1795. int getpftid(xtring pftname) {
  1796. int id = -1;
  1797. for(unsigned int i=0; i< this->nobj; i++) {
  1798. Pft& pft = (*this)[i];
  1799. if(pft.name == pftname) {
  1800. id = pft.id;
  1801. break;
  1802. }
  1803. }
  1804. return id;
  1805. }
  1806. };
  1807. /// The one and only linked list of Pft objects
  1808. extern Pftlist pftlist;
  1809. /// Container for crop-specific data at the individual level
  1810. struct cropindiv_struct : public Serializable {
  1811. //Plant carbon biomass variables are all on patch area basis (kgC/m2)
  1812. /// year's harvestable organ C biomass (= ycmass_plant)
  1813. double cmass_ho;
  1814. /// above-ground pool C biomass (when calculating daily cmass_leaf from lai_crop) (= ycmass_agpool)
  1815. double cmass_agpool;
  1816. double cmass_stem;
  1817. /// year's maximum value of leaf C biomass
  1818. double cmass_leaf_max;
  1819. /// grs_cmass_leaf value saved at day before senescence (for LAI-calculation in allometry)
  1820. double cmass_leaf_sen;
  1821. /// today's increase of whole plant C biomass
  1822. double dcmass_plant;
  1823. /// today's increase of leaf C biomass
  1824. double dcmass_leaf;
  1825. /// today's increase of root C biomass
  1826. double dcmass_root;
  1827. /// today's increase of harvestable organ C biomass
  1828. double dcmass_ho;
  1829. /// today's increase of above-ground pool C biomass
  1830. double dcmass_agpool;
  1831. double dcmass_stem;
  1832. /// today's increase of leaf N biomass
  1833. double dnmass_leaf;
  1834. /// today's increase of root N biomass
  1835. double dnmass_root;
  1836. /// today's increase of harvestable organ N biomass
  1837. double dnmass_ho;
  1838. /// today's increase of above-ground pool N biomass
  1839. double dnmass_agpool;
  1840. ///CARBON
  1841. /// daily updated whole plant C biomass, reset at harvest day
  1842. double grs_cmass_plant;
  1843. /// daily updated leaf C biomass, reset at harvest day
  1844. double grs_cmass_leaf;
  1845. /// daily updated root C biomass, reset at harvest day
  1846. double grs_cmass_root;
  1847. /// daily updated harvestable organ C biomass, reset at harvest day
  1848. double grs_cmass_ho;
  1849. /// daily updated above-ground pool C biomass, reset at harvest day
  1850. double grs_cmass_agpool;
  1851. /// daily updated dead leaf C biomass, reset at harvest day
  1852. double grs_cmass_dead_leaf;
  1853. /// daily updated stem pool C biomass, reset at harvest day
  1854. double grs_cmass_stem;
  1855. /// carbon content of harvestable organs saved on first day of land use change year
  1856. double grs_cmass_leaf_luc;
  1857. /// carbon content of harvestable organs saved on first day of land use change year
  1858. double grs_cmass_root_luc;
  1859. /// carbon content of harvestable organs saved on first day of land use change year
  1860. double grs_cmass_ho_luc;
  1861. /// carbon content of above-ground pool saved on first day of land use change year
  1862. double grs_cmass_agpool_luc;
  1863. /// carbon content of dead leaves saved on first day of land use change year
  1864. double grs_cmass_dead_leaf_luc;
  1865. /// carbon content of stem saved on first day of land use change year
  1866. double grs_cmass_stem_luc;
  1867. /// daily updated whole plant C biomass, reset at day 0
  1868. double ycmass_plant;
  1869. /// daily updated leaf C biomass, reset at day 0
  1870. double ycmass_leaf;
  1871. /// daily updated root C biomass, reset at day 0
  1872. double ycmass_root;
  1873. /// daily updated harvestable organ C biomass, reset at day 0
  1874. double ycmass_ho;
  1875. /// daily updated above-ground pool C biomass, reset at day 0
  1876. double ycmass_agpool;
  1877. /// daily updated dead leaf C biomass, reset at day 0
  1878. double ycmass_dead_leaf;
  1879. /// daily updated stem C biomass, reset at day 0
  1880. double ycmass_stem;
  1881. /// year's whole plant C biomass at time of harvest (cumulative if several harvest events)
  1882. double harv_cmass_plant;
  1883. /// year's leaf C biomass at time of harvest (cumulative if several harvest events)
  1884. double harv_cmass_leaf;
  1885. /// year's root C biomass at time of harvest (cumulative if several harvest events)
  1886. double harv_cmass_root;
  1887. /// year's harvestable organ C biomass at time of harvest (cumulative if several harvest events)
  1888. double harv_cmass_ho;
  1889. /// year's above-ground pool C biomass at time of harvest (cumulative if several harvest events)
  1890. double harv_cmass_agpool;
  1891. /// year's stem C biomass at time of harvest (cumulative if several harvest events)
  1892. double harv_cmass_stem;
  1893. ///NITROGEN
  1894. /// nitrogen content of harvestable organs
  1895. double nmass_ho;
  1896. /// nitrogen content of above-ground pool
  1897. double nmass_agpool;
  1898. /// nitrogen content of dead leaves
  1899. double nmass_dead_leaf;
  1900. /// nitrogen content of harvestable organs saved on first day of land use change year
  1901. double nmass_ho_luc;
  1902. /// nitrogen content of above-ground pool saved on first day of land use change year
  1903. double nmass_agpool_luc;
  1904. /// nitrogen content of dead leaves saved on first day of land use change year
  1905. double nmass_dead_leaf_luc;
  1906. /// daily updated leaf N biomass, reset at day 0
  1907. double ynmass_leaf;
  1908. /// daily updated root N biomass, reset at day 0
  1909. double ynmass_root;
  1910. /// daily updated harvestable organ N biomass, reset at day 0
  1911. double ynmass_ho;
  1912. /// daily updated above-ground pool N biomass, reset at day 0
  1913. double ynmass_agpool;
  1914. /// daily updated dead leaf N biomass, reset at day 0
  1915. double ynmass_dead_leaf;
  1916. /// year's leaf N biomass at time of harvest (cumulative if several harvest events)
  1917. double harv_nmass_leaf;
  1918. /// year's root N biomass at time of harvest (cumulative if several harvest events)
  1919. double harv_nmass_root;
  1920. /// year's harvestable organ N biomass at time of harvest (cumulative if several harvest events)
  1921. double harv_nmass_ho;
  1922. /// year's above-ground pool N biomass at time of harvest (cumulative if several harvest events)
  1923. double harv_nmass_agpool;
  1924. /// dry weight crop yield harvested this year (cumulative if several harvest events), based on harv_cmass_xx
  1925. double harv_yield;
  1926. /// harvestable organ C biomass at the last two harvest events this year
  1927. double cmass_ho_harvest[2];
  1928. /// harvestable organ N biomass at the last two harvest events this year
  1929. double nmass_ho_harvest[2];
  1930. /// dry weight crop yield at the last two harvest events this year
  1931. double yield_harvest[2];
  1932. /// dry weight crop yield grown this year (cumulative if several harvest events), based on ycmass_xx
  1933. double yield;
  1934. /// whether this pft is the main crop in the stand (pft.id==stand.pftid)
  1935. bool isprimarycrop;
  1936. /// whether this pft is allowed to compete with the main crop during the same growing period (for future use)
  1937. bool isprimarycovegetation;
  1938. /// whether this pft is grown during a second growing period, different from the primary (main) crop (for future use)
  1939. // bool issecondarycrop;
  1940. /// set to true if pft.isintercropgrass is true and the stand's main crop pft.intercrop is "naturalgrass"
  1941. bool isintercropgrass;
  1942. cropindiv_struct() {
  1943. cmass_ho=0.0;
  1944. cmass_agpool=0.0;
  1945. cmass_stem = 0.0;
  1946. cmass_leaf_max=0.0;
  1947. cmass_leaf_sen=0.0;
  1948. yield=0.0;
  1949. yield_harvest[0]=0.0;
  1950. yield_harvest[1]=0.0;
  1951. dcmass_leaf=0.0;
  1952. dcmass_root=0.0;
  1953. dcmass_plant=0.0;
  1954. dcmass_ho=0.0;
  1955. dcmass_agpool=0.0;
  1956. grs_cmass_leaf=0.0;
  1957. grs_cmass_root=0.0;
  1958. grs_cmass_plant=0.0;
  1959. grs_cmass_ho=0.0;
  1960. grs_cmass_agpool=0.0;
  1961. grs_cmass_stem = 0.0;
  1962. grs_cmass_dead_leaf = 0.0;
  1963. grs_cmass_leaf_luc=0.0;
  1964. grs_cmass_root_luc=0.0;
  1965. grs_cmass_ho_luc=0.0;
  1966. grs_cmass_agpool_luc=0.0;
  1967. grs_cmass_dead_leaf_luc = 0.0;
  1968. grs_cmass_stem_luc = 0.0;
  1969. nmass_ho=0.0;
  1970. nmass_agpool=0.0;
  1971. nmass_dead_leaf = 0.0;
  1972. ycmass_leaf=0.0;
  1973. ycmass_root=0.0;
  1974. ycmass_plant=0.0;
  1975. ycmass_ho=0.0;
  1976. ycmass_agpool=0.0;
  1977. ycmass_stem = 0.0;
  1978. ycmass_dead_leaf = 0.0;
  1979. harv_cmass_leaf=0.0;
  1980. harv_cmass_root=0.0;
  1981. harv_cmass_root=0.0;
  1982. harv_cmass_ho=0.0;
  1983. harv_yield=0.0;
  1984. harv_cmass_agpool=0.0;
  1985. harv_cmass_stem = 0.0;
  1986. cmass_ho_harvest[0]=0.0;
  1987. cmass_ho_harvest[1]=0.0;
  1988. //Nitrogen
  1989. dnmass_leaf=0.0;
  1990. dnmass_root=0.0;
  1991. dnmass_ho=0.0;
  1992. dnmass_agpool=0.0;
  1993. ynmass_leaf=0.0;
  1994. ynmass_root=0.0;
  1995. ynmass_ho=0.0;
  1996. ynmass_agpool=0.0;
  1997. ynmass_dead_leaf = 0.0;
  1998. harv_nmass_leaf=0.0;
  1999. harv_nmass_root=0.0;
  2000. harv_nmass_root=0.0;
  2001. harv_nmass_ho=0.0;
  2002. harv_nmass_agpool=0.0;
  2003. nmass_dead_leaf_luc = 0.0;
  2004. nmass_ho_harvest[0]=0.0;
  2005. nmass_ho_harvest[1]=0.0;
  2006. // ecev3
  2007. nmass_ho_luc=0.0;
  2008. nmass_agpool_luc = 0.0;
  2009. isprimarycrop=false;
  2010. isprimarycovegetation=false;
  2011. // issecondarycrop=false;
  2012. isintercropgrass=false;
  2013. }
  2014. void serialize(ArchiveStream& arch);
  2015. };
  2016. /// A vegetation individual.
  2017. /** In population mode this is the average individual of a PFT population;
  2018. * in cohort mode: the average individual of a cohort;
  2019. * in individual mode: an individual plant. Each grass PFT is represented as a single
  2020. * individual in all modes. Individual objects are collected within list arrays of
  2021. * class Vegetation (defined below), of which there is one for each patch, and include
  2022. * a reference to their 'parent' Vegetation object. Use the createobj member function
  2023. * of class Vegetation to add new individuals.
  2024. */
  2025. class Individual : public Serializable {
  2026. public:
  2027. /// reference to Pft object containing static parameters for this individual
  2028. Pft& pft;
  2029. /// reference to Vegetation object to which this Individual belongs
  2030. Vegetation& vegetation;
  2031. /// id code (0-based, sequential)
  2032. int id;
  2033. /// leaf C biomass on modelled area basis (kgC/m2)
  2034. double cmass_leaf;
  2035. /// fine root C biomass on modelled area basis (kgC/m2)
  2036. double cmass_root;
  2037. /// sapwood C biomass on modelled area basis (kgC/m2)
  2038. double cmass_sap;
  2039. /// heartwood C biomass on modelled area basis (kgC/m2)
  2040. double cmass_heart;
  2041. /// C "debt" (retrospective storage) (kgC/m2)
  2042. double cmass_debt;
  2043. /// Total C mass at land use change (kgC/m2)
  2044. double cmass_tot_luc;
  2045. /// leaf C mass after tunrnover
  2046. double cmass_leaf_post_turnover;
  2047. /// root C mass after turnover
  2048. double cmass_root_post_turnover;
  2049. /// Latest tunover day for this individual
  2050. int last_turnover_day;
  2051. /// leaf N biomass on modelled area basis (kgN/m2)
  2052. double nmass_leaf;
  2053. /// root N biomass on modelled area basis (kgN/m2)
  2054. double nmass_root;
  2055. /// sap N biomass on modelled area basis (kgN/m2)
  2056. double nmass_sap;
  2057. /// heart N biomass on modelled area basis (kgN/m2)
  2058. double nmass_heart;
  2059. /// leaf N biomass on modelled area basis saved on first day of land use change year
  2060. double nmass_leaf_luc;
  2061. /// root N biomass on modelled area basis on first day of land use change year
  2062. double nmass_root_luc;
  2063. /// sap N biomass on modelled area basis on first day of land use change year
  2064. double nmass_sap_luc;
  2065. /// heart N biomass on modelled area basis on first day of land use change year
  2066. double nmass_heart_luc;
  2067. /// total N biomass on modelled area basis on first day of land use change year
  2068. double nmass_tot_luc;
  2069. /// foliar projective cover (FPC) under full leaf cover as fraction of modelled area
  2070. double fpc;
  2071. /// foliar projective cover (FPC) this day as fraction of modelled area
  2072. double fpc_daily;
  2073. /// monthly average daily foliar projective cover (FPC) as fraction of modelled area
  2074. double mfpc[12];
  2075. /// fraction of PAR absorbed by foliage over projective area today, taking account of leaf phenological state
  2076. double fpar;
  2077. /// monthly average fraction of PAR absorbed by foliage over projective area, taking account of leaf phenological state
  2078. double mfpar[12];
  2079. /// average density of individuals over patch (indiv/m2)
  2080. double densindiv;
  2081. /// vegetation phenological state (fraction of potential leaf cover)
  2082. double phen;
  2083. /// annual sum of daily fractional leaf cover
  2084. /** Equivalent number of days with full leaf cover
  2085. * (population mode only; reset on expected coldest day of year)
  2086. */
  2087. double aphen;
  2088. /// annual number of days with full leaf cover) (raingreen PFTs only; reset on 1 January)
  2089. int aphen_raingreen;
  2090. /// Photosynthesis values for this individual under non-water-stress conditions
  2091. PhotosynthesisResult photosynthesis;
  2092. /// sub-daily version of the above variable (NB: daily units)
  2093. std::vector<PhotosynthesisResult> phots;
  2094. /// accumulated NPP over modelled area (kgC/m2/year);
  2095. /** annual NPP following call to growth module on last day of simulation year */
  2096. double anpp;
  2097. /// actual evapotranspiration over projected area (mm/day)
  2098. double aet;
  2099. /// annual actual evapotranspiration over projected area (mm/year)
  2100. double aaet;
  2101. /// leaf to root mass ratio
  2102. double ltor;
  2103. /// plant height (m)
  2104. double height;
  2105. /// plant crown area (m2)
  2106. double crownarea;
  2107. /// increment in fpc since last simulation year
  2108. double deltafpc;
  2109. /// bole height, i.e. height above ground of bottom of crown cylinder (m)
  2110. /** (individual and cohort modes only) */
  2111. double boleht;
  2112. /// patch-level lai for this individual or cohort (function fpar)
  2113. double lai;
  2114. /// patch-level lai for cohort in current vertical layer (function fpar)
  2115. double lai_layer;
  2116. /// individual leaf area index (individual and cohort modes only)
  2117. double lai_indiv;
  2118. /// patch-level individual leaf area index (individual and cohort modes only)
  2119. double lai_daily;
  2120. /// daily individual leaf area index (individual and cohort modes only)
  2121. double lai_indiv_daily;
  2122. /// growth efficiency (NPP/leaf area) for each of the last five simulation years (kgC/m2/yr)
  2123. Historic<double, NYEARGREFF> greff_5;
  2124. /// increment of wood C for each of the last five simulation years (kgC/m2/yr)
  2125. Historic<double, 10> cmass_wood_inc_5;
  2126. /// individual/cohort age (years)
  2127. double age;
  2128. /// monthly LAI (including phenology component)
  2129. double mlai[12];
  2130. /// monthly maximum LAI (including phenology component)
  2131. double mlai_max[12];
  2132. /// FPAR assuming full leaf cover for all vegetation
  2133. double fpar_leafon;
  2134. /// LAI for current layer in canopy (cohort/individual mode; see function fpar)
  2135. double lai_leafon_layer;
  2136. /// non-water-stressed canopy conductance on FPC basis (mm/s)
  2137. double gpterm;
  2138. /// sub-daily version of the above variable (mm/s)
  2139. std::vector<double> gpterms;
  2140. /// interception associated with this individual today (patch basis)
  2141. double intercep;
  2142. /// accumulated mean fraction of potential leaf cover
  2143. double phen_mean;
  2144. /// whether individual subject to water stress
  2145. bool wstress;
  2146. /// leaf nitrogen that is photosyntetic active
  2147. double nactive;
  2148. /// Nitrogen extinction scalar
  2149. /** Scalar to account for leaf nitrogen not following the optimal light
  2150. * extinction, but is shallower.
  2151. */
  2152. double nextin;
  2153. /// long-term storage of labile nitrogen
  2154. double nstore_longterm;
  2155. /// storage of labile nitrogen
  2156. double nstore_labile;
  2157. /// long-term storage of labile nitrogen saved on first day of land use change year
  2158. double nstore_longterm_luc;
  2159. /// storage of labile nitrogen saved on first day of land use change year
  2160. double nstore_labile_luc;
  2161. /// daily total nitrogen demand
  2162. double ndemand;
  2163. /// fraction of individual nitrogen demand available for uptake
  2164. double fnuptake;
  2165. /// annual nitrogen uptake
  2166. double anuptake;
  2167. /// maximum size of nitrogen storage
  2168. double max_n_storage;
  2169. /// scales annual npp to maximum nitrogen storage
  2170. double scale_n_storage;
  2171. /// annual nitrogen limitation on vmax
  2172. double avmaxnlim;
  2173. /// annual optimal leaf C:N ratio
  2174. double cton_leaf_aopt;
  2175. /// annual average leaf C:N ratio
  2176. double cton_leaf_aavr;
  2177. /// plant mobile nitrogen status
  2178. double cton_status;
  2179. /// total carbon in compartments before growth
  2180. double cmass_veg;
  2181. /// total nitrogen in compartments before growth
  2182. double nmass_veg;
  2183. /// whether individual subject to nitrogen stress
  2184. bool nstress;
  2185. /// daily leaf nitrogen demand calculated from Vmax (kgN/m2)
  2186. double leafndemand;
  2187. /// daily root nitrogen demand based on leafndemand
  2188. double rootndemand;
  2189. /// daily sap wood nitrogen demand based on leafndemand
  2190. double sapndemand;
  2191. /// daily labile nitrogen demand based on npp
  2192. double storendemand;
  2193. /// daily harvestable organ nitrogen demand
  2194. double hondemand;
  2195. /// leaf fraction of total nitrogen demand
  2196. double leaffndemand;
  2197. /// root fraction of total nitrogen demand
  2198. double rootfndemand;
  2199. /// sap fraction of total nitrogen demand
  2200. double sapfndemand;
  2201. /// store fraction of total nitrogen demand
  2202. double storefndemand;
  2203. /// daily leaf nitrogen demand over possible uptake (storage demand)
  2204. double leafndemand_store;
  2205. /// daily root nitrogen demand over possible uptake (storage demand)
  2206. double rootndemand_store;
  2207. /// The daily C lossed from leaves due to senescense, only crops.
  2208. double daily_cmass_leafloss;
  2209. /// The daily N lossed from leaves due to senescense, only crops.
  2210. double daily_nmass_leafloss;
  2211. /// The daily C lossed from roots due to senescense, only crops.
  2212. double daily_cmass_rootloss;
  2213. /// The daily N lossed from roots due to senescense, only crops.
  2214. double daily_nmass_rootloss;
  2215. /// Number of days with non-negligible phenology this month
  2216. int nday_leafon;
  2217. // Whether this individual is truly alive.
  2218. /** Set to false for first year after the Individual object is created, then true. */
  2219. bool alive;
  2220. /// NPP this day
  2221. double dnpp;
  2222. // bvoc
  2223. /// isoprene production (mg C m-2 d-1)
  2224. double iso;
  2225. /// monoterpene production (mg C m-2 d-1) per monoteprene species
  2226. double mon[NMTCOMPOUNDS];
  2227. /// monoterpene storage pool (mg C m-2) per monoterpene species
  2228. double monstor[NMTCOMPOUNDS];
  2229. /// isoprene seasonality factor (-)
  2230. double fvocseas;
  2231. // Lambda output
  2232. /// monthly lambda (Ci/Ca)
  2233. double mlambda_gpp[12];
  2234. /// monthly gpp
  2235. double mgpp[12];
  2236. /// Pointer to struct with crop-specific data
  2237. cropindiv_struct *cropindiv;
  2238. // MEMBER FUNCTIONS
  2239. public:
  2240. // Constructor function for objects of class Individual
  2241. // Initialisation of certain member variables
  2242. Individual(int i,Pft& p,Vegetation& v);
  2243. ~Individual();
  2244. /// Access functions for cropindiv:
  2245. cropindiv_struct* get_cropindiv() const;
  2246. cropindiv_struct* set_cropindiv();
  2247. void serialize(ArchiveStream& arch);
  2248. /// Report a flux associated with this Individual
  2249. /** Fluxes from 'new' Individuals (alive == false) will not be reported */
  2250. void report_flux(Fluxes::PerPFTFluxType flux_type, double value);
  2251. /// Report a flux associated with this Individual
  2252. /** Fluxes from 'new' Individuals (alive == false) will not be reported */
  2253. void report_flux(Fluxes::PerPatchFluxType flux_type, double value);
  2254. /// Report a flux associated with this Individual
  2255. /** Fluxes from 'new' Individuals (alive == false) will not be reported */
  2256. void report_flux(Fluxes::DailyPerPatchFluxType flux_type, double value);
  2257. #ifdef CRESCENDO_FACE
  2258. /// Report a flux associated with this Individual
  2259. /** Fluxes from 'new' Individuals (alive == false) will not be reported */
  2260. void report_flux(Fluxes::DailyPerPatchFACEFluxType flux_type, double value);
  2261. #endif
  2262. /// Whether an individual is either a true crop or a cover crop grass
  2263. inline bool istruecrop_or_intercropgrass() const {
  2264. return (pft.landcover==CROPLAND && (pft.phenology==CROPGREEN || cropindiv->isintercropgrass));
  2265. }
  2266. /// Whether harvest and turnover is done on actual C and N on harvest or turnover day, which can occur any day of the year.
  2267. bool has_daily_turnover() const;
  2268. /// Whether resetting of grs_cmass and turnover (if has_daily_turnover() returns true) of continuous grass is to be done this day.
  2269. /** This should occur at the very end of the growing period */
  2270. bool is_turnover_day() const;
  2271. /// Reduce current biomass due to mortality and/or fire
  2272. /** The removed biomass is put into litter pools and/or goes to fire fluxes.
  2273. *
  2274. * \param mortality fraction of Individual's biomass killed due to
  2275. * mortality (including fire)
  2276. * \param mortality_fire fraction of Individual's biomass killed due to
  2277. * fire only
  2278. */
  2279. void reduce_biomass(double mortality, double mortality_fire);
  2280. /// Total storage of nitrogen
  2281. double nstore() const {
  2282. return nstore_longterm + nstore_labile;
  2283. }
  2284. /// Total carbon wood biomass
  2285. double cmass_wood() const {
  2286. return cmass_sap + cmass_heart - cmass_debt;
  2287. }
  2288. /// Total nitrogen wood biomass
  2289. double nmass_wood() const {
  2290. return nmass_sap + nmass_heart;
  2291. }
  2292. /// Total carbon biomass
  2293. double ccont(double scale_indiv = 1.0, bool luc = false) const;
  2294. /// Total nitrogen biomass
  2295. double ncont(double scale_indiv = 1.0, bool luc = false) const;
  2296. /// Leaf carbon biomass
  2297. double cleafcont(double scale_indiv = 1.0, bool luc = false) const;
  2298. /// Leaf nitrogen biomass
  2299. double nleafcont(double scale_indiv = 1.0, bool luc = false) const;
  2300. /// Root carbon biomass
  2301. double crootcont(double scale_indiv = 1.0, bool luc = false) const;
  2302. /// Root nitrogen biomass
  2303. double nrootcont(double scale_indiv = 1.0, bool luc = false) const;
  2304. /// Whether grass growth is uninterrupted by crop growth.
  2305. bool continous_grass() const;
  2306. /// Checks whether any grs_cmass is negative, in which case it is zeroed and fluxes are corrected (only cropland).
  2307. double check_C_mass();
  2308. /// Checks whether any nmass is negative, in which case it is zeroed and fluxes are corrected (only cropland).
  2309. double check_N_mass();
  2310. /// Save cmass-values on first day of the year of land cover change in expanding stands
  2311. void save_cmass_luc();
  2312. /// Save nmass-values on first day of the year of land cover change in expanding stands
  2313. void save_nmass_luc();
  2314. /// Current leaf C:N ratio
  2315. /**
  2316. * \param use_phen Set to false if indiv.phen shouldn't be considered
  2317. * when calculating C:N ratio
  2318. */
  2319. double cton_leaf(bool use_phen = true) const;
  2320. /// Current fine root C:N ratio
  2321. /**
  2322. * \param use_phen Set to false if indiv.phen shouldn't be considered
  2323. * when calculating C:N ratio
  2324. */
  2325. double cton_root(bool use_phen = true) const;
  2326. /// Current sap C:N ratio
  2327. double cton_sap() const;
  2328. /// Gets the individual's Patchpft
  2329. Patchpft& patchpft() const;
  2330. /// Transfers the individual's biomass (C and N) to litter and harvest pools/fluxes
  2331. /**
  2332. * \param harvest Set to true if some of the biomass should be harvested,
  2333. * harvest will be done according to the PFT's harvest efficiency
  2334. * and residue outtake.
  2335. */
  2336. void kill(bool harvest = false);
  2337. /// Annual mean wscal - water stress parameter (0-1 range; 1 = minimum stress)
  2338. /** Value only valid at end of year, after call to canopy_exchange().
  2339. *
  2340. * Currently, all Individuals belonging to a Patchpft share the same water stress.
  2341. */
  2342. double wscal_mean() const;
  2343. /// Gets the individual's daily cmass_leaf value
  2344. double cmass_leaf_today() const;
  2345. /// Gets the individual's daily cmass_root value
  2346. double cmass_root_today() const;
  2347. /// Gets the individual's daily LAI value (patch-level)
  2348. /** Based on total leaf area for whatever the individual represents
  2349. * (individual, cohort, population), over the whole patch.
  2350. */
  2351. double lai_today() const;
  2352. /// Gets the individual's daily LAI value (individual-level)
  2353. /** Based on the leaf area for the average individual and
  2354. * the average individual's crown area.
  2355. */
  2356. double lai_indiv_today() const;
  2357. /// Gets the Nitrogen limited LAI, Eq. 8 Olin 2015
  2358. double lai_nitrogen_today() const;
  2359. /// Gets the individual's daily fpc value
  2360. double fpc_today() const;
  2361. /// Gets the growingseason status for crop individual. Non-crop individuals always return true.
  2362. bool growingseason() const;
  2363. /// The N demand of the storage, only used for PNV.
  2364. double ndemand_storage(double cton_leaf_opt);
  2365. };
  2366. /// The vegetation in a patch - a list of individuals
  2367. /** Functionality for building, maintaining, referencing and destroying a list array of
  2368. * Individual objects. A single Vegetation object is defined for each patch. A
  2369. * reference to the parent Patch object (defined below) is included as a member
  2370. * variable.
  2371. *
  2372. * Functionality is inherited from the ListArray_idin1 template type in the GUTIL
  2373. * Library. Sequential Individual objects can be referenced as array elements by id,
  2374. * or by iteration through the linked list:
  2375. *
  2376. * Vegetation vegetation
  2377. * ...
  2378. * vegetation.firstobj();
  2379. * while (vegetation.isobj) {
  2380. * Individual& thisindiv=vegetation.getobj();
  2381. * // query or modify object thisindiv here
  2382. * vegetation.nextobj();
  2383. * }
  2384. */
  2385. class Vegetation : public ListArray_idin2<Individual,Pft,Vegetation>, public Serializable {
  2386. public:
  2387. // MEMBER VARIABLES
  2388. /// reference to parent Patch object
  2389. Patch& patch;
  2390. // MEMBER FUNCTIONS
  2391. /// constructor (initialises member variable patch)
  2392. Vegetation(Patch& p):patch(p) {};
  2393. void serialize(ArchiveStream& arch);
  2394. };
  2395. /// Soiltype stores static parameters for soils and the snow pack.
  2396. /** One Soiltype object is defined for each Gridcell. State variables for soils
  2397. * are held by objects of class Soil, of which there is one for each patch
  2398. * (see below).
  2399. */
  2400. class Soiltype {
  2401. // MEMBER VARIABLES
  2402. public:
  2403. /// available water holding capacity as fraction of soil volume
  2404. double awc_frac;
  2405. /// available water holding capacity of soil layers [0=upper layer] (mm)
  2406. double awc[NSOILLAYER];
  2407. /// coefficient in percolation calculation (K in Eqn 31, Haxeltine & Prentice 1996)
  2408. double perc_base;
  2409. /// exponent in percolation calculation (=4 in Eqn 31, Haxeltine & Prentice 1996)
  2410. double perc_exp;
  2411. /// thermal diffusivity at 0% WHC (mm2/s)
  2412. double thermdiff_0;
  2413. /// thermal diffusivity at 15% WHC (mm2/s)
  2414. double thermdiff_15;
  2415. /// thermal diffusivity at 100% WHC (mm2/s)
  2416. double thermdiff_100;
  2417. /// wilting point of soil layers [0=upper layer] (mm) Cosby et al 1984
  2418. double wp[NSOILLAYER];
  2419. /// saturation point. Cosby et al 1984
  2420. double wsats[NSOILLAYER];
  2421. /// year at which to calculate equilibrium soil carbon
  2422. int solvesom_end;
  2423. /// year at which to begin documenting means for calculation of equilibrium soil carbon
  2424. int solvesom_begin;
  2425. /// water holding capacity plus wilting point for whole soil volume
  2426. double wtot;
  2427. // For CENTURY ...
  2428. /// fraction of soil that is sand
  2429. double sand_frac;
  2430. /// fraction of soil that is clay
  2431. double clay_frac;
  2432. /// fraction of soil that is silt
  2433. double silt_frac;
  2434. // ecev3
  2435. // New volumetric soil moisture parameters from H-TESSEL/IFS - see Balsamo et al.
  2436. // Units: m3 m-3
  2437. double wilt_point;
  2438. // Wilting point
  2439. double field_cap;
  2440. // Field capacity
  2441. double whcap;
  2442. // Water holding capacity (field_cap - wilt_point)
  2443. // MEMBER FUNCTIONS
  2444. public:
  2445. /// Constructor: initialises certain member variables
  2446. Soiltype() {
  2447. solvesom_end = SOLVESOM_END;
  2448. solvesom_begin = SOLVESOM_BEGIN;
  2449. }
  2450. /// Override the default SOM years with 70-80% of the spin-up period length
  2451. void updateSolveSOMvalues(const int& nyrspinup) {
  2452. solvesom_end = static_cast<int>(0.8 * nyrspinup);
  2453. solvesom_begin = static_cast<int>(0.7 * nyrspinup);
  2454. }
  2455. };
  2456. /// CENTURY SOIL POOL
  2457. class Sompool : public Serializable {
  2458. public:
  2459. /// Constructor
  2460. Sompool() {
  2461. // Initialise pool
  2462. cmass = 0.0;
  2463. nmass = 0.0;
  2464. ligcfrac = 0.0;
  2465. delta_cmass = 0.0;
  2466. delta_nmass = 0.0;
  2467. fracremain = 0.0;
  2468. litterme = 0.0;
  2469. fireresist = 0.0;
  2470. ntoc = 0.0; // ecev3
  2471. cdec = 0.0; // ecev3
  2472. ndec = 0.0; // ecev3
  2473. // ecev3 - extra initialisation
  2474. ntoc = 0.0;
  2475. cdec = 0.0;
  2476. ndec = 0.0;
  2477. for (int m = 0; m < 12; m++) {
  2478. mfracremain_mean[m] = 0.0;
  2479. }
  2480. }
  2481. /// C mass in pool kgC/m2
  2482. double cmass;
  2483. /// Nitrogen mass in pool kgN/m2
  2484. double nmass;
  2485. /// (potential) decrease in C following decomposition today (kgC/m2)
  2486. double cdec;
  2487. /// (potential) decrease in nitrogen following decomposition today (kgN/m2)
  2488. double ndec;
  2489. /// daily change in carbon and nitrogen
  2490. double delta_cmass,delta_nmass;
  2491. /// lignin fractions
  2492. double ligcfrac;
  2493. /// fraction of pool remaining after decomposition
  2494. double fracremain;
  2495. /// nitrogen to carbon ratio
  2496. double ntoc;
  2497. // Fire
  2498. /// soil litter moisture flammability threshold (fraction of AWC)
  2499. double litterme;
  2500. /// soil litter fire resistance (0-1)
  2501. double fireresist;
  2502. // Fast SOM spinup variables
  2503. /// monthly mean fraction of carbon pool remaining after decomposition
  2504. double mfracremain_mean[12];
  2505. void serialize(ArchiveStream& arch);
  2506. };
  2507. /// This struct contains litter for solving Century SOM pools.
  2508. /** \see equilsom() */
  2509. struct LitterSolveSOM {// : public Serializable {
  2510. /// Constructs an empty result
  2511. LitterSolveSOM() {
  2512. clear();
  2513. }
  2514. /// Clears all members
  2515. void clear() {
  2516. for (int p = 0; p < NSOMPOOL; p++) {
  2517. clitter[p] = 0.0;
  2518. nlitter[p] = 0.0;
  2519. }
  2520. }
  2521. /// Add litter
  2522. void add_litter(double cvalue, double nvalue, int pool) {
  2523. clitter[pool] += cvalue;
  2524. nlitter[pool] += nvalue;
  2525. }
  2526. double get_clitter(int pool) {
  2527. return clitter[pool];
  2528. }
  2529. double get_nlitter(int pool) {
  2530. return nlitter[pool];
  2531. }
  2532. //void serialize(ArchiveStream& arch);
  2533. private:
  2534. /// Carbon litter
  2535. double clitter[NSOMPOOL];
  2536. /// Nitrogen litter
  2537. double nlitter[NSOMPOOL];
  2538. };
  2539. /// Soil stores state variables for soils and the snow pack.
  2540. /** Initialised by a call to initdrivers. One Soil object is defined for each patch.
  2541. * A reference to the parent Patch object (defined below) is included as a member
  2542. * variable. Soil static parameters are stored as objects of class Soiltype, of which
  2543. * there is one for each grid cell. A reference to the Soiltype object holding the
  2544. * static parameters for this soil is included as a member variable.
  2545. */
  2546. class Soil : public Serializable {
  2547. // MEMBER VARIABLES
  2548. public:
  2549. /// reference to parent Patch object
  2550. Patch& patch;
  2551. /// reference to Soiltype object holding static parameters for this soil
  2552. Soiltype& soiltype;
  2553. /// water content of soil layers [0=upper layer] as fraction of available water holding capacity;
  2554. double wcont[NSOILLAYER];
  2555. /// DLE - the average wcont over the growing season, for each soil layer
  2556. double awcont[NSOILLAYER];
  2557. /// water content of sublayer of upper soil layer for which evaporation from the bare soil surface is possible
  2558. /** fraction of available water holding capacity */
  2559. double wcont_evap;
  2560. /// daily water content in upper soil layer for each day of year
  2561. double dwcontupper[Date::MAX_YEAR_LENGTH];
  2562. /// mean water content in upper soil layer for last month
  2563. /** (valid only on last day of month following call to daily_accounting_patch) */
  2564. double mwcontupper;
  2565. /// stored snow as average over modelled area (mm rainfall equivalents)
  2566. double snowpack;
  2567. /// total runoff today (mm/day)
  2568. double runoff;
  2569. /// soil temperature today at 0.25 m depth (deg C)
  2570. double temp;
  2571. /// daily temperatures for the last month (deg C)
  2572. /** (valid only on last day of month following call to daily_accounting_patch) */
  2573. double dtemp[31];
  2574. /// mean soil temperature for the last month (deg C)
  2575. /** (valid only on last day of month following call to daily_accounting_patch) */
  2576. double mtemp;
  2577. /// mean top soil temperature for every month (deg K)
  2578. double mtemp_K[12];
  2579. /// Carbon transfer between litter and soil (kg C m-2)
  2580. double litter2soilc;
  2581. /// Nitrogen transfer between litter and soil (kg N m-2)
  2582. double litter2soiln;
  2583. /** respiration response to today's soil temperature at 0.25 m depth
  2584. * incorporating damping of Q10 due to temperature acclimation (Lloyd & Taylor 1994)
  2585. */
  2586. double gtemp;
  2587. /// soil organic matter (SOM) pool with c. 1000 yr turnover (kgC/m2)
  2588. double cpool_slow;
  2589. /// soil organic matter (SOM) pool with c. 33 yr turnover (kgC/m2)
  2590. double cpool_fast;
  2591. // Running sums (converted to long term means) maintained by SOM dynamics module
  2592. /// mean annual litter decomposition (kgC/m2/yr)
  2593. double decomp_litter_mean;
  2594. /// mean value of decay constant for fast SOM fraction
  2595. double k_soilfast_mean;
  2596. /// mean value of decay constant for slow SOM fraction
  2597. double k_soilslow_mean;
  2598. // Parameters used by function soiltemp and updated monthly
  2599. double alag, exp_alag;
  2600. /// water content of soil layers [0=upper layer] as fraction of available water holding capacity
  2601. double mwcont[12][NSOILLAYER];
  2602. /// daily water content in lower soil layer for each day of year
  2603. double dwcontlower[Date::MAX_YEAR_LENGTH];
  2604. double dwcontlower_today; // ecev3 use a daily value to minimize memory issues
  2605. /// mean water content in lower soil layer for last month
  2606. /** (valid only on last day of month following call to daily_accounting_patch) */
  2607. // double mwcontlower; // ecev3 - no longer needed
  2608. /// rainfall and snowmelt today (mm)
  2609. double rain_melt;
  2610. /// upper limit for percolation (mm)
  2611. double max_rain_melt;
  2612. /// whether to percolate today
  2613. bool percolate;
  2614. /// CRESCENDO
  2615. /// Monthly averaged depth of snow layer (m rainfall equivalents)
  2616. double msnd[12];
  2617. // Snow density (kg m-3), value from Ling and Zhang, 2006
  2618. double snowdens;
  2619. /// C4MIP / CRESCENDO
  2620. double mcLitter[12];
  2621. double mcLitterCwd[12];
  2622. double mcLitterSurf[12];
  2623. double mcLitterSubSurf[12];
  2624. double mcLitterAbove[12];
  2625. double mcLitterBelow[12];
  2626. double mcSoil[12];
  2627. double mcMedium[12];
  2628. double mcSlow[12];
  2629. double mnLitter[12];
  2630. double mnLitterCwd[12];
  2631. double mnLitterSurf[12];
  2632. double mnLitterSubSurf[12];
  2633. double mnSoil[12];
  2634. double mnMineralNH4[12];
  2635. double mnMineralNO3[12];
  2636. double dtsl[366][NSOILLAYER];
  2637. double dmrsol[366][NSOILLAYER];
  2638. #ifdef CRESCENDO_FACE
  2639. // CRESCENDO FACE only variables
  2640. // daily carbon Fine Litter above [kg C m-2]
  2641. double dcflita[366];
  2642. // daily nitrogen litter aboveground [kg N m-2]
  2643. double dnlit[366];
  2644. // daily carbon Fine Litter below [kg C m-2]
  2645. double dcflitb[366];
  2646. // daily nitrogen litter belowground [kg N m-2]
  2647. double dnrlit[366];
  2648. // daily carbon Coarse Litter [kg C m-2]
  2649. double dcclitb[366];
  2650. // daily nitrogen dead wood [kg N m-2]
  2651. double dndw[366];
  2652. // daily carbon Soil [kg C m-2]
  2653. double dcsoil[366];
  2654. // daily nitrogen soil total [kg N m-2]
  2655. double dnsoil[366];
  2656. // daily mineral soil nitrogen [kg N m-2]
  2657. double dnmineral[366];
  2658. #endif
  2659. //////////////////////////////////////////////////////////////////////////////////
  2660. // CENTURY SOM pools and other variables
  2661. Sompool sompool[NSOMPOOL];
  2662. /// daily percolation (mm)
  2663. double dperc;
  2664. /// fraction of decayed organic nitrogen leached each day;
  2665. double orgleachfrac;
  2666. /// soil mineral nitrogen pool (kgN/m2)
  2667. double nmass_avail;
  2668. /// soil nitrogen input (kgN/m2)
  2669. double ninput;
  2670. /// annual sum of nitrogen mineralisation
  2671. double anmin;
  2672. /// annual sum of nitrogen immobilisation
  2673. double animmob;
  2674. /// annual leaching from available nitrogen pool
  2675. double aminleach;
  2676. /// annual leaching of organics nitrogen from the active nitrogen pool
  2677. double aorgNleach;
  2678. /// total annual nitrogen fixation
  2679. double anfix;
  2680. /// calculated annual mean nitrogen fixation
  2681. double anfix_calc;
  2682. /// annual leaching of organics carbon from the active carbon pool
  2683. double aorgCleach;
  2684. // Variables for fast spinup of SOM pools
  2685. /// monthly fraction of available mineral nitrogen taken up
  2686. double fnuptake_mean[12];
  2687. /// monthly fraction of organic carbon/nitrogen leached
  2688. double morgleach_mean[12];
  2689. /// monthly fraction of available mineral nitrogen leached
  2690. double mminleach_mean[12];
  2691. /// annual nitrogen fixation
  2692. double anfix_mean;
  2693. // Solving Century SOM pools
  2694. /// years at which to begin documenting for calculation of Century equilibrium
  2695. int solvesomcent_beginyr;
  2696. /// years at which to end documentation and start calculation of Century equilibrium
  2697. int solvesomcent_endyr;
  2698. /// Cumulative litter pools for one year.
  2699. LitterSolveSOM litterSolveSOM;
  2700. std::vector<LitterSolveSOM> solvesom;
  2701. /// stored nitrogen deposition in snowpack
  2702. double snowpack_nmass;
  2703. // MEMBER FUNCTIONS
  2704. public:
  2705. /// constructor (initialises member variable patch)
  2706. Soil(Patch& p,Soiltype& s):patch(p),soiltype(s) {
  2707. initdrivers();
  2708. }
  2709. void initdrivers() {
  2710. // Initialises certain member variables
  2711. alag = 0.0;
  2712. exp_alag = 1.0;
  2713. cpool_slow = 0.0;
  2714. cpool_fast = 0.0;
  2715. decomp_litter_mean = 0.0;
  2716. k_soilfast_mean = 0.0;
  2717. k_soilslow_mean = 0.0;
  2718. wcont[0] = 0.0;
  2719. wcont[1] = 0.0;
  2720. wcont_evap = 0.0;
  2721. snowpack = 0.0;
  2722. orgleachfrac = 0.0;
  2723. snowdens = 362.0;
  2724. mwcontupper = 0.0;
  2725. //mwcontlower = 0.0;
  2726. for (int mth=0; mth<12; mth++) {
  2727. mwcont[mth][0] = 0.0;
  2728. mwcont[mth][1] = 0.0;
  2729. fnuptake_mean[mth] = 0.0;
  2730. morgleach_mean[mth] = 0.0;
  2731. mminleach_mean[mth] = 0.0;
  2732. msnd[mth] = 0.0;
  2733. mcLitter[mth] = 0.0;
  2734. mcLitterCwd[mth] = 0.0;
  2735. mcLitterSurf[mth] = 0.0;
  2736. mcLitterSubSurf[mth] = 0.0;
  2737. mcSoil[mth] = 0.0;
  2738. mcMedium[mth] = 0.0;
  2739. mcSlow[mth] = 0.0;
  2740. mnLitter[mth] = 0.0;
  2741. mnLitterCwd[mth] = 0.0;
  2742. mnLitterSurf[mth] = 0.0;
  2743. mnLitterSubSurf[mth] = 0.0;
  2744. mnSoil[mth] = 0.0;
  2745. mnMineralNH4[mth] = 0.0;
  2746. mnMineralNO3[mth] = 0.0;
  2747. }
  2748. std::fill_n(dwcontupper, Date::MAX_YEAR_LENGTH, 0.0);
  2749. // std::fill_n(dwcontlower, Date::MAX_YEAR_LENGTH, 0.0); // ecev3
  2750. dwcontlower_today = 0.0;
  2751. /////////////////////////////////////////////////////
  2752. // Initialise CENTURY pools
  2753. // Set initial CENTURY pool N:C ratios
  2754. // Parton et al 1993, Fig 4
  2755. sompool[SOILMICRO].ntoc = 1.0 / 15.0;
  2756. sompool[SURFHUMUS].ntoc = 1.0 / 15.0;
  2757. sompool[SLOWSOM].ntoc = 1.0 / 20.0;
  2758. sompool[SURFMICRO].ntoc = 1.0 / 20.0;
  2759. // passive has a fixed value
  2760. sompool[PASSIVESOM].ntoc = 1.0 / 9.0;
  2761. nmass_avail = 0.0;
  2762. ninput = 0.0;
  2763. anmin = 0.0;
  2764. animmob = 0.0;
  2765. aminleach = 0.0;
  2766. aorgNleach = 0.0;
  2767. aorgCleach = 0.0;
  2768. anfix = 0.0;
  2769. anfix_calc = 0.0;
  2770. anfix_mean = 0.0;
  2771. snowpack_nmass = 0.0;
  2772. dperc = 0.0;
  2773. solvesomcent_beginyr = (int)(SOLVESOMCENT_SPINBEGIN * (nyear_spinup - freenyears) + freenyears);
  2774. solvesomcent_endyr = (int)(SOLVESOMCENT_SPINEND * (nyear_spinup - freenyears) + freenyears);
  2775. }
  2776. void serialize(ArchiveStream& arch);
  2777. };
  2778. /// Container for crop-specific data at patchpft level
  2779. struct cropphen_struct : public Serializable {
  2780. /// latest sowing date
  2781. int sdate;
  2782. /// sowing date of growing period ending in latest harvest this year
  2783. int sdate_harv;
  2784. /// sowing dates of growing periods ending in the two latest harvests this year
  2785. int sdate_harvest[2];
  2786. /// sowing dates of growing periods starting this year
  2787. int sdate_thisyear[2];
  2788. /// number of sowings this year
  2789. int nsow;
  2790. /// latest harvest date
  2791. int hdate;
  2792. /// two latest harvest dates this year
  2793. int hdate_harvest[2];
  2794. /// last date for harvest
  2795. int hlimitdate;
  2796. /// last day of heat unit sampling period, set in Crop_sowing_date_new()
  2797. int hucountend;
  2798. /// number of harvests this year
  2799. int nharv;
  2800. /// whether sdate_harvest[0] happened last year
  2801. bool sownlastyear;
  2802. /// latest senescence start date this year
  2803. int sendate;
  2804. /// latest beginning of intercropseason (2 weeks after the harvest date)
  2805. int bicdate;
  2806. /// latest end of intercropseason (2 weeks before the sowing date)
  2807. int eicdate;
  2808. /// number of growing days this growing period
  2809. int growingdays;
  2810. /// number of growing days this year (used for wscal_mean calculation)
  2811. int growingdays_y;
  2812. /// length of growingseason ending in last harvest
  2813. int lgp;
  2814. /// base temp for heat unit calculation (°C)
  2815. double tb;
  2816. /// number of vernalising days required
  2817. int pvd;
  2818. /// number of accumulated vernalizing days
  2819. int vdsum;
  2820. /// heat unit reduction factor due to vernalization [0-1]
  2821. double vrf;
  2822. /// heat unit reduction factor due to photoperiodism [0-1]
  2823. double prf;
  2824. /// potential heat units required for crop maturity (°Cd)
  2825. double phu;
  2826. /// potential heat units that would have been used without dynamic phu calculation
  2827. double phu_old;
  2828. /// heat unit sum aquired during last growing period (°Cd)
  2829. double husum;
  2830. /// heat unit sum aquired durin sampling period, starting with sdate
  2831. double husum_sampled;
  2832. /// this year's heat unit sum aquired from sdate to hucountend
  2833. double husum_max;
  2834. /// running mean of recent past's husum_max
  2835. double husum_max_10;
  2836. /// number of heat units sampling years
  2837. int nyears_hu_sample;
  2838. /// fraction of growing season [0-1] (husum/phu)
  2839. double fphu;
  2840. /// fraction of growing season at latest harvest
  2841. double fphu_harv;
  2842. /// whether in period of heat unit sampling
  2843. bool hu_samplingperiod;
  2844. /// number of heat unit sampling days
  2845. int hu_samplingdays;
  2846. /// harvest index today [0-1, >1 if below-ground ho], harvestable organ/above-ground C for above-ground harvestable organs, dependent on fphu, reduced by water stress
  2847. double hi;
  2848. /// fraction of harvest index today
  2849. double fhi;
  2850. /// phenology (fphu) contribution of fraction of harvest index today
  2851. double fhi_phen; //Phenology (fPHU) compoment of fhi
  2852. /// water stress contribution of fraction of harvest index today
  2853. double fhi_water;
  2854. /// fraction of harvest index at latest harvest
  2855. double fhi_harv;
  2856. /// sum of crop patch demand (patch.wdemand) during crop growing period, reset on harvest day
  2857. double demandsum_crop;
  2858. /// sum of crop supply (patchpft.wsupply) during crop growing period, reset on harvest day
  2859. double supplysum_crop;
  2860. /// whether inside crop/intercrop grass growing period
  2861. bool growingseason;
  2862. /// whether yesterday was inside crop/intercrop grass growing period
  2863. bool growingseason_ystd;
  2864. /// whether inside crop senescence
  2865. bool senescence;
  2866. /// whether yesterday was inside crop senescence
  2867. bool senescence_ystd;
  2868. /// whether inside intercrop crass growing period (main crop pft variable)
  2869. bool intercropseason;
  2870. double vdsum_alloc;
  2871. double vd;
  2872. /// The fraction of the daily assimilates allocated to roots.
  2873. double f_alloc_root;
  2874. /// The fraction of the daily assimilates allocated to leaves.
  2875. double f_alloc_leaf;
  2876. /// The fraction of the daily assimilates allocated to harvestable organs, seeds.
  2877. double f_alloc_horg;
  2878. /// The fraction of the daily assimilates allocated to stem.
  2879. double f_alloc_stem;
  2880. /// Development stage from Wang & Engel 1998
  2881. double dev_stage;
  2882. // A variable holding the memory of whether this field was fertilised or not.
  2883. bool fertilised[3];
  2884. cropphen_struct() {
  2885. sdate=-1;
  2886. sdate_harv=-1;
  2887. nsow=0;
  2888. sownlastyear=false;
  2889. sendate=-1;
  2890. hdate=-1;
  2891. hlimitdate=-1;
  2892. hucountend=-1;
  2893. nharv=0;
  2894. tb=0.0;
  2895. pvd=0;
  2896. vdsum=0;
  2897. vrf=1.0;
  2898. phu=0.0;
  2899. phu_old=0.0;
  2900. husum_max=0.0;
  2901. husum_sampled=0.0;
  2902. husum_max_10=0.0;
  2903. nyears_hu_sample = 0;
  2904. prf=1.0;
  2905. husum=0.0;
  2906. fphu=0.0;
  2907. fphu_harv=0.0;
  2908. hu_samplingdays=0;
  2909. hu_samplingperiod=false;
  2910. hi=0.0;
  2911. fhi=0.0;
  2912. fhi_phen=0.0;
  2913. fhi_water=1.0;
  2914. fhi_harv=0.0;
  2915. demandsum_crop=0.0;
  2916. supplysum_crop=0.0;
  2917. growingseason=false; //Initialized to true for normal grass growth (CC3G & CC4G) in establishment
  2918. growingseason_ystd=false;
  2919. senescence=false;
  2920. senescence_ystd=false;
  2921. intercropseason=false;
  2922. bicdate=-1;
  2923. eicdate=-1;
  2924. growingdays=0;
  2925. growingdays_y=0;
  2926. lgp=0;
  2927. for(int j=0;j<2;j++) {
  2928. sdate_harvest[j]=-1;
  2929. hdate_harvest[j]=-1;
  2930. sdate_thisyear[j]=-1;
  2931. }
  2932. vdsum_alloc=0.0;
  2933. vd = 0.0;
  2934. f_alloc_root=0.0;
  2935. f_alloc_leaf=0.0;
  2936. f_alloc_horg=0.0;
  2937. f_alloc_stem=0.0;
  2938. dev_stage = 0.0;
  2939. fertilised[0] = false;
  2940. fertilised[1] = false;
  2941. fertilised[2] = false;
  2942. }
  2943. void serialize(ArchiveStream& arch);
  2944. };
  2945. /// State variables common to all individuals of a particular PFT in a particular patch
  2946. /** Used in individual and cohort modes only. */
  2947. class Patchpft : public Serializable {
  2948. // MEMBER VARIABLES:
  2949. public:
  2950. /// id code (equal to value of member variable id in corresponding Pft object)
  2951. int id;
  2952. /// reference to corresponding Pft object in PFT list
  2953. Pft& pft;
  2954. /// potential annual net assimilation (leaf-level net photosynthesis) at forest floor (kgC/m2/year)
  2955. double anetps_ff;
  2956. /// water stress parameter (0-1 range; 1=minimum stress)
  2957. double wscal;
  2958. /// running sum (converted to annual mean) for wscal
  2959. double wscal_mean;
  2960. /// potential annual net assimilation at forest floor averaged over establishment interval (kgC/m2/year)
  2961. double anetps_ff_est;
  2962. /// first-year value of anetps_ff_est
  2963. double anetps_ff_est_initial;
  2964. /// annual mean wscal averaged over establishment interval
  2965. double wscal_mean_est;
  2966. /// vegetation phenological state (fraction of potential leaf cover), updated daily
  2967. double phen;
  2968. /// annual sum of daily fractional leaf cover
  2969. /** equivalent number of days with full leaf cover
  2970. * (reset on expected coldest day of year)
  2971. */
  2972. double aphen;
  2973. /// whether PFT can establish in this patch under current conditions
  2974. bool establish;
  2975. /// running total for number of saplings of this PFT to establish (cohort mode)
  2976. double nsapling;
  2977. /// leaf-derived litter for PFT on modelled area basis (kgC/m2)
  2978. double litter_leaf;
  2979. /// fine root-derived litter for PFT on modelled area basis (kgC/m2)
  2980. double litter_root;
  2981. /// remaining sapwood-derived litter for PFT on modelled area basis (kgC/m2)
  2982. double litter_sap;
  2983. /// year's sapwood-derived litter for PFT on modelled area basis (kgC/m2)
  2984. double litter_sap_year;
  2985. /// remaining heartwood-derived litter for PFT on modelled area basis (kgC/m2)
  2986. double litter_heart;
  2987. /// year's heartwood-derived litter for PFT on modelled area basis (kgC/m2)
  2988. double litter_heart_year;
  2989. /// litter derived from allocation to reproduction for PFT on modelled area basis (kgC/m2)
  2990. double litter_repr;
  2991. /// leaf-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  2992. double nmass_litter_leaf;
  2993. /// root-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  2994. double nmass_litter_root;
  2995. /// remaining sapwood-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  2996. double nmass_litter_sap;
  2997. /// year's sapwood-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  2998. double nmass_litter_sap_year;
  2999. /// remaining heartwood-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  3000. double nmass_litter_heart;
  3001. /// year's heartwood-derived nitrogen litter for PFT on modelled area basis (kgN/m2)
  3002. double nmass_litter_heart_year;
  3003. /// non-FPC-weighted canopy conductance value for PFT under water-stress conditions (mm/s)
  3004. double gcbase;
  3005. /// daily value of the above variable (mm/s)
  3006. double gcbase_day;
  3007. /// evapotranspirational "supply" function for this PFT today (mm/day)
  3008. double wsupply;
  3009. double wsupply_leafon;
  3010. /// fractional uptake of water from each soil layer today
  3011. double fwuptake[NSOILLAYER];
  3012. /// whether water-stress conditions for this PFT
  3013. bool wstress;
  3014. /// daily version of the above variable
  3015. bool wstress_day;
  3016. /// carbon depository for long-lived products like wood
  3017. double harvested_products_slow;
  3018. /// nitrogen depository for long-lived products like wood
  3019. double harvested_products_slow_nmass;
  3020. /// first and last day of crop sowing window, calculated in crop_sowing_patch() or Crop_sowing_date_new()
  3021. int swindow[2];
  3022. /// daily value of water deficit, calculated in irrigated_water_uptake()
  3023. double water_deficit_d;
  3024. /// yearly sum of water deficit
  3025. double water_deficit_y;
  3026. /// Struct for crop-specific variables
  3027. cropphen_struct *cropphen;
  3028. // MEMBER FUNCTIONS:
  3029. /// Constructor: initialises id, pft and data members
  3030. Patchpft(int i,Pft& p):id(i),pft(p) {
  3031. litter_leaf = 0.0;
  3032. litter_root = 0.0;
  3033. litter_sap = 0.0;
  3034. litter_sap_year = 0.0;
  3035. litter_heart = 0.0;
  3036. litter_heart_year = 0.0;
  3037. litter_repr = 0.0;
  3038. nmass_litter_leaf = 0.0;
  3039. nmass_litter_root = 0.0;
  3040. nmass_litter_sap = 0.0;
  3041. nmass_litter_sap_year = 0.0;
  3042. nmass_litter_heart = 0.0;
  3043. nmass_litter_heart_year = 0.0;
  3044. wscal = 1.0;
  3045. wscal_mean = 1.0;
  3046. anetps_ff = 0.0;
  3047. aphen = 0.0;
  3048. phen = 0.0;
  3049. wsupply = 0.0;
  3050. wsupply_leafon = 0.0;
  3051. anetps_ff_est = 0.0;
  3052. anetps_ff_est_initial = 0.0;
  3053. wscal_mean_est = 0.0;
  3054. nsapling = 0;
  3055. for(int i=0;i<NSOILLAYER;i++)
  3056. fwuptake[i]=0.0;
  3057. cropphen = NULL;
  3058. harvested_products_slow = 0.0;
  3059. harvested_products_slow_nmass = 0.0;
  3060. swindow[0]=-1;
  3061. swindow[1]=-1;
  3062. if(pft.landcover==CROPLAND)
  3063. {
  3064. cropphen=new cropphen_struct;
  3065. }
  3066. // ecev3 - more initialisation
  3067. phen = 0.0;
  3068. anetps_ff_est = 0.0;
  3069. anetps_ff_est_initial = 0.0;
  3070. wscal_mean_est = 0.0;
  3071. }
  3072. ~Patchpft() {
  3073. if(cropphen) {
  3074. delete cropphen;
  3075. }
  3076. }
  3077. /// safe method to obtain cropphen_struct pointer
  3078. cropphen_struct* get_cropphen();
  3079. /// safe method to set cropphen_struct variables
  3080. cropphen_struct* set_cropphen();
  3081. bool growingseason() const;
  3082. void serialize(ArchiveStream& arch);
  3083. };
  3084. /// Stores data for a patch.
  3085. /** In cohort and individual modes, replicate patches are
  3086. * required in each stand to accomodate stochastic variation; in population mode there
  3087. * should be just one Patch object, representing average conditions for the entire
  3088. * stand. A reference to the parent Stand object (defined below) is included as a
  3089. * member variable.
  3090. */
  3091. class Patch : public Serializable {
  3092. public:
  3093. // MEMBER VARIABLES
  3094. /// id code in range 0-npatch for patch
  3095. int id;
  3096. /// reference to parent Stand object
  3097. Stand& stand;
  3098. /// list array [0...npft-1] of Patchpft objects (initialised in constructor)
  3099. ListArray_idin1<Patchpft,Pft> pft;
  3100. /// vegetation for this patch
  3101. Vegetation vegetation;
  3102. /// soil for this patch
  3103. Soil soil;
  3104. /// fluxes for this patch
  3105. Fluxes fluxes;
  3106. /// FPAR at top of grass canopy today
  3107. double fpar_grass;
  3108. /// FPAR at soil surface today
  3109. double fpar_ff;
  3110. /// mean growing season PAR at top of grass canopy (J/m2/day)
  3111. double par_grass_mean;
  3112. /// number of days in growing season, estimated from mean vegetation leaf-on fraction
  3113. /** \see function fpar in canopy exchange module */
  3114. int nday_growingseason;
  3115. /// total patch FPC
  3116. double fpc_total;
  3117. /// whether patch was disturbed last year
  3118. bool disturbed;
  3119. /// patch age (years since last disturbance)
  3120. int age;
  3121. /// probability of fire this year
  3122. double fireprob;
  3123. /// whether management has started on this patch
  3124. bool managed;
  3125. /// cutting intensity (initial percent of trees cut, further selection at individual level has to be done in a separate function)
  3126. double man_strength;
  3127. bool managed_this_year;
  3128. bool plant_this_year;
  3129. /// DLE - the number of days over which wcont is averaged for this patch
  3130. /** i.e. those days for which daily temp > 5.0 degC */
  3131. int growingseasondays;
  3132. // Variables used by new hydrology (Dieter Gerten 2002-07)
  3133. /// interception by vegetation today on patch basis (mm)
  3134. double intercep;
  3135. /// annual sum of AET (mm/year)
  3136. double aaet;
  3137. /// annual sum of AET (mm/year) for each of the last five simulation years
  3138. Historic<double, NYEARAAET> aaet_5;
  3139. /// annual sum of soil evaporation (mm/year)
  3140. double aevap;
  3141. /// annual sum of interception (mm/year)
  3142. double aintercep;
  3143. /// annual sum of runoff (mm/year)
  3144. double asurfrunoff;
  3145. /// annual sum of runoff (mm/year)
  3146. double adrainrunoff;
  3147. /// annual sum of runoff (mm/year)
  3148. double abaserunoff;
  3149. /// annual sum of runoff (mm/year)
  3150. double arunoff;
  3151. /// annual sum of potential evapotranspiration (mm/year)
  3152. double apet;
  3153. /// equilibrium evapotranspiration today, deducting interception (mm)
  3154. double eet_net_veg;
  3155. /// transpirative demand for patch, patch vegetative area basis (mm/day)
  3156. double wdemand;
  3157. /// daily average of the above variable (mm/day)
  3158. double wdemand_day;
  3159. /// transpirative demand for patch assuming full leaf cover today
  3160. /** mm/day, patch vegetative area basis */
  3161. double wdemand_leafon;
  3162. /// rescaling factor to account for spatial overlap between individuals/cohorts populations
  3163. double fpc_rescale;
  3164. /// monthly AET (mm/month)
  3165. double maet[12];
  3166. /// monthly soil evaporation (mm/month)
  3167. double mevap[12];
  3168. /// monthly interception (mm/month)
  3169. double mintercep[12];
  3170. /// monthly runoff (mm/month)
  3171. double mrunoff[12];
  3172. /// monthly surface runoff (mm/month)
  3173. double mrunoff_surf[12];
  3174. /// monthly PET (mm/month)
  3175. double mpet[12];
  3176. /// daily nitrogen demand
  3177. double ndemand;
  3178. /// annual nitrogen fertilization (kgN/m2/year)
  3179. double anfert;
  3180. /// daily nitrogen fertilization (kgN/m2/day)
  3181. double dnfert;
  3182. /// daily value of irrigation water (mm), set in irrigation(), derived from water_deficit_d
  3183. double irrigation_d;
  3184. /// monthly sum of irrigation water (mm)
  3185. double irrigation_m[12];
  3186. /// yearly sum of irrigation water (mm)
  3187. double irrigation_y;
  3188. /// whether litter is to be sent to the soil today
  3189. bool is_litter_day;
  3190. /// number of harvests and/or cover-crop killing or turnover events
  3191. int nharv;
  3192. /// whether today is a harvest day and/or cover-crop killing or turnover day
  3193. bool isharvestday;
  3194. // C4MIP / CRESCENDO
  3195. /// monthly vegetation carbon (kg C m-2)
  3196. double mcVeg[12];
  3197. /// monthly vegetation nitrogen (kg N m-2)
  3198. double mnVeg[12];
  3199. /// monthly leaf carbon (kg C m-2)
  3200. double mcLeaf[12];
  3201. /// monthly leaf nitrogen (kg N m-2)
  3202. double mnLeaf[12];
  3203. /// monthly root carbon (kg C m-2)
  3204. double mcRoot[12];
  3205. /// monthly root nitrogen (kg N m-2)
  3206. double mnRoot[12];
  3207. /// monthly stem carbon (kg C m-2)
  3208. double mcStem[12];
  3209. /// monthly stem nitrogen (kg N m-2)
  3210. double mnStem[12];
  3211. /// monthly other plant parts carbon (kg C m-2)
  3212. double mcOther[12];
  3213. /// monthly other plant parts carbon (Phen) (kg C m-2)
  3214. double mcOtherPhen[12];
  3215. /// monthly other plant parts nitrogen (kg N m-2)
  3216. double mnOther[12];
  3217. /// monthly product carbon (kg C m-2)
  3218. double mcProduct[12];
  3219. /// monthly product nitrogen (kg N m-2)
  3220. double mnProduct[12];
  3221. /// monthly total land carbon (kg C m-2)
  3222. double mcLand[12];
  3223. /// monthly total land nitrogen (kg N m-2)
  3224. double mnLand[12];
  3225. /// daily total LAI (m2 m-2)
  3226. double dlai[366];
  3227. /// daily PET (mm day-1)
  3228. double dpet[366];
  3229. /// daily AET (mm day-1)
  3230. double daet[366];
  3231. /// daily soil evaporation (mm day-1)
  3232. double devap[366];
  3233. /// daily interception by vegetation (mm day-1)
  3234. double dintercep[366];
  3235. /// daily runoff (mm day-1)
  3236. double dmrro[366];
  3237. /// LUMIP deforest_glob: Whether for this patch a deforestation is active
  3238. bool deforest_active;
  3239. #ifdef CRESCENDO_FACE
  3240. /// CRESCENDO FACE only variables
  3241. /// daily runoff (mm day-1)
  3242. double drunoff[366];
  3243. /// daily drainage (mm day-1)
  3244. double ddrain[366];
  3245. /// daily leaf carbon (kg C m-2)
  3246. double dcLeaf[366];
  3247. /// daily leaf nitrogen (kg N m-2)
  3248. double dnLeaf[366];
  3249. /// daily root carbon (kg C m-2)
  3250. double dcRoot[366];
  3251. /// daily root nitrogen (kg N m-2)
  3252. double dnRoot[366];
  3253. /// daily stem carbon (kg C m-2)
  3254. double dcStem[366];
  3255. /// daily stem nitrogen (kg N m-2)
  3256. double dnStem[366];
  3257. /// daily other plant parts carbon (kg C m-2)
  3258. double dcOther[366];
  3259. /// daily other plant parts nitrogen (kg N m-2)
  3260. double dnOther[366];
  3261. /// Leaf carbon growth (kg C m-2)
  3262. double gl;
  3263. /// Wood carbon growth
  3264. double gw;
  3265. /// Root carbon growth
  3266. double gr;
  3267. #endif
  3268. // MEMBER FUNCTIONS
  3269. /// Constructor: initialises various members and builds list array of Patchpft objects.
  3270. Patch(int i,Stand& s,Soiltype& st);
  3271. void serialize(ArchiveStream& arch);
  3272. /// Returns the Climate for this Patch
  3273. /** This function returns a const reference to prevent code which operates
  3274. * on a patch basis to modify the climate and thereby affect other
  3275. * patches/stands.
  3276. */
  3277. const Climate& get_climate() const;
  3278. /// Returns whether we should model fire in this patch
  3279. bool has_fires() const;
  3280. /// Returns whether we should model disturbances in this patch
  3281. bool has_disturbances() const;
  3282. /// Total patch carbon biomass and litter
  3283. double ccont(double scale_indiv = 1.0, bool luc = false);
  3284. /// Total patch nitrogen biomass and litter
  3285. double ncont(double scale_indiv = 1.0, bool luc = false);
  3286. /// Total patch carbon fluxes so far this year
  3287. double cflux();
  3288. /// Total patch nitrogen fluxes so far this year
  3289. double nflux();
  3290. /// Get 5-year mean of wood C mass increase (periodic annual increment)
  3291. double get_cmass_wood_inc_5() {
  3292. double cmass_wood_inc_5_mean = 0.0;
  3293. for (unsigned int i=0; i<vegetation.nobj; i++) {
  3294. // Disregard shrubs (crownarea_max = 10)
  3295. Individual& indiv = vegetation[i];
  3296. if(indiv.pft.lifeform == TREE && indiv.pft.crownarea_max > 10) {
  3297. if(indiv.cmass_wood_inc_5.size())
  3298. cmass_wood_inc_5_mean += indiv.cmass_wood_inc_5.mean();
  3299. }
  3300. }
  3301. return cmass_wood_inc_5_mean;
  3302. }
  3303. /// Get cmass_wood of all individuals in patch
  3304. double cmass_wood() {
  3305. double cmass_wood = 0.0;
  3306. for (unsigned int i=0; i<vegetation.nobj; i++) {
  3307. Individual& indiv = vegetation[i];
  3308. cmass_wood += indiv.cmass_wood();
  3309. }
  3310. return cmass_wood;
  3311. }
  3312. };
  3313. /// Container for variables common to individuals of a particular PFT in a stand.
  3314. /** Used in individual and cohort modes only
  3315. */
  3316. class Standpft : public Serializable {
  3317. public:
  3318. // MEMBER VARIABLES
  3319. int id;
  3320. Pft& pft;
  3321. /// net C allocated to reproduction for this PFT in all patches of this stand this year (kgC/m2)
  3322. double cmass_repr;
  3323. /// maximum value of Patchpft::anetps_ff for this PFT in this stand so far in the simulation (kgC/m2/year)
  3324. double anetps_ff_max;
  3325. /// FPC sum for this PFT as average for stand
  3326. double fpc_total;
  3327. /// Photosynthesis values for this PFT under non-water-stress conditions
  3328. PhotosynthesisResult photosynthesis;
  3329. /// Whether this PFT is allowed to grow in this stand
  3330. bool active;
  3331. /// Whether this PFT is planted in this stand
  3332. bool plant;
  3333. /// Whether this PFT is allowed to establish (after planting) in this stand
  3334. bool reestab;
  3335. /// Whether this PFT is irrigated in this stand
  3336. bool irrigated;
  3337. /// sowing date specified in stand type or read from input file
  3338. int sdate_force;
  3339. /// harvest date specified in stand type or read from input file
  3340. int hdate_force;
  3341. // MEMBER FUNCTIONS
  3342. /// Constructor: initialises various data members
  3343. Standpft(int i,Pft& p):id(i),pft(p) {
  3344. anetps_ff_max = 0.0;
  3345. active = !run_landcover;
  3346. plant = false;
  3347. reestab = false;
  3348. irrigated = false;
  3349. sdate_force = -1;
  3350. hdate_force = -1;
  3351. }
  3352. void serialize(ArchiveStream& arch);
  3353. };
  3354. /// The stand class corresponds to a modelled area of a specific landcover type in a grid cell.
  3355. /** There may be several stands of the same landcover type (but with different settings).
  3356. */
  3357. class Stand : public ListArray_idin2<Patch,Stand,Soiltype>, public Serializable {
  3358. public:
  3359. // MEMBER VARIABLES
  3360. /// list array [0...npft-1] of Standpft (initialised in constructor)
  3361. ListArray_idin1<Standpft,Pft> pft;
  3362. /// A number identifying this Stand within the grid cell
  3363. int id;
  3364. /// stand type id
  3365. int stid;
  3366. /// pft id of main crop, updated during rotation
  3367. int pftid;
  3368. /// current crop rotation item
  3369. int current_rot;
  3370. /// number of days passed in current rotation item
  3371. int ndays_inrotation;
  3372. /// Returns true if stand is in fallow (with cover crop grass)
  3373. bool infallow;
  3374. /// Returns true if crop rotation item is to be updated today
  3375. bool isrotationday;
  3376. /// Returns true if current crop management hydrology == irrigated, updated during rotation
  3377. bool isirrigated;
  3378. /// Returns true if the stand's main crop pft intercrop==naturalgrass and a pft with isintercrop==true is in the pftlist.
  3379. bool hasgrassintercrop;
  3380. /// gdd5-value at first intercrop grass growth
  3381. double gdd0_intercrop;
  3382. /// old fraction of this stand relative to the gridcell before update
  3383. double frac_old;
  3384. /// used during land cover change involving several calls to reveiving_stand_change()
  3385. /** Set to frac_old in reduce_stands(), then modified in donor_stand_change() and receiving_stand_change().
  3386. */
  3387. double frac_temp;
  3388. /// fraction unavailable for transfer to other stand types
  3389. double protected_frac;
  3390. /// net stand fraction change
  3391. double frac_change;
  3392. /// gross fraction increase
  3393. double gross_frac_increase;
  3394. /// gross fraction decrease
  3395. double gross_frac_decrease;
  3396. /// fraction that has been cloned from another stand
  3397. double cloned_fraction;
  3398. /// Returns true if this stand is cloned from another stand
  3399. bool cloned;
  3400. /// pointer to array of fractions transferred from this stand to other stand types
  3401. double *transfer_area_st;
  3402. /// land cover origin of this stand
  3403. landcovertype origin;
  3404. /// used for output from separate stands
  3405. double anpp;
  3406. /// used for output from separate stands
  3407. double cmass;
  3408. /// Seed for generating random numbers within this Stand
  3409. /** The reason why Stand has its own seed, rather than using for instance
  3410. * a single global seed is to make it easier to compare results when using
  3411. * different land cover types.
  3412. *
  3413. * Randomness not associated with a specific stand, but rather a whole
  3414. * grid cell should instead use the seed in the Gridcell class.
  3415. *
  3416. * \see randfrac()
  3417. */
  3418. long seed;
  3419. /// type of landcover
  3420. /** \see landcovertype
  3421. * initialised in constructor
  3422. */
  3423. landcovertype landcover;
  3424. /// The year when this stand was created.
  3425. /** Will typically be year zero unless running with dynamic
  3426. * land cover.
  3427. *
  3428. * Needed to set patchpft.anetps_ff_est_initial
  3429. */
  3430. int first_year;
  3431. // The year this stand was cloned from another stand
  3432. int clone_year;
  3433. /// scaling factor for stands that have grown in area this year (old fraction/new fraction)
  3434. double scale_LC_change;
  3435. // ecev3 - NEW MEMBER VARIABLES
  3436. /// Integer type identifying the IFS high vegetation type (0-20). 0 for low vegetation
  3437. //int typehigh;
  3438. /// Fraction of the gridcell covered by the dominant vegetation type
  3439. //double frachigh;
  3440. /// grass LAI on stand basis
  3441. //float laiphen_grass[366];
  3442. /// total LAI on stand basis
  3443. //float laiphen_total[366];
  3444. /// total daily natural cflux on stand basis (kg C m-2)
  3445. float dcfluxnat_today;
  3446. /// total daily anthropogenic cflux on stand basis (kg C m-2)
  3447. float dcfluxant_today;
  3448. /// total daily NPP on stand basis (kg C m-2)
  3449. float dnpp_today;
  3450. /// Sum of natural fluxes. Updated on Dec 31
  3451. double previousyearsCfluxNat; // was previousyearsCflux
  3452. /// Sum of anthropogenic fluxes. Updated on Dec 31
  3453. float previousyearsCfluxAnt; // was previousyearsCfireflux, now a float since it took the place of dnpp_today
  3454. /// Total land C pool on 1st of Jan
  3455. double cLand;
  3456. /// Total land C flux during the year
  3457. double cFlux;
  3458. // MEMBER FUNCTIONS
  3459. /// Constructs a Stand
  3460. /** \param i The id for the stand within the grid cell
  3461. * \param gc The parent grid cell
  3462. * \param st The soil type to be used within this Stand
  3463. * \param landcover The type of landcover to use for this stand
  3464. */
  3465. Stand(int i, Gridcell* gc, Soiltype& st, landcovertype landcover, int no_patch = 0);
  3466. ~Stand();
  3467. /// Gives the fraction of this Stand relative to the whole grid cell
  3468. double get_gridcell_fraction() const;
  3469. /// Gives the fraction of this Stand relative to its land cover type; NB: unsafe to use within landcover_dynamics() !
  3470. double get_landcover_fraction() const;
  3471. /// Set the fraction of this Stand relative to the gridcell
  3472. void set_gridcell_fraction(double fraction);
  3473. /// Returns the number of patches in this Stand
  3474. unsigned int npatch() const { return nobj; }
  3475. /// Returns true if stand is true crop stand, as opposed to pasture grass grown on cropland or other land cover
  3476. inline bool is_true_crop_stand() {
  3477. return landcover==CROPLAND && pft[pftid].pft.phenology==CROPGREEN; // OK also for fallow (pftid always cropgreen)
  3478. }
  3479. /// Moves crop rotation forward
  3480. void rotate();
  3481. /// Returns area transferred to other land cover during land cover change
  3482. double transfer_area_lc(landcovertype to);
  3483. /// Initiates new stand land cover settings
  3484. void init_stand_lu(StandType& st, double fraction);
  3485. /// Total stand carbon biomass and litter
  3486. double ccont(double scale_indiv = 1.0);
  3487. /// Total stand nitrogen biomass and litter
  3488. double ncont(double scale_indiv = 1.0);
  3489. /// Total stand carbon fluxes so far this year
  3490. double cflux();
  3491. /// Total stand nitrogen fluxes so far this year
  3492. double nflux();
  3493. /// Creates a duplicate stand with a new landcovertype
  3494. /** The new stand is added to this stand's gridcell.
  3495. *
  3496. * \returns reference to the new stand
  3497. */
  3498. Stand& clone(StandType& st, double fraction);
  3499. void serialize(ArchiveStream& arch);
  3500. /// Returns the Climate for this Stand
  3501. /** This function returns a const reference to prevent code which operates
  3502. * on a stand basis to modify the climate and thereby affect other
  3503. * stands.
  3504. */
  3505. const Climate& get_climate() const;
  3506. /// Returns the Gridcell containing this Stand
  3507. Gridcell& get_gridcell() const;
  3508. private:
  3509. /// Pointer to parent object, could be a null pointer
  3510. /** Prefer to access the gridcell through get_gridcell(), even internally
  3511. * within the Stand class.
  3512. */
  3513. Gridcell* gridcell;
  3514. /// Soil type to be used in this Stand
  3515. Soiltype& soiltype;
  3516. /// Fraction of this stand relative to the gridcell
  3517. /** used by crop stands; initialized in constructor to 1,
  3518. * set in landcover_init()
  3519. */
  3520. double frac;
  3521. };
  3522. /// State variables common to all individuals of a particular PFT in a GRIDCELL.
  3523. class Gridcellpft : public Serializable {
  3524. public:
  3525. // MEMBER VARIABLES
  3526. /// A number identifying this object within its list array
  3527. int id;
  3528. /// A reference to the Pft object for this Gridcellpft
  3529. Pft& pft;
  3530. /// annual degree day sum above threshold damaging temperature
  3531. /** used in calculation of heat stess mortality; Sitch et al 2000, Eqn 55
  3532. */
  3533. double addtw;
  3534. /// Michaelis-Menten kinetic parameters
  3535. /** Half saturation concentration for N uptake (Rothstein 2000, Macduff 2002)
  3536. */
  3537. double Km;
  3538. ///Crop-specific variables:
  3539. /// whether the daily temperature has fallen below the autumn temperature limit (tempautumn) this year
  3540. bool autumnoccurred;
  3541. /// whether the daily temperature has risen above the spring temperature limit (tempspring) this year
  3542. bool springoccurred;
  3543. /// whether the daily temperature has fallen below the vernalization limit (trg) this year
  3544. bool vernstartoccurred;
  3545. /// whether the daily temperature rises over the vernalization limit (trg) this year
  3546. bool vernendoccurred;
  3547. /// first day when temperature fell below the autumn temperature limit (tempautumn) this year
  3548. int first_autumndate;
  3549. /// 20-year mean
  3550. int first_autumndate20;
  3551. /// memory of the last 20 years' values
  3552. int first_autumndate_20[20];
  3553. /// last day when temperature rose above the spring temperature limit (tempspring) this year
  3554. int last_springdate;
  3555. /// 20-year mean
  3556. int last_springdate20;
  3557. /// memory of the last 20 years' values
  3558. int last_springdate_20[20];
  3559. /// last day when temperature has fallen below the vernilisation temperature limit (trg) this year (if vernstartoccurred==true)
  3560. int last_verndate;
  3561. /// 20-year mean
  3562. int last_verndate20;
  3563. /// memory of the last 20 years' values
  3564. int last_verndate_20[20];
  3565. /// default sowing date (pft.sdatenh/sdatesh)
  3566. int sdate_default;
  3567. /// calculated sowing date from temperature limits
  3568. int sdatecalc_temp;
  3569. /// calculated sowing date from precipitation limits
  3570. int sdatecalc_prec;
  3571. /// sowing date from input file
  3572. int sdate_force;
  3573. /// harvest date from input file
  3574. int hdate_force;
  3575. /// N fertilization from input file
  3576. double Nfert_read;
  3577. /// default harvest date (pft.hlimitdatenh/hlimitdatesh)
  3578. int hlimitdate_default;
  3579. /// whether autumn sowing is either calculated or prescribed
  3580. bool wintertype;
  3581. /// first and last day of crop sowing window, calculated in calc_sowing_windows()
  3582. int swindow[2];
  3583. /// first and last day of crop sowing window for irrigated crops, calculated in calc_sowing_windows()
  3584. int swindow_irr[2];
  3585. /// temperature limits precludes crop sowing
  3586. bool sowing_restriction;
  3587. // MEMBER FUNCTIONS
  3588. /// Constructs a Gridcellpft object
  3589. /** \param i The id for this object
  3590. * \param p A reference to the Pft for this Gridcellpft
  3591. */
  3592. Gridcellpft(int i,Pft& p):id(i),pft(p) {
  3593. addtw = 0.0;
  3594. Km = 0.0;
  3595. autumnoccurred=false;
  3596. springoccurred=false;
  3597. vernstartoccurred=false;
  3598. vernendoccurred=false;
  3599. first_autumndate=-1;
  3600. first_autumndate20=-1;
  3601. last_springdate=-1;
  3602. last_springdate20=-1;
  3603. last_verndate=-1;
  3604. last_verndate20=-1;
  3605. for (int year=0;year<20;year++) {
  3606. first_autumndate_20[year]=-1;
  3607. last_springdate_20[year]=-1;
  3608. last_verndate_20[year]=-1;
  3609. }
  3610. sdate_default=-1;
  3611. sdate_force=-1;
  3612. hdate_force=-1;
  3613. Nfert_read=-1;
  3614. sdatecalc_temp=-1;
  3615. sdatecalc_prec=-1;
  3616. hlimitdate_default=-1;
  3617. wintertype=false;
  3618. swindow[0]=-1;
  3619. swindow[1]=-1;
  3620. sowing_restriction = false;
  3621. }
  3622. void serialize(ArchiveStream& arch);
  3623. };
  3624. /// State variables common to all individuals of a particular STANDTYPE in a GRIDCELL.
  3625. class Gridcellst : public Serializable {
  3626. public:
  3627. // MEMBER VARIABLES
  3628. /// A number identifying this object within its list array
  3629. int id;
  3630. /// A reference to the StandType object for this Gridcellst
  3631. StandType& st;
  3632. /// fraction of this stand type relative to the gridcell
  3633. double frac;
  3634. /// old fraction of this stand type relative to the gridcell before update
  3635. double frac_old;
  3636. /// original input value of old fraction of this stand type before rescaling
  3637. double frac_old_orig;
  3638. /// fraction unavailable for transfer to other stand types
  3639. double protected_frac;
  3640. /// net fraction change
  3641. double frac_change;
  3642. /// gross fraction increase
  3643. double gross_frac_increase;
  3644. /// gross fraction decrease
  3645. double gross_frac_decrease;
  3646. // current number of stands of this stand type
  3647. int nstands;
  3648. /// Nitrogen fertilisation amount
  3649. double nfert;
  3650. /// Harvested forest area fraction
  3651. double woodharv_frac;
  3652. /// Wood harvest volume
  3653. double woodharv_vol;
  3654. // MEMBER FUNCTIONS
  3655. /// Constructs a Gridcellst object
  3656. /** \param i The id for this object
  3657. * \param s A reference to the StandType for this Gridcellst
  3658. */
  3659. Gridcellst(int i,StandType& s):id(i),st(s) {
  3660. frac = 1.0;
  3661. frac_old = 0.0;
  3662. frac_old_orig = 0.0;
  3663. protected_frac = 0.0;
  3664. frac_change = 0.0;
  3665. gross_frac_increase = 0.0;
  3666. gross_frac_decrease = 0.0;
  3667. nstands = 0;
  3668. nfert = -1.0;
  3669. woodharv_frac = -1.0;
  3670. woodharv_vol = -1.0;
  3671. }
  3672. void serialize(ArchiveStream& arch);
  3673. };
  3674. struct forest_lc_frac_transfer {
  3675. double primary[NLANDCOVERTYPES][NLANDCOVERTYPES];
  3676. double secondary_young[NLANDCOVERTYPES][NLANDCOVERTYPES];
  3677. forest_lc_frac_transfer() {
  3678. for(int i=0;i<NLANDCOVERTYPES;i++) {
  3679. for(int j=0;j<NLANDCOVERTYPES;j++) {
  3680. primary[i][j] = 0.0;
  3681. secondary_young[i][j] = 0.0;
  3682. }
  3683. }
  3684. };
  3685. };
  3686. struct forest_st_frac_transfer {
  3687. double* primary;
  3688. double* secondary_young;
  3689. forest_st_frac_transfer(int nst) {
  3690. primary = new double[nst * nst];
  3691. secondary_young = new double[nst * nst];
  3692. for(int i=0;i<nst*nst;i++) {
  3693. primary[i] = 0.0;
  3694. secondary_young[i] = 0.0;
  3695. }
  3696. };
  3697. ~forest_st_frac_transfer(){
  3698. if(primary)
  3699. delete[] primary;
  3700. if(secondary_young)
  3701. delete[] secondary_young;
  3702. }
  3703. };
  3704. /// Storage of land cover fraction data and some land cover change-related pools and fluxes
  3705. struct Landcover : public Serializable {
  3706. Landcover();
  3707. /// The fractions of the different land cover types.
  3708. /** landcoverfrac is read in from land cover input file or from
  3709. * instruction file in getlandcover().
  3710. */
  3711. double frac[NLANDCOVERTYPES];
  3712. /// The land cover fractions from the previous year
  3713. /** Used to keep track of the changes when running with dynamic
  3714. * land cover.
  3715. */
  3716. double frac_old[NLANDCOVERTYPES];
  3717. double frac_change[NLANDCOVERTYPES];
  3718. /// Wood harvest information read from input file.
  3719. Wood_harvest_struct wood_harvest;
  3720. /// Transfer matrices
  3721. double frac_transfer[NLANDCOVERTYPES][NLANDCOVERTYPES];
  3722. forest_lc_frac_transfer forest_lc_frac_transfer_s;
  3723. /// Whether the land cover fractions changed for this grid cell this year
  3724. /** \see landcover_dynamics
  3725. */
  3726. bool updated;
  3727. /// ecev3 - Gridcell-level C flux from slow harvested products TODAY
  3728. double dcflux_harvest_slow;
  3729. /// Gridcell-level C flux from harvest associated with landcover change TODAY
  3730. double dcflux_landuse_change;
  3731. /// Gridcell-level C flux from slow harvested products
  3732. double acflux_harvest_slow;
  3733. /// Gridcell-level C products from harvest associated with landcover change
  3734. double harvest_product;
  3735. /// Gridcell-level N products from harvest associated with landcover change
  3736. double harvest_product_nmass;
  3737. /// Gridcell-level C residue input to litter from harvest associated with landcover change
  3738. double acflux_harvest_wood_res;
  3739. /// Gridcell-level C flux from harvest associated with landcover change
  3740. double acflux_landuse_change;
  3741. /// Gridcell-level N flux from slow harvested products
  3742. double anflux_harvest_slow;
  3743. /// Gridcell-level N flux from harvest associated with landcover change
  3744. double anflux_landuse_change;
  3745. /// Landcover-level C flux from slow harvested products (donating landcover)
  3746. double acflux_harvest_slow_lc[NLANDCOVERTYPES];
  3747. /// Landcover-level C products from harvest associated with landcover change
  3748. double harvest_product_lc[NLANDCOVERTYPES];
  3749. /// Landcover-level N products from harvest associated with landcover change
  3750. double harvest_product_nmass_lc[NLANDCOVERTYPES];
  3751. /// Landcover-level C residue input to litter from harvest associated with landcover change (donating landcover)
  3752. double acflux_harvest_wood_res_lc[NLANDCOVERTYPES];
  3753. /// Landcover-level C flux from harvest associated with landcover change (donating landcover)
  3754. double acflux_landuse_change_lc[NLANDCOVERTYPES];
  3755. /// Landcover-level N flux from slow harvested products (donating landcover)
  3756. double anflux_harvest_slow_lc[NLANDCOVERTYPES];
  3757. /// Landcover-level N flux from harvest associated with landcover change (donating landcover)
  3758. double anflux_landuse_change_lc[NLANDCOVERTYPES];
  3759. /// Which landcover types create new stands when area increases.
  3760. bool expand_to_new_stand[NLANDCOVERTYPES];
  3761. /// Whether to pool all transferred land from a donor landcover (overrides different landcover targets of different stand types and stands in a landcover)
  3762. bool pool_to_all_landcovers[NLANDCOVERTYPES];
  3763. /// Whether to pool transferred land to a receptor landcover (crop and pasture stands to new natural stand: pool!)
  3764. bool pool_from_all_landcovers[NLANDCOVERTYPES];
  3765. void serialize(ArchiveStream& arch);
  3766. };
  3767. /// The Gridcell class corresponds to a modelled locality or grid cell.
  3768. /** Member variables include an object of type Climate (holding climate, insolation and
  3769. * CO2 data), a object of type Soiltype (holding soil static parameters) and a list
  3770. * array of Stand objects. Soil objects (holding soil state variables) are associated
  3771. * with patches, not gridcells. A separate Gridcell object must be declared for each modelled
  3772. * locality or grid cell.
  3773. */
  3774. class Gridcell : public GuessContainer<Stand>, public Serializable {
  3775. public:
  3776. // MEMBER VARIABLES
  3777. /// climate, insolation and CO2 for this grid cell
  3778. Climate climate;
  3779. /// soil static parameters for this grid cell
  3780. Soiltype soiltype;
  3781. /// landcover fractions and landcover-specific variables
  3782. Landcover landcover;
  3783. /// Total gridcell C mass on first day of each month including accumulated NPP [kg C m-2]
  3784. double mcLand1[12];
  3785. /// Total gridcell C mass on Jan 1 including yearly fluxes happening on Dec 31 previous year [kg C m-2]
  3786. double cLand;
  3787. /// Total gridcell C flux (including organic C leaching) over current year but with previous years Dec 31 yearly fluxes [kg C m-2]
  3788. double cFlux;
  3789. /// Previous years Dec 31 yearly natural fluxes [kg C m-2]
  3790. double previousyearsCfluxNat; // was previousyearsCflux
  3791. /// Previous years Dec 31 yearly anthropogenic fluxes [kg C m-2]
  3792. double previousyearsCfluxAnt; // was previousyearsCfireflux
  3793. // ecev3 - For coupling to IFS - MUST be serialized!!!!
  3794. int id;
  3795. int ifs_index;
  3796. int IFStypehigh; // 0 to 20
  3797. double IFSfrachigh; // 0 to 1
  3798. int IFStypelow; // 0 to 20
  3799. double IFSfraclow; // 0 to 1. Note: IFSfrachigh + IFSfraclow <= 1
  3800. bool transferhightolow;
  3801. int simulationyear; // 0 to nyear_spinup during spinup, then date.year
  3802. bool isspinup;
  3803. int ndep_lon_index, ndep_lat_index; // For CMIP6 N dep data
  3804. int ndep_index; // For conservatively remapped CMIP6 N dep data
  3805. double mdrynhx[12], mwetnhx[12], mdrynoy[12], mwetnoy[12], mndrydep[12], mnwetdep[12];
  3806. // ecev3 - the following do not need to be serialized
  3807. double laiphen_high_today; // updated daily
  3808. double laiphen_low_today; // updated daily
  3809. double landcover_fpc[NLANDCOVERTYPES]; // updated on Dec 31
  3810. double landcover_lai[NLANDCOVERTYPES]; // updated on Dec 31
  3811. double naturaltreeFPC; // (0-1) - NATURAL stand, calculated on Dec 31
  3812. double naturalgrassFPC; // (0-1) - NATURAL stand, calculated on Dec 31
  3813. int fixedLUafter; // Year from which on Land Use is frozen
  3814. // ecev3 - inputs from IFS to be output for checking
  3815. double ifs_co2[366];
  3816. double ifs_par[366];
  3817. double ifs_lw[366];
  3818. double ifs_precip[366];
  3819. double ifs_temp2m[366];
  3820. double ifs_tempsoil[366];
  3821. double ifs_soilw_surf[366];
  3822. double ifs_soilw_deep[366];
  3823. /// average gridcell soil column wcont for this year for each of the last five simulation years
  3824. Historic<double, 5> awcont_5;
  3825. Date date; // allow each gridcell to keep track of its own date
  3826. /// Nitrogen deposition forcing for current gridcell
  3827. Lamarque::NDepData ndepts;
  3828. /// list array [0...npft-1] of Gridcellpft (initialised in constructor)
  3829. ListArray_idin1<Gridcellpft,Pft> pft;
  3830. /// list array [0...nst-1] of Gridcellst (initialised in constructor)
  3831. ListArray_idin1<Gridcellst,StandType> st;
  3832. /// object for keeping track of carbon and nitrogen balance
  3833. MassBalance balance;
  3834. /// Seed for generating random numbers within this Gridcell
  3835. /** The reason why Gridcell has its own seed, rather than using for instance
  3836. * a single global seed is to make it easier to compare results when for
  3837. * instance changing the order in which the simulation proceeds. It also
  3838. * gets serialized together with the rest of the Gridcell state to make it
  3839. * possible to get exactly identical results after a restart.
  3840. *
  3841. * \see randfrac()
  3842. */
  3843. long seed;
  3844. // MEMBER FUNCTIONS
  3845. /// Constructs a Gridcell object
  3846. Gridcell();
  3847. /// Longitude for this grid cell
  3848. double get_lon() const;
  3849. /// Latitude for this grid cell
  3850. double get_lat() const;
  3851. /// Set longitude and latitude for this grid cell
  3852. void set_coordinates(double longitude, double latitude);
  3853. /// Get nitrogen deposition data for this point
  3854. bool getndep(const char* ndepfile, double rcp);
  3855. /// Get historical CMIP6 nitrogen deposition data for this point
  3856. bool getndepCMIP6(const char* ndepfile, int fixedNDepafter);
  3857. /// Get simulation year
  3858. int getsimulationyear(int year);
  3859. void serialize(ArchiveStream& arch);
  3860. /// Creates a new Stand in this grid cell
  3861. Stand& create_stand(landcovertype lc, int no_patch = 0);
  3862. /// Creates new stand and initiates land cover settings when run_landcover==true
  3863. Stand& create_stand_lu(StandType& st, double fraction, int no_patch = 0);
  3864. /// Total gridcell carbon biomass and litter
  3865. double ccont();
  3866. /// Total gridcell nitrogen biomass and litter
  3867. double ncont();
  3868. /// Total gridcell carbon fluxes so far this year
  3869. double cflux();
  3870. /// Total gridcell nitrogen fluxes so far this year
  3871. double nflux();
  3872. /// Deletes the stand which the iterator is pointing at
  3873. /** Returns an iterator pointing to the object following the erased object.
  3874. */
  3875. iterator delete_stand(iterator itr);
  3876. /// Returns number of stands
  3877. unsigned int nbr_stands() const;
  3878. // ecev3 - set first year
  3879. void set_first_year(int fy);
  3880. private:
  3881. /// Longitude for this grid cell
  3882. double lon;
  3883. /// Latitude for this grid cell
  3884. double lat;
  3885. };
  3886. #endif // LPJ_GUESS_GUESS_H
  3887. ///////////////////////////////////////////////////////////////////////////////////////
  3888. // REFERENCES
  3889. //
  3890. // LPJF refers to the original FORTRAN implementation of LPJ as described by Sitch
  3891. // et al 2000
  3892. // Delmas, R., Lacaux, J.P., Menaut, J.C., Abbadie, L., Le Roux, X., Helaa, G., Lobert, J., 1995.
  3893. // Nitrogen compound emission from biomass burning in tropical African Savanna FOS/DECAFE 1991
  3894. // experiment. Journal of Atmospheric Chemistry 22, 175-193.
  3895. // Cosby, B. J., Hornberger, C. M., Clapp, R. B., & Ginn, T. R. 1984 A statistical
  3896. // exploration of the relationships of soil moisture characteristic to the
  3897. // physical properties of soil.
  3898. // Water Resources Research, 20: 682-690.
  3899. // Franzlubbers, AJ & Stuedemann, JA 2009 Soil-profile organic carbon and total
  3900. // nitrogen during 12 years of pasture management in the Southern Piedmont USA.
  3901. // Agriculture Ecosystems & Environment, 129, 28-36.
  3902. // Friend, A. D., Stevens, A. K., Knox, R. G. & Cannell, M. G. R. 1997. A
  3903. // process-based, terrestrial biosphere model of ecosystem dynamics
  3904. // (Hybrid v3.0). Ecological Modelling, 95, 249-287.
  3905. // Fulton, MR 1991 Adult recruitment rate as a function of juvenile growth in size-
  3906. // structured plant populations. Oikos 61: 102-105.
  3907. // Haxeltine A & Prentice IC 1996 BIOME3: an equilibrium terrestrial biosphere
  3908. // model based on ecophysiological constraints, resource availability, and
  3909. // competition among plant functional types. Global Biogeochemical Cycles 10:
  3910. // 693-709
  3911. // Lloyd, J & Taylor JA 1994 On the temperature dependence of soil respiration
  3912. // Functional Ecology 8: 315-323
  3913. // Macduff, JH, Humphreys, MO & Thomas, H 2002. Effects of a stay-green mutation on
  3914. // plant nitrogen relations in Lolium perenne during N starvation and after
  3915. // defoliation. Annals of Botany, 89, 11-21.
  3916. // Monsi M & Saeki T 1953 Ueber den Lichtfaktor in den Pflanzengesellschaften und
  3917. // seine Bedeutung fuer die Stoffproduktion. Japanese Journal of Botany 14: 22-52
  3918. // Olin S., G. Schurgers, M. Lindeskog, D. Wårlind, B. Smith, P. Bodin, J.
  3919. // Holmér, and A. Arneth. 2015 Biogeosciences Discuss., 12, 1047-1111. The
  3920. // impact of atmospheric CO2 and N management on yields and tissue C:N in
  3921. // the main wheat regions of Western Europe
  3922. // Parton, W. J., Hanson, P. J., Swanston, C., Torn, M., Trumbore, S. E., Riley, W.
  3923. // & Kelly, R. 2010. ForCent model development and testing using the Enriched
  3924. // Background Isotope Study experiment. Journal of Geophysical
  3925. // Research-Biogeosciences, 115.
  3926. // Prentice, IC, Sykes, MT & Cramer W 1993 A simulation model for the transient
  3927. // effects of climate change on forest landscapes. Ecological Modelling 65: 51-70.
  3928. // Reich, PB, Walters MB & Ellsworth DS 1992 Leaf Life-Span in Relation to Leaf,
  3929. // Plant, and Stand Characteristics among Diverse Ecosystems.
  3930. // Ecological Monographs 62: 365-392.
  3931. // Sitch, S, Prentice IC, Smith, B & Other LPJ Consortium Members (2000) LPJ - a
  3932. // coupled model of vegetation dynamics and the terrestrial carbon cycle. In:
  3933. // Sitch, S. The Role of Vegetation Dynamics in the Control of Atmospheric CO2
  3934. // Content, PhD Thesis, Lund University, Lund, Sweden.
  3935. // Sykes, MT, Prentice IC & Cramer W 1996 A bioclimatic model for the potential
  3936. // distributions of north European tree species under present and future climates.
  3937. // Journal of Biogeography 23: 209-233.
  3938. // Wang, E, Engel, T, 1998 Simulation of phenological development of wheat crops
  3939. // Agricultural Systems 58:1-24
  3940. // White, M A, Thornton, P E, Running, S. & Nemani, R 2000 Parameterization and
  3941. // Sensitivity Analysis of the BIOME-BGC Terrestrial Ecosystem Model: Net Primary
  3942. // Production Controls. Earth Interactions, 4, 1-55.