function varargout = init_my_wind_ig_12(varargin)
% Model initialization function of power_wind_ig
% By default the functions loads the initial state vector xInitial to start
% the simulation in steady-state. This is done in the Model properties/
% Callbacks/ InitFcn section of the model. The vector is saved in a mat
% file.
% You can use this function to regenerate the initial state vector, after a
% change in the model, by typing: init_power_wind_ig(1) at the command line.
% Review the code below to make sure it still apply to your updated model.
%xInitial = init_my_wind_ig_12;
load my_wind_ig_12.mat
if nargin==0 && nargout==1
varargout{1} = xInitial;
end
% Regenerate initial state vector
if nargin==1
% 1. The name of the model is:
model = 'my_wind_ig_12';
disp(['Regenerate initial state vector of ',model,' model:'])
% 2. Make sure the model is loaded in memory
open_system(model);
% 3. Deactivate programmed transients:
disp('- Deactivate programmed transients...')
block = [model,'/Wind Farm/Three-Phase Fault'];
set_param(block,'FaultA','off');
set_param(block,'FaultB','off');
set_param(block,'FaultC','off');
set_param(block,'GroundFault','off');
% 4. Estimated time to reach steady-state:
StopTime = '50'; % time to reach steady-state
% 5. Simulate to reach steady-state:
disp('- Running the model to steady-state...')
simout = sim(model,'LoadInitialState','off','SaveFinalState','on','StopTime',StopTime);
% 6. Get the new initial state values:
disp('- Get the new initial state vector...')
xInitial = simout.get('xFinal');
% 7. Save the initial state vector in mat file:
save my_wind_ig_12.mat xInitial
disp('- Closing the model...')
close_system(model,0)
disp('Done.')
end