;;; safir-common.dai -- Calibrations common to all SAFIR field sites.
;; 
;; DO NOT EDIT THIS FILE!  Instead, make your changes to your version
;; of 'safir-site.dai'.

;; Use standard parameterizations.
(input file "tillage.dai")
(input file "crop.dai")
(input file "fertilizer.dai")
(input file "log.dai")

(defvolume left-drip drip-depth
  "The left drip point."
  (left finite 0 [cm])
  (right finite 5 [cm]))

(defvolume right-drip drip-depth
  "The right drip point."
  (left finite 25 [cm])
  (right finite 30 [cm]))

(defvolume left-side box 
  "The left side of the root zone."
  (right finite 15 [cm]))

(defvolume right-side box 
  "The right side of the root zone."
  (left finite 15 [cm]))

(defABAproduction "Fulai Liu uptake" uptake
  "ABA concentration in water uptake as function of water potential.
Based on data collected by Fulai Liu, 2007."
  ;; 'h' is the soil potential in [cm].  This function converts 'h'
  ;; into an ABA concentration in water from that volume of soil.
  (expr (* 26.625 [ng/cm^3] (exp (* -4.2816 [MPa^-1] (convert h [MPa]))))))

;; We then define parameters for Farquhar and Ball.
(defphotosynthesis "Potato Farquhar" FC_C3
  "Farquhar parameters for potatoes."
  ;; This is the main calibration effect for unlimited production.
  (Xn 1.0e-3 [mol/mol/s])
  ;;Farquhar parameters for potatos, calibrated by Fuilai
  (Kc25 27.24 [Pa])
  (Ko25 16580 [Pa])
  (Gamma25 3.74 [Pa])
  ;; ABA effect on stomata conductance according to Fulai et al., 2005:
  ;; Molecular weight of ABA (Abscisic Acid) = 264.32 g mol^-1.
  (ABAeffect ABA-exp 
       (alpha 0.7368)
       ;; k = 0.0062 cm^3 pmol^-1 
       ;; OLD: k = (0.0062 * 1.0e-12 / 264.32) cm^3 g^-1 = 23456e-12 cm^3 g^-1
       ;; NEW: k = (0.0062 / (1.0e-12 * 264.32)) cm^3 g^-1 = 23456416 cm^3 g^-1
       
       (k 23456416 [cm^3/g]))
  ;; Minimal stomatal conductance for potatos (Fuilai et al., 2005)
  (b 0.1074 [mol/m^2/s])
  ;; Slope coefficient in Ball model for potatoes (Fuilai, personal comm.)
  (m 15) 
  ;; Intended for avoiding excessive growth for early crops in cold climate.
  (TempEff (0 1) (100 1)))

;; We readjust our FertOrgaNic Folva for SAFIR
(defcrop "Potato; Folva; SAFIR" "Potato; Folva"
  "The Folva Potato calibrated for FertOrgaNic adjusted for ABA"
  ;; Farquhar-Ball takes care of N stress.
  (enable_N_stress false)
  ;; ABA takes care of water stress.
  (water_stress_effect none)
  ;; ABA production in roots is affected by soil water potential.
  (Root (ABAprod "Fulai Liu uptake")
        (MaxWidth 1.5 [m]))
  ;; Stomata conductivity is affected by ABA.
  (LeafPhot "Potato Farquhar")
  ;; Initial growth governed by seeds:
  ;; NCrop will force Daisy to calculate a new number based on seed    
  ;; amount and N concentration as specified below.    
  (Prod (NCrop -1.0))    
  ;; Here we select the     
  (Seed release       
        ;; We release 30% of the carbon per day. It is first order,          
        ;; so the total amount will be decreasing over time.         
        (rate 0.3 [d^-1]) 
        ;; 80% of the potatoes are water.        
        (DM_fraction 0.20 [])    ;Based on Serbia 2006 yield  
        ;; Almost half of the seeds is available as carbon assimilate.         
        (C_fraction 0.4676 [])          
        ;; The potatoes also contain some nitrogen to get the crop started.
        (N_fraction 2.0 [%]))    ;Based on Serbia 2006 yield
  ;; The initial leaves are very thin. LeafAIMod for Potato Folva 
  ;; is included in this data.     
  (Canopy (LeafAIMod (0.0 2.2) (0.4 1.1)(1.5 1.1)(2.0 0.3))))

;;----------------------------------------
;; Some additional log files.
;;----------------------------------------

(deflog "Root zone water" crop
  "Water status of each side of the root zone."
  (when hourly)
  (where "root_zone_water.dlf")
  (entries (interval (tag "ABA")
                     (description "ABA in incomming water.")
                     (path column "${column}" 
                           Vegetation crops crops "${crop}" Root ABAExtraction)
                     (spec fixed RootSystem ABAExtraction))
           (interval (tag "Uptake")
                     (description "Water uptake from the root zone.")
                     (path column "${column}" 
                           Vegetation crops crops "${crop}" Root H2OExtraction)
                     (spec fixed RootSystem H2OExtraction)
                     (dimension "mm/h"))
           (interval (tag "Actual")
                     (description "Actual water content of the root zone.")
                     (path column "${column}" SoilWater Theta)
                     (spec fixed SoilWater Theta)
                     (dimension "mm")
                     (min_root_density 0.1 [cm/cm^3]))
           (water_interval (tag "FC")
                           (h 2 [pF])
                           (description "Root zone water content at field capacity.")
                           (path column "${column}" SoilWater Theta)
                           (spec fixed SoilWater Theta)
                           (dimension "mm")
                           (min_root_density 0.1 [cm/cm^3]))
           (water_interval (tag "WP")
                           (h -15000.0 [cm])
                           (description "Root zone water content at wilting point.")
                           (path column "${column}" SoilWater Theta)
                           (spec fixed SoilWater Theta)
                           (dimension "mm")
                           (min_root_density 0.1 [cm/cm^3]))))

;; Base program.
(defprogram Safir Daisy 
  "SAFIR common setup."

  ;; Let us know that the simulation is running.
  (print_time periodic)
  
  ;; Create these log files.
  (output harvest
          ("Soil nitrogen")
          ("Field nitrogen")
          ("Soil water")
          ("Field water")
          ("Root zone water" 
           (crop "SiteCrop") 
           (when (crop_ds_after "SiteCrop" 0.0))
           (volume left-side)
           (where "prd_left.dlf"))
          ("Root zone water" 
           (crop "SiteCrop") 
           (when (crop_ds_after "SiteCrop" 0.0))
           (volume right-side)
           (where "prd_right.dlf"))
          ("Crop Production" 
           (crop "SiteCrop"))))

;;; safir-common.dai ends here.
