Download apply object-oriented programming
Transcript
Bathtub1
delay
tub
to drain
1 Bathtub1 model {
2
delay = 2 ‘minutes‘
3
to_drain flow = bathtub / delay
4
bathtub stock = {
5
outflow: to_drain
6
initial: 500 ‘liters‘
7
}
8 }
Figure 5.1: Bathtub1 model definition
optional, and a stock initialization may contain multiple outflows, inflows and biflows. e initial parameter is required, and each stock initialization must contain an initial expression.
5.3.1 Main model
Because each modeling project (group of files) can define a number of models, it is necessary to have a
mechanism to decide which model to run when simulating the project. By convention, this is the model
named main. To run our Bathtub1 model, we would define a main model with a single instance of the
Bathtub object, along with specifications of how long the model should run for, as in figure 5.2. e
creation of an instance of the bathtub model is the same as initializing a stock, with the difference that the
Bathtub1
class name appears directly before the opening curly brace (‘{’) and the initialization parameters
are different. In the case of this model of a bathtub, there aren’t any initialization parameters needed.
Time is a special variable in Boosd. It can only be defined in the main model, to avoid confusion about
when the simulation should start, end and at which time step (dt) the model should run. It is initialized
39