Show/Hide Toolbars

HOMER Pro 3.16

Navigation: Design > Components Tab > Controller

Controller Troubleshooting

Scroll Prev Top Next More

HOMER Logo


If you see the "DLL Load Library Failed. Error Code ..." error message when you calculate your system, HOMER could not use the DLL containing the control algorithm for one or more of your controllers. If your system contains several controllers (listed as tab on the Controller Set Up page), calculate the system with one controller at a time to figure out which one is causing the error.

 

Generator Order or Combined Dispatch Troubleshooting

If you are using a controller—Generator Order or Combined Dispatch — when you encounter this error, then there might be a problem with your DLL, such as missing dependencies. Sometimes failure to load a DLL can be caused by missing libraries on your computer. Installing the Visual C++ Redistributable from Microsoft might help:  https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads For 64-bit installations of HOMER, download the x64 version of the redistributable. For 32-bit HOMER installations, download the x86 version. 

         If you still continue to get the error message, then you might have a corrupt installation of HOMER. Uninstall HOMER. Ensure that all of its directories (the HOMER Energy folders in Documents and in Program Files) are deleted. Reinstall HOMER. If the problem still occurs, contact us at customer support: support@homerenergy.com.

MATLAB Troubleshooting

The most likely cause for this error is improper configuration of the MATLAB Link controller. If errors occur while running the MATLAB dispatch, you may see the message "No feasible solutions found."

shots_components_controller_matlab_no_feasible

First, ensure that your system actually produces at least one feasible result by running your system with one of the original HOMER dispatch algorithms, Cycle Charging or Load Following.

"DLL Load Library Failed"

Look in the message list in the lower-left corner of the HOMER page for specific error messages. You can hover your mouse over a message or click on it to see the full message text. One potential issue is that HOMER might be unable to find your MATLAB installation. If this occurs, the DLL Load Library Failed error message appears.

shots_components_controller_matlab_dll_load_fail

There are three common causes for this error message:

The "Path to the MATLAB installation directory" input is incorrect.

The "Path to the MATLAB installation directory" points to a 32-bit/64-bit version of MATLAB and you are using 64-bit HOMER Pro, or it points to a 64-bit version of MATLAB and you are using 32-bit HOMER Pro.

Your MATLAB license is expired.

If you see this message, ensure that the path specified for the input "Path to the MATLAB installation directory" is correct. Also check that you are accessing the correct version of MATLAB (32-bit or 64-bit) to match your version of HOMER Pro. If you are using the 64-bit version of HOMER Pro, you'll see the letters "x64" in the HOMER Pro title bar. On most 64-bit computers, 32-bit programs are installed in "Program Files (x86)" and not in "Program Files". If you need a different version of MATLAB, you can download it from the MathWorks website. You can have both 32-bit and 64-bit versions of both MATLAB and HOMER Pro installed on your computer at the same time.

Make sure you can run MATLAB outside of HOMER Pro. If you do not have an active MATLAB license, the MATLAB Link does not work.

"Cannot start Matlab Engine: code -3"

If HOMER is able to find your MATLAB installation, but it cannot open MATLAB. One possible cause of this error is that your installation of MATLAB is not registered with your operating system. To fix it, open a command window as administrator (right-click on the Command window icon and choose "run as administrator." Enter the command "matlab /regserver" to tell MATLAB to re-register itself on your computer.

"Error Using cd"

If HOMER is able to find your MATLAB installation, but not the working directory you specified, the "MATLAB error: Error using cd..." error message appears in the message list in the lower-left corner of the HOMER Pro window.

shots_components_controller_matlab_cd_fail

Hover your mouse over the message to see the full text. If you see this error, check the path you specified for the "Working directory" entry. The path might be spelled wrong or not exist. HOMER gives MATLAB the cd('C:\your\path') command where "C:\your\path" is the path you specified for the "Working directory" entry, and MATLAB gives an error. If it is not clear by checking the path name, open MATLAB and use the "cd" command to debug this step.

MATLAB Error While Executing

When the steps above are completed, HOMER sends the simulation_parameters variable to the MATLAB workspace, and then calls your MatlabStartSimulation command using the syntax listed above. If any of the three functions are missing, or if the names are spelled wrong, HOMER provides the corresponding error message in the Suggestions area in the lower-left area of the page when the calculation is finished.

shots_components_controller_matlab_error

You can hover your mouse over the message or click it to see the full text of the error message. In this example, the full text of the message is:

MATLAB error while executing '[new_simulation_state, custom_variables] = MatlabDispatchWrong(simulation_parameters, simulation_state, custom_variables);': Undefined function 'MatlabDispatchWrong for input arguments of type 'struct'.

This message can be broken down into several parts to make it easier to understand. The first part of the message says: MATLAB error while executing 'stuff':. The stuff in quotes is the exact command that HOMER gives to MATLAB. In this example, it is:

[new_simulation_state, custom_variables] = MatlabDispatchWrong(simulation_parameters, simulation_state, custom_variables);

Verify that this command is correct. The second part of the error message is the exact message from MATLAB:

Undefined function 'MatlabDispatchWrong' for input arguments of type 'struct'.

This as MATLAB's way of stating that it could not find the MatlabDispatchWrong function. The error message provides information about what went wrong.

Another issue is that your M-file might cause an error while it is running. If that happens, the error message is similar to the example above, except the second part of the message, which contains MATLAB's exact error message, is different. It states what went wrong and may give you the number of the line in your M-file where the error occurred. For example:

MATLAB error while executing '[new_simulation_state, custom_variables] = MatlabDispatch(simulation_parameters, simulation_state, custom_variables);': Reference to non-existent field 'wrong_field_name'. Error in MatlabDispatch (line 30) simulation_state.wrong_field_name;

You can see from the error message that the MatlabDispatch function tried to access a field of the simulation_state structure that does not exist, and it happened on line 30 of that function (which is written in the MatlabDispatch.m file).

If you still continue to get the error message, then you might have a corrupt installation of HOMER. Uninstall HOMER. Ensure that all of its directories (the HOMER Energy folders in Documents and in Program Files) are deleted. Reinstall HOMER. If the problem still occurs, contact us at customer support: support@homerenergy.com.

 

Debugging an Engine Crash

 

It’s possible to cause the simulation engine to crash from your MATLAB code by setting simulation variable values that can’t be handled in the engine. For example, setting values to NaN (not-a-number) in simulation_state could cause a crash. If the simulation crashes, it will return an error message like “Engine terminated abnormally” or “Exit code -2”, visible in the “Helpful Tips” section of the user interface. It’s possible-- but rare-- that there could be a bug in the simulation engine. To check, you can add a built-in controller like Cycle-Charging to see if the simulation is able to run normally. If it can, it’s probably your MATLAB that’s causing the problem.

One way to debug your code is to write the MATLAB workspace to disk from your MatlabDispatch function by using the save() command (https://www.mathworks.com/help/matlab/ref/save.html). This is described above under “Debugging Interactively”. Write the command so it’s called every time your code is called (i.e., don’t put “save” inside an “if” statement) The MatlabDispatch function is called over and over, for each timestep (8,760 with an hourly simulation) for each simulation. Your code will save the workspace again every timestep until the engine crashes. The file that’s left after the run (and the crash) will contain the variable values that caused the engine to crash.

Tips for debugging your MATLAB code:

                - Make the HOMER model as simple as possible (part 1): Remove components one by one until you find the minimum set of components necessary to reproduce the crash.

                - Make the HOMER model as simple as possible (part 2): Turn off the optimizer on all components – use the search space only. Enter a single value in the search space. Don’t include a zero (remove a component if it isn’t needed to reproduce the crash). Set up the problem so only a single simulation runs.

                - Make the HOMER model as simple as possible (part 3): Remove sensitivity variables. It’s possible that only certain combinations of sensitivity variables cause a crash – figure out that combination and run only that one. Again, set up the problem so that calculating runs only a single simulation. (see this for more information on the sensitivity-optimization-simulation approach in HOMER: https://support.ul-renewables.com/homer-manuals-pro/solving_problems_with_homer.html)

                - Add the MATLAB “save” command to your functions (described above under “Debugging Interactively”) so you can run your functions interactively in MATLAB. Remove “save” when you’re done debugging to help your code run faster.