分析函数构造
分析架构,在设计方案之间进行选择或改进现有设计。您可以使用分析函数与 System Composer™ 架构模型一起执行系统分析和权衡研究。分析函数是一个 MATLAB® 函数,它使用模型实例中每个元素的属性以及组件和架构层级的实例特定参数计算评估架构所需的值。使用分析函数计算分析结果,并确定用于行为模型的最佳参数,以仿真架构系统。
类型 | 小节 |
---|---|
汇总分析 | 四旋翼无人机设计中的卷积分析 |
基于类的分析 | 基于类别的电池选型分析 |
基于分配的分析 | 基于分配的轮胎压力监测分析 |
剩余使用寿命 (RUL) 分析 | 移动机器人设计的剩余使用寿命分析 |
变体分析 | 胰岛素输液泵设计的变体分析 |
参数分析 | 汽车轮胎平均磨损的参数分析 |
有关分析函数和架构实例的更多信息,请参阅分析架构。
提示
要了解更多关于 System Composer 概念在系统工程设计中的应用,请参阅System Composer 概念。
四旋翼无人机设计中的卷积分析
使用汇总分析函数计算模型元素属性的总值或平均值。使用构造型为模型元素分配属性。有关详细信息,请参阅在配置文件中定义和设置构造型。
在此示例中,分析函数 CostAndWeightRollupAnalysis
计算模型中所有组件的总成本,并与分析查看器工具兼容。
function CostAndWeightRollupAnalysis(instance,varargin) % Analysis function for the RobotPhysicalArchitecture.slx example % Calculate total price if instance.isComponent() && ~isempty(instance.Components)... && instance.hasValue('SystemProfile.PhysicalElement.UnitCost') sysComponent_unitPrice = 0; for child = instance.Components if child.hasValue('SystemProfile.PhysicalElement.UnitCost') comp_price = child.getValue('SystemProfile.PhysicalElement.UnitCost'); sysComponent_unitPrice = sysComponent_unitPrice + comp_price; end end instance.setValue('SystemProfile.PhysicalElement.UnitCost',sysComponent_unitPrice); end
此分析函数遍历架构实例。首先,将 sysComponent_unitPrice
变量设置为零,以便每次运行分析时,累加的值不会无限累积。检查每个组件实例的 UnitCost
属性值。所有 UnitCost
属性的值被求和并保存在 sysComponent_unitPrice
变量中。最后,当前组件实例的 UnitCost
属性将更新为 sysComponent_unitPrice
的值。有关更多信息,请参阅编写分析函数和使用具有属性的机器人系统进行简单的汇总分析。
在此示例中,分析函数 calculateEndurance
的一个部分使用组件实例属性计算四轴飞行器的耐久性。然后,使用函数 setValue
将计算出的耐久值设置为四轴飞行器的架构实例。
if payloadBatteryCapacity == 0 totalPower = powerConsumption + hoverPower/efficiency; endurance = (batteryCapacity/1000)/(totalPower/voltage)*60; else payloadEndurance = (payloadBatteryCapacity/1000)/(powerConsumption/voltage)*60; flightEndurance = (batteryCapacity/1000)/((hoverPower/efficiency)/voltage)*60; if flightEndurance < payloadEndurance endurance = flightEndurance; else endurance = payloadEndurance; warning('Endurance is limited by payload electronics.') end end instance.setValue('AirVehicle.Endurance',endurance)
有关更多信息和支持文件,请参阅使用四轴飞行器架构设计计算耐久性。
基于类别的电池选型分析
使用 MATLAB 类对分析函数进行迭代,或对类进行实例化。
在此示例中,名为 computeBatterySizing
的类包含对分析函数 computeLoad
有用的属性和方法。
classdef computeBatterySizing < handle properties totalCrankingInrushCurrent; totalCrankingCurrent; totalAccesoriesCurrent; totalKeyOffLoad; batteryCCA; batteryCapacity; puekertcoefficient; end methods function obj = computeBatterySizing(obj) obj.totalCrankingInrushCurrent = 0; obj.totalCrankingCurrent = 0; obj.totalAccesoriesCurrent = 0; obj.totalKeyOffLoad = 0; obj.batteryCCA = 0; obj.batteryCapacity = 0; obj.puekertcoefficient = 1.2; end function obj = displayResults(obj) tempNumdaysToDischarge = ... (((obj.batteryCapacity/obj.puekertcoefficient)*0.3)/(obj.totalKeyOffLoad*1e-3))/24; disp("Total KeyOffLoad: " + num2str(obj.totalKeyOffLoad) + " mA"); disp("Number of days required for KeyOffLoad to discharge 30% of battery: " + ... num2str(tempNumdaysToDischarge) + "."); disp("Total CrankingInRush current: " + num2str(obj.totalCrankingInrushCurrent) + " A"); disp("Total Cranking current: " + num2str(obj.totalCrankingCurrent) + " A"); if(obj.totalCrankingCurrent > obj.batteryCCA) disp("The Cold Cranking Amps of the specified battery is not sufficient to start the car 0 F.") else disp("CCA of the specified battery is sufficient to start the car at 0 F.") end end end end
有关更多信息和支持文件,请参阅电池选型与汽车电气系统分析。
基于分配的轮胎压力监测分析
功能到逻辑分配矩阵将功能架构中的组件分配到逻辑架构中的组件。覆盖率分析是确定所有元素是否已分配的最基本分析形式。
首先,打开此示例的工程。然后,加载分配集并收集场景。
scExampleTirePressureMonitorSystem
allocSet = systemcomposer.allocation.load('FunctionalAllocation');
scenario = allocSet.Scenarios;
确认系统中的每个函数都已分配。
import systemcomposer.query.*; [~, allFunctions] = ... allocSet.SourceModel.find(HasStereotype(IsStereotypeDerivedFrom("TPMSProfile.Function"))); unAllocatedFunctions = []; for i = 1:numel(allFunctions) if isempty(scenario.getAllocatedTo(allFunctions(i))) unAllocatedFunctions = [unAllocatedFunctions allFunctions(i)]; end end if isempty(unAllocatedFunctions) fprintf('All functions are allocated'); else fprintf('%d Functions have not been allocated', numel(unAllocatedFunctions)); end
All functions are allocated
输出验证所有函数均已分配。
有关更多信息和支持文件,请参阅胎压监测系统中的架构分配。
移动机器人设计的剩余使用寿命分析
剩余使用寿命 (RUL) 分析估算不同子系统在发生故障前剩余的使用时间。目标是提前预测维护需求,从而最大限度地减少系统中断。
在此示例中,分析函数 scMobileRobotAnalysis
与工具分析查看器兼容。
function scMobileRobotAnalysis(instance,varargin) ExpectedYearsBeforeFirstMaintenance = 2; if ~instance.isArchitecture() if instance.hasValue("HardwareBaseStereotype.Life") Life = instance.getValue("HardwareBaseStereotype.Life"); UsagePerDay = instance.getValue("HardwareBaseStereotype.UsagePerDay"); UsagePerYear = instance.getValue("HardwareBaseStereotype.UsagePerYear"); WillSurvive = Life > UsagePerDay * UsagePerYear * ExpectedYearsBeforeFirstMaintenance; instance.setValue("HardwareBaseStereotype.ExceedExpectedMaintenance", WillSurvive); end end end
运行此分析函数后,您可以优化所需的第一个预期维护时间(以年为单位)。超过预期维护时间(在此例中设置为两年)的每个组件都会用复选框标记。未检查的组件应进行优化或更换为更耐用的部件。
有关更多信息和支持文件,请参阅定义移动机器人的构造型并执行分析。
胰岛素输液泵设计的变体分析
使用变体分析,通过与计算出的度量进行比较,选择一个最佳的变体组合。
在此示例中,分析函数 OutcomeAnalysis
用于确定胰岛素输液泵的最佳配置。此独立分析函数不涉及分析查看器工具。相反,分析函数使用 iterate
函数,可直接从 MATLAB 命令行窗口执行。
函数 OutcomeAnalysis
首先收集所有名为 Pump
和 BGSensor
的变体选择项组件。
function outcomes = OutcomeAnalysis() modelname = 'InsulinInfusionPumpSystem'; therapyModel = systemcomposer.openModel(modelname); components = therapyModel.Architecture.Components; for idx = 1:numel(components) if strcmp(components(idx).Name,'Pump') pumps = components(idx).getChoices; pumpNames = {}; for jdx = 1:numel(pumps) pumpNames{end+1} = pumps(jdx).Name; end elseif strcmp(components(idx).Name,'BGSensor') sensors = components(idx).getChoices; sensorNames = {}; for jdx = 1:numel(sensors) sensorNames{end+1} = sensors(jdx).Name; end end end
然后,分析函数收集所有变体组合以进行迭代。
config.Sensor = sensorNames{1}; config.Pump = pumpNames{1}; configs = {}; for idx = 1:numel(sensorNames) for jdx = 1:numel(pumpNames) config.Sensor = sensorNames{idx}; config.Pump = pumpNames{jdx}; configs{end+1} = config; end end
分析函数依次激活变体,遍历模型属性,并收集结果。要设置变体组合,OutcomeAnalysis
使用 setVariants
函数。为了计算结果,OutcomeAnalysis
使用了 computeOutcome
函数。
outcomes = {}; for idx = 1:numel(configs) hOutcome = OutcomeContainer(configs{idx}); therapyModel.iterate('Topdown',@setVariants,configs{idx}); therapyModel.iterate('BottomUp',@computeOutcome,hOutcome); hOutcome.setWeights([1e-6 1 10 1 1000]'); outcomes{end+1} = hOutcome; end
最后,分析函数绘制净结果图,以显示最佳设计选择。
properties = {'Lower NRE','Higher Accuracy','Better Compliance',... 'Sooner To Market','Lower Operating Cost'}; plotMatrix = zeros(numel(outcomes), numel(properties)); plotStrings = {}; for idx = 1:numel(outcomes) plotStrings{idx} = [outcomes{idx}.Sensor '+' outcomes{idx}.Pump]; plotMatrix(idx,1) = 1/(outcomes{idx}.NRE); plotMatrix(idx,2) = outcomes{idx}.Accuracy; plotMatrix(idx,3) = outcomes{idx}.Compliance; plotMatrix(idx,4) = 1/(outcomes{idx}.TimeToMarket); plotMatrix(idx,5) = 1/(outcomes{idx}.AnnualCost); end colmin = zeros(1,5); colmax = max(plotMatrix); normalizedMatrix = rescale(plotMatrix,'InputMin',colmin,'InputMax',colmax); if exist('spider_plot') == 2 fig = figure; spider_plot(normalizedMatrix,'AxesLabels',properties,'FillOption','on',... 'FillTransparency',0.1,'AxesDisplay','one'); title(sprintf('Trade Study Outcome'),... 'FontSize', 14); legend(plotStrings, 'Location', 'eastoutside'); pos = fig.Position; pos(2) = pos(2) - pos(4); pos(3) = 2*pos(3); pos(4) = 2*pos(4); fig.Position = pos; else vals = sum(normalizedMatrix,2)/5; x_labels = categorical(plotStrings); h = bar(x_labels,vals); title('Net outcome'); ax = h.Parent; ax.YLabel.String = 'Normalized units'; end
有关更多信息和支持文件,请参阅使用基于模型的系统工程设计胰岛素输液泵。
汽车轮胎平均磨损的参数分析
架构模型中的参数提供了一种定义实例特定参数值的方法。这些参数值在多个组件中引用的同一模型的不同实例中是唯一的。您可以使用标准模板中的轮子引用组件,并将 mWheel.slx
模型链接到四个不同的组件,从而在汽车架构模型中使用该轮子四次。
在分析中使用参数来分析四个车轮的 Wear
参数值,并计算轮胎的平均磨损,作为耐久性的衡量标准。
function calculateAverages(instance,varargin) % Analysis function calculating the average wear of tires in a vehicle % Pass the number of tires as an input to the analysis function if numel(varargin) > 0 numTires = eval(varargin{1}); end % Get the architecture instance as a place to accumulate the total wear using a % stereotype property if instance.isArchitecture archInst = instance; else % Get the architecture instance from the path of the node currently being % iterated instName = strsplit(instance.QualifiedName,'/'); archInst = systemcomposer.analysis.lookup(string(instName{1})); end if instance.isComponent && any(instance.getParameterNames.matches("Wear")) % Get the stored stereotype property value on the architecture instance accumulatedValue = archInst.getValue('AxleProfile.Metrics.total_wear'); % Get the evaluated parameter value from the instance currentValue = instance.getEvaluatedParameterValue("Wear"); % Update the accumulated value newValue = accumulatedValue + currentValue; % Update the stereotype property value on the architecture instance archInst.setValue('AxleProfile.Metrics.total_wear',num2str(newValue)); if newValue > 0 fprintf(sprintf("Average wear of tires: %f\n", ... newValue/numTires)); end end end
有关更多信息和支持文件,请参阅汽车轮胎平均磨损分析。
另请参阅
systemcomposer.analysis.Instance
| iterate
| instantiate
| deleteInstance
| update
| refresh
| save
| loadInstance
| lookup
| getValue
| setValue
| hasValue
| getParameter
| getEvaluatedParameterValue
| getParameterNames
| getParameterValue
| setParameterValue