Forum

Important Notice for New User Registrations

To combat an increasing number of spam and bot registrations, we now manually approve all new user registrations. While this may cause a delay until your account is approved, this step is essential to ensure the quality and security of this forum.

To help us verify your registration as legitimate, please use a clear name as user name or an official email address (such as a work, university, or similar address). If you’re concerned that we may not recognize your registration as non-spam, feel free to email us at with a request to approve your username.

Please or Register to create posts and topics.

Simulation Failed — Return all -1 but .sim file was loaded successfully

Hi All,

I have encountered something really strange here.  And I am writing this post to seek some assistance.

I was running the MATLAB script that I wrote successfully on my old Laptop, which has MATLAB R2022b installed. I downloaded the file on my new laptop, which has MATLAB R2025b installed, and the script does not work anymore. I got to successfully entered the simulation loop; however, all values are -1. I check the .sim file I have, and everything seems fine (can be opened by the QBlade.exe and run). Thus, I am really clueless here.

I am using MinGW64 Compiler (version 8.1.0), and I don’t have Visual Studio C++ Compiler installed. Below is my code. Could someone look at it and tell me why? Thanks in advance!

 

%% Helix of NREL5MW in script
clear
close all
addpath(‘.\Functions’);
%clc
%% Define paths
UserPath = ‘.\wakeMixing’;
QBladePath = ‘.\QBladeEE_2.0.9\’; % change
SourcePath = [UserPath ‘Source\’];
DllPath = [QBladePath ‘QBladeEE_2.0.9.dll’]; % change
simFile = [SourcePath ‘NREL5MW_1turbine.sim’];
addpath(‘.\Functions’);
loadlibrary(DllPath,’QBladeLibInclude.h’,’alias’,’QBladeDLL’)
m = libfunctions(‘QBladeDLL’);
if isempty(m)
fprintf(‘Error’)
end
%% Data file (Chage this accordingly)
simTime = 3000; % in timestep, actual time is simTime*timestep(Q-blade define)
timeStep = 0.1; % same with the Q-blade setting
simLen = simTime * timeStep; % seconds
%% Load project and Initialize simulation
%this is setup using relative path and depends on the location of this file
calllib(‘QBladeDLL’,’createInstance’,2,64);
calllib(‘QBladeDLL’,’setLibraryPath’,DllPath);
calllib(‘QBladeDLL’,’loadSimDefinition’,simFile);
calllib(‘QBladeDLL’,’initializeSimulation’)
% Variables
valuestr = ‘Rotational Speed [rpm]’;
valuestr2 = ‘Gen. HSS Torque [Nm]’;
valuestr3 = ‘Tip Speed Ratio [-]’;
Azimu1 = ‘Azimuthal Position Blade 1 [deg]’;
Azimu2 = ‘Azimuthal Position Blade 2 [deg]’;
Azimu3 = ‘Azimuthal Position Blade 3 [deg]’;
Pit1 = ‘Pitch Angle Blade 1 [deg]’;
Pit2 = ‘Pitch Angle Blade 2 [deg]’;
Pit3 = ‘Pitch Angle Blade 3 [deg]’;
PowerVar = ‘Aerodynamic Power [kW]’;
CpVar = ‘Power Coefficient [-]’;
Moop1Var = ‘Aero. OOP RootBend. Mom. Blade 1 [Nm]’;
Mip1Var = ‘Aero. IP RootBend. Mom. Blade 1 [Nm]’;
Moop2Var = ‘Aero. OOP RootBend. Mom. Blade 2 [Nm]’;
Mip2Var = ‘Aero. IP RootBend. Mom. Blade 2 [Nm]’;
Moop3Var = ‘Aero. OOP RootBend. Mom. Blade 3 [Nm]’;
Mip3Var = ‘Aero. IP RootBend. Mom. Blade 3 [Nm]’;
%% Set Turbulent Wind
U_inflow = 10; % Inflow wind speed, same with the Q-blade setting
D_NREL5MW = 126; % Rotor diameter
Hub_NREL5MW = 90; % Hub height
%% Defining Torque Control Setting
% This need to be changed when inflow windspeed is varied
K = 2.24;
N = 97; % Gearbox ratio
%% Simulation
% pre-define array to speed up code
TSR_store = zeros(simTime, 1);
Power_store = zeros(simTime, 1);
% blade 1
Moop1_store = zeros(simTime, 1);
Mip1_store = zeros(simTime, 1);
Mflap1_store = zeros(simTime, 1);
Medge1_store = zeros(simTime, 1);
% blade 2
Moop2_store = zeros(simTime, 1);
Mip2_store = zeros(simTime, 1);
Mflap2_store = zeros(simTime, 1);
Medge2_store = zeros(simTime, 1);
% blade 3
Moop3_store = zeros(simTime, 1);
Mip3_store = zeros(simTime, 1);
Mflap3_store = zeros(simTime, 1);
Medge3_store = zeros(simTime, 1);
Cp_store = zeros(simTime, 1);
%% Simulation
% start simulation
tic
f = waitbar(0,’Initializing Simulation’);
disp(“Initialized”)
for i = 1:1:simTime
calllib(‘QBladeDLL’,’advanceTurbineSimulation’);
% Get current value
omega = calllib(‘QBladeDLL’,’getCustomData_at_num’,valuestr, 0, 0);
genTorqueQB = calllib(‘QBladeDLL’,’getCustomData_at_num’,valuestr2, 0, 0);
TSR = calllib(‘QBladeDLL’,’getCustomData_at_num’,valuestr3, 0, 0);
Azimuth1 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Azimu1, 0, 0);
Azimuth2 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Azimu2, 0, 0);
Azimuth3 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Azimu3, 0, 0);
Pitch1 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Pit1, 0, 0);
Pitch2 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Pit2, 0, 0);
Pitch3 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Pit3, 0, 0);
Power = calllib(‘QBladeDLL’,’getCustomData_at_num’, PowerVar, 0, 0);
Cp = calllib(‘QBladeDLL’,’getCustomData_at_num’, CpVar, 0, 0);
Moop1 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Moop1Var, 0, 0);
Mip1 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Mip1Var, 0, 0);
Moop2 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Moop2Var, 0, 0);
Mip2 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Mip2Var, 0, 0);
Moop3 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Moop3Var, 0, 0);
Mip3 = calllib(‘QBladeDLL’,’getCustomData_at_num’, Mip3Var, 0, 0);
% ==================== Control
% I. Torque control to maintain optimal TSR of 9
omega_g = omega*N; % rotor to generator
genTorque = K.*(omega_g*(2*pi/60))^2;
% II. Send control signal to qblade
calllib(‘QBladeDLL’,’setControlVars_at_num’,[genTorque 0 …
0 0 0],0);
% ==================== Store values
% omega_store(i,:) = omega;
% genTorqueQB_store(i,:) = genTorqueQB;
% genTorque_store(i,:) = genTorque;
TSR_store(i) = TSR;
Power_store(i) = Power;
Cp_store(i) = Cp;
% blade 1
Moop1_store(i) = Moop1;
Mip1_store(i) = Mip1;
Mflap1_store(i) = Moop1*cosd(Pitch1) + Mip1*sind(Pitch1);
Medge1_store(i) = -Moop1*sind(Pitch1) + Mip1*cosd(Pitch1);
% blade 2
Moop2_store(i) = Moop2;
Mip2_store(i) = Mip2;
Mflap2_store(i) = Moop2*cosd(Pitch2) + Mip2*sind(Pitch2);
Medge2_store(i) = -Moop2*sind(Pitch2) + Mip2*cosd(Pitch2);
% blade 3
Moop3_store(i) = Moop3;
Mip3_store(i) = Mip3;
Mflap3_store(i) = Moop3*cosd(Pitch3) + Mip3*sind(Pitch3);
Medge3_store(i) = -Moop3*sind(Pitch3) + Mip3*cosd(Pitch3);
AzimuthAngles(i,:) = [Azimuth1 Azimuth2 Azimuth3];
PitchAngles(i,:) = [Pitch1 Pitch2 Pitch3];
waitbar(i/simTime, f, sprintf(‘Simulation Running: %.1f%%’, (i/simTime)*100));
end
close(f)
calllib(‘QBladeDLL’,’closeInstance’);
toc

Hi,

A return value of -1 generally means that the variable name was not found or the simulation did not advance correctly, so QBlade is returning its error/default value rather than real data. This often indicates initialization issues, invalid strings, or a failed simulation step. While its hard to pinpoint the exact issue a few things I would try:

1. Download the latest QBlade release

2. Check advanceTurbineSimulation() return value, if the simulation is advancing correctly “true” should be returned (function bool advanceTurbineSimulation();)

3. Enable a log file for further debugging – MATLAB won’t show QBlade’s console output: (function: void setLogFile(char *str);)

4. Check if your paths are correct (this might have changed when switching machines) try to use absolute paths.

5. Ensure all strings use plain ASCII apostrophes, not curly quotes. Many editors automatically replace straight ASCII quotes with curly typographic quotes during copy-and-paste, and although they look similar, MATLAB and DLLs interpret them as completely different characters.

6. Check if the variables you are requesting are actually stored during the simulation (verify this in the GUI). Variable filters or settings that only store data after a certain time can prevent those values from being available through the interface.

7. Finally, make sure the variable names you use in the Matlab script are exactly as in the QBlade graph.

Let me know is this helps to fix things on your side.

Best regards,

David

Hi David,

Thanks for the instruction.

The simulations run successfully, finally! Turns out the naming of the variables changed in the latest version. In addition, I also made a typo in the path definition. Just a quick follow-up question, I noticed that the generator torque is not an accessible variable anymore, instead, only the aerodynamic torque can be accessed. Could you tell me now to get access to the generator torque?

Best

Hi,

if you are running a simulation with a structural model the generator torque is output in the variable “Gen. HSS Torque [Nm]” found in the “Structural Time Graph”.

Best regards,

David

zcdc0429 has reacted to this post.
zcdc0429

Hey David,

Thanks for the help!

Just a quick question: is there a table that lists the names of all variables? I am doing this by reviewing the X-axis and Y-axis variable options in the “graphic view” of the QBlade software, then copying the corresponding names into the MATLAB script. That’s how I missed the generator torque variable totally.

Looking forward to your response. And again, really appreciate your help.

Best

Scroll to Top