osr

Two models run in a time step synchonization pattern where one of the models is the OpenSimRoot simulation code and the other is a dummy stand in. This example demonstrates how to run OSR simulations as part of yggdrasil integrations and the use of the timesync model parameter and communication pattern.

C Version

Model Code:

  1#define _USE_MATH_DEFINES  // Required to use M_PI with MSVC
  2#include <math.h>
  3#include <stdio.h>
  4#include "YggInterface.h"
  5
  6
  7int timestep_calc(double t, const char* t_units, generic_t state) {
  8  int ret = 0;
  9  if (ret >= 0) {
 10    ret = generic_map_set_double(state, "carbonAllocation2Roots", 10.0, "g");
 11  }
 12  if (ret >= 0) {
 13    ret = generic_map_set_double(state, "saturatedConductivity", 10.0, "cm/day");
 14  }
 15  return ret;
 16}
 17
 18
 19int main(int argc, char *argv[]) {
 20
 21  double t_step = atof(argv[1]);
 22  char* t_units = argv[2];
 23  int exit_code = 0;
 24  printf("Hello from C other_model: timestep %f %s\n", t_step, t_units);
 25  double t_start = 0.0;
 26  double t_end = 1.0;
 27  size_t nkeys, ikey;
 28  char** keys = NULL;
 29  if (strcmp(t_units, "hr") == 0) {
 30    t_end = 24.0 * t_end;
 31  }
 32  int ret;
 33  generic_t state_send = init_generic_map();
 34  generic_t state_recv = init_generic_map();
 35  ret = timestep_calc(t_start, t_units, state_send);
 36  if (ret < 0) {
 37    printf("other_model(C): Error in initial timestep calculation.");
 38    return -1;
 39  }
 40
 41  // Set up connections matching yaml
 42  // Timestep synchronization connection will be 'timesync'
 43  comm_t* timesync = yggTimesync("timesync", t_units);
 44  dtype_t* out_dtype = create_dtype_json_object(0, NULL, NULL, true);
 45  comm_t* out = yggOutputType("output", out_dtype);
 46
 47  // Initialize state and synchronize with other models
 48  double t = t_start;
 49  ret = rpcCall(timesync, t, state_send, &state_recv);
 50  if (ret < 0) {
 51    printf("other_model(C): Initial sync failed.\n");
 52    return -1;
 53  }
 54  nkeys = generic_map_get_keys(state_recv, &keys);
 55  printf("other_model(C): t = %5.1f %-3s", t, t_units);
 56  for (ikey = 0; ikey < nkeys; ikey++) {
 57    printf(", %s = %+ 5.2f", keys[ikey],
 58	   generic_map_get_double(state_recv, keys[ikey]));
 59  }
 60  printf("\n");
 61
 62  // Send initial state to output
 63  generic_t msg = copy_generic(state_recv);
 64  ret = generic_map_set_double(msg, "time", t, t_units);
 65  if (ret < 0) {
 66    printf("other_model(C): Failed to set time in initial output map.\n");
 67    return -1;
 68  }
 69  ret = yggSend(out, msg);
 70  if (ret < 0) {
 71    printf("other_model(C): Failed to send initial output for t=%f.\n", t);
 72    return -1;
 73  }
 74  destroy_generic(&msg);
 75
 76  // Iterate until end
 77  while (t < t_end) {
 78
 79    // Perform calculations to update the state
 80    t = t + t_step;
 81    ret = timestep_calc(t, t_units, state_send);
 82    if (ret < 0) {
 83      printf("other_model(C): Error in timestep calculation for t = %f.\n", t);
 84      return -1;
 85    }
 86
 87    // Synchronize the state
 88    ret = rpcCall(timesync, t, state_send, &state_recv);
 89    if (ret < 0) {
 90      printf("other_model(C): sync for t=%f failed.\n", t);
 91      return -1;
 92    }
 93    nkeys = generic_map_get_keys(state_recv, &keys);
 94    printf("other_model(C): t = %5.1f %-3s", t, t_units);
 95    for (ikey = 0; ikey < nkeys; ikey++) {
 96      printf(", %s = %+ 5.2f", keys[ikey],
 97	     generic_map_get_double(state_recv, keys[ikey]));
 98    }
 99    printf("\n");
100
101    // Send output
102    generic_t msg = copy_generic(state_recv);
103    ret = generic_map_set_double(msg, "time", t, t_units);
104    if (ret < 0) {
105      printf("other_model(C): Failed to set time in output map.\n");
106      return -1;
107    }
108    ret = yggSend(out, msg);
109    if (ret < 0) {
110      printf("other_model(C): Failed to send output for t=%f.\n", t);
111      return -1;
112    }
113    destroy_generic(&msg);
114  }
115
116  printf("Goodbye from C other_model\n");
117  destroy_generic(&state_send);
118  destroy_generic(&state_recv);
119  return 0;
120    
121}
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: c
19    args:
20      - ./src/other_model.c
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table

C++ Version

Model Code:

  1#define _USE_MATH_DEFINES  // Required to use M_PI with MSVC
  2#include <math.h>
  3#include <stdio.h>
  4#include "YggInterface.hpp"
  5
  6
  7int timestep_calc(double t, const char* t_units, generic_t state) {
  8  int ret = 0;
  9  if (ret >= 0) {
 10    ret = generic_map_set_double(state, "carbonAllocation2Roots", 10.0, "g");
 11  }
 12  if (ret >= 0) {
 13    ret = generic_map_set_double(state, "saturatedConductivity", 10.0, "cm/day");
 14  }
 15  return ret;
 16}
 17
 18
 19int main(int argc, char *argv[]) {
 20
 21  double t_step = atof(argv[1]);
 22  char* t_units = argv[2];
 23  int exit_code = 0;
 24  printf("Hello from C++ other_model: timestep %f %s\n", t_step, t_units);
 25  double t_start = 0.0;
 26  double t_end = 1.0;
 27  size_t nkeys, ikey;
 28  char** keys = NULL;
 29  if (strcmp(t_units, "hr") == 0) {
 30    t_end = 24.0 * t_end;
 31  }
 32  int ret;
 33  generic_t state_send = init_generic_map();
 34  generic_t state_recv = init_generic_map();
 35  ret = timestep_calc(t_start, t_units, state_send);
 36  if (ret < 0) {
 37    printf("other_model(C++): Error in initial timestep calculation.");
 38    return -1;
 39  }
 40
 41  // Set up connections matching yaml
 42  // Timestep synchronization connection will default to 'timesync'
 43  YggTimesync timesync("timesync", t_units);
 44  dtype_t* out_dtype = create_dtype_json_object(0, NULL, NULL, true);
 45  YggOutput out("output", out_dtype);
 46
 47  // Initialize state and synchronize with other models
 48  double t = t_start;
 49  ret = timesync.call(3, t, state_send, &state_recv);
 50  if (ret < 0) {
 51    printf("other_model(C++): Initial sync failed.\n");
 52    return -1;
 53  }
 54  nkeys = generic_map_get_keys(state_recv, &keys);
 55  printf("other_model(C++): t = %5.1f %-3s", t, t_units);
 56  for (ikey = 0; ikey < nkeys; ikey++) {
 57    printf(", %s = %+ 5.2f", keys[ikey],
 58	   generic_map_get_double(state_recv, keys[ikey]));
 59  }
 60  printf("\n");
 61
 62  // Send initial state to output
 63  generic_t msg = copy_generic(state_recv);
 64  ret = generic_map_set_double(msg, "time", t, t_units);
 65  if (ret < 0) {
 66    printf("other_model(C++): Failed to set time in initial output map.\n");
 67    return -1;
 68  }
 69  ret = out.send(1, msg);
 70  if (ret < 0) {
 71    printf("other_model(C++): Failed to send initial output for t=%f.\n", t);
 72    return -1;
 73  }
 74  destroy_generic(&msg);
 75
 76  // Iterate until end
 77  while (t < t_end) {
 78
 79    // Perform calculations to update the state
 80    t = t + t_step;
 81    ret = timestep_calc(t, t_units, state_send);
 82    if (ret < 0) {
 83      printf("other_model(C++): Error in timestep calculation for t = %f.\n", t);
 84      return -1;
 85    }
 86
 87    // Synchronize the state
 88    ret = timesync.call(3, t, state_send, &state_recv);
 89    if (ret < 0) {
 90      printf("other_model(C++): sync for t=%f failed.\n", t);
 91      return -1;
 92    }
 93    nkeys = generic_map_get_keys(state_recv, &keys);
 94    printf("other_model(C++): t = %5.1f %-3s", t, t_units);
 95    for (ikey = 0; ikey < nkeys; ikey++) {
 96      printf(", %s = %+ 5.2f", keys[ikey],
 97	     generic_map_get_double(state_recv, keys[ikey]));
 98    }
 99    printf("\n");
100
101    // Send output
102    generic_t msg = copy_generic(state_recv);
103    ret = generic_map_set_double(msg, "time", t, t_units);
104    if (ret < 0) {
105      printf("other_model(C++): Failed to set time in output map.\n");
106      return -1;
107    }
108    ret = out.send(1, msg);
109    if (ret < 0) {
110      printf("other_model(C++): Failed to send output for t=%f.\n", t);
111      return -1;
112    }
113    destroy_generic(&msg);
114  }
115
116  printf("Goodbye from C++ other_model\n");
117  destroy_generic(&state_send);
118  destroy_generic(&state_recv);
119  return 0;
120    
121}
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: c++
19    args:
20      - ./src/other_model.cpp
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table

Fortran Version

Model Code:

  1program main
  2  use fygg
  3
  4  ! Declare resulting variables and create buffer for received message
  5  logical :: timestep_calc
  6  logical :: ret = .true.
  7  type(yggcomm) :: timesync, out
  8  character(len=32) :: arg
  9  character(len=0), dimension(0) :: dtype_keys
 10  type(yggdtype), dimension(0) :: dtype_vals
 11  type(yggdtype) :: out_dtype
 12  real(kind=8) :: t_step, t_start, t_end, t
 13  character(len=32) :: t_units
 14  character(len=20), dimension(:), pointer :: keys
 15  type(ygggeneric) :: state_send, state_recv, msg
 16  real(kind=8), pointer :: x
 17  integer :: i
 18
 19  call get_command_argument(1, arg)
 20  read(arg, *) t_step
 21  call get_command_argument(2, arg)
 22  read(arg, *) t_units
 23  call get_command_argument(3, arg)
 24  write (*, '("Hello from Fortran other_model: timestep ",F10.5," ",A3)') &
 25       t_step, trim(t_units)
 26  t_start = 0.0
 27  t_end = 5.0
 28  if (t_units.eq."hr") then
 29     t_end = 24.0 * t_end
 30  end if
 31  state_send = init_generic_map()
 32  state_recv = init_generic_map()
 33  ret = timestep_calc(t_start, t_units, state_send)
 34  if (.not.ret) then
 35     write (*, '("other_model(Fortran): Error in initial timestep &
 36          &calculation.")')
 37  end if
 38
 39  ! Set up connections matching yaml
 40  ! Timestep synchronization connection will be 'timesync'
 41  timesync = ygg_timesync("timesync", t_units)
 42  out_dtype = create_dtype_json_object(0, dtype_keys, dtype_vals, .true.)
 43  out = ygg_output_type("output", out_dtype)
 44
 45  ! Initialize state and synchronize with other models
 46  t = t_start
 47  ret = ygg_rpc_call(timesync, [yggarg(t), yggarg(state_send)], &
 48       yggarg(state_recv))
 49  if (.not.ret) then
 50     write (*, '("other_model(Fortran): Initial sync failed.")')
 51     stop 1
 52  end if
 53  write (*, '("other_model(Fortran): t = ",F5.1," ",A3)', advance="no") &
 54       t, adjustl(t_units)
 55  call generic_map_get_keys(state_recv, keys)
 56  do i = 1, size(keys)
 57     call generic_map_get(state_recv, trim(keys(i)), x)
 58     write (*, '(SP,", ",A," = ",F5.2)', advance="no") &
 59          trim(keys(i)), x
 60  end do
 61  write (*, '("")')
 62
 63  ! Send initial state to output
 64  msg = copy_generic(state_recv)
 65  call generic_map_set(msg, "time", t, t_units)
 66  ret = ygg_send_var(out, yggarg(msg))
 67  if (.not.ret) then
 68     write (*, '("other_model(Fortran): Failed to send initial output &
 69          &for t=",F10.5,".")') t
 70     stop 1
 71  end if
 72  call free_generic(msg)
 73
 74  ! Iterate until end
 75  do while (t.lt.t_end)
 76
 77     ! Perform calculations to update the state
 78     t = t + t_step
 79     ret = timestep_calc(t, t_units, state_send)
 80     if (.not.ret) then
 81        write (*, '("other_model(Fortran): Error in timestep &
 82             &calculation for t = ",F10.5,".")') t
 83        stop 1
 84     end if
 85
 86     ! Synchronize the state
 87     ret = ygg_rpc_call(timesync, [yggarg(t), yggarg(state_send)], &
 88          yggarg(state_recv))
 89     if (.not.ret) then
 90        write (*, '("other_model(Fortran): sync failed for t=",F10.5,&
 91             &".")') t
 92        stop 1
 93     end if
 94     write (*, '("other_model(Fortran): t = ",F5.1," ",A3)', advance="no") &
 95          t, adjustl(t_units)
 96     call generic_map_get_keys(state_recv, keys)
 97     do i = 1, size(keys)
 98        call generic_map_get(state_recv, keys(i), x)
 99        write (*, '(SP,", ",A," = ",F5.2)', advance="no") &
100             trim(keys(i)), x
101     end do
102     write (*, '("")')
103
104     ! Send output
105     msg = copy_generic(state_recv)
106     call generic_map_set(msg, "time", t, t_units)
107     ret = ygg_send_var(out, yggarg(msg))
108     if (.not.ret) then
109        write (*, '("other_model(Fortran): Failed to send output for &
110             &t=",F10.5,".")') t
111        stop 1
112     end if
113     call free_generic(msg)
114
115  end do
116
117  write (*, '("Goodbye from Fortran other_model")')
118  call free_generic(state_send)
119  call free_generic(state_recv)
120
121end program main
122
123
124function timestep_calc(t, t_units, state) result (ret)
125  use fygg
126  implicit none
127  real(kind=8) :: t
128  character(len=*) :: t_units
129  type(ygggeneric) :: state
130  logical :: ret
131  ret = .true.
132  if (ret) then
133     call generic_map_set(state, "carbonAllocation2Roots", 10.0, "g")
134     call generic_map_set(state, "saturatedConductivity", 10.0, "cm/day")
135  end if
136end function timestep_calc
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: fortran
19    args:
20      - ./src/other_model.f90
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table

Matlab Version

Model Code:

 1function timesync(t_step, t_units)
 2
 3  t_step = str2num(t_step);
 4  fprintf('Hello from Matlab other_model: timestep = %f %s\n', t_step, t_units);
 5  t_step = t_step * str2symunit(t_units);
 6  t_start = 0.0000000000000001 * str2symunit(t_units);
 7  t_end = 1.0 * str2symunit('day');
 8  state = containers.Map('UniformValues', false, 'ValueType', 'any');
 9  state('carbonAllocation2Roots') = 10.0 * str2symunit('g');
10  state('saturatedConductivity') = 10.0 * str2symunit('cm/day');
11
12  % Set up connections matching yaml
13  % Timestep synchonization connection will default to 'timesync'
14  timesync = YggInterface('YggTimesync', 'timesync');
15  out = YggInterface('YggOutput', 'output');
16
17  % Initialize state and synchronize with other models
18  t = t_start;
19  [ret, state] = timesync.call(t, state);
20  if (~ret);
21    error('other_model(Matlab): Initial sync failed.');
22  end;
23  [t_data, t_unit] = separateUnits(t);
24  fprintf('other_model(Matlab): t = %5.1f %-1s', ...
25	  t_data, symunit2str(t_unit));
26  for k = keys(state)
27    fprintf(', %s = %+ 5.2f', k{1}, state(k{1}));
28  end;
29  fprintf('\n');
30
31  % Send initial state to output
32  msg_keys = keys(state);
33  msg_keys{length(msg_keys) + 1} = 'time';
34  msg_vals = values(state);
35  msg_vals{length(msg_vals) + 1} = t;
36  msg = containers.Map(msg_keys, msg_vals, 'UniformValues', false);
37  flag = out.send(msg);
38
39  % Iterate until end
40  while (simplify(t/t_end) < 1)
41
42    % Perform calculations to update the state
43    t = t + t_step;
44    state = containers.Map('UniformValues', false, 'ValueType', 'any');
45    state('carbonAllocation2Roots') = 10.0 * str2symunit('g');
46    state('saturatedConductivity') = 10.0 * str2symunit('cm/day');
47
48    % Synchronize the state
49    [ret, state] = timesync.call(t, state);
50    if (~ret);
51      error(sprintf('other_model(Matlab): sync for t=%f failed.\n', t));
52    end;
53    [t_data, t_unit] = separateUnits(t);
54    fprintf('other_model(Matlab): t = %5.1f %-1s', ...
55            t_data, symunit2str(t_unit));
56    for k = keys(state)
57      fprintf(', %s = %+ 5.2f', k{1}, state(k{1}));
58    end;
59    fprintf('\n');
60
61    % Send output
62    msg_keys = keys(state);
63    msg_keys{length(msg_keys) + 1} = 'time';
64    msg_vals = values(state);
65    msg_vals{length(msg_vals) + 1} = t;
66    msg = containers.Map(msg_keys, msg_vals, 'UniformValues', false);
67    flag = out.send(msg);
68    if (~flag);
69      error(sprintf('other_model(Matlab): Failed to send output for t=%s.\n', t));
70    end;
71  end;
72
73  disp('Goodbye from Matlab other_model');
74  
75end
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: matlab
19    args:
20      - ./src/other_model.m
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table

Python Version

Model Code:

 1import sys
 2from yggdrasil import units
 3from yggdrasil.interface.YggInterface import (
 4    YggTimesync, YggOutput)
 5
 6
 7def timestep_calc(t):
 8    r"""Updates the state based on the time where x is a sine wave
 9    with period of 10 days and y is a cosine wave with a period of 5 days.
10
11    Args:
12        t (float): Current time.
13
14    Returns:
15        dict: Map of state parameters.
16
17    """
18    state = {"carbonAllocation2Roots": units.add_units(10.0, 'g'),
19             "saturatedConductivity": units.add_units(10.0, 'cm/day')}
20    return state
21
22
23def main(t_step, t_units):
24    r"""Function to execute integration.
25
26    Args:
27        t_step (float): The time step that should be used.
28        t_units (str): Units of the time step.
29
30    """
31    print('Hello from Python other_model: timestep = %s %s' % (t_step, t_units))
32    t_step = units.add_units(t_step, t_units)
33    t_start = units.add_units(0.0, t_units)
34    t_end = units.add_units(1.0, 'day')
35    state = timestep_calc(t_start)
36
37    # Set up connections matching yaml
38    # Timestep synchonization connection will default to 'timesync'
39    timesync = YggTimesync('timesync')
40    out = YggOutput('output')
41
42    # Initialize state and synchronize with other models
43    t = t_start
44    ret, state = timesync.call(t, state)
45    if not ret:
46        raise RuntimeError("other_model(Python): Initial sync failed.")
47    print('other_model(Python): t = % 8s' % t, end='')
48    for k, v in state.items():
49        print(', %s = %+ 5.2f' % (k, v), end='')
50    print('')
51
52    # Send initial state to output
53    flag = out.send(dict(state, time=t))
54    if not flag:
55        raise RuntimeError("other_model(Python): Failed to send "
56                           "initial output for t=%s." % t)
57    
58    # Iterate until end
59    while t < t_end:
60
61        # Perform calculations to update the state
62        t = t + t_step
63        state = timestep_calc(t)
64
65        # Synchronize the state
66        ret, state = timesync.call(t, state)
67        if not ret:
68            raise RuntimeError("other_model(Python): sync for t=%f failed." % t)
69        print('other_model(Python): t = % 8s' % t, end='')
70        for k, v in state.items():
71            print(', %s = %+ 5.2f' % (k, v), end='')
72        print('')
73
74        # Send output
75        flag = out.send(dict(state, time=t))
76        if not flag:
77            raise RuntimeError("other_model(Python): Failed to send output for t=%s." % t)
78
79    print('Goodbye from Python other_model')
80
81
82if __name__ == '__main__':
83    # Take time step from the first argument
84    main(float(sys.argv[1]), sys.argv[2])
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: python
19    args:
20      - ./src/other_model.py
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table

R Version

Model Code:

 1library(yggdrasil)
 2
 3
 4timestep_calc <- function(t) {
 5  state = list(carbonAllocation2Roots=units::set_units(10.0, 'g', mode="standard"),
 6               saturatedConductivity=units::set_units(10.0, 'cm/day', mode="standard"))
 7  return(state)
 8}
 9
10main <- function(t_step, t_units) {
11
12  fprintf('Hello from R other_model: timestep = %f %s', t_step, t_units)
13  t_step <- units::set_units(t_step, t_units, mode="standard")
14  t_start <- units::set_units(0.0, t_units, mode="standard")
15  t_end <- units::set_units(1.0, 'day', mode="standard")
16  state <- timestep_calc(t_start)
17
18  # Set up connections matching yaml
19  # Timestep synchronization connection will default to 'timesync'
20  timesync <- YggInterface('YggTimesync', 'timesync')
21  out <- YggInterface('YggOutput', 'output')
22
23  # Initialize state and synchronize with other models
24  t <- t_start
25  c(ret, state) %<-% timesync$call(t, state)
26  if (!ret) {
27    stop('other_model(R): Initial sync failed.')
28  }
29  fprintf('other_model(R): t = %5.1f %-1s',
30          units::drop_units(t), units::deparse_unit(t))
31  for (k in names(state)) {
32    fprintf(', %s = %+ 5.2f', k, state[[k]])
33  }
34  fprintf('\n')
35
36  # Send initial state to output
37  msg = state
38  msg[['time']] = t
39  flag <- out$send(msg)
40  if (!flag) {
41    stop(sprintf('other_model(R): Failed to send initial output for t=%s', t))
42  }
43
44  # Iterate until end
45  while (t < t_end) {
46        
47    # Perform calculations to update the state
48    t <- t + t_step
49    state <- timestep_calc(t)
50
51    # Synchronize the state
52    c(ret, state) %<-% timesync$call(t, state)
53    if (!ret) {
54      stop(sprintf('other_model(R): sync for t=%f failed.', t))
55    }
56    fprintf('other_model(R): t = %5.1f %-1s',
57            units::drop_units(t), units::deparse_unit(t))
58    for (k in names(state)) {
59      fprintf(', %s = %+ 5.2f', k, state[[k]])
60    }
61    fprintf('\n')
62
63    # Send output
64    msg = state
65    msg[['time']] = t
66    flag <- out$send(msg)
67    if (!flag) {
68      stop(sprintf('other_model(R): Failed to send output for t=%s.', t))
69    }
70  }
71
72  print('Goodbye from R other_model')
73  
74}
75
76
77args = commandArgs(trailingOnly=TRUE)
78main(as.double(args[[1]]), args[[2]])
  1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2<!--
  3	Simulation file for SimRoot version 5. This development version, build July 2007
  4	Author: Jouke Postma
  5	Note: 
  6	
  7	PLEASE KEEP THIS HEADER UP TO DATE! LIST BELOW WHO YOU ARE, WHEN AND WHAT CHANGES YOU MADE AND WHY. LIST YOUR SOURCE AS MUCH AS POSSIBLE!
  8
  9	change log: 
 10	11-july-07 added support for include files. 
 11	
 12	
 13-->
 14<!--STYLE SHEET SECTION: feel free to attach any stylesheet of your choosing-->
 15<!--?xml-stylesheet type="text/xsl" href="tree-view2.xsl"?-->
 16<?xml-stylesheet type="text/xsl" href="XML/treeview.xsl"?>
 17
 18<!--SIMULATION MODEL-->
 19<SimulationModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../scripts/XML/SimulaXMLSchema.xsd">
 20  
 21	<SimulaBase name="soil">
 22	</SimulaBase>	
 23
 24	
 25	<SimulaBase name="plants">
 26		<SimulaBase name="maize" objectGenerator="seedling">
 27			<SimulaConstant name="plantType" type="string">
 28			<!-- 	H99 w64a 36H56 noRCAinLaterals maize-aerenchyma--> 
 29				maize-aerenchyma
 30			</SimulaConstant>	
 31			<SimulaConstant name="plantingTime"  unit="day" type="time">
 32				0
 33			</SimulaConstant>	
 34			<SimulaConstant name="plantPosition" type="coordinate">
 35					0 -2 0
 36			</SimulaConstant>
 37		</SimulaBase>	
 38	</SimulaBase>	
 39
 40	<!-- <SimulaIncludeFile fileName="plantParameters/Maize/Maize/simulationControlParameters.xml"/> -->
 41	<SimulaBase name="simulationControls">
 42		<SimulaBase name="outputParameters">
 43			<SimulaBase name="defaults">
 44			<!-- optional section - if an export module section does not list end/start/interval times than you can specify a default here-->
 45				<SimulaConstant
 46					name="startTime"
 47					type="time"> 0.</SimulaConstant>
 48				<SimulaConstant
 49					name="endTime"
 50					type="time"> 1</SimulaConstant>
 51				<SimulaConstant
 52					name="timeInterval"
 53					type="time"> 1.</SimulaConstant>
 54			</SimulaBase>
 55			<SimulaBase name="probeAllObjects">
 56				<SimulaConstant
 57					name="run"
 58					type="bool">
 59					1 <!--this does not result in any output, just tries to run the code for debugging purposes-->
 60				</SimulaConstant>
 61				<SimulaConstant
 62					name="timeInterval"
 63					type="time">1</SimulaConstant>
 64				<SimulaConstant
 65					name="requestedVariables"
 66					type="string"> carbonAllocation2Roots, saturatedWaterContent,
 67				</SimulaConstant>
 68			</SimulaBase>	
 69			<SimulaBase name="table">
 70				<SimulaConstant
 71					name="run"
 72					type="bool"> 1</SimulaConstant>
 73				<!--SimulaConstant name="timeInterval" type="time"> 1.0	</SimulaConstant-->
 74				<SimulaConstant
 75					name="searchingDepth"
 76					type="integer"> 5</SimulaConstant>
 77				<SimulaConstant
 78					name="skipTheseVariables"
 79					type="string"> primaryRoot, hypocotyl,
 80				</SimulaConstant>
 81			</SimulaBase>
 82		</SimulaBase>
 83	</SimulaBase>
 84	
 85	<SimulaIncludeFile fileName="templates/plantTemplateFullModel.xml"/>
 86	<!-- SimulaIncludeFile fileName="environments/Rocksprings/Rocksprings-maize.xml"/-->
 87	<SimulaIncludeFile fileName="environments/WageningseBovenBuurt/WageningseBovenBuurt-maize.xml"/>
 88
 89	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeGeometry.xml" />
 90	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeDryweight.xml" />
 91
 92	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorusBC.xml" /-->
 93	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePhosphorus3D.xml" /-->
 94	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrateBasic.xml"/-->
 95	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeWaterModule.xml"/>
 96	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeNitrate3D.xml"/-->
 97	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludePotassium3D.xml" /-->
 98
 99	<SimulaIncludeFile fileName="templates/configurationCarbon.xml"/>
100	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeStress.xml"/>
101	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootHairs.xml"/>
102	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeAerenchyma.xml"/>
103	<SimulaIncludeFile fileName="templates/plantTemplate.IncludeRootLengthProfile.xml"/>
104	<!--SimulaIncludeFile fileName="templates/plantTemplate.IncludeLocalNutrientResponses.xml"/-->
105
106	<SimulaBase name="rootTypeParameters" >
107	  <!--SimulaIncludeFile fileName="plantParameters/Maize/H99/maize.xml"/>
108		<SimulaIncludeFile fileName="plantParameters/Maize/W64a/maize.xml"/>
109		<SimulaIncludeFile fileName="plantParameters/Maize/36H56/maize.xml"/-->
110	  <SimulaIncludeFile fileName="plantParameters/Maize/Maize/maize.xml"/>
111	</SimulaBase>
112</SimulationModel>
113
114

Model YAML:

 1models:
 2  - name: timesync
 3    language: timesync
 4    additional_variables:
 5      osr_model: [carbonAllocation2Roots, saturatedConductivity]
 6      other_model: [saturatedWaterContent]
 7  - name: osr_model
 8    language: osr
 9    timesync:
10      inputs:  [carbonAllocation2Roots, saturatedConductivity]
11      outputs: [saturatedWaterContent]
12    args:
13      - ./src/osr_model.xml
14    copy_xml_to_osr: True
15    update_interval:
16      timesync: 0.1
17  - name: other_model
18    language: R
19    args:
20      - ./src/other_model.R
21      - 3
22      - hr
23    timesync: True
24    outputs:
25      name: output
26      default_file:
27        name: other_model_output.txt
28        in_temp: True
29        filetype: table