文档

Model Reference Basics

You can include one model in another by using aModel堵塞。每个实例Modelblock is amodel reference。For simulation and code generation, blocks within a引用模型作为一个单位一起执行。包含引用模型的模型是parent model。一个collection of parent and referenced models constitutes a模型层次结构

模型可以作为独立模型和引用模型的功能,而无需更改模型或任何从中衍生的实体。要将引用模型用作独立模型,引用模型不能依赖于仅从高级模型可用的数据。

Model Reference Advantages

像子系统一样,模型参考可以使您可以从层次上组织大型模型。像库一样,模型参考可以使您可以定义一组块并重复使用它。模型参考提供了几个优点,这些优点与子系统和库中不可用。这些优势中有几个优势是由参考模型独立于汇编的参考模型而产生的Modelblock, including:

  • Modular development

    您可以独立于使用它的模型开发引用模型。

  • 模型保护

    With a金宝app®Coder™许可证,您可以掩盖引用模型的内容,使您可以在不揭示其知识产权的情况下分发该模型。

    使用Simul金宝appink许可证,您可以参考第三方提供的受保护模型。根据授予的受保护模型权限,您可以查看,模拟和生成受保护模型的代码。

  • 通过参考

    您可以多次参考模型而不制作冗余副本,并且多个模型可以引用相同的模型。

  • 增量加载

    Simulink software loads a referenced model when it is needed, which speeds up model loading.

  • 一个ccelerated simulation

    Simulink software can convert a referenced model to code and simulate the model by running the code, which is faster than interactive simulation.

  • Incremental code generation

    一个ccelerated simulation generates code only if the model has changed since the code was previously generated.

  • Independent configuration sets

    这configuration set used by a referenced model can differ from the configuration set of its parent or other referenced models.

For a video summarizing model reference advantages, seeModular Design Using Model Referencing

来compare model references, subsystems, and libraries, see在模型组件的类型中选择。您可以在同一模型中使用多个组件化技术。

模型层次结构

引用的模型可以包含Model阻止参考低级模型。这top modelis the top model in a hierarchy of referenced models. Where only one level of model reference exists, the parent model and top model are the same. To prevent cyclic inheritance, aModelblock cannot refer directly or indirectly to a model that is superior to it in the model hierarchy. This figure shows cyclic inheritance.

父模型可以包含多个Modelblocks that reference the same referenced model, as long as the referenced model does not define global data. For example, thesldemo_mdlref_basicmodel includesModel引用相同引用模型的三个实例的块,sldemo_mdlref_counter

引用的模型也可以在任何级别的其他父模型中出现。

Model Block and Referenced Model Interface

一个Model块显示与IT引用模型的根级输入,输出和控制端口相对应的输入,输出和控制端口。要将引用模型连接到父模型的其他元素,请使用这些Model块端口。将信号连接到Model块端口将信号连接到引用模型中的相应端口。

在模型中sldemo_mdlref_basic, 每个Modelblock has three inputs: twoConstant块和a脉冲发生器堵塞。EachModelblock has one output signal logged to a scope. Because the input signal from each脉冲发生器block uses a different sample time, the output signal from eachModelblock differs for each model instance.

要连接到父模型,请参考模型sldemo_mdlref_counterincludes threeInport块(,,,,lower,,,,and输入)和一个Outportblock (output)。如果您更改引用模型中的端口,请刷新Modelblock to reflect these changes.

Signal attributes in the referenced model are independent from the context of theModel堵塞。例如,信号尺寸和数据类型不会在整个Model块边界。来define signal attributes in the referenced model, define block parameters for root-levelInportand在公交元素中blocks.

For more information, see模型参考接口和边界

Model Workspaces and Data Dictionaries

Each model has its own workspace for storing variable values. In a model hierarchy, each model workspace acts as a unique namespace. Therefore, you can use the same variable name in multiple model workspaces. To share data among models, you can use a data dictionary.

Duplicate data definitions can exist in a model reference hierarchy under these conditions:

  • 层次结构中的每个模型只能看到一个定义。

  • Definitions must be the same across models in the hierarchy.

有关您可以在何处存储变量和对象的更多信息,请参阅Determine Where to Store Variables and Objects for Simulink Models

引用模型执行

使用外部信号来控制是否Model模拟过程中的块执行,请参阅修改有条件执行的引用模型

Variant Subsystem可以包含块Modelblocks as variant systems. For information on variant systems, seeWhat Are Variants and When to Use Them

默认情况下,块参数在每个中具有相同的值Modelblock instance of a reusable referenced model. To specify a different block parameter value for each instance of a reusable referenced model, create model arguments. For example, if you add aGainblock to modelsldemo_mdlref_counter,,,,model arguments allow each of the three instances of this model to use different gain values. See可重复使用的参考模型的参数化实例

使用模型面具,您可以控制Model块并自定义块显示模型参数的方式。对于模型掩码要求,请参阅型号面具

Referenced Model Simulation and Code Generation

您可以解释性(在正常模式)或通过将引用模型编译为代码并执行代码(以加速器模式)来模拟引用的模型。有关详细信息,请参阅选择模型层次结构的仿真模式

金宝appSimulink缓存文件包含可以加快模拟和代码生成的构建工件。有关更多信息和示例工作流,请参阅Share Build Artifacts for Faster Simulation and Code Generation

来learn about considerations for generating code for a referenced model, seeCode Generation of Referenced Models(金宝appSimulink编码器)。

也可以看看

Blocks

相关示例

更多关于