Show/Hide Toolbars

HOMER Pro 3.16

Navigation: Design > Components Tab > Controller > MATLAB Link

MatlabStartSimulation Function

Scroll Prev Top Next More

HOMER Logo


HOMER calls MatlabStartSimulation before each simulation.

[myErr, custom_variables] = MatlabStartSimulation(simulation_parameters)

The MatlabStartSimulation function checks the problem, returns errors if needed, and initializes values in the custom_variables output if desired. In some cases, this function is nearly empty. It must at least initialize the return arguments myErr and custom_variables to be a valid function.

The simulation_parameters variable contains all the information about the current system and the current simulation, such as information about each generator, PV, converter, or battery in the system, as well as the load. You can return errors in the myErr variable. For example, a dispatch algorithm is designed to handle systems with components on the AC bus only, with no DC components or converter. You can check the simulation_parameters variable to see if each generator, PV, battery, and load in the system is on the AC bus. You can also check that there is no converter. If any of those conditions are not met, the function returns a "simulation" error with a message like: "This MATLAB dispatch can't handle DC components."

The myErr variable must contain two fields: error_description and severity_code. The error_description text string is displayed to the user. The severity_code can be set to DISPATCH_SIMULATION_ERROR or DISPATCH_CRITICAL_ERROR. If the value is set to anything else; i.e., blank; there is no error. Depending on the severity code of the error returned, HOMER skips the simulation or the entire calculation run.

You can also set values for the custom_variables output here. HOMER does nothing with the values in this variable, but you can use it to save values for use in MatlabDispatch and MatlabEndSimulation. You can also change the values in custom_variables in each time step in the MatlabDispatch function.

The following table contains examples of commands you might use in your MatlabStartSimulation function.

Command

Description

myErr.error_description = 'Danger!';

This text error message is displayed to the user in the Suggestions list in the lower-left part of the HOMER page. You must set one of the two severity codes below or the error does nothing.

myErr.severity_code = 'DISPATCH_SIMULATION_ERROR';

Setting this severity code skips the simulation.

myErr.severity_code = 'DISPATCH_CRITICAL_ERROR';

Setting this severity code skips the rest of the calculation.

custom_variables.anything = 0;

You can add fields to custom_variables and use or modify them later in MatlabDispatch.

See also

Controller

Cycle Charging