function varargout = testgui(varargin)
% TESTGUI M-file for testgui.fig
% TESTGUI, by itself, creates a new TESTGUI or
raises the existing
% singleton*.
%
% H =
TESTGUI returns the handle to a new TESTGUI or the handle to
% the
existing singleton*.
%
% TESTGUI('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in TESTGUI.M with the
given input arguments.
%
% TESTGUI('Property','Value',...) creates a new
TESTGUI or raises the
% existing singleton*. Starting
from the left, property value pairs are
% applied to the GUI before testgui_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to
testgui_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
testgui
% Last Modified by GUIDE v2.5 28-Aug-2010 19:04:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton,
...
'gui_OpeningFcn', @testgui_OpeningFcn, ...
'gui_OutputFcn',
@testgui_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 testgui is made visible.
function testgui_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
testgui (see VARARGIN)
% Choose default command line output for testgui
handles.output = hObject;
% init COMSOL object
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('C:\');
model.modelNode.create('mod1');
model.geom.create('geom1', 2);
model.mesh.create('mesh1', 'geom1');
model.physics.create('ht', 'HeatTransfer', 'geom1');
model.study.create('std1');
model.study('std1').feature.create('stat',
'Stationary');
% insert the model into handles
handles.MyData=model;
% init COMSOL geometry
model.geom('geom1').feature.create('sq1', 'Square');
model.geom('geom1').feature('sq1').set('base',
'center');
model.geom('geom1').feature.create('c1', 'Circle');
model.geom('geom1').feature('c1').set('r', '0.05');
model.geom('geom1').runAll;
mphgeom(model,'geom1');
% set the popup menu of mesh
handle=handles.pop_mesh;
set(handle,'String',{'Extremely fine','Extra
fine','Finer','Fine',...
'Normal','Coarse','Coarser','Extra Coarse','Extremely
Coarse'});
set(handle,'Value',5);
% create mesh
model.mesh('mesh1').feature.create('ftri1', 'FreeTri');
% select material
model.material.create('mat1');
model.material('mat1').name('Aluminum');
model.material('mat1').materialModel('def').set('relpermeability',
'1');
model.material('mat1').materialModel('def').set('heatcapacity',
'900[J/(kg*K)]');
model.material('mat1').materialModel('def').set('thermalconductivity',
'160[W/(m*K)]');
model.material('mat1').materialModel('def').set('electricconductivity',
'3.774e7[S/m]');
model.material('mat1').materialModel('def').set('relpermittivity',
'1');
model.material('mat1').materialModel('def').set('thermalexpansioncoefficient',
'23e-6[1/K]');
model.material('mat1').materialModel('def').set('density',
'2700[kg/m^3]');
model.material('mat1').materialModel.create('Enu',
[native2unicode(hex2dec('6768'), 'Cp1252') ' '
native2unicode(hex2dec('6c0f'), 'Cp1252') ' '
native2unicode(hex2dec('6a21'), 'Cp1252') ' '
native2unicode(hex2dec('91cf'), 'Cp1252') ' '
native2unicode(hex2dec('548c'), 'Cp1252') ' '
native2unicode(hex2dec('6cca'), 'Cp1252') ' '
native2unicode(hex2dec('677e'), 'Cp1252') ' '
native2unicode(hex2dec('6bd4'), 'Cp1252') ]);
model.material('mat1').materialModel('Enu').set('poissonsratio',
'0.33');
model.material('mat1').materialModel('Enu').set('youngsmodulus',
'70e9[Pa]');
model.material('mat1').materialModel.create('Murnaghan',
'Murnaghan');
model.material('mat1').materialModel('Murnaghan').set('n',
'-3.5e11[Pa]');
model.material('mat1').materialModel('Murnaghan').set('m',
'-3.3e11[Pa]');
model.material('mat1').materialModel('Murnaghan').set('muLame',
'2.6e10[Pa]');
model.material('mat1').materialModel('Murnaghan').set('l',
'-2.5e11[Pa]');
model.material('mat1').materialModel('Murnaghan').set('lambLame',
'5.1e10[Pa]');
model.material('mat1').materialModel.create('Lame', ['Lame '
native2unicode(hex2dec('5e38'), 'Cp1252') ' '
native2unicode(hex2dec('6570'), 'Cp1252') ]);
model.material('mat1').materialModel('Lame').set('muLame',
'2.6e10[Pa]');
model.material('mat1').materialModel('Lame').set('lambLame',
'5.1e10[Pa]');
model.material('mat1').materialModel.create('NeoHookean',
'Neo-Hookean');
model.material('mat1').materialModel('NeoHookean').set('mu',
'2.6e10[Pa]');
model.material('mat1').materialModel('NeoHookean').set('lambda',
'5.1e10[Pa]');
model.material('mat1').selection.set([1]);
model.material.create('mat2');
model.material('mat2').name('Copper');
model.material('mat2').materialModel('def').set('relpermeability',
'1');
model.material('mat2').materialModel('def').set('electricconductivity',
'5.998e7[S/m]');
model.material('mat2').materialModel('def').set('thermalexpansioncoefficient',
'17e-6[1/K]');
model.material('mat2').materialModel('def').set('heatcapacity',
'385[J/(kg*K)]');
model.material('mat2').materialModel('def').set('relpermittivity',
'1');
model.material('mat2').materialModel('def').set('density',
'8700[kg/m^3]');
model.material('mat2').materialModel('def').set('thermalconductivity',
'400[W/(m*K)]');
model.material('mat2').materialModel.create('Enu',
[native2unicode(hex2dec('6768'), 'Cp1252') ' '
native2unicode(hex2dec('6c0f'), 'Cp1252') ' '
native2unicode(hex2dec('6a21'), 'Cp1252') ' '
native2unicode(hex2dec('91cf'), 'Cp1252') ' '
native2unicode(hex2dec('548c'), 'Cp1252') ' '
native2unicode(hex2dec('6cca'), 'Cp1252') ' '
native2unicode(hex2dec('677e'), 'Cp1252') ' '
native2unicode(hex2dec('6bd4'), 'Cp1252') ]);
model.material('mat2').materialModel('Enu').set('poissonsratio',
'0.35');
model.material('mat2').materialModel('Enu').set('youngsmodulus',
'110e9[Pa]');
model.material('mat2').materialModel.create('linzRes',
[native2unicode(hex2dec('7ebf'), 'Cp1252') ' '
native2unicode(hex2dec('6027'), 'Cp1252') ' '
native2unicode(hex2dec('5316'), 'Cp1252') ' '
native2unicode(hex2dec('7535'), 'Cp1252') ' '
native2unicode(hex2dec('963b'), 'Cp1252') ' '
native2unicode(hex2dec('7387'), 'Cp1252') ]);
model.material('mat2').materialModel('linzRes').set('alpha',
'0.0039[1/K]');
model.material('mat2').materialModel('linzRes').set('rho0',
'1.72e-8[ohm*m]');
model.material('mat2').materialModel('linzRes').set('Tref',
'298[K]');
model.material('mat2').selection.set([2]);
% create physics
model.physics('ht').feature.create('hs1', 'HeatSource',
2);
model.physics('ht').feature('hs1').selection.set([2]);
model.physics('ht').feature.create('temp1',
'TemperatureBoundary', 1);
model.physics('ht').feature('temp1').selection.set([1 2 3
4]);
model.physics('ht').feature('hs1').set('Q', 1, '100');
% create solution
model.sol.create('sol1');
model.sol('sol1').feature.create('st1', 'StudyStep');
model.sol('sol1').feature('st1').set('study', 'std1');
model.sol('sol1').feature('st1').set('studystep',
'stat');
model.sol('sol1').feature.create('v1', 'Variables');
model.sol('sol1').feature.create('s1', 'Stationary');
model.sol('sol1').feature('s1').feature.create('fc1',
'FullyCoupled');
model.sol('sol1').feature('s1').feature('fc1').set('dtech',
'auto');
model.sol('sol1').feature('s1').feature('fc1').set('initstep',
0.01);
model.sol('sol1').feature('s1').feature('fc1').set('minstep',
1.0E-6);
model.sol('sol1').feature('s1').feature('fc1').set('maxiter',
50);
model.sol('sol1').feature('s1').feature.create('d1',
'Direct');
model.sol('sol1').feature('s1').feature('d1').set('linsolver',
'pardiso');
model.sol('sol1').feature('s1').feature('fc1').set('linsolver',
'd1');
model.sol('sol1').feature('s1').feature.remove('fcDef');
model.sol('sol1').attach('std1');
% create postprocessing
model.result.create('pg1', 2);
model.result('pg1').set('data', 'dset1');
model.result('pg1').feature.create('surf1', 'Surface');
model.result('pg1').feature('surf1').set('expr', 'T');
model.result('pg1').feature('surf1').set('wireframe',
'off');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes testgui wait for user response (see
UIRESUME)
% uiwait(handles.testgui);
% --- Outputs from this function are returned to the command
line.
function varargout = testgui_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;
% --- Executes on selection change in pop_mesh.
function pop_mesh_Callback(hObject, eventdata, handles)
% hObject handle to
pop_mesh (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
pop_mesh contents as cell array
% contents{get(hObject,'Value')} returns selected
item from pop_mesh
% --- Executes during object creation, after setting all
properties.
function pop_mesh_CreateFcn(hObject, eventdata, handles)
% hObject handle to
pop_mesh (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
function edit_radius_Callback(hObject, eventdata,
handles)
% hObject handle to
edit_radius (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 edit_radius
as text
% str2double(get(hObject,'String')) returns
contents of edit_radius as a double
% --- Executes during object creation, after setting all
properties.
function edit_radius_CreateFcn(hObject, eventdata,
handles)
% hObject handle to
edit_radius (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 button press in pb_geom.
function pb_geom_Callback(hObject, eventdata, handles)
% hObject handle to
pb_geom (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with
handles and user data (see GUIDATA)
model = handles.MyData;
str=get(handles.edit_radius,'String');
model.geom('geom1').feature('c1').set('r', str);
model.geom('geom1').runAll;
mphgeom(model,'geom1','parent',handles.result);
% --- Executes on button press in pb_solve.
function pb_solve_Callback(hObject, eventdata, handles)
% hObject handle to
pb_solve (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with
handles and user data (see GUIDATA)
model = handles.MyData;
str = get(handles.edit_heatsource, 'String');
model.physics('ht').feature('hs1').set('Q', 1, str);
model.sol('sol1').runAll;
mphplot(model, 'pg1', 'rangenum',1,'parent',
handles.result);
function edit_heatsource_Callback(hObject, eventdata,
handles)
% hObject handle to
edit_heatsource (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
edit_heatsource as text
% str2double(get(hObject,'String')) returns
contents of edit_heatsource as a double
% --- Executes during object creation, after setting all
properties.
function edit_heatsource_CreateFcn(hObject, eventdata,
handles)
% hObject handle to
edit_heatsource (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 button press in pb_mesh.
function pb_mesh_Callback(hObject, eventdata, handles)
% hObject handle to
pb_mesh (see GCBO)
% eventdata reserved - to be defined in a
future version of MATLAB
% handles structure with
handles and user data (see GUIDATA)
model = handles.MyData;
val = get(handles.pop_mesh,'Value');
str = int2str(val);
model.mesh('mesh1').feature('size').set('hauto', str);
model.mesh('mesh1').run;
mphmesh(model,'mesh1','parent',handles.result);