Commit 38ef536b authored by Philipp Schäfer's avatar Philipp Schäfer

Comsol

-introduced new itaComsolNode to read write Comsol parameters
parent 80d5b28a
......@@ -11,6 +11,7 @@ classdef itaComsolModel < handle
% -Materials
% -Physics
% -especially, impedances at boundaries
% -sources
% -Mesh
% -Study
%
......@@ -39,6 +40,7 @@ classdef itaComsolModel < handle
properties(Access = private)
mModel; %Comsol model node (com.comsol.clientapi.impl.ModelClient)
mParameterNode;
mSelectionNode;
mFunctionNode;
mGeometryNode;
......@@ -52,6 +54,7 @@ classdef itaComsolModel < handle
properties(Dependent = true, SetAccess = private)
modelNode; %The comsol model node
parameter; %Interface to access Comsol parameter clients (itaComsolParameters)
selection; %Interface to access Comsol selection clients (itaComsolSelection)
func; %Interface to access Comsol function clients (itaComsolFunction)
geometry; %Interface to access Comsol geometry sequences (itaComsolMaterial)
......@@ -67,7 +70,10 @@ classdef itaComsolModel < handle
function out = get.modelNode(obj)
out = obj.mModel;
end
function out = get.parameter(obj)
out = obj.mParameterNode;
end
function out = get.selection(obj)
out = obj.mSelectionNode;
end
......@@ -105,6 +111,7 @@ classdef itaComsolModel < handle
error('Input must be a comsol model (com.comsol.clientapi.impl.ModelClient)')
end
obj.mModel = comsolModel;
obj.mParameterNode = itaComsolParameters(obj);
obj.mSelectionNode = itaComsolSelection(obj);
obj.mFunctionNode = itaComsolFunction(obj);
obj.mGeometryNode = itaComsolGeometry(obj);
......
......@@ -25,7 +25,7 @@ classdef (Abstract)itaComsolNode < handle
mNodeClassName;
end
properties(Dependent = true, Access = protected)
modelNode; %Comsol model node (=mModel.modelNode)
modelNode; %Comsol model node (= mModel.modelNode)
end
properties(Dependent = true)
activeNode; %The active child node
......@@ -142,6 +142,8 @@ classdef (Abstract)itaComsolNode < handle
out = comsolNode.objectNames();
elseif ismethod( comsolNode, 'feature' )
out = itaComsolNode.getChildNodeTags( comsolNode.feature() );
elseif ismethod( comsolNode, 'group' )
out = itaComsolNode.getChildNodeTags( comsolNode.group() );
else
error(['Comsol Node of type "' class(comsolNode) '" does not seem to have a function to return children'])
end
......
classdef itaComsolParameters < itaComsolNode
%itaComsolParameters Interface to the param (=parameter) nodes of an itaComsolModel
% ...
%% Constructor
methods
function obj = itaComsolParameters(comsolModel)
%Expects an itaComsolModel as input
obj@itaComsolNode(comsolModel, 'param', 'com.comsol.clientapi.impl.ModelParamClient')
end
end
%% Set & Get
methods
function Set(obj, parameterName, value)
%Sets a comsol parameter given its name and a new value
% Both input are expected to be char row vectors. This also
% makes sense for the value since usually a unit should be
% specified
assert(ischar(parameterName) && isrow(parameterName), 'parameterName must be a char row vector')
assert(ischar(parameterName) && isrow(parameterName), 'value must be a char row vector')
parameterNodeNames = obj.All;
for idxNode = 1:numel(parameterNodeNames)
paramNode = parameterNodeNames{idxNode};
if ~any(strcmp(cell(paramNode.varnames), parameterName)); continue; end
paramNode.set(parameterName, value)
return;
end
error('Parameter of with given name is not defined')
end
function out = List(obj)
%Returns a list of all parameters and their values as Nx2 cell
%array
out = cell(0);
parameterNodeNames = obj.All;
for idxNode = 1:numel(parameterNodeNames)
paramNode = parameterNodeNames{idxNode};
parameterNames = paramNode.varnames;
for idxParam = 1:numel(parameterNames)
paramName = char(parameterNames(idxParam));
paramValue = paramNode.get(paramName);
if isa(paramValue, 'java.lang.String'); paramValue = char(paramValue); end
out(end+1, :) = {paramName, paramValue};
end
end
end
end
%% Bool
methods
function out = Exists(obj, parameterName)
%Returns true if given parameter is part of the model
assert(ischar(parameterName) && isrow(parameterName), 'parameterName must be a char row vector')
list = obj.List;
out = any(strcmp(list(:,1), parameterName));
end
end
end
\ No newline at end of file
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