How to make Matlab to wait until the PDE toolbox computes the solution?

4 vues (au cours des 30 derniers jours)
GHULAM RASOOL
GHULAM RASOOL le 5 Juin 2016
Commenté : GHULAM RASOOL le 6 Juin 2016
I want to extract mesh and solution data using script from the PDE toolbox however, when i run the following script the code does provide the pde solution but it doesn't seem to extract the data which might be because it doesn't wait for GUI to complete. However, when I run the commands to extract the data separately after i get the PDE solution it does work but that would meaning running the extraction commands separately in another script or in the workspace. Therefore, I want to incorporate everything in one script and it should provide PDE solution and data in single run.
function pdemodel
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',9);
set(ax,'DataAspectRatio',[1 1.5 1]);
set(ax,'PlotBoxAspectRatio',[1 0.66666666666666663 1]);
set(ax,'XLim',[0 2]);
set(ax,'YLim',[0 2]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');
% Geometry description:
pderect([0 1 1 0],'R1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1')
% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,...
'neu',...
1,...
'0',...
'sin(2*t)')
pdesetbd(3,...
'neu',...
1,...
'0',...
'0')
pdesetbd(2,...
'neu',...
1,...
'0',...
'0')
pdesetbd(1,...
'neu',...
1,...
'0',...
'0')
% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
pdetool('initmesh')
pdetool('refine')
% PDE coefficients:
pdeseteq(2,...
'1.0',...
'0',...
'(0)+(0).*(0.0)',...
'(1.0).*(1.0)',...
'0:0.1:10',...
'0.0',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0';...
'1.0';...
'1.0';...
'0 ';...
'0 ';...
'0.0'])
% Solve parameters:
setappdata(pde_fig,'solveparam',...
str2mat('0','1872','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))
% Plotflags and user data strings:
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 1 1 0 0 0 101 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
% Solve PDE:
pdetool('solve')
function [p,e,t,u] = getpetu
%GETPETU Get p,e,t,and u.
pde_fig=findobj(allchild(0),'flat','Tag','PDETool');
if isempty(pde_fig)
error('PDE Toolbox GUI not active.')
end
u = get(findobj(pde_fig,'Tag','PDEPlotMenu'),'UserData');
h=findobj(get(pde_fig,'Children'),'flat','Tag','PDEMeshMenu');
hp=findobj(get(h,'Children'),'flat','Tag','PDEInitMesh');
he=findobj(get(h,'Children'),'flat','Tag','PDERefine');
ht=findobj(get(h,'Children'),'flat','Tag','PDEMeshParam');
p=get(hp,'UserData');
e=get(he,'UserData');
t=get(ht,'UserData');
  2 commentaires
Walter Roberson
Walter Roberson le 5 Juin 2016
When I scan the code, I do not seem to find the point at which the data is being extracted?
GHULAM RASOOL
GHULAM RASOOL le 6 Juin 2016
Thanks for the quick reply. I have corrected the code and it should run fine now. The code is successful up to pdetool ('solve') command however it doesn't provide the mesh data (p,e,t) and solution data (u) in single run. So I have to run the last bit of the code again to get data. The updated script is follows:
function pdemodel
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',9);
set(ax,'DataAspectRatio',[1 1.5 1]);
set(ax,'PlotBoxAspectRatio',[1 0.66666666666666663 1]);
set(ax,'XLim',[0 2]);
set(ax,'YLim',[0 2]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');
% Geometry description:
pderect([0 1 1 0],'R1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1')
% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,...
'neu',...
1,...
'0',...
'sin(2*t)')
pdesetbd(3,...
'neu',...
1,...
'0',...
'0')
pdesetbd(2,...
'neu',...
1,...
'0',...
'0')
pdesetbd(1,...
'neu',...
1,...
'0',...
'0')
% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
pdetool('initmesh')
pdetool('refine')
% PDE coefficients:
pdeseteq(2,...
'1.0',...
'0',...
'(0)+(0).*(0.0)',...
'(1.0).*(1.0)',...
'0:0.1:10',...
'0.0',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0';...
'1.0';...
'1.0';...
'0 ';...
'0 ';...
'0.0'])
% Solve parameters:
setappdata(pde_fig,'solveparam',...
str2mat('0','1872','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))
% Plotflags and user data strings:
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 1 1 0 0 0 101 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
% Solve PDE:
pdetool('solve')
%Get mesh data p,e,t and solution u from the pde toolbox:
pde_fig=findobj(allchild(0),'flat','Tag','PDETool');
if isempty(pde_fig)
error('PDE Toolbox GUI not active.')
end
u = get(findobj(pde_fig,'Tag','PDEPlotMenu'),'UserData');
h=findobj(get(pde_fig,'Children'),'flat','Tag','PDEMeshMenu');
hp=findobj(get(h,'Children'),'flat','Tag','PDEInitMesh');
he=findobj(get(h,'Children'),'flat','Tag','PDERefine');
ht=findobj(get(h,'Children'),'flat','Tag','PDEMeshParam');
p=get(hp,'UserData');
e=get(he,'UserData');
t=get(ht,'UserData');

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by