itaComsolResult

-added functions to get the correct database tag for BEM simulations
-NOTE: Getting BEM results is still disabled due to issues with Comsol Livelink functions

itaComsolDataset
-added this subnote of itaComsolResult
-allows to access and filter datasets
parent 5c104467
classdef itaComsolDataset < itaComsolNode
%itaComsolDataset Interface to the result.dataset nodes of an itaComsolModel
% Allows to access the dataset nodes of the Comsol model. Also provides
% functions to filter datasets with a specific source (=solver or
% other dataset) and datasets of a specific type.
%
% See also itaComsolModel, itaComsolNode, itaComsolResult
%
% Reference page in Help browser
% <a href="matlab:doc itaComsolDataset">doc itaComsolDataset</a>
% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
% </ITA-Toolbox>
%% Constructor
methods
function obj = itaComsolDataset(comsolModel)
%Expects an itaComsolModel as input
obj@itaComsolNode(comsolModel, 'dataset',...
'com.comsol.clientapi.impl.ExportFeatureClient', comsolModel.modelNode.result)
end
end
%% Filter datasets
methods
function datasets = Filter(obj, sourceDataTag, type)
%Returns all dataset nodes matching the filter settings
% Inputs (default):
% sourceDataTag: Tag of the source for this set (either solution or other dataset)
% type (''): Dataset type (e.g. dset, grid, ...)
if nargin == 2; type = ''; end
assert(isempty(sourceDataTag) || ( ischar(sourceDataTag) && isrow(sourceDataTag) ),...
'Inputs must either be empty or a char row vector')
assert(isempty(type) || ( ischar(type) && isrow(type) ),...
'Inputs must either be empty or a char row vector')
datasets = obj.All();
if ~isempty(sourceDataTag)
datasets = obj.filterSource(datasets, sourceDataTag);
end
if ~isempty(type)
datasets = obj.filterType(datasets, type);
end
end
function gridDatasets = Grids(obj, sourceDataTag)
%Returns all grid dataset nodes. Alternatively, the tag of the
%source data can be given as a filter.
% Inputs (default):
% sourceDataTag (''): Tag of the source for this set (either solution or other dataset)
gridDatasets = obj.Filter(sourceDataTag, 'grid');
end
end
methods(Access = private, Static = true)
function filteredDsets = filterType(datasets, type)
filteredDsets = {};
for idxDset = 1:numel(datasets)
dset = datasets{idxDset};
if contains(char(dset.tag), type)
filteredDsets{end+1} = dset; %#ok<AGROW>
end
end
end
function filteredDsets = filterSource(datasets, sourceDataTag)
filteredDsets = {};
for idxDset = 1:numel(datasets)
dset = datasets{idxDset};
if dset.hasProperty('data')
compareString = char(dset.getString('data'));
elseif dset.hasProperty('solution')
compareString = char(dset.getString('solution'));
else
continue;
end
if strcmp(compareString, sourceDataTag)
filteredDsets{end+1} = dset; %#ok<AGROW>
end
end
end
end
end
\ No newline at end of file
......@@ -25,9 +25,11 @@ classdef itaComsolResult < handle
mResultDomain = 'freq'; %'freq' | 'time'
mExport;
mDataset;
end
properties(Dependent = true)
export; %Grants access to result data export (see itaComsolExport)
dataset; %Grants access to dataset nodes (see itaComsolDataset)
end
%% Constructor
......@@ -39,6 +41,7 @@ classdef itaComsolResult < handle
obj.mModel = comsolModel;
obj.mExport = itaComsolExport(comsolModel);
obj.mDataset = itaComsolDataset(comsolModel);
end
end
......@@ -47,6 +50,9 @@ classdef itaComsolResult < handle
function out = get.export(obj)
out = obj.mExport;
end
function out = get.dataset(obj)
out = obj.mDataset;
end
end
%% Public result getters
......@@ -86,6 +92,15 @@ classdef itaComsolResult < handle
% p: itaResult with one entry per simulation
% metaData: struct with info on parametric sweep
assert(ischar(expression) && isrow(expression), 'First input must be char row vector with the expression of the result')
%NOTE - PSC:
%Since the Comsol functions mphinterp and mpheval work
%significantly different for the pabe physics, getting pabe
%results is disabled for now. I am waiting for the Comsol
%Support to help me with this.
if contains(expression, 'pabe')
error('Evaluating BEM (pabe) results is not supported at the moment');
end
if nargin == 2
[res, metaData] = obj.getResultAtMeshNodes(expression);
else
......@@ -101,7 +116,9 @@ classdef itaComsolResult < handle
%% Extract results
methods(Access = private)
function [res, metaData] = getResultAtMeshNodes(obj, expression)
datasetTag = obj.getDatasetTag(expression);
assert( ~contains(expression, 'pabe'), 'Cannot return expression' )
datasetTag = obj.getDirectDatasetTag();
metaData = obj.createMetaDataStruct(datasetTag);
if ~isempty(metaData.parameterValues) %Param sweep
res = itaResult([1 metaData.nSimulations]);
......@@ -188,16 +205,31 @@ classdef itaComsolResult < handle
methods(Access = private)
function datasetTag = getDatasetTag(obj, expression)
if contains(expression, 'pabe')
datasetTag = 'grid1';
datasetTag = obj.getBemDatasetTag();
else
if ~contains(expression, 'acpr')
warning('Expression does not contain physics-tag. Assuming acpr physics.')
end
solTag = obj.getMainSolverTag();
info = mphsolinfo(obj.mModel.modelNode, 'soltag', solTag);
datasetTag = info.dataset;
datasetTag = obj.getDirectDatasetTag();
end
end
function datasetTag = getDirectDatasetTag(obj)
solTag = obj.getMainSolverTag();
info = mphsolinfo(obj.mModel.modelNode, 'soltag', solTag);
datasetTag = info.dataset;
if iscell(datasetTag)
datasetTag = datasetTag{1};
end
end
function datasetTag = getBemDatasetTag(obj)
%Uses the first grid dataset that is derived from the main
%solution of this study
directDataset = obj.getDirectDatasetTag();
gridDatasets = obj.dataset.Grids(directDataset);
datasetTag = '';
if isempty(gridDatasets); return; end
datasetTag = char(gridDatasets{1}.tag);
end
function solTag = getMainSolverTag(obj)
study = obj.mModel.study.activeNode;
allSolvers = study.getSolverSequences('all');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment