Generate a BioCro model definition
write_model.RdTo facilitate the creation and validation of new BioCro models,
write_model stores the contents of a BioCro crop model definition
(see crop_model_definitions) in an R script to make its
modules and parameter values human-readable.
Usage
write_model(
name,
direct_modules,
differential_modules,
initial_values,
parameters,
ode_solver
)Arguments
- name
A string specifying a name for the model.
- direct_modules
A list or vector of fully-qualified direct module names that can be passed to
run_biocroas itsdirect_module_namesinput argument.- differential_modules
A list or vector of fully-qualified differential module names that can be passed to
run_biocroas itsdifferential_module_namesinput argument.- initial_values
A list of named elements that can be passed to
run_biocroas itsinitial_valuesinput argument.- parameters
A list of named elements that can be passed to
run_biocroas itsparametersinput argument.- ode_solver
A list of named elements that can be passed to
run_biocroas itsode_solverinput argument.
Details
This function returns a string and has no file I/O. Use
writeLines to print the output to console, or to save the
output. See examples below. Note that it is customary to name the R script
file as name.R, where name is the value provided to the function
itself.
The initial_values and parameters will be alphabetized
(case-insensitive). The ode_solver elements will be printed in the
customary BioCro order. The direct_modules and
differential_modules will not be reordered.
Examples
if (require(BioCro)) {
# Create a definition string for Soybean-BioCro
out <- with(BioCro::soybean, {write_model(
'test_soybean_model',
direct_modules,
differential_modules,
initial_values,
parameters,
ode_solver
)})
# Use writeLines to print to console
writeLines(out)
if (interactive()) {
# Use writeLines to save as a `.R` file
writeLines(out, "./test_soybean_model.R")
}
}
#> test_soybean_model <- list(
#> direct_modules = list(
#> "BioCro:maintenance_respiration_calculator",
#> "BioCro:senescence_coefficient_logistic",
#> "BioCro:stefan_boltzmann_longwave",
#> partitioning_coefficients = "BioCro:partitioning_coefficient_logistic",
#> leaf_water_stress = "BioCro:leaf_water_stress_exponential",
#> specific_leaf_area = "BioCro:sla_linear",
#> "BioCro:parameter_calculator",
#> "BioCro:height_from_lai",
#> "BioCro:canopy_gbw_thornley",
#> "BioCro:soil_evaporation",
#> stomata_water_stress = "BioCro:stomata_water_stress_linear",
#> "BioCro:format_time",
#> "BioCro:soybean_development_rate_calculator",
#> solar_coordinates = "BioCro:solar_position_michalsky",
#> "BioCro:shortwave_atmospheric_scattering",
#> "BioCro:incident_shortwave_from_ground_par",
#> "BioCro:ten_layer_canopy_properties",
#> canopy_photosynthesis = "BioCro:ten_layer_c3_canopy",
#> "BioCro:ten_layer_canopy_integrator",
#> "BioCro:carbon_assimilation_to_biomass",
#> partitioning_growth_calculator = "BioCro:partitioning_growth_calculator"
#> ),
#> differential_modules = list(
#> senescence = "BioCro:senescence_logistic",
#> "BioCro:maintenance_respiration",
#> "BioCro:partitioning_growth",
#> soil_profile = "BioCro:two_layer_soil_profile",
#> "BioCro:development_index",
#> thermal_time = "BioCro:thermal_time_linear"
#> ),
#> ode_solver = list(
#> type = "boost_rkck54",
#> output_step_size = 1.000000,
#> adaptive_rel_error_tol = 1.000000e-04,
#> adaptive_abs_error_tol = 1.000000e-04,
#> adaptive_max_steps = 200
#> ),
#> initial_values = list(
#> cws1 = 0.32,
#> cws2 = 0.32,
#> DVI = -1,
#> Grain = 1e-05,
#> Leaf = 0.06312,
#> LeafLitter = 0,
#> Rhizome = 1e-07,
#> RhizomeLitter = 0,
#> Root = 0.00789,
#> RootLitter = 0,
#> Shell = 1e-05,
#> soil_water_content = 0.32,
#> Stem = 0.00789,
#> StemLitter = 0,
#> TTc = 0
#> ),
#> parameters = list(
#> alpha1 = 0,
#> alphab1 = 0,
#> alphaLeaf = 23.3677144900876,
#> alphaRhizome = 0,
#> alphaRoot = 36.967,
#> alphaSeneLeaf = 43.7855824917775,
#> alphaSeneRhizome = 10,
#> alphaSeneRoot = 10,
#> alphaSeneStem = 10.8796343751991,
#> alphaShell = 11.545163924099,
#> alphaStem = 22.1267681013877,
#> atmospheric_pressure = 101325,
#> atmospheric_scattering = 0.3,
#> atmospheric_transmittance = 0.6,
#> b0 = 0.008,
#> b1 = 10.6,
#> beta_PSII = 0.5,
#> betaLeaf = -18.1101308143176,
#> betaRhizome = -Inf,
#> betaRoot = -40.1915,
#> betaSeneLeaf = -26.6770775076378,
#> betaSeneRhizome = -10,
#> betaSeneRoot = -10,
#> betaSeneStem = -4.61049860554787,
#> betaShell = -8.4831815000548,
#> betaStem = -16.2339597898586,
#> Catm = 372.59,
#> chil = 0.81,
#> dry_biomass_per_carbon = 30.026,
#> electrons_per_carboxylation = 4.5,
#> electrons_per_oxygenation = 5.25,
#> emissivity_sky = 1,
#> grc_grain = 0,
#> grc_leaf = 0,
#> grc_rhizome = 0,
#> grc_root = 0.00250052529027345,
#> grc_shell = 0,
#> grc_stem = 0.0190775428773556,
#> growth_respiration_fraction = 0,
#> Gs_min = 0.001,
#> Gstar_c = 19.02,
#> Gstar_Ea = 37830,
#> heightf = 6,
#> hydrDist = 0,
#> iSp = 3.5,
#> Jmax_at_25 = 195,
#> Jmax_at_25_mature = 195,
#> Jmax_c = 17.57,
#> Jmax_Ea = 43540,
#> k_diffuse = 0.7,
#> Kc_c = 38.05,
#> Kc_Ea = 79430,
#> km_leaf_litter = 2,
#> Ko_c = 20.3,
#> Ko_Ea = 36380,
#> kpLN = 0,
#> kRhizome_emr = 0,
#> kRhizome_emr_DVI = 0,
#> lat = 40,
#> leaf_reflectance_nir = 0.42,
#> leaf_reflectance_par = 0.1,
#> leaf_transmittance_nir = 0.42,
#> leaf_transmittance_par = 0.05,
#> LeafN = 2,
#> LeafN_0 = 2,
#> leafwidth = 0.1,
#> lnfun = 0,
#> longitude = -88,
#> maturity_group = 3,
#> min_gbw_canopy = 0.005,
#> mrc_grain = 0,
#> mrc_leaf = 0.000297139012738621,
#> mrc_rhizome = 0,
#> mrc_root = 1.00017330160141e-06,
#> mrc_shell = 0,
#> mrc_stem = 0.000297139012738621,
#> O2 = 210,
#> par_energy_content = 0.219,
#> par_energy_fraction = 0.5,
#> phi1 = 0.01,
#> phi2 = 1.5,
#> phi_PSII_0 = 0.352,
#> phi_PSII_1 = 0.022,
#> phi_PSII_2 = -0.00034,
#> rateSeneLeaf = 0.00999312745523112,
#> rateSeneRhizome = 0,
#> rateSeneRoot = 0,
#> rateSeneStem = 0.00215689869131893,
#> remobilization_fraction = 0.6,
#> retrans = 0.9,
#> retrans_rhizome = 1,
#> rfl = 0.2,
#> RL_at_25 = 1.28,
#> RL_c = 18.72,
#> RL_Ea = 46390,
#> Rmax_emrV0 = 0.199,
#> rsdf = 0.44,
#> rsec = 0.2,
#> sf_jmax = 0.2,
#> soil_air_entry = -2.6,
#> soil_b_coefficient = 5.2,
#> soil_bulk_density = 1.35,
#> soil_clay_content = 0.34,
#> soil_clod_size = 0.04,
#> soil_depth1 = 0,
#> soil_depth2 = 2.5,
#> soil_depth3 = 10,
#> soil_field_capacity = 0.32,
#> soil_reflectance = 0.2,
#> soil_sand_content = 0.32,
#> soil_saturated_conductivity = 6.4e-05,
#> soil_saturation_capacity = 0.52,
#> soil_silt_content = 0.34,
#> soil_transmission = 0.01,
#> soil_wilting_point = 0.2,
#> sowing_fractional_doy = 0,
#> Sp_thermal_time_decay = 0,
#> specific_heat_of_air = 1010,
#> tbase = 10,
#> Tbase_emr = 10,
#> theta_0 = 0.76,
#> theta_1 = 0.018,
#> theta_2 = -0.00037,
#> timestep = 1,
#> Tmax_emrV0 = 45,
#> Tmax_R0R1 = 45,
#> Tmax_R1R7 = 38.7,
#> Tmin_emrV0 = 5,
#> Tmin_R0R1 = 5,
#> Tmin_R1R7 = 0,
#> Topt_emrV0 = 31.5,
#> Topt_R0R1 = 31.5,
#> Topt_R1R7 = 21.5,
#> Tp_at_25 = 13,
#> Tp_c = 19.77399,
#> Tp_Ha = 62990,
#> Tp_Hd = 182140,
#> Tp_S = 588,
#> TTemr_threshold = 60,
#> Vcmax_at_25 = 110,
#> Vcmax_c = 26.35,
#> Vcmax_Ea = 65330,
#> windspeed_height = 5,
#> wsFun = 2
#> )
#> )