Download ModelWorks - Terrestrial Systems Ecology
Transcript
ModelWorks 2.0 - Theory 5.1.2.c Elementary simulation run This level can always be accessed by the simulationist directly without going through the experiment level (see above)4 by choosing the menu command Start run under menu Simulation. Otherwise this level is the next level below the level of the structured simulation (Experiment) (Fig. T16). An elementary simulation run is provided by ModelWorks and has not to be programmed by the modeler. It is exactly the same as calling the procedure SimMaster.SimRun via the client interface. ModelWorks supports this level by requiring the modeler to specify for each model an Initialize and Terminate procedure. The organization of an elementary simulation run is shown in more details in Fig. T17. ModelWorks will execute for every model in the sequence of their declaration the Initialize procedures once at the begin of the simulation run and the Terminate procedures once at the end of the simulation run. Note that the execution of the Initialize procedures happens at a moment when ModelWorks has already assigned the initial values to all state variables. This is important to know, since this design makes it possible to overwrite the values assigned by ModelWorks with other values, for instance during a structured simulation which is used to draw a phase portrait. Typical use of Initialize and Terminate procedures is also the opening and closing of a file at the begin respectively the end of a simulation run in order to write simulation results onto a file different from the stash file. Note also that in contrast to the procedure md passed to ModelWorks as actual argument in the call to procedure RunSimMaster (it is called only once per simulation session and typically declares the models and model objects), the procedures Initialize and Terminate may be called many, i.e. n or n!k times during a single simulation session. The actual number depends on how many times the simulationist starts a simulation run directly or via an experiment and is not known to the modeler. Whenever ModelWorks calls client procedures such as procedures Initialize or Terminate, the calling sequence is the same as the declaration order in the model definition program. 5.1.2.d Integration or time step The lowest level is that of an integration or time step. ModelWorks supports this level by requiring the modeler to specify for each model an Input, Output, and Dynamic client procedure. ModelWorks will execute for every model the Output, Input, and Dynamic procedures during every integration step at least once. Only Dynamic may be called from once up to times the order of the current integration method during a single integration step. Note also that in contrast to the procedures Initialize and Terminate (which are called only once per simulation run), the procedures Input, Output, and Dynamic are called many, i.e. i times during an elementary simulation run (Fig. T16). In the integration loop, user commands, such as pausing or stopping the simulation, are processed first. This enables an interactive control of the simulation. After that, the client procedures of the models are called. Their calling sequence guarantees a correct coupling of more than one model, independently of their installation order (see also chapter Model formalisms). The calculation order which meets all these requirements is shown in Fig. T18: First, the Output procedures of all models, then all Input procedures are called. Thereafter, the numerical integration can be done. Depending on the integration algorithm, the procedure Dynamic will be called once or several times for the evaluation of the derivatives. Every submodel is integrated as an independent unit. Therefore it is possible to integrate different submodels with different integration algorithms. This can be of interest if some models are numer- 4This level could also be understood as a structured simulation (experiment) with k=1 (see above). T 53