Demo entry 6789044

飞轮计算GUI主程序

   

Submitted by pi on Apr 25, 2019 at 06:28
Language: Matlab. Code size: 28.3 kB.

function varargout = FlywheelDesign(varargin)
% FLYWHEELDESIGN MATLAB code for FlywheelDesign.fig
%      FLYWHEELDESIGN, by itself, creates a new FLYWHEELDESIGN or raises the existing
%      singleton*.
%
%      H = FLYWHEELDESIGN returns the handle to a new FLYWHEELDESIGN or the handle to
%      the existing singleton*.
%
%      FLYWHEELDESIGN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FLYWHEELDESIGN.M with the given input arguments.
%
%      FLYWHEELDESIGN('Property','Value',...) creates a new FLYWHEELDESIGN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FlywheelDesign_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FlywheelDesign_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help FlywheelDesign

% Last Modified by GUIDE v2.5 27-Aug-2017 19:54:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FlywheelDesign_OpeningFcn, ...
                   'gui_OutputFcn',  @FlywheelDesign_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before FlywheelDesign is made visible.
function FlywheelDesign_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FlywheelDesign (see VARARGIN)

% Choose default command line output for FlywheelDesign
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes FlywheelDesign wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = FlywheelDesign_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

%***********************************************************************************************************************************************


function Rin_Callback(hObject, eventdata, handles)
% hObject    handle to Rin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Rin as text
%        str2double(get(hObject,'String')) returns contents of Rin as a double
Rin = str2double(get(hObject,'String'));
if (Rin <= 0)||( Rin > 1e4)
    errordlg('请输入一个小于 1e4 的正值!');
end


% --- Executes during object creation, after setting all properties.
function Rin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Rin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Rex_Callback(hObject, eventdata, handles)
% hObject    handle to Rex (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Rex as text
%        str2double(get(hObject,'String')) returns contents of Rex as a double
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(hObject,'String'));
if Rin >= Rex
    errordlg('飞轮内半径必须 小于 外半径!');
elseif Rex >= 1e4
    errordlg('飞轮外半径过于庞大!');
else
    set(handles.FlywheelShape,'XLim',[0,Rex]);
    rectangle('Position',[Rin,0,(Rex-Rin),100],'Parent',handles.FlywheelShape,'LineStyle','-.','LineWidth',2);%参数[x, y, w, h]
end



% --- Executes during object creation, after setting all properties.
function Rex_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Rex (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function LayerNum_Callback(hObject, eventdata, handles)
% hObject    handle to LayerNum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of LayerNum as text
%        str2double(get(hObject,'String')) returns contents of LayerNum as a double
layernum = str2double(get(hObject,'String'));
if (layernum >0)&&(layernum < 100)&&(mod(layernum*10,10)==0)
    contents = (1:1:layernum)';
    set(handles.nthLayer,'String',contents);%生成层数的列表
else
    errordlg('请输入一个 <100 的正整数!');
end
% 导入材料组分基本弹性数据
[fname,fE1,fE2,fmiu,fdens,fsth] = textread('FibersProperty.txt','%s %f %f %f %f %f');
[mname,mEx,mmiu,mdens,msth] = textread('MatrixProperty.txt','%s %f %f %f %f');
set(handles.FiberKind,'String',fname);%生成纤维的列表
set(handles.MatrixKind,'String',mname);%生成树脂的列表
%
set(handles.VolumeRatio,'String','60');
set(handles.Thickness,'String','0');
set(handles.Interference,'String','0');
%
MPselect = zeros(layernum,6);% 建立数组,存材料定义:No.;fiber;Matrix;Vf;thk;delta
MPvalues = zeros(layernum,8);% 建立数组,存储各层轮缘属性:No.;E1;E2;miu;dens;thk;delta;strength
set(handles.MPdata,'UserData',MPselect);
set(handles.Calculate,'UserData',MPvalues);
%
% disp(get(handles.MPdata,'UserData'));
% disp(get(handles.Calculate,'UserData'));
%



% --- Executes during object creation, after setting all properties.
function LayerNum_CreateFcn(hObject, eventdata, handles)
% hObject    handle to LayerNum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Speed_Callback(hObject, eventdata, handles)
% hObject    handle to Speed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Speed as text
%        str2double(get(hObject,'String')) returns contents of Speed as a double



% --- Executes during object creation, after setting all properties.
function Speed_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Speed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




%**********************************************************************************************************************************

% --- Executes on selection change in nthLayer.
function nthLayer_Callback(hObject, eventdata, handles)
% hObject    handle to nthLayer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns nthLayer contents as cell array
%        contents{get(hObject,'Value')} returns selected item from nthLayer
noLayer = get(hObject,'Value');
OriMPselect = get(handles.MPdata,'UserData');%提取出现有的材料选择
OriMPvalues = get(handles.Calculate,'UserData');%提取出现有的轮缘材料参数
if noLayer == OriMPselect(noLayer,1)
    % 显示在图表中
    disptable = cell(5,2);
    disptable{1,1} = 'E11/GPa';
    disptable{2,1} = 'E22/GPa';
    disptable{3,1} = 'PoissonRatio';
    disptable{4,1} = 'Dens/kg/m^3';
    disptable{5,1} = 'X11/MPa';
    disptable{1,2} = OriMPvalues(noLayer,2);
    disptable{2,2} = OriMPvalues(noLayer,3);
    disptable{3,2} = OriMPvalues(noLayer,4);
    disptable{4,2} = OriMPvalues(noLayer,5);
    disptable{5,2} = OriMPvalues(noLayer,8);
    set(handles.MPtable,'Data',disptable);
    set(handles.FiberKind,'Value',OriMPselect(noLayer,2));
    set(handles.MatrixKind,'Value',OriMPselect(noLayer,3));
    set(handles.VolumeRatio,'String',OriMPselect(noLayer,4));
    set(handles.Thickness,'String',OriMPselect(noLayer,5));
    set(handles.Interference,'String',OriMPselect(noLayer,6));
end
if noLayer > 1
    set(handles.Interference,'Visible','on');
else
    set(handles.Interference,'Visible','off');
end


% --- Executes during object creation, after setting all properties.
function nthLayer_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nthLayer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%



% --- Executes on selection change in FiberKind.
function FiberKind_Callback(hObject, eventdata, handles)
% hObject    handle to FiberKind (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns FiberKind contents as cell array
%        contents{get(hObject,'Value')} returns selected item from FiberKind


% --- Executes during object creation, after setting all properties.
function FiberKind_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FiberKind (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in MatrixKind.
function MatrixKind_Callback(hObject, eventdata, handles)
% hObject    handle to MatrixKind (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns MatrixKind contents as cell array
%        contents{get(hObject,'Value')} returns selected item from MatrixKind


% --- Executes during object creation, after setting all properties.
function MatrixKind_CreateFcn(hObject, eventdata, handles)
% hObject    handle to MatrixKind (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in VolumeRatio.
function VolumeRatio_Callback(hObject, eventdata, handles)
% hObject    handle to VolumeRatio (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns VolumeRatio contents as cell array
%        contents{get(hObject,'Value')} returns selected item from VolumeRatio
Vf = str2double(get(hObject,'String'));
if (Vf<0)||(Vf>100)
    Vf = 60;
    set(hObject,'String',Vf);
    errordlg('纤维体积率Vf为 0-100 以内的数值!');
end


% --- Executes during object creation, after setting all properties.
function VolumeRatio_CreateFcn(hObject, eventdata, handles)
% hObject    handle to VolumeRatio (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in Thickness.
function Thickness_Callback(hObject, eventdata, handles)
% hObject    handle to Thickness (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns Thickness contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Thickness
thk = str2double(get(hObject,'String'));
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
if (thk<0)||(thk>(Rex-Rin))
    thk = (Rex-Rin)/10;
    set(hObject,'String',thk);
    errordlg('输入单层轮缘厚度值大于零且小于飞轮总壁厚!');
end




% --- Executes during object creation, after setting all properties.
function Thickness_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Thickness (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in Interference.
function Interference_Callback(hObject, eventdata, handles)
% hObject    handle to Interference (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns Interference contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Interference


% --- Executes during object creation, after setting all properties.
function Interference_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Interference (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
set(hObject,'Visible','off','String',0);



%********************************************************************************************************************************************


% --- Executes on button press in ReDefine.
function ReDefine_Callback(hObject, eventdata, handles)
% hObject    handle to ReDefine (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%
cla(handles.FlywheelShape);%清空飞轮结构视图
cla(handles.ResultImage);%清空结果绘制视图
%
set(handles.MPtable,'Data',zeros(5,2));%轮缘有效参数列表归零
set(handles.Rin,'String',0);
set(handles.Rex,'String',0);
set(handles.LayerNum,'String',0);
set(handles.Speed,'String',0);
set(handles.nthLayer,'String','1','Value',1);
set(handles.FiberKind,'String','non','Value',1);
set(handles.MatrixKind,'String','non','Value',1);
set(handles.VolumeRatio,'String',0);
set(handles.Thickness,'String',0);
set(handles.Interference,'String',0,'Visible','off');
set(handles.MPdata,'UserData',[]);%将材料定义控件寄存的轮缘定义数组清空
set(handles.Calculate,'UserData',[]);%将执行计算控件寄存的材料属性数组清空
set(handles.Check,'UserData',0);%将材料参数检查正确标记设置归零
set(get(handles.ResultImage,'XLabel'),'String','');
set(get(handles.ResultImage,'YLabel'),'String','');
set(gca,'FontSize',12);



% --- Executes on button press in HookStress.
function HookStress_Callback(hObject, eventdata, handles)
% hObject    handle to HookStress (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 提取数据
data = get(hObject,'UserData');
Radius = data(:,1);
HookStress = data(:,2);
cla(handles.ResultImage);%清空结果绘制视图
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
gap = (Rex-Rin)/10;
set(handles.ResultImage,'XLim',[Rin-gap,Rex+gap]);
line(Radius,HookStress,'Parent',handles.ResultImage,'LineWidth',3,'Color','r');
set(get(handles.ResultImage,'XLabel'),'String','Radial Positions, R/mm','fontsize',12);
set(get(handles.ResultImage,'YLabel'),'String','Hook Stress, St/MPa','fontsize',12);
set(gca,'FontSize',12);






% --- Executes on button press in RadialStress.
function RadialStress_Callback(hObject, eventdata, handles)
% hObject    handle to RadialStress (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 提取数据
data = get(hObject,'UserData');
Radius = data(:,1);
RadialStress = data(:,2);
cla(handles.ResultImage);%清空结果绘制视图
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
gap = (Rex-Rin)/10;
set(handles.ResultImage,'XLim',[Rin-gap,Rex+gap]);
line(Radius,RadialStress,'Parent',handles.ResultImage,'LineWidth',3,'Color','b');
set(get(handles.ResultImage,'XLabel'),'String','Radial Positions, R/mm','fontsize',12);
set(get(handles.ResultImage,'YLabel'),'String','Radial Stress, Sr/MPa','fontsize',12);
set(gca,'FontSize',12);


% --- Executes on button press in RadialDisp.
function RadialDisp_Callback(hObject, eventdata, handles)
% hObject    handle to RadialDisp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 提取数据
data = get(hObject,'UserData');
Radius = data(:,1);
RadialDisp = data(:,2);
cla(handles.ResultImage);%清空结果绘制视图
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
gap = (Rex-Rin)/10;
set(handles.ResultImage,'XLim',[Rin-gap,Rex+gap]);
line(Radius,RadialDisp,'Parent',handles.ResultImage,'LineWidth',3,'Color','k');
set(get(handles.ResultImage,'XLabel'),'String','Radial Positions, R/mm','fontsize',12);
set(get(handles.ResultImage,'YLabel'),'String','Radial Deformation, Ur/um','fontsize',12);
set(gca,'FontSize',12);



% --- Executes on button press in ImageSave.
function ImageSave_Callback(hObject, eventdata, handles)
% hObject    handle to ImageSave (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[f,p]=uiputfile({'*.jpg'},'保存文件');
str=strcat(p,f);
% pix=getframe(handles.ResultImage);
pix=getframe(gcf);
imwrite(pix.cdata,str,'jpg')


% --- Executes on button press in Exit.
function Exit_Callback(hObject, eventdata, handles)
% hObject    handle to Exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close gcf;



% --- Executes on button press in MPdata.
function MPdata_Callback(hObject, eventdata, handles)
% hObject    handle to MPdata (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% 建立数组,存材料定义:No.;fiber;Matrix;Vf;thk;delta
noLayer = get(handles.nthLayer,'Value');
noFiber = get(handles.FiberKind,'Value');
noMatrix = get(handles.MatrixKind,'Value');
Vf = str2double(get(handles.VolumeRatio,'String'));
thk = str2double(get(handles.Thickness,'String'));
delta = str2double(get(handles.Interference,'String'));
if noLayer == 1
    delta = 0;
    set(handles.Interference,'String',delta);
end
%
if delta < 0
    delta = 0;
    set(handles.Interference,'String',delta);
    errordlg('过盈量必须大于零!');
end
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
if (thk <= 0)||(thk >(Rex-Rin))
    errordlg('单层轮缘厚度必须大于零,且小于给定飞轮总壁厚!');
end
%
OriMPselect = get(handles.MPdata,'UserData');
layernum = str2double(get(handles.LayerNum,'String'));
if layernum > 1
    lastthk = (Rex-Rin) - sum(OriMPselect(1:(layernum-1),5));%计算获得的最后一层厚度
else
    lastthk = Rex - Rin; %防止出现仅仅只有一层的轮缘
end
if lastthk <= 0
    errordlg('各层材料厚度之和大于轮缘设定厚度,需要调整!');
end
if noLayer == layernum
    thk = lastthk;
    set(handles.Thickness,'String',thk);%如果是最后一层,把计算厚度结果给上去
end
newselect = [noLayer,noFiber,noMatrix,Vf,thk,delta];
OriMPselect(noLayer,:) = newselect;
set(handles.MPdata,'UserData',OriMPselect);%存储到材料定义选项数据中
%
% disp(get(handles.MPdata,'UserData'));
% 读取材料组分参数
[fname,fE1,fE2,fmiu,fdens,fsth] = textread('FibersProperty.txt','%s %f %f %f %f %f');%纤维
[mname,mEx,mmiu,mdens,msth] = textread('MatrixProperty.txt','%s %f %f %f %f');%基体
OriMPvalues = get(handles.Calculate,'UserData');%原本的轮缘材料参数
% 需要填充第noLayer行数据:No.;E1;E2;miu;dens;thk;delta;strength
% 计算轮缘复合材料的有效弹性模量
Vf = Vf * 0.01;
E1 = fE1(noFiber)*Vf + mEx(noMatrix)*(1-Vf);
E2 = mEx(noMatrix)/(1-sqrt(Vf)*(1-mEx(noMatrix)/fE2(noFiber)));
miu = Vf*fmiu(noFiber) + (1-Vf)*mmiu(noMatrix);
dens = Vf*fdens(noFiber) + (1-Vf)*mdens(noMatrix);
strength = Vf*fsth(noFiber) + (1-Vf)*msth(noMatrix);
OriMPvalues(noLayer,:) = [noLayer, E1, E2, miu, dens, thk, delta, strength]; 
set(handles.Calculate,'UserData',OriMPvalues);
% disp(num2str(get(handles.Calculate,'UserData')));

% 将计算的轮缘有效弹性参数显示在表格中
disptable = cell(5,2);
disptable{1,1} = 'E11/GPa';
disptable{2,1} = 'E22/GPa';
disptable{3,1} = 'PoissonRatio';
disptable{4,1} = 'Dens/kg/m^3';
disptable{5,1} = 'X11/MPa';
disptable{1,2} = E1;
disptable{2,2} = E2;
disptable{3,2} = miu;
disptable{4,2} = dens;
disptable{5,2} = strength;
set(handles.MPtable,'Data',disptable);

% 将定义的轮缘厚度OriMPselect(:,5)绘制在图像中
for kk=1:1:layernum
    if OriMPselect(kk,5)>0
        try
            temp = sum(OriMPselect(1:(kk-1),5));
        catch
            temp = 0;
        end
        xpoint = temp + Rin;%把增量加上去,作为矩形的起始点
        Rvalue = rand(1);
        Gvalue = rand(1);
        Bvalue = rand(1);
        set(handles.FlywheelShape,'XLim',[0,Rex]);
        rectangle('Position',[xpoint,0,OriMPselect(kk,5),100],'Parent',handles.FlywheelShape,'FaceColor',[Rvalue,Gvalue,Bvalue]);%参数[x, y, w, h]
        text('Position',[xpoint+OriMPselect(kk,5)/2,50],'String',kk,'Parent',handles.FlywheelShape,'Color','w','FontSize',16,'HorizontalAlignment','center');
    else
        break;%直接跳出来
    end
end
set(handles.Check,'UserData',0);%检查标记归零,意味着每次都要材料属性检查


% --- Executes on button press in Check. 检查轮缘设置参数
function Check_Callback(hObject, eventdata, handles)
% hObject    handle to Check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
OriMPselect = get(handles.MPdata,'UserData');%原本的材料选择
OriMPvalues = get(handles.Calculate,'UserData');%原本的轮缘材料参数
Fibername = get(handles.FiberKind,'String');
Matrixname = get(handles.MatrixKind,'String');
%
num = size(OriMPselect,1);
OutputInfo = cell(num,11);
for kk=1:1:num
   OutputInfo{kk,1} = OriMPselect(kk,1);            % No.
   OutputInfo{kk,2} = Fibername{OriMPselect(kk,2)}; %Fiber
   OutputInfo{kk,3} = Matrixname{OriMPselect(kk,3)};%Matrix
   OutputInfo{kk,4} = OriMPselect(kk,4);            %Vf
   OutputInfo{kk,5} = OriMPselect(kk,5);            %thk
   OutputInfo{kk,6} = OriMPselect(kk,6);            %delta
   %
   OutputInfo{kk,7} = OriMPvalues(kk,2); %E11
   OutputInfo{kk,8} = OriMPvalues(kk,3); %E22
   OutputInfo{kk,9} = OriMPvalues(kk,4); %miu
   OutputInfo{kk,10} = OriMPvalues(kk,5);%dens
   OutputInfo{kk,11} = OriMPvalues(kk,8);%strength   
end % 编号No
%disp(OutputInfo);
%
hchkfig = figure('Position',[100,100,1200,500]);
htable = uitable('Parent',hchkfig,'FontSize',12,'Position',[50,50,1100,400],'ColumnWidth',{96});
set(htable,'ColumnName',{'层号','纤维','基体','纤维体积率/%','厚度/mm','过盈量/mm','环向模量/GPa','径向模量/GPa','泊松比','密度/kg/m^3','环向强度/MPa'});
set(htable,'Data',OutputInfo);
%
% 再看看所有的厚度加起来等不等于实现给定的轮缘壁厚
Rin = str2double(get(handles.Rin,'String'));
Rex = str2double(get(handles.Rex,'String'));
thkall = sum(OriMPvalues(:,6));
if thkall==(Rex-Rin)
    set(hObject,'UserData',1);
else
    errordlg('各层轮缘厚度总和与飞轮内外径约束不匹配,请调整!');
end
% disp(get(hObject,'UserData'));
%

%*********************************************************************************************************************************************************************
% --- Executes on button press in Calculate.
function Calculate_Callback(hObject, eventdata, handles)
% hObject    handle to Calculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 先清空图像结果输出
cla(handles.ResultImage);%清空结果绘制视图
set(get(handles.ResultImage,'XLabel'),'String','','FontSize',14);
set(get(handles.ResultImage,'YLabel'),'String','','FontSize',14);
% 材料属性检查正确标记
% disp(get(handles.Check,'UserData'));
CheckSign = get(handles.Check,'UserData');
if CheckSign == 1
    % 轮缘形状参数和转速
    Rin = str2double(get(handles.Rin,'String'));
    Rex = str2double(get(handles.Rex,'String'));
    Angspeed = 2 * acos(-1) * str2double(get(handles.Speed,'String')) / 60.0;
    % 轮缘材料参数
    MPvalues = get(handles.Calculate,'UserData');%原本的轮缘材料参数
    % 将材料属性值恢复到mks
    Rin = Rin * 0.001;
    Rex = Rex * 0.001;
    MPvalues(:,2) = MPvalues(:,2).*1e9;
    MPvalues(:,3) = MPvalues(:,3).*1e9;
    MPvalues(:,6) = MPvalues(:,6).*0.001;
    MPvalues(:,7) = MPvalues(:,7).*0.001;
    % 计算处理程序
    [Radius,RadialStress,HookStress,RadialDisp] = computationalprocess(Rin,Rex,MPvalues,Angspeed);
    % 把结果单位换算成自定义单位,mm,MPa,MPa,um
    Radius = Radius.*1000;
    RadialStress = RadialStress.*1e-6;
    HookStress = HookStress.*1e-6;
    RadialDisp = RadialDisp.*1e6;
    
    %% 自定义数据导出模块
    % 导出数据到文件
    filename = 'resuultdata.xlsx';
    xlswrite(filename, [Radius,RadialStress,HookStress,RadialDisp])
    %%
    % 复制给对应的绘图控件
    set(handles.RadialStress,'UserData',[Radius,RadialStress]);
    set(handles.HookStress,'UserData',[Radius,HookStress]);
    set(handles.RadialDisp,'UserData',[Radius,RadialDisp]);
else
    errordlg('请先进行材料属性赋予结果检查!');
end

This snippet took 0.04 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).