The first step is to import the MShePy module by the command import MShePy. The command will import the MShePy version corresponding to the specified Python version (see previous section).
The second step is to define at which point of the simulation custom functions defined in the plugin should be executed. MIKE SHE emits six different signals at predefined moments in the simulation. For each signal that is being emitted one or more plugin functions can be executed. The connection between the signal and the plugin function (or “slot”) is simply made by a naming convention. The function definitions are shown in Table 15.1 below.
The third step is to describe actions, which are executed at the defined moments during the simulation, possibly using functions available in the Python environment. An overview of functions included in the MShePy library is provided in the following section. The same plugin file can contain different functions executed at different moments in the simulation. A simple example is shown below for a function printing in the log file the initial timestep count (0) and then the timestep number at each timestep.
|
import MShePy |
#Import MShePy module |
|
timestep = 0 |
#Define a global variable |
|
def enterSimulator(): |
#Define the time slot |
|
global timeStep |
|
|
MShePy.wm.log("The timestep is {0}".format(timeStep)) |
#Print initial timestep in log file |
|
|
|
|
def postTimeStep(): |
#Define the time slot |
|
global timeStep |
|
|
MShePy.wm.log("The timestep is {0}".format(timeStep)) |
#Print timestep in log file |
|
timeStep +=1 |
#Calculate next time step |