Files
3D_EDFM_SIM-X/gui_support/app/EDFMSimulatorGuide.m
T
2026-04-28 22:00:30 +08:00

187 lines
6.7 KiB
Matlab

function varargout = EDFMSimulatorGuide(varargin)
%EDFMSIMULATORGUIDE GUIDE-compatible EDFM simulator GUI for MATLAB R2022a.
% APP = EDFMSIMULATORGUIDE launches the converted GUIDE/uicontrol version
% of the App Designer interface. The UI is built from standard figure,
% uipanel, uicontrol, uitable and axes objects so it can be inspected and
% adjusted with GUIDE-era tools in MATLAB R2022a. GUIDE does not support
% uitabgroup, so pages are implemented as switchable uipanel containers.
if nargin > 0 && ischar(varargin{1})
feval(varargin{:});
return;
end
startup;
handles = initializeGuideLayout();
fig = handles.UIFigure;
app = EDFMGuideApp(handles);
app.Controller = EDFMAppController(app);
handles.App = app;
guidata(fig, handles);
configureGuideCallbacks(app, fig);
app.Controller.startup();
set(fig, 'Visible', 'on');
if nargout > 0
varargout{1} = app;
end
end
function handles = initializeGuideLayout()
figFile = fullfile(fileparts(mfilename('fullpath')), 'EDFMSimulatorGuide.fig');
if exist(figFile, 'file') == 2
fig = openfig(figFile, 'reuse', 'invisible');
handles = guihandles(fig);
handles.UIFigure = fig;
else
handles = createEDFMSimulatorGuideLayout();
end
end
function configureGuideCallbacks(app, fig)
if isprop(app, 'PageDropDown')
app.PageDropDown.ValueChangedFcn = @(src, event) onMainPageChanged(fig);
end
if isprop(app, 'DiscretizationPageDropDown')
app.DiscretizationPageDropDown.ValueChangedFcn = @(src, event) onDiscretizationPageChanged(fig);
end
if isprop(app, 'FlowPageDropDown')
app.FlowPageDropDown.ValueChangedFcn = @(src, event) onFlowPageChanged(fig);
end
app.NewConfigButton.ButtonPushedFcn = @(src, event) onNewConfig(fig);
app.LoadTemplateButton.ButtonPushedFcn = @(src, event) onLoadTemplate(fig);
app.ImportConfigButton.ButtonPushedFcn = @(src, event) onImportConfig(fig);
app.ExportConfigButton.ButtonPushedFcn = @(src, event) onExportConfig(fig);
app.RunButton.ButtonPushedFcn = @(src, event) onRun(fig);
app.ImportResultButton.ButtonPushedFcn = @(src, event) onImportResult(fig);
app.ExportResultButton.ButtonPushedFcn = @(src, event) onExportResult(fig);
app.PlotWellResponseButton.ButtonPushedFcn = @(src, event) onActivateCasePlot(fig, 'plot_well_response');
app.Plot2DLayerButton.ButtonPushedFcn = @(src, event) onActivateCasePlot(fig, 'plot_2d_layer');
app.Plot3DDistributionButton.ButtonPushedFcn = @(src, event) onRunCasePlot(fig, 'plot_3d_distribution');
app.PlotPermButton.ButtonPushedFcn = @(src, event) onRunCasePlot(fig, 'plot_perm');
app.PlotSPDPButton.ButtonPushedFcn = @(src, event) onRunCasePlot(fig, 'plot_sp_dp');
app.PlotLayerDropDown.ValueChangedFcn = @(src, event) onPlotOptionChanged(fig);
app.PlotPropertyDropDown.ValueChangedFcn = @(src, event) onPlotOptionChanged(fig);
app.PlotWellDropDown.ValueChangedFcn = @(src, event) onPlotOptionChanged(fig);
app.PlotMetricDropDown.ValueChangedFcn = @(src, event) onPlotOptionChanged(fig);
app.PlotTimeStepSlider.ValueChangedFcn = @(src, event) onPlotOptionChanged(fig);
app.AddWell1RowButton.ButtonPushedFcn = @(src, event) onAddTableRow(fig, 'Well1Table');
app.DeleteWell1RowButton.ButtonPushedFcn = @(src, event) onDeleteTableRow(fig, 'Well1Table');
app.AddWell2RowButton.ButtonPushedFcn = @(src, event) onAddTableRow(fig, 'Well2Table');
app.DeleteWell2RowButton.ButtonPushedFcn = @(src, event) onDeleteTableRow(fig, 'Well2Table');
app.AddFracLocRowButton.ButtonPushedFcn = @(src, event) onAddTableRow(fig, 'FractureWellLocationTable');
app.DeleteFracLocRowButton.ButtonPushedFcn = @(src, event) onDeleteTableRow(fig, 'FractureWellLocationTable');
app.AddScheduleRowButton.ButtonPushedFcn = @(src, event) onAddTableRow(fig, 'ScheduleTable');
app.DeleteScheduleRowButton.ButtonPushedFcn = @(src, event) onDeleteTableRow(fig, 'ScheduleTable');
app.Well1Table.CellSelectionCallback = @(src, event) onTableSelection(fig, 'Well1Table', event);
app.Well2Table.CellSelectionCallback = @(src, event) onTableSelection(fig, 'Well2Table', event);
app.FractureWellLocationTable.CellSelectionCallback = @(src, event) onTableSelection(fig, 'FractureWellLocationTable', event);
app.ScheduleTable.CellSelectionCallback = @(src, event) onTableSelection(fig, 'ScheduleTable', event);
end
function onMainPageChanged(fig)
handles = guidata(fig);
pageTags = {'ModelTab', 'GridTab', 'FractureTab', 'DiscretizationTab', ...
'FlowTab', 'WellsTab', 'SolverRunTab', 'ResultsTab'};
showSelectedPanel(handles, 'PageDropDown', pageTags);
guidata(fig, handles);
end
function onDiscretizationPageChanged(fig)
handles = guidata(fig);
showSelectedPanel(handles, 'DiscretizationPageDropDown', {'SPTab', 'DPTab'});
guidata(fig, handles);
end
function onFlowPageChanged(fig)
handles = guidata(fig);
showSelectedPanel(handles, 'FlowPageDropDown', {'GasWaterTab', 'OilWaterTab', 'MultiComponentTab'});
guidata(fig, handles);
end
function showSelectedPanel(handles, selectorName, panelTags)
if ~isfield(handles, selectorName)
return;
end
selectedIndex = get(handles.(selectorName), 'Value');
selectedIndex = min(max(1, selectedIndex), numel(panelTags));
for i = 1:numel(panelTags)
if isfield(handles, panelTags{i}) && isgraphics(handles.(panelTags{i}))
if i == selectedIndex
set(handles.(panelTags{i}), 'Visible', 'on');
else
set(handles.(panelTags{i}), 'Visible', 'off');
end
end
end
end
function app = getGuideApp(fig)
handles = guidata(fig);
app = handles.App;
end
function onNewConfig(fig)
getGuideApp(fig).Controller.newConfig();
end
function onLoadTemplate(fig)
app = getGuideApp(fig);
app.Controller.loadTemplate(app.TemplateDropDown.Value);
end
function onImportConfig(fig)
getGuideApp(fig).Controller.importConfig();
end
function onExportConfig(fig)
getGuideApp(fig).Controller.exportConfig();
end
function onRun(fig)
getGuideApp(fig).Controller.runCurrentConfig();
end
function onImportResult(fig)
getGuideApp(fig).Controller.importResults();
end
function onExportResult(fig)
getGuideApp(fig).Controller.exportResults();
end
function onActivateCasePlot(fig, actionId)
getGuideApp(fig).Controller.activateCasePlot(actionId);
end
function onRunCasePlot(fig, actionId)
getGuideApp(fig).Controller.runCasePlot(actionId);
end
function onPlotOptionChanged(fig)
getGuideApp(fig).Controller.onPlotOptionChanged();
end
function onAddTableRow(fig, tableName)
getGuideApp(fig).Controller.addTableRow(tableName);
end
function onDeleteTableRow(fig, tableName)
getGuideApp(fig).Controller.deleteSelectedTableRow(tableName);
end
function onTableSelection(fig, tableName, event)
indices = [];
if nargin >= 3 && isstruct(event) && isfield(event, 'Indices')
indices = event.Indices;
elseif nargin >= 3
try
if isprop(event, 'Indices')
indices = event.Indices;
end
catch
end
end
getGuideApp(fig).Controller.onTableSelectionChanged(tableName, indices);
end