itaMaterial

-added enums for parameter types, e.g.
   -soundhard (impedance, absorption)
   -null (scattering)

itaSimulationInputItem
-added frequency vector for Raven third-octave bands

itaMaterialVisualizer
-fixes according to new parameter types
parent a2978b3d
......@@ -10,6 +10,10 @@ classdef itaMaterial < itaSimulationInputItem
% </ITA-Toolbox>
properties(Access = private, Hidden = true)
mImpedanceType = ImpedanceType.UserDefined;
mAbsorptionType = ImpedanceType.UserDefined;
mScatteringType = ScatteringType.UserDefined;
mImpedance;
mAbsorption;
mScattering;
......@@ -21,6 +25,10 @@ classdef itaMaterial < itaSimulationInputItem
end
properties(Dependent = true)
impedanceType; %ImpedanceType
absorptionType; %ImpedanceType
scatteringType; %ScatteringType
impedance; %Impedance Z - itaSuper
absorption; %Absorption coefficient alpha - itaSuper
scattering; %Scattering coefficient s - itaSuper
......@@ -51,8 +59,35 @@ classdef itaMaterial < itaSimulationInputItem
end
end
methods(Static = true)
function obj = SoundHard()
obj = itaMaterial;
obj.mImpedanceType = ImpedanceType.SoundHard;
obj.mAbsorptionType = ImpedanceType.SoundHard;
end
function obj = SoundHardNoScattering()
obj = itaMaterial;
obj.mImpedanceType = ImpedanceType.SoundHard;
obj.mAbsorptionType = ImpedanceType.SoundHard;
obj.mScatteringType = ScatteringType.Zero;
end
end
%% Set functions
methods
function this = set.impedanceType(this, impedanceType)
assert(isa(impedanceType, 'ImpedanceType'), 'The impedanceType property must be an object of the class ImpedanceType.')
this.mImpedanceType = impedanceType;
end
function this = set.absorptionType(this, absorptionType)
assert(isa(absorptionType, 'ImpedanceType'), 'The absorptionType property must be an object of the class ImpedanceType.')
this.mAbsorptionType = absorptionType;
end
function this = set.scatteringType(this, scatterType)
assert(isa(scatterType, 'ScatteringType'), 'The scatteringType property must be an object of the class ImpedanceType.')
this.mScatteringType = scatterType;
end
function this = set.impedance(this, impedance)
if isnumeric(impedance) && isempty(impedance)
this.mImpedance = [];
......@@ -105,8 +140,24 @@ classdef itaMaterial < itaSimulationInputItem
%% Get functions
methods
function impedanceType = get.impedanceType(this)
impedanceType = this.mImpedanceType;
end
function absorptionType = get.absorptionType(this)
absorptionType = this.mAbsorptionType;
end
function scatteringType = get.scatteringType(this)
scatteringType = this.mScatteringType;
end
function alpha = get.absorption(this)
alpha = this.mAbsorption;
switch this.mAbsorptionType
case ImpedanceType.SoundHard
freqData = zeros( size(this.gaThirdOctavefreqs) );
alpha = itaResult(freqData, this.gaThirdOctavefreqs, 'freq');
otherwise
alpha = this.mAbsorption;
end
end
function alpha = get.absorptionFromImpedance(this)
......@@ -124,25 +175,49 @@ classdef itaMaterial < itaSimulationInputItem
end
function scattering = get.scattering(this)
scattering = this.mScattering;
switch this.mScatteringType
case ScatteringType.Zero
freqData = zeros( size(this.gaThirdOctavefreqs) );
scattering = itaResult(freqData, this.gaThirdOctavefreqs, 'freq');
otherwise
scattering = this.mScattering;
end
end
function Z = get.impedance(this)
Z = this.mImpedance;
switch this.mImpedanceType
case ImpedanceType.SoundHard
Z = inf;
otherwise
Z = this.mImpedance;
end
end
end
%% Booleans
methods
function bool = HasImpedanceType(this, impedanceType)
assert(isa(impedanceType, 'ImpedanceType'), 'Input must be an ImpedanceType')
bool = arrayfun(@(x) x.mImpedanceType == impedanceType, this);
end
function bool = HasAbsorptionType(this, impedanceType)
assert(isa(impedanceType, 'ImpedanceType'), 'Input must be an ImpedanceType')
bool = arrayfun(@(x) x.mAbsorptionType == impedanceType, this);
end
function bool = HasScatteringType(this, scatterType)
assert(isa(scatterType, 'ScatteringType'), 'Input must be a ScatteringType')
bool = arrayfun(@(x) x.mScatteringType == scatterType, this);
end
function bool = HasAbsorption(this)
bool = arrayfun(@(x) ~isempty(x.mAbsorption), this);
bool = arrayfun(@(x) ~isempty(x.mAbsorption), this) | this.absorptionDefinedByType();
end
function bool = HasScattering(this)
bool = arrayfun(@(x) ~isempty(x.mScattering), this);
bool = arrayfun(@(x) ~isempty(x.mScattering), this) | this.scatteringDefinedByType();
end
function bool = HasImpedance(this)
bool = arrayfun(@(x) ~isempty(x.mImpedance), this);
bool = arrayfun(@(x) ~isempty(x.mImpedance), this) | this.impedanceDefinedByType();
end
function bool = HasGaData(this)
......@@ -156,6 +231,23 @@ classdef itaMaterial < itaSimulationInputItem
bool = this.HasImpedance();
end
end
methods(Access = private)
function bool = impedanceDefinedByType(this)
bool = ~this.HasImpedanceType(ImpedanceType.UserDefined);
end
function bool = absorptionDefinedByType(this)
bool = ~this.HasAbsorptionType(ImpedanceType.UserDefined);
end
function bool = scatteringDefinedByType(this)
bool = ~this.HasScatteringType(ScatteringType.UserDefined);
end
end
methods(Hidden = true)
function bool = HasNonInfImpedance(this)
bool = this.HasImpedance & ~this.HasImpedanceType(ImpedanceType.SoundHard);
end
end
methods(Access = private)
function bool = mediumImpedanceDefined(this)
......
......@@ -70,7 +70,7 @@ classdef itaMaterialVisualizer < handle
function varargout = plotImpedance(this, varargin)
%Plots the impedance for all given materials
% For specification of plot input arguments: See ita_plot_freq()
[fgh, ax] = this.plotParameter('impedance', 'HasImpedance', varargin{:});
[fgh, ax] = this.plotParameter('impedance', 'HasNonInfImpedance', varargin{:});
ylabel(ax, 'Impedance\it Z');
if nargout
varargout{1} = fgh;
......@@ -83,7 +83,7 @@ classdef itaMaterialVisualizer < handle
function [fgh, ax] = plotParameter(this, parameter, checkFunction, varargin)
materialsWithParameter = this.mMaterials(this.mMaterials.(checkFunction));
if numel(materialsWithParameter) == 0
error('Cannot plot material parameter, since it is specified for none of the given materials')
error('Cannot plot material parameter, since it is not specified or cannot be visualized for any of the given materials')
end
parameterData = itaResult();
......
......@@ -24,7 +24,11 @@ classdef (Abstract) itaSimulationInputItem
properties(Access = protected)
mName = '';
end
end
properties(Access = protected, Constant = true)
gaThirdOctavefreqs = [20, 25, 31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000]';
end
%% Set / Get
......
classdef ImpedanceType
%ImpedanceType Summary of this class goes here
% Detailed explanation goes here
enumeration
UserDefined, SoundHard;
end
end
classdef ScatteringType
%ScatteringType Summary of this class goes here
% Detailed explanation goes here
enumeration
UserDefined, Zero; %, Constant;
end
end
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