Code covered by the BSD License  

Highlights from
Co-Blade: Software for Analysis and Design of Composite Blades

image thumbnail

Co-Blade: Software for Analysis and Design of Composite Blades

by

 

18 Sep 2012 (Updated )

Analysis and design of composite blades for wind and hydrokinetic turbines

startDataGUI(iSIM, SIM, OPT, BLADE, WEB, AF, Panel, LaminaSS)
function startDataGUI(iSIM, SIM, OPT, BLADE, WEB, AF, Panel, LaminaSS)

%% re-assign some structure variable names (for convenience)                 
NUM_SEC = BLADE.NUM_SEC;

%%                                                            
figTitle = [SIM.case{iSIM} ': Data Visualization'];
figPlot  = figure('name', figTitle, ...
                  'color', 'white', ...
                  'units','normalized',...
                  'outerposition',[0.1 0.1 0.8 0.8], ...
                  'NumberTitle', 'off');
              
figTitle = [SIM.case{iSIM} ': Data Selection Menu'];
figMenu  = figure('name', figTitle, ...
                  'color', 'white', ...
                  'units','normalized',...
                  'outerposition',[0.05 0.1 0.4 0.8], ...
                  'MenuBar', 'none', ...
                  'NumberTitle', 'off');

%% Define parameters for a uitable
figure(figMenu)
clf

colnames = {'Stn', 'Top Panel', 'Top Layer', 'Bot. Panel', 'Bot. Layer', 'Web Panel', 'Web Layer'};
colfmt   = {'char', 'char', 'char', 'char', 'char', 'char', 'char'};
coledit  = [false true true true true true true];
colwdt   = {40,'auto','auto','auto','auto','auto','auto'};
pos      = [0.02 0.02 0.96 0.73]; %[left bottom width height]
htable   = uitable('Parent',                figMenu, ...
                   'Units',                 'normalized', ...
                   'Position',              pos, ...
                   'Data',                  [], ... 
                   'RowName',               [], ...
                   'ColumnName',            colnames, ...
                   'ColumnFormat',          colfmt, ...
                   'ColumnWidth',           colwdt, ...
                   'ColumnEditable',        coledit);

% Create three check boxes to toggle plots for top/bottom/web surfaces
pan1 = uicontrol('Parent',   figMenu, ...
                 'Style',    'frame', ...
                 'Units',    'normalized', ...
                 'Position', [0.02 0.77 0.3 0.21]); %[left bottom width height]
cb1  = uicontrol('Parent',   figMenu, ...
                 'Style',    'checkbox',...
                 'Units',    'normalized',...
                 'Position', [0.03 0.94 0.25 0.03],...
                 'String',   'Plot Top Surfaces',...
                 'Value',    0);
cb2  = uicontrol('Parent',   figMenu, ...
                 'Style',    'checkbox',...
                 'Units',    'normalized',...
                 'Position', [0.03 0.9 0.25 0.03],...
                 'String',   'Plot Bottom Surfaces',...
                 'Value',    0);
cb3  = uicontrol('Parent',   figMenu, ...
                 'Style',    'checkbox',...
                 'Units',    'normalized',...
                 'Position', [0.03 0.86 0.25 0.03],...
                 'String',   'Plot Web Surfaces',...
                 'Value',    0);
cb4  = uicontrol('Parent',   figMenu, ...
                 'Style',    'checkbox',...
                 'Units',    'normalized',...
                 'Position', [0.03 0.82 0.25 0.03],...
                 'String',   'Plot LE and TE',...
                 'Value',    1);
cb5  = uicontrol('Parent',   figMenu, ...
                 'Style',    'checkbox',...
                 'Units',    'normalized',...
                 'Position', [0.03 0.78 0.25 0.03],...
                 'String',   'Plot Cross Sections',...
                 'Value',    1);
             
% create a radio-button to select to plot panel data or layer data
rb  = uibuttongroup('Parent',   figMenu, ...
                    'Units',    'Normalized', ...
                    'Position', [0.34 0.9 0.64 0.08]); %[left bottom width height]
rb1 = uicontrol('Parent',   rb, ...
                'Style',    'radio', ...
                'Units',    'normalized',...
                'Position', [0.02 0.52 0.46 0.46],...
                'String',   'Panel Data');
rb2 = uicontrol('Parent',   rb, ...
                'Style',    'radio', ...
                'Units',    'normalized',...
                'Position', [0.52 0.52 0.46 0.46],...
                'String',   'Layer Data');
set(rb,'SelectedObject',rb2);

% create a pop-up list to select the panel property
panelChoices = {'t:      thickness', ...
                'E_eff:  effective Young''s modulus', ...
                'G_eff:  effective shear modulus', ...
                'nu_eff: effective Poisson ratio'};
panelMenu = uicontrol('Parent',   rb, ...
                      'Style',    'popupmenu',...
                      'Units',    'normalized',...
                      'Position', [0.02 0.02 0.46 0.46],...
                      'String',   panelChoices, ...
                      'FontName', 'FixedWidth', ...
                      'BackgroundColor', 'white');

% create a pop-up list to select which the layer property
layerChoices = {'e_11_maxabs: normal strain', ...
                'e_22_maxabs: transverse strain', ...
                'e_12_maxabs: shear strain', ...
                's_11_maxabs: normal stress', ...
                's_22_maxabs: transverse stress', ...
                's_12_maxabs: shear stress', ...
                's_11_fc_T:   max stress failure criteria (normal tension)', ...
                's_11_fc_C:   max stress failure criteria (normal compression)', ...
                's_22_fc_T:   max stress failure criteria (transverse tension)', ...
                's_22_fc_C:   max stress failure criteria (transverse compression)', ...
                's_12_fc_S:   max stress failure criteria (shear)'};
layerMenu = uicontrol('Parent',   rb, ...
                      'Style',    'popupmenu',...
                      'Units',    'normalized',...
                      'Position', [0.52 0.02 0.46 0.46],...
                      'String',   layerChoices, ...
                      'FontName', 'FixedWidth', ...
                      'BackgroundColor', 'white');

% create text boxes to select min and max stations to plot
box1 = uicontrol('Parent',   figMenu, ...
                 'Style',    'edit', ...
                 'Units',    'Normalized', ...
                 'Position', [0.34 0.86 0.05 0.03], ... %[left bottom width height]
                 'String',   1, ...
                 'BackgroundColor', 'white', ...
                 'Callback', @data_callback);
box2 = uicontrol('Parent',   figMenu, ...
                 'Style',    'edit', ...
                 'Units',    'Normalized', ...
                 'Position', [0.34 0.83 0.05 0.03], ...
                 'String',   num2str(NUM_SEC), ...
                 'BackgroundColor', 'white', ...
                 'Callback', @data_callback);
             
% Create a text label to say what edit boxes do
txt1 = uicontrol('Parent',     figMenu, ...
                 'Style',      'text',...
                 'Units',      'normalized',...
                 'Position',   [0.40 0.87 0.2 0.02],...
                 'String',     'Inboard Station',...
                 'FontWeight', 'normal', ...
                 'BackgroundColor', 'white', ...
                 'HorizontalAlignment', 'left');
txt2 = uicontrol('Parent',     figMenu, ...
                 'Style',      'text',...
                 'Units',      'normalized',...
                 'Position',   [0.40 0.84 0.2 0.02],...
                 'String',     'Outboard Station',...
                 'FontWeight', 'normal', ...
                 'BackgroundColor', 'white', ...
                 'HorizontalAlignment', 'left');
txt3 = uicontrol('Parent',     figMenu, ...
                 'Style',      'text',...
                 'Units',      'normalized',...
                 'Position',   [0.34 0.79 0.64 0.03],...
                 'String',     'In the table below edit ONLY the values between square brackets []',...
                 'FontWeight', 'normal', ...
                 'BackgroundColor', 'white', ...
                 'HorizontalAlignment', 'left');  
txt4 = uicontrol('Parent',     figMenu, ...
                 'Style',      'text',...
                 'Units',      'normalized',...
                 'Position',   [0.34 0.76 0.64 0.03],...
                 'String',     'to select which panels and layers to visualize.',...
                 'FontWeight', 'normal', ...
                 'BackgroundColor', 'white', ...
                 'HorizontalAlignment', 'left');             
% create a push botton to update the plot
pb1 = uicontrol('Parent',     figMenu, ...
                'Style',      'pushbutton',...
                'Units',      'normalized',...
                'Position',   [0.68 0.84 0.30 0.05],... 
                'String',     'Update Plot',...
                'Callback',   @plot_callback);
            
data_callback            
     
figure(figPlot)
clf
view(50,20)
plot_callback

%%
% Subfuntions implementing the callbacks
% ------------------------------------------

    function plot_callback(hObject, eventdata)
    % hObject     Handle to Plot menu
    % eventdata   Not used

    figure(figPlot);
    [az el] = view;
    clf(figPlot)

    PlotSurf.Top       = get(cb1,'Value');
    PlotSurf.Bot       = get(cb2,'Value');
    PlotSurf.Web       = get(cb3,'Value');
    PlotSurf.LE_TE     = get(cb4,'Value');
    PlotSurf.CrossSec  = get(cb5,'Value');
    PlotSurf.Data      = get(get(rb,'SelectedObject'),'String');
    panelSelected      = get(panelMenu,'Value');
    panelString        = get(panelMenu,'String');
    layerSelected      = get(layerMenu,'Value');
    layerString        = get(layerMenu,'String');
    PlotSurf.panelData = panelString{panelSelected};
    PlotSurf.layerData = layerString{layerSelected};
        
    stn1 = str2double(get(box1,'string'));
    stn2 = str2double(get(box2,'string'));
    
    % Obtain the most recent data when the user hits the plot button
    newData = get(htable, 'Data');
    ijEdit  = getEditableIndex(newData);
    
    iiTopPanel = zeros(0,1);
    iiTopLayer = zeros(0,1);
    iiBotPanel = zeros(0,1);
    iiBotLayer = zeros(0,1);
    iiWebPanel = zeros(0,1);
    iiWebLayer = zeros(0,1);
    for n = 1:length(ijEdit)
        if     ijEdit(n,2) == 2
            iiTopPanel = [iiTopPanel; ijEdit(n,1)];
        elseif ijEdit(n,2) == 3
            iiTopLayer = [iiTopLayer; ijEdit(n,1)];
        elseif ijEdit(n,2) == 4
            iiBotPanel = [iiBotPanel; ijEdit(n,1)];
        elseif ijEdit(n,2) == 5
            iiBotLayer = [iiBotLayer; ijEdit(n,1)];
        elseif ijEdit(n,2) == 6
            iiWebPanel = [iiWebPanel; ijEdit(n,1)];
        elseif ijEdit(n,2) == 7
            iiWebLayer = [iiWebLayer; ijEdit(n,1)];
        end
    end
    
    PlotSurf.TopPanel = cell(NUM_SEC,1);
    PlotSurf.BotPanel = cell(NUM_SEC,1);
    PlotSurf.WebPanel = cell(NUM_SEC,1);
    PlotSurf.TopPanel(stn1:stn2) = newData(iiTopPanel,2);
    PlotSurf.BotPanel(stn1:stn2) = newData(iiBotPanel,4);
    PlotSurf.WebPanel(stn1:stn2) = newData(iiBotPanel,6);
    
    jTop = 0;  
    jBot = 0;
    jWeb = 0;
    topLayer = newData(iiTopLayer,3);
    botLayer = newData(iiBotLayer,5);
    webLayer = newData(iiWebLayer,7);
    for i = stn1:stn2
        iTop = jTop + 1;
        jTop = iTop + Panel(i).Top.nPanels - 1;
        PlotSurf.TopLayer(i).layer = topLayer(iTop:jTop);
        
        iBot = jBot + 1;
        jBot = iBot + Panel(i).Bot.nPanels - 1;
        PlotSurf.BotLayer(i).layer = botLayer(iBot:jBot);
        
        if Panel(i).Web.nPanels == 0
            iWeb = jWeb;
            jWeb = iWeb;
            PlotSurf.WebLayer(i).layer = {};
        else
            iWeb = jWeb + 1;
            jWeb = iWeb + Panel(i).Web.nPanels - 1;
            PlotSurf.WebLayer(i).layer = webLayer(iWeb:jWeb);
        end       
    end

    plotSurfaceData(OPT, BLADE, WEB, AF, stn1, stn2, Panel, PlotSurf, LaminaSS);
    
    view(az, el)
    figure(figMenu);
    
    end % function plot_callback

% ------------------------------------------

    function data_callback(hObject, eventdata)
    % hObject     Handle to Plot menu
    % eventdata   Not used
    % compute the table data

    stn1 = str2double(get(box1,'string'));
    stn2 = str2double(get(box2,'string'));
    
    if ~mod(stn1,1) == 0 || ~mod(stn2,1) == 0 || stn1 > stn2 || stn1 < 1 || stn2 > NUM_SEC
        error('ERROR: stn1 and stn2 must be positive integers, and 1 <= stn1 < stn2 <= NUM_SEC');
    end
    
    data = cell(0,7); 
    for n = stn1:stn2

        maxPanels = max([Panel(n).Top.nPanels; ...
                         Panel(n).Bot.nPanels; ...
                         Panel(n).Web.nPanels]);
        nLam                           = zeros(maxPanels,3);
        nLam(1:Panel(n).Top.nPanels,1) = Panel(n).Top.nLam;
        nLam(1:Panel(n).Bot.nPanels,2) = Panel(n).Bot.nLam;
        nLam(1:Panel(n).Web.nPanels,3) = Panel(n).Web.nLam;
        maxLam = max(nLam,[],2);

        lamBuf = cell(maxPanels,3);   
        for m = 1:maxPanels
            lamBuf{m,1} = cell(maxLam(m),1);
            lamBuf{m,2} = cell(maxLam(m),1);
            lamBuf{m,3} = cell(maxLam(m),1);
            % top
            for k = 1:Panel(n).Top.nPanels
                ii  = Panel(n).Top.nLam(k);
                lamBuf{k,1}(1:ii) = Panel(n).Top.matName{k};
            end
            % bottom
            for k = 1:Panel(n).Bot.nPanels
                ii  = Panel(n).Bot.nLam(k);
                lamBuf{k,2}(1:ii) = Panel(n).Bot.matName{k};
            end
            % webs
            for k = 1:Panel(n).Web.nPanels
                ii  = Panel(n).Web.nLam(k);
                lamBuf{k,3}(1:ii) = Panel(n).Web.matName{k};
            end
        end

        bufPan                           = cell(maxPanels,3);
        bufPan(1:Panel(n).Top.nPanels,1) = num2cell( 1:Panel(n).Top.nPanels );
        bufPan(1:Panel(n).Bot.nPanels,2) = num2cell( 1:Panel(n).Bot.nPanels );
        if Panel(n).Web.nPanels >= 1
        bufPan(1:Panel(n).Web.nPanels,3) = num2cell( 1:Panel(n).Web.nPanels );
        end

        cHeader = {n, ['[' num2str(1:Panel(n).Top.nPanels) ']'], [], ...
                      ['[' num2str(1:Panel(n).Bot.nPanels) ']'], [], ... 
                      ['[' num2str(1:Panel(n).Web.nPanels) ']'], []};
        c_stn = cell(0,7);
        for m = 1:maxPanels
            c1    = {[], bufPan{m,1}, select(lamBuf{m,1}), ...
                         bufPan{m,2}, select(lamBuf{m,2}), ...
                         bufPan{m,3}, select(lamBuf{m,3})};
            c2    = [cell(maxLam(m),1), cell(maxLam(m),1), lamBuf{m,1}, ...
                                        cell(maxLam(m),1), lamBuf{m,2}, ...
                                        cell(maxLam(m),1), lamBuf{m,3}];  
            c_stn = [c_stn; c1; c2];    
        end    
        data = [data; cHeader; c_stn];  
    end
    set(htable,'Data',data);
    end % function data_callback

end % function startDataGUI

% ------------------------------------------

function ijEdit = getEditableIndex(data)

    % now find all the editable cells by detecting if the first character is a "["
    % indEdit   = zeros(0,1);
    % indNoEdit = zeros(0,1);
    ijEdit    = zeros(0,2);
    for n = 1:size(data,1)
        for m = 1:size(data,2)
            if ischar(class(data{n,m})) && strncmpi(data{n,m},'[',1)
                % this is an editable field  
                ijEdit = [ijEdit; n,m];
            end
        end
    end

end % function getEditableIndex

function index = select(data)

    if iscellstr(data(1))
        index = ['[' num2str(1) ']'];
    else
        index = [];
    end

end % function select

Contact us