型号参考¶
在本演示中,我们将使用一个简单的示例来说明如何在Engee中使用Model块。
模型引用本身就是使用 Model 块对另一个模型的引用。此类模型用于创建系统模型的层次结构。参考模型是子系统重用、单元测试、并行构建和大型系统的理想选择。
要实现我们的演示,我们需要两个模型:一个主模型和一个参考模型。

在我们的示例中,我们用简单的元素实现了一个带有两个输入端口的计数器,这两个输入端口分别定义了计数器的步进值和最大值。

之后,我们就可以继续开发主模型,在主模型中,我们将使用 Model 块引用已实现的计数器。
为了连接模型,我们将使用模型选择功能。

现在,在打开的文件管理器窗口中选择我们已经实现的计数器模型。

这样,我们就有了一个带有子系统的基本模型,并将其存储在一个单独的文件中。通过这种实现方式,我们可以在一个项目中多次重复使用这个计数器。同时,在更改了参考子系统中的逻辑后,我们将把这些更改应用到引用原始模型的所有模块中。

现在,让我们运行模型并分析计数器运行的正确性。
Out[0]:
run_model (generic function with 1 method)
Building...
Progress 100%
Progress 100%
Out[0]:
Dict{String, DataFrame} with 1 entry:
"Model.Cnt" => 11×2 DataFrame…
从上图可以看出,计数器确实以 1 为增量递增,计数器的最大值为 5。
这样的计数器可以无限增加。下面的示例展示了一个有两个并行计数器的模型。

在这种情况下,当再次添加区块时,有必要更新连接器,以便与重复的子系统进行进一步的工作。

Building...
Progress 100%
Progress 100%
Out[0]:
Dict{String, DataFrame} with 2 entries:
"Model.Cnt" => 11×2 DataFrame…
"Model-1.Cnt" => 11×2 DataFrame…
我们可以看到,在这种情况下,两个计数器并行工作,且具有不同的最大值。
在本示例中,我们分析了使用模型参考的可能性,并展示了如何将其应用到项目中。这种系统设计方法大大简化了项目工作,也减少了在项目发生变化时编辑模块所花费的时间。
{"id": "59ae536d-ccc9-4593-b4ee-24246ee14d98", "data": [{"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y", "legendgroup": "y1", "zmax": null, "line": {"color": "rgba(0, 154, 250, 1.000)", "shape": "linear", "dash": "solid", "width": 1}, "y": [1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1], "type": "scatter", "x": [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 21, "currentCount": 21}}}], "config": {"showlegend": true, "xaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [0, 2.5, 5, 7.5, 10], "range": [-0.3000000000000007, 10.3], "domain": [0.02137649460484106, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["0.0", "2.5", "5.0", "7.5", "10.0"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [], "height": 400, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "yaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [1, 2, 3, 4, 5], "range": [0.8799999999999999, 5.12], "domain": [0.03762029746281716, 0.9901574803149606], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["1", "2", "3", "4", "5"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "legend": {"yanchor": "auto", "xanchor": "auto", "bordercolor": "rgba(0, 0, 0, 1)", "bgcolor": "rgba(255, 255, 255, 1.000)", "borderwidth": 1, "tracegroupgap": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}, "text": ""}, "traceorder": "normal", "x": 1}, "width": 586.921875}}
{"id": "b1b99caa-a1c1-41b4-bd41-868ca6247619", "data": [{"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y1", "zmin": null, "yaxis": "y", "legendgroup": "y1", "zmax": null, "line": {"color": "rgba(0, 154, 250, 1.000)", "shape": "linear", "dash": "solid", "width": 1}, "y": [1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1], "type": "scatter", "x": [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 21, "currentCount": 21}}}, {"showlegend": true, "mode": "lines", "xaxis": "x", "colorbar": {"title": {"text": ""}}, "name": "y2", "zmin": null, "yaxis": "y", "legendgroup": "y2", "zmax": null, "line": {"color": "rgba(227, 111, 71, 1.000)", "shape": "linear", "dash": "solid", "width": 1}, "y": [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 1, 1, 2, 2, 3, 3, 4, 4], "type": "scatter", "x": [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10], "zaxis": null, "z": null, "metadata": {"shouldEnableSmartZoom": false, "smartZoomParams": {"minCount": 25000, "maxCount": 21, "currentCount": 21}}}], "config": {"showlegend": true, "xaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [0, 2.5, 5, 7.5, 10], "range": [-0.3000000000000007, 10.3], "domain": [0.02137649460484106, 0.9934383202099737], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["0.0", "2.5", "5.0", "7.5", "10.0"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "y", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "annotations": [], "height": 400, "margin": {"l": 0, "b": 20, "r": 0, "t": 20}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "yaxis": {"showticklabels": true, "gridwidth": 0.5, "tickvals": [1, 2, 3, 4, 5, 6, 7], "range": [0.8199999999999998, 7.18], "domain": [0.03762029746281716, 0.9901574803149606], "mirror": false, "tickangle": 0, "showline": true, "ticktext": ["1", "2", "3", "4", "5", "6", "7"], "zeroline": false, "tickfont": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "zerolinecolor": "rgba(0, 0, 0, 1)", "anchor": "x", "visible": true, "ticks": "inside", "tickmode": "array", "linecolor": "rgba(0, 0, 0, 1)", "showgrid": true, "title": {"text": "", "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}}, "gridcolor": "rgba(0, 0, 0, 0.1)", "tickcolor": "rgb(0, 0, 0)", "type": "linear"}, "legend": {"yanchor": "auto", "xanchor": "auto", "bordercolor": "rgba(0, 0, 0, 1)", "bgcolor": "rgba(255, 255, 255, 1.000)", "borderwidth": 1, "tracegroupgap": 0, "y": 1, "font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 11}, "title": {"font": {"color": "rgba(0, 0, 0, 1)", "family": "sans-serif", "size": 15}, "text": ""}, "traceorder": "normal", "x": 1}, "width": 586.921875}}