Initialization

It's often useful to create a model outside of the context of simulation, such as when developing the model or harnessing the models for analysis purposes. The initialize function provides this behavior.

The preferred method is the do form. It works like this:

initialize(user_data; init_fcn = ...) do my_model

    # Do something with my_model.

end

This is particularly helpful when the model uses Resources, because this makes sure the resources are closed when the model is no longer necessary.

Further, this works with a model description directly, in which case no init_fcn is necessary:

initialize(model_description) do my_model

    # Do something with my_model.

end

Using the do form isn't required. Two other methods exist:

my_model = initialize(user_data; init_fcn = ...)
my_model = initialize(model_description)

See below for the full interface.

SystemsOfSystems.initializeFunction
initialize(user_data; init_fcn, seed = 0, t_start = 0)

Creates the initial model form from the given user_data, init_fcn, seed, and start time, t_start. See simulate for a definition of these inputs.

If the model_description contains any resources (open files, connections), call Base.close(model_description, model) to release those resources. Alternatively, consider using the do form: initialize(user_data) do model ... end.

source
initialize(model_description; seed = 0, t_start = 0)

Creates the initial model form from the given ModelDescription, seed, and start time, t_start.

If the model_description contains any resources (open files, connections), call Base.close(model_description, model) to release those resources. Alternatively, consider using the do form: initialize(model_description) do model ... end.

source
initialize(f, user_data; init_fcn, kwargs...)

This form of initialize allows the do pattern, like so:

initialize(user_data; init_fcn = ..., kwargs...) do m
    # Do something with model m.
    ...
end

This is useful when a model opens a resource, like a file. When the do block is finished, this function will automatically close all opened resources, even if there was an error.

Optional keyword arguments:

  • seed: An integer or BranchingSeed
  • t_start: The time to use for initialization
source
initialize(f, model_description::ModelDescription; kwargs...)

This form of initialize allows the do pattern:

initialize(model_description; kwargs...) do m
    # Do something with model m.
    ...
end

This is useful when a model opens a resource, like a file. When the do block is finished, this function will automatically close all opened resources, even if there was an error.

Optional keyword arguments:

  • seed: An integer or BranchingSeed
  • t_start: The time to use for initialization
source