Show/Hide Toolbars

HOMER Pro 3.16

Navigation: Design > Components Tab > Controller > MATLAB Link

MatlabDispatch Function

Scroll Prev Top Next More

HOMER Logo


HOMER calls MatlabDispatch at the beginning of each time step in the simulation.

[simulation_state, custom_variables] = MatlabDispatch(simulation_parameters, simulation_state, custom_variables)

MatlabDispatch has three input variables:

1.simulation_state: This structure contains variables that can vary in each time step of the simulation. You must set up some of the values for every time step (in the MatlabDispatch function) in order to control the operation of the system.

2.simulation_parameters: This structure contains variables that are defined by the HOMER Model. They are all read-only and do not change during the course of the simulation.

3.custom_variables: This user-defined variable is not used by HOMER. You can use it to keep track of values needed for your algorithm over the course of a simulation. This variable can be a structure, array, or scalar, depending on how you define it.

The following tables contain examples of commands you might use in your MatlabDispatch function.

Using a component (PV, Battery, Generator etc.)

Action

Command

Description

Check whether the component is present

simulation_parameters.has_generator

Check whether this variable is set to true before performing calculations for the component. Some optimization cases might exclude a component that is present in the model.

Check whether the component is on the AC or DC bus

simulation_parameters.generators.is_AC

Check whether the component is on the AC or DC bus. All actions of this component affect the buses accordingly.

Set the power the component should be producing

simulation_state.generators(i).power_setpoint = simulation_state.generators(i).power_available;

This command sets the generator number (i) to its maximum power output.

simulation_state.generators(i).power_setpoint = simulation_parameters.generators(i).minimum_load;

This command sets the generator number (i) to its minimum load.

simulation_state.generators(i).power_setpoint = simulation_state.generators(i).power_available * 0.8

Use only 80% of the power produced by the generator.

Add to the Operating Capacity

simulation_state.ac_bus.operating_capacity_served = simulation_state.ac_bus.operating_capacity_served + simulation_state.generators(i).power_available;

Depending on which bus the component uses, it contributes its maximum possible power available to the bus' operating capacity.

Note: The generator number, designated as (i), identifies which numbered generator you are addressing. The number can be anything from 0 to the maximum number of generators.

Setting Output Parameters for Each Time Step

It is important to set each of these parameters on both the AC and DC bus separately.

In the table below:

load_supplied_ac is the sum of all production on the AC bus.

operating_capacity_ac is the sum of the operating capacity of all components on the AC bus.

Parameter

Command

Description

Load Served

simulation_state.ac_bus.load_served = min(load_supplied_ac, simulation_state.ac_bus.load_requested);

Takes the minimum of the load produced on the AC bus and the AC load. If the load is completely satisfied, the load served should be equal to the load requested.

Unmet Load

simulation_state.ac_bus.unmet_load = max(simulation_state.ac_bus.load_requested - load_supplied_ac, 0);

If the load requested on the AC bus is completely met by the production on the AC bus, the unmet load is 0.

Excess Electricity

simulation_state.ac_bus.excess_electricity = max(load_supplied_ac - load_requested_ac, 0);

If production on the AC bus is more than requested, the remaining amount becomes excess electricity.

Operating Capacity Served

simulation_state.ac_bus.operating_capacity_served = operating_capacity_ac;

The sum of the renewable generation, the maximum battery discharge power (DC bus only), and the power available from all operating generators should not exceed the operating_capacity_requested.

Capacity Shortage

simulation_state.ac_bus.capacity_shortage = max(simulation_state.ac_bus.operating_capacity_requested - operating_capacity_ac, 0);

The capacity shortage occurs when the operating capacity served is less than than the operating capacity requested on that bus.

Notice that HOMER does not check whether your settings obey the laws of physics. You can set the value for the capacity shortage for each time step to whatever you like, independent of whether you actually turn on a generator or produce any power. It is important to set these values correctly to ensure accurate results.

The Listing of simulation_state section of the help lists the fields for the simulation_state variable; fields marked with an asterisk should be set by the MatlabDispatch function for each time step. If your algorithm does not support a component, you do not need to set any values for that component's fields.

See also

Controller

Cycle Charging