;;; OpenMI_management.dai -- Example of management imported through OpenMI coupling 

(description "Simulation for use in OpenMI coupling with irrigation defined as input exchange item.")

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

;; Weather data 
(weather default  "dk-taastrup.dwf")

;; We have some very sandy soil.
(defhorizon Ap FAO3
  "Top soil."
  (clay 8.0 [%])
  (silt 10.5 [%])
  (sand 81.5 [%])
  (humus 1.12 [%])
  (C_per_N 11.0 [g C/g N])
  (dry_bulk_density 1.5 [g/cm^3]))

(defhorizon C Ap
  "C horizon."
  (humus 0.12 [%]))

;; We build the column from the horizons.
(defcolumn Andeby default
  "The B.And farm, Andeby, 2002."
  ;; Location (X Y) point
  (location (-10 100))
  ;; Extern input
  (scope name "Lower_boundary_input")
  ;; Daisy use solute NO3 concentration in lower boundary given by: 
  (Chemistry multi (combine (N (trace NH4 (NO3(C_below "NO3 conc. groundwater"))))))
  ;; Daisy use groundwater table from OpenMI with the pipe model below:
  (Groundwater pipe (pressure_table extern 
				    (value "GroundWaterTable")
				    (initial_value -200 [cm])))
  (Soil (horizons (-20 [cm] Ap) (-2.5 [m] C))
    	(MaxRootingDepth 60.0 [cm]))
  (OrganicMatter original (init (input 1400 [kg C/ha/y])))
  (Bioclimate default))

;; Use these columns:
(column Andeby)

;; Simulation period.
(time 1986 12 1 1)
(stop 1988 4 1 1)

(defaction MyMan activity
  (wait (at 1987 3 20 1))
  (plowing)
  (wait (at 1987 4 5 1))
  (progn
    (sow "Grass")
    (sow "Spring Barley"))
  (wait (at 1987 9 5 1))
  (harvest "Spring Barley")
  (wait (at 1987 10 10 1))
  (harvest "Grass"
	   (stub 8.0 [cm])  ;Leave 8 cm stub.
	   (stem 1.00 []))  ;Harvest everything above stub.
  )

;; Simulation of MyMan activity with irrigation through OpenMI
(manager (while (wait false)
	   (OpenMI_fertigation (scope name fertigation)
			       ;; Drip line placement.
			       (from -5 [cm])
			       (to  -15 [cm]))
	   (MyMan)))
	   
;; Export these items through OpenMI.
(output (Lower_boundary_output (column Andeby))
	(Crop_soil_content (column Andeby) (to -50 [cm]))
	;; An ordinary log file:
        ("Soil Water Potential" (column Andeby)))

;; Import these items through OpenMI.
(exchange (Lower_boundary_input (column Andeby))
	  (fertigation (column Andeby)))

;;; OpenMI_management.dai ends here.
