Specifying the Model Code
The workflow for for model development, debugging and analysis in Magnolia is relatively simple. The following steps summarize the tasks involved in creating and running a Magnolia model.
Creating and Opening a Model
A new model can be created by selecting “File -> New -> CSL Model” from the main menu or toolbar. A skeleton CSL file (shown below) will be displayed in a code editor, which can then be edited. Alternatively, an existing model can be opened using either the appropriate main menu/toolbar buttons, or by navigating the filesystem in the browser window and double-clicking the desired file. The model will be built upon loading; and errors in the model will be displayed in the alerts window and command window after the model is loaded.
A detailed explanation of CSL syntax is presented in the "Modeling Language Overview" and "CSL Language Reference" sections.
!
! Magnolia CSL model file
!
model Model_1
initial
! The INITIAL section contains statements which are evaluated
! once at the beginning of the simulation run
end ! initial
dynamic
! The DYNAMIC section contains statements which are evaluated
! at each output time point
derivative
! The DERIVATIVE section contains statements which are
! used to compute derivatives
! Example: exponential decay
constant k = 1.0 ! Decay rate constant
constant xic = 10.0 ! Initial condition
xd = -k*x ! Derivative
x = integ(xd, xic) ! Integrate derivative to compute state
constant tstop = 10.0
termt(t >= tstop, 'Stopped on time limit')
end ! derivative
discrete DISCRETE_1
! DISCRETE sections contain statements which are only
! evaluated at specific time points. A model
! can contain an arbitrary number of DISCRETE sections.
end ! DISCRETE_1
end ! dynamic
terminal
! The TERMINAL section contains statements which are evaluated
! once at the conclusion of the simulation run
end
end ! program
Building the Model
The model is built (translated and compiled) both when it is opened, and when it is executed. This process happens quickly even for large files. A small “wait” dialog is show during this process, but this dialog may be visible for only a fraction of a second.