主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

systemcomposer.analysis.ArchitectureInstance

分析实例中的架构

    说明

    一个 ArchitectureInstance 对象代表一个架构的实例。

    创建对象

    使用 instantiate 函数创建一个架构实例。

    instance = instantiate(model.Architecture,'LatencyProfile','NewInstance', ...
    'Function',@calculateLatency,'Arguments','3','Strict',true, ...
    'NormalizeUnits',false,'Direction','PreOrder')

    属性

    全部展开

    实例名称,指定为字符向量。

    示例: 'NewInstance'

    数据类型: char

    实例的子组件,指定为 systemcomposer.analysis.ComponentInstance 对象数组。

    实例端口,指定为 systemcomposer.analysis.PortInstance 对象数组。

    连接子组件的实例中的连接器,指定为 systemcomposer.analysis.ConnectorInstance 对象数组。

    实例中的参数,指定为 systemcomposer.analysis.InstanceParameter 对象数组。

    设计模型中的架构引用,指定为 systemcomposer.arch.Architecture 对象。

    是否对实例化中的属性值进行单位归一化处理,指定为 1 (true) 或 0 (false)。

    数据类型: logical

    实例设定应用了构造型时,实例是否获取属性,指定为 1 (true) 或 0 (false)。

    数据类型: logical

    分析函数,指定为运行分析时要执行的 MATLAB 函数句柄。

    示例: @calculateLatency

    分析方向,指定为以下枚举之一:

    • systemcomposer.IteratorDirection.TopDown

    • systemcomposer.IteratorDirection.BottomUp

    • systemcomposer.IteratorDirection.PreOrder

    • systemcomposer.IteratorDirection.PostOrder

    或下列选项之一的字符向量:'TopDown''PreOrder''PostOrder''BottomUp'

    数据类型: enum | char

    分析参量,指定为分析函数可选参量的字符向量。

    示例: '3'

    数据类型: char

    当设计模型发生变化时,分析查看器是否自动更新,指定为 1 (true) 或 0 (false)。

    数据类型: logical

    对象函数

    getValue从元素实例中获取属性值
    setValue为元素实例设置属性值
    hasValue查找元素实例是否具有属性值
    iterate遍历模型元素
    save保存架构实例
    update更新架构模型
    refresh刷新架构实例
    isArchitecture查找实例是否为架构实例
    isComponent查找实例是否为组件实例
    isConnector查找实例是否为连接器实例
    isPort查找实例是否为端口实例
    getParameter从架构或组件获取参数
    getEvaluatedParameterValue从元素中获取参数的计算值
    getParameterNames获取元素上的参数名
    getParameterValue获取参数值
    setParameterValue设置参数值

    示例

    全部折叠

    为布线有延迟的系统创建分析实例。使用的材料有铜、光纤和 Wi-Fi®。

    使用构造型和属性创建延迟配置文件

    创建一个 System Composer™ 配置文件,其中包含基础、连接器、组件和端口构造型。根据分析需要,为每个构造型添加带有默认值的属性。

    profile = systemcomposer.profile.Profile.createProfile("LatencyProfileC");

    添加带有属性的基本构造型。

    latencybase = profile.addStereotype("LatencyBase");
    latencybase.addProperty("latency",Type="double");
    latencybase.addProperty("dataRate",Type="double",DefaultValue="10");

    添加一个带有属性的连接器构造型。

    connLatency = profile.addStereotype("ConnectorLatency",...
        Parent="LatencyProfileC.LatencyBase");
    connLatency.addProperty("secure",Type="boolean",DefaultValue="true");
    connLatency.addProperty("linkDistance",Type="double");

    添加带有属性的组件构造型。

    nodeLatency = profile.addStereotype("NodeLatency",...
        Parent="LatencyProfileC.LatencyBase");
    nodeLatency.addProperty("resources",Type="double",DefaultValue="1");

    添加带有属性的端口构造型。

    portLatency = profile.addStereotype("PortLatency",...
        Parent="LatencyProfileC.LatencyBase");
    portLatency.addProperty("queueDepth",Type="double",DefaultValue="4.29");
    portLatency.addProperty("dummy",Type="int32");

    使用分析函数实例化

    创建新模型并应用配置文件。在模型中创建组件、端口和连接。对模型元素应用构造型。最后,使用分析函数进行实例化。

    model = systemcomposer.createModel("archModel");
    systemcomposer.openModel("archModel")
    ans = 
      Model with properties:
    
                       Name: 'archModel'
             SimulinkHandle: 153.0012
               Architecture: [1×1 systemcomposer.arch.Architecture]
                   Profiles: [0×0 systemcomposer.profile.Profile]
        InterfaceDictionary: [1×1 systemcomposer.interface.Dictionary]
                      Views: [0×0 systemcomposer.view.View]
               Interactions: [0×0 systemcomposer.interaction.Interaction]
    
    
    arch = model.Architecture;

    将配置文件应用到模型。

    model.applyProfile("LatencyProfileC");

    创建组件、端口和连接。

    componentSensor = addComponent(arch,"Sensor");
    sensorPorts = addPort(componentSensor.Architecture,{'MotionData','SensorPower'},{'in','out'});
    
    componentPlanning = addComponent(arch,"Planning");
    planningPorts = addPort(componentPlanning.Architecture,...
        {'Command','SensorPower','MotionCommand'},...
        {'in','in','out'});
    componentMotion = addComponent(arch,"Motion");
    motionPorts = addPort(componentMotion.Architecture,...
        {'MotionCommand','MotionData'},{'in','out'});
    
    c_sensorData = connect(arch,componentSensor,componentPlanning);
    c_motionData = connect(arch,componentMotion,componentSensor);
    c_motionCommand = connect(arch,componentPlanning,componentMotion);

    清理画布。

    Simulink.BlockDiagram.arrangeSystem("archModel"); 

    对模型元素批量应用构造型。

    batchApplyStereotype(arch,"Component","LatencyProfileC.NodeLatency");
    batchApplyStereotype(arch,"Port","LatencyProfileC.PortLatency");
    batchApplyStereotype(arch,"Connector","LatencyProfileC.ConnectorLatency");

    使用分析函数进行实例化。

    instance = instantiate(model.Architecture,"LatencyProfileC","NewInstance",...
        Function=@calculateLatency,Arguments="3", ...
        Strict=true,NormalizeUnits=false,Direction="PreOrder")
    instance = 
      ArchitectureInstance with properties:
    
            Specification: [1×1 systemcomposer.arch.Architecture]
                 IsStrict: 1
           NormalizeUnits: 0
         AnalysisFunction: @calculateLatency
        AnalysisDirection: PreOrder
        AnalysisArguments: '3'
          ImmediateUpdate: 0
              listenerFnc: []
               Components: [1×3 systemcomposer.analysis.ComponentInstance]
                    Ports: [0×0 systemcomposer.analysis.PortInstance]
               Connectors: [1×3 systemcomposer.analysis.ConnectorInstance]
               Parameters: [0×0 systemcomposer.analysis.InstanceParameter]
                     Name: 'NewInstance'
    
    

    检查组件、端口和连接器实例

    从组件、端口和连接器实例中获取属性。

    defaultResources = instance.Components(1).getValue("LatencyProfileC.NodeLatency.resources")
    defaultResources = 
    1
    
    defaultSecure = instance.Connectors(1).getValue("LatencyProfileC.ConnectorLatency.secure")
    defaultSecure = logical
       1
    
    
    defaultQueueDepth = instance.Components(1).Ports(1).getValue("LatencyProfileC.PortLatency.queueDepth")
    defaultQueueDepth = 
    4.2900
    

    概述

    将典型的汽车电气系统建模为架构模型,并运行基本分析。模型中的元素可大致分为源或负载两类。源和负载的各种属性是作为构造型的一部分设置的。此示例使用规范 API 的 iterate 方法遍历模型的每个元素,并使用构造型属性运行分析。

    模型结构

    发电机在发动机运转时为蓄电池充电。蓄电池和发电机支持车辆的电力负载,如 ECU、收音机和车身控制装置。电感负载(如电机和其他线圈)已定义了 InRushCurrent 构造型属性。根据为每个组件设置的属性,执行以下分析:

    • KeyOffLoad 合计。

    • KeyOffLoad 放电 30% 所需的天数。

    • CrankingInRush 总电流。

    • Cranking 总电流。

    • 根据蓄电池冷启动安培数 (CCA),蓄电池在 0°F 时启动车辆的能力。放电时间根据 Puekert 系数 (k) 计算得出,该系数描述了放电速率与电池可用容量之间的关系。

    加载模型并运行分析

    archModel = systemcomposer.loadModel('scExampleAutomotiveElectricalSystemAnalysis');

    实例化电池选型类,该类由分析函数使用,用于存储分析结果。

    objcomputeBatterySizing = computeBatterySizing;

    使用迭代器运行分析。

    archModel.iterate('Topdown',@computeLoad,objcomputeBatterySizing)

    显示分析结果。

    objcomputeBatterySizing.displayResults
    Total KeyOffLoad: 158.708 mA
    Number of days required for KeyOffLoad to discharge 30% of battery: 55.789.
    Total CrankingInRush current: 70 A
    Total Cranking current: 104 A
    CCA of the specified battery is sufficient to start the car at 0 F.
    
    ans = 
      computeBatterySizing with properties:
    
        totalCrankingInrushCurrent: 70
              totalCrankingCurrent: 104
            totalAccesoriesCurrent: 71.6667
                   totalKeyOffLoad: 158.7080
                        batteryCCA: 500
                   batteryCapacity: 850
                puekertcoefficient: 1.2000
    
    

    scExampleAutomotiveElectricalSystemAnalysis_m_01.png

    关闭模型

    bdclose('scExampleAutomotiveElectricalSystemAnalysis');

    详细信息

    全部展开

    版本历史记录

    在 R2019a 中推出