Skip to contents padding-top: 70px;

To 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_biocro as its direct_module_names input argument.

differential_modules

A list or vector of fully-qualified differential module names that can be passed to run_biocro as its differential_module_names input argument.

initial_values

A list of named elements that can be passed to run_biocro as its initial_values input argument.

parameters

A list of named elements that can be passed to run_biocro as its parameters input argument.

ode_solver

A list of named elements that can be passed to run_biocro as its ode_solver input 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.

Value

A string containing a new BioCro model definition R script.

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.h")
  }
}
#> test_soybean_model <- list(
#>     direct_modules = list(
#>         "BioCro:format_time",
#>         "BioCro:stomata_water_stress_linear",
#>         "BioCro:sla_linear",
#>         "BioCro:parameter_calculator",
#>         "BioCro:soybean_development_rate_calculator",
#>         "BioCro:leaf_water_stress_exponential",
#>         "BioCro:partitioning_coefficient_logistic",
#>         "BioCro:soil_evaporation",
#>         "BioCro:solar_position_michalsky",
#>         "BioCro:shortwave_atmospheric_scattering",
#>         "BioCro:incident_shortwave_from_ground_par",
#>         "BioCro:height_from_lai",
#>         "BioCro:canopy_gbw_thornley",
#>         "BioCro:stefan_boltzmann_longwave",
#>         "BioCro:ten_layer_canopy_properties",
#>         "BioCro:ten_layer_c3_canopy",
#>         "BioCro:ten_layer_canopy_integrator",
#>         "BioCro:no_leaf_resp_neg_assim_partitioning_growth_calculator",
#>         "BioCro:senescence_coefficient_logistic",
#>         "BioCro:carbon_assimilation_to_biomass"
#>     ),
#>     differential_modules = list(
#>         "BioCro:senescence_logistic",
#>         "BioCro:maintenance_respiration",
#>         "BioCro:partitioning_growth",
#>         "BioCro:two_layer_soil_profile",
#>         "BioCro:development_index",
#>         "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(
#>         "Leaf" = 0.06312,
#>         "Stem" = 0.00789,
#>         "Root" = 0.00789,
#>         "Grain" = 1e-05,
#>         "Shell" = 1e-05,
#>         "LeafLitter" = 0,
#>         "RootLitter" = 0,
#>         "StemLitter" = 0,
#>         "soil_water_content" = 0.32,
#>         "cws1" = 0.32,
#>         "cws2" = 0.32,
#>         "DVI" = -1,
#>         "TTc" = 0,
#>         "Rhizome" = 1e-07,
#>         "RhizomeLitter" = 0
#>     ),
#>     parameters = list(
#>         "soil_air_entry" = -2.6,
#>         "soil_b_coefficient" = 5.2,
#>         "soil_bulk_density" = 1.35,
#>         "soil_clay_content" = 0.34,
#>         "soil_field_capacity" = 0.32,
#>         "soil_sand_content" = 0.32,
#>         "soil_saturated_conductivity" = 6.4e-05,
#>         "soil_saturation_capacity" = 0.52,
#>         "soil_silt_content" = 0.34,
#>         "soil_wilting_point" = 0.2,
#>         "iSp" = 3.5,
#>         "Sp_thermal_time_decay" = 0,
#>         "LeafN" = 2,
#>         "LeafN_0" = 2,
#>         "vmax_n_intercept" = 0,
#>         "vmax1" = 110,
#>         "alphab1" = 0,
#>         "alpha1" = 0,
#>         "maturity_group" = 3,
#>         "Tbase_emr" = 10,
#>         "TTemr_threshold" = 60,
#>         "Rmax_emrV0" = 0.199,
#>         "Tmin_emrV0" = 5,
#>         "Topt_emrV0" = 31.5,
#>         "Tmax_emrV0" = 45,
#>         "Tmin_R0R1" = 5,
#>         "Topt_R0R1" = 31.5,
#>         "Tmax_R0R1" = 45,
#>         "Tmin_R1R7" = 0,
#>         "Topt_R1R7" = 21.5,
#>         "Tmax_R1R7" = 38.7,
#>         "sowing_fractional_doy" = 0,
#>         "alphaLeaf" = 23.8895,
#>         "alphaStem" = 24.8248,
#>         "betaLeaf" = -18.0851,
#>         "betaStem" = -18.5214,
#>         "alphaRoot" = 36.967,
#>         "betaRoot" = -40.1915,
#>         "alphaShell" = 13.5955,
#>         "betaShell" = -9.9809,
#>         "kRhizome_emr" = 0,
#>         "rsec" = 0.2,
#>         "soil_clod_size" = 0.04,
#>         "soil_reflectance" = 0.2,
#>         "soil_transmission" = 0.01,
#>         "specific_heat_of_air" = 1010,
#>         "lat" = 40,
#>         "longitude" = -88,
#>         "atmospheric_pressure" = 101325,
#>         "atmospheric_transmittance" = 0.6,
#>         "atmospheric_scattering" = 0.3,
#>         "par_energy_fraction" = 0.5,
#>         "par_energy_content" = 0.219,
#>         "heightf" = 6,
#>         "min_gbw_canopy" = 0.005,
#>         "dry_biomass_per_carbon" = 30.026,
#>         "emissivity_sky" = 1,
#>         "chil" = 0.81,
#>         "k_diffuse" = 0.7,
#>         "kpLN" = 0,
#>         "leaf_reflectance_nir" = 0.42,
#>         "leaf_reflectance_par" = 0.1,
#>         "leaf_transmittance_nir" = 0.42,
#>         "leaf_transmittance_par" = 0.05,
#>         "lnfun" = 0,
#>         "Gstar_c" = 19.02,
#>         "Gstar_Ea" = 37830,
#>         "Jmax_c" = 17.57,
#>         "Jmax_Ea" = 43540,
#>         "Kc_c" = 38.05,
#>         "Kc_Ea" = 79430,
#>         "Ko_c" = 20.3,
#>         "Ko_Ea" = 36380,
#>         "phi_PSII_0" = 0.352,
#>         "phi_PSII_1" = 0.022,
#>         "phi_PSII_2" = -0.00034,
#>         "Rd_c" = 18.72,
#>         "Rd_Ea" = 46390,
#>         "theta_0" = 0.76,
#>         "theta_1" = 0.018,
#>         "theta_2" = -0.00037,
#>         "Tp_c" = 19.77399,
#>         "Tp_Ha" = 62990,
#>         "Tp_Hd" = 182140,
#>         "Tp_S" = 588,
#>         "Vcmax_c" = 26.35,
#>         "Vcmax_Ea" = 65330,
#>         "jmax" = 195,
#>         "jmax_mature" = 195,
#>         "sf_jmax" = 0.2,
#>         "electrons_per_carboxylation" = 4.5,
#>         "electrons_per_oxygenation" = 5.25,
#>         "tpu_rate_max" = 13,
#>         "Rd" = 1.28,
#>         "Catm" = 372.59,
#>         "O2" = 210,
#>         "b0" = 0.008,
#>         "b1" = 10.6,
#>         "Gs_min" = 0.001,
#>         "windspeed_height" = 5,
#>         "beta_PSII" = 0.5,
#>         "leafwidth" = 0.1,
#>         "growth_respiration_fraction" = 0,
#>         "grc_stem" = 0.02828,
#>         "grc_root" = 0.0027,
#>         "mrc_leaf" = 0.00048836,
#>         "mrc_stem" = 0.00048836,
#>         "mrc_root" = 1e-05,
#>         "mrc_grain" = 1e-05,
#>         "retrans" = 0.9,
#>         "retrans_rhizome" = 1,
#>         "rateSeneLeaf" = 0.012198,
#>         "rateSeneStem" = 0.000117,
#>         "rateSeneRoot" = 0,
#>         "rateSeneRhizome" = 0,
#>         "alphaSeneLeaf" = 48.32,
#>         "alphaSeneStem" = 4.1937,
#>         "alphaSeneRoot" = 10,
#>         "alphaSeneRhizome" = 10,
#>         "betaSeneLeaf" = -29.5393,
#>         "betaSeneStem" = -3.3124,
#>         "betaSeneRoot" = -10,
#>         "betaSeneRhizome" = -10,
#>         "remobilization_fraction" = 0.6,
#>         "soil_depth1" = 0,
#>         "soil_depth2" = 2.5,
#>         "soil_depth3" = 10,
#>         "wsFun" = 2,
#>         "hydrDist" = 0,
#>         "rfl" = 0.2,
#>         "rsdf" = 0.44,
#>         "phi1" = 0.01,
#>         "phi2" = 1.5,
#>         "tbase" = 10,
#>         "km_leaf_litter" = 2,
#>         "timestep" = 1
#>     )
#> )