什么会影响 Modelica 中的仿真运行时间 [英] what does impact a simulation runtime in Modelica

查看:74
本文介绍了什么会影响 Modelica 中的仿真运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了使我在 Modelica 中的模型模拟运行得更快,我问以下问题:什么会影响 Modelica 中的仿真运行时间?

In order to make my model simulation's in Modelica run faster am asking the following quesion : What does impact simulation runtime in Modelica ?

我会感谢任何可能的帮助.

i will aprecicate any help possible.

推荐答案

更多细节可以参考我的书Modelica by Application -- Power Systems"(网址)

More details can be consulted from my book "Modelica by Application -- Power Systems" (URL)

什么会影响运行时性能?

我.应用编译技术

自然,面向对象的 Modelica 模型,即使是微不足道的模型,也会对应于大型方程组.Modelica 仿真环境通常会优化此类生成的模型:

Naturally, object-oriented Modelica models, even trivial ones, would correspond to a large-scale system of equations. Modelica simulation environments would usually optimize such generated models:

  • 通过删除微不足道的方程(即别名方程)来减少可能方程的数量
  • 使用所谓的 BLT 变换将大块方程组分解为更小的级联方程组块,这些块可以以顺序方式更快地求解,而不是作为单个方程块,
  • 解决s.c.使用撕裂方法的大型代数环.
  • 理论上它甚至可以走得太远,如果可能的话,尝试以解析的方式求解方程组块,而不是进行昂贵的数值积分

因此,运行时性能将受到底层 Modelica 编译器的影响,以及它利用基于方程的编译器方法的程度.通常需要激活一些额外的设置来利用所有可能的此类技术.需要挖掘文档以启用此类设置.

Thus, the runtime performance would be influenced by the underlying Modelica compiler and how far does it exploit equation-based compiler methods. Usually some extra settings need to be activated to exploit all possible kind of such techniques. Digging the documentation to enable such settings is needed.

二.模型的性质

模型的性质会影响运行时性能,尤其是:

The nature of the model would influence the runtime performance, particularly:

  1. 该模型是一个大型系统吗?还是小规模的?
  2. 是强非线性还是半线性?
  3. 得到的优化方程系统对应于模型是稀疏的(即大量方程组,每个方程的变量数量很少,例如电力系统网络模型)还是密集的(例如多体系统和生化网络)
  4. 这是一个僵硬的系统吗?(例如,具有多个子系统的系统,其中一些表现出非常快的动态,而另一些表现出非常缓慢的动态)
  5. 系统是否表现出大量的状态事件
  6. ...

III 求解器的选择

给定模型的上述特征通常会影响求解器的理想选择.求解器可以在很大程度上影响运行时性能(和准确性).可以按以下顺序制定求解器选择策略:

The mentioned characteristics of a given model would typically influence the ideal choice of the solver. The solver can largely influence the runtime performance (and accuracy). A strategy for solver choice could be made in the following order:

  1. 对于非刚性弱非线性模型,理想的选择是显式方法,例如更高阶的单步 Runga-Kutta 或多步 Adam-Bashforth.如果准确性不那么重要,可以尝试一种执行速度更快的低阶显式方法.当然,增加求解器容错能力也会加快模拟速度.

  1. For a non-stiff weakly nonlinear model, the ideal choice would be an explicit method, e.g. Single-step Runga-Kutta or Multi-step Adam-Bashforth of higher order. If accuracy is less significant, one can attempt an explicit method of a lower order which would executes faster. Naturally, increasing the solver error tolerance would also speed-up the simulation.

但是,可能会发生这种情况,特别是对于大型系统,数值稳定性可能更难以保证.然后,应该尝试显式求解器的较小求解器步长(和/或较小的误差容限).在这种情况下,容错较大的隐式求解器可以与容错较小的显式求解器相媲美.

However, it could happen, particularly for large-scale systems, that numerical stability could be more difficult to guarantee. Then, smaller solver step-sizes (and/or smaller error tolerance) for explicit solvers should be attempted. In this case, an implicit solver with larger error tolerance can be comparable with an explicit solver with a smaller tolerance.

实际上,最好同时尝试这两种方法,比较结果的准确性,并确定显式方法是否能产生相对准确的结果.但是,作为警告,这只是一种启发式方法,因为系统不一定在整个可允许参数值空间上具有相同的行为.

Actually, it is wise to try both methods, comparing the accuracy of the results, and figuring out if explicit methods produce comparably accurate results. However, as a warning this would be just a heuristic, since the system does not necessarily have the same behavior over the entire space of admissible parameter values.

  1. 为了增加模型的非线性,选择将更倾向于使用可变步长技术的现代求解器.在这里,我将从隐式可变步长 Runga-Kutta(即单步)和/或隐式可变步多步方法 Adams-Moulton 开始.对于这两个类别,您可以扩大求解器容差和/或降低求解器误差阶数,并确定模拟是否能生成相对准确的解(但运行时间更快).

  1. For increasing nonlinearity of the model, the choice would tend more towards modern solvers making use of variable step-size techniques. Here I would start with implicit variable-step Runga-Kutta (i.e. single-step) and/or the implicit variable-step multi-step methods, Adams–Moulton. For both of these classes, one can enlarge the solver tolerance and/or lower the solver error order and figure out if the simulation produces comparably accurate solutions (but with faster runtime).

前几类方法的实现通常在误差控制方面不太保守,因此,为了增加模型的刚度或可扩展性差的模型,选择更倾向于现代求解器实现所谓的数值更稳定后向微分公式(BDF),saDASSL、CVODE、IDA.这些求解器(可以)也使用 s.c.自适应步长控制系统的雅可比矩阵.

Implementations of the previous classes of methods are usually less conservative with error control, and therefore, for increasing stiffness of the model or badly scalable models, the choice would tend more towards modern solvers implementing so-called numerically more stable backward differentiation formula (BDF), s.a. DASSL, CVODE, IDA. These solvers (can) also make use of the s.c. Jacobian of the system for adaptive step-size control.

像 LSODAR 这样的现代求解器可以在显式和隐式求解器之间切换并执行自动错误顺序控制(在不同顺序之间切换),如果人们不了解有关模型行为的那么多信息,则是一个不错的选择.可能某些 Modelica 环境具有使用自动切换的高级求解器.但是,如果事先知道模型的行为,那么使用其他建议的方法也是明智的,因为 LSODAR 在需要时可能无法执行最佳切换.

A modern solver like LSODAR that switches between explicit and implicit solvers and also perform automatic error order control (switching between different orders) is a good choice if one does not know that much information about the behavior of the model. May be some Modelica environments have an advanced solver making use of automatic switching. However, if one knows the behavior of the model in advance, it is also wise to use other suggested methods since LSODAR may not perform the most optimal switching when needed.

x....

3,4 和 5 类求解器之间的比较并不容易判断,还取决于系统是连续的还是混合的,即底层的寻根算法.

The comparisons between solvers from classes 3,4 and 5 are not straightforward to judge and it depends also on whether the system is continuous or hybrid, i.e. the underlying root-finding algorithms.

通常 DASSL 可能会更慢,因为它在步长/误差控制方面更为保守.所以看起来IDA等的速度更快.一些已发表的作品可以提供有关此类比较的一些直觉.如果 Modelica 库包含所有可能的模型类型并运行所有可能的基准测试,那就太好了.准确性和运行时间来得出更多求解器/模型特定的结论.ScalableTestSuite Modelica 库.

Usually DASSL could be slower as it is more conservative with step-size/error control. So it seems that IDA and others are faster. Some published works exist that can give some intuitions regarding such comparisons. It would be nice to have a Modelica library including all possible types of models and running all possible benchmarks w.r.t. accuracy and runtime to draw some more solver/model specific conclusions. A library that could be used and extended for such a purpose is the ScalableTestSuite Modelica library.

四.高级方面

  1. Modelica 社区已经发表了一些关于使用稀疏求解器来利用雅可比矩阵的预期稀疏性的作品.如果仿真环境提供这样的功能,通常会显着提高大规模模型的运行时性能.

  1. There have been some published works in the Modelica community regarding making use of sparse solvers to exploit the expected sparsity of the Jacobian. If such a feature is provided by the simulation environment, this would usually significantly improve the runtime performance of large-scale models.

对于具有大量事件的模型,以标准方式进行数值积分可能非常低效.特别具有挑战性的是,当一个事件被触发时,可以进一步触发其他状态事件集,并且应该评估状态事件队列.寻根算法可能会进一步触发其他事件,并且求解器可能会挂在 s.c. 中.喋喋不休的情况.有针对这种情况的高级策略,s.c.滑动模式,但是我不确定 Modelica 模拟环境在多大程度上解决了这个问题.

For models with massive number of events, numerical integration in the standard way can be extremely inefficient. Particularly challenging is when an event is triggered, other sets of state-events could be further triggered and a queue of state-events should be evaluated. The root-finding algorithm could further trigger other events and the solver could be hanging on in a s.c. chattering situation. There are advanced strategies for such situations, s.c. sliding mode, however I am not sure how far Modelica simulation environments are handing this issue.

一组建议的解决方案(也适用于具有高刚度的系统)是采用所谓的 QSS(量化状态系统)方法.这对于无法使用显式求解器求解的模型尤其有益.有显式和隐式 QSS 方法.还有其他值得尝试的数值积分策略,其中在逼近状态事件时仅评估整个方程系统的子集.在这里,我不确定此类求解器是否可用.

One set of suggested solutions (also for systems with high degree of stiffness) is to employ so called QSS (quantized state system) methods. This would be significantly beneficial particularly for models that can not be solved using explicit solvers. There are both explicit and implicit QSS methods. There have been also other worth-to-try numerical integration strategies where only subsets of the entire equation system is evaluated when approximating a state event. Here I am not sure about availability of such solvers.

某些仿真环境区分两种可能影响仿真运行时间的仿真模式:ODE 模式和 DAE 模式.在第一种模式中,系统被简化为 ODE 系统,其中可能具有额外的非线性方程组级联块.在 DAE 模式下,系统被简化为索引为 1 的 DAE 系统.前一种模式将有益于密集系统,该系统展示了使用 s.c. 求解的非线性方程的大型级联块.撕裂方法而不是数值积分.DAE 模式将有利于使用稀疏求解器求解的大规模稀疏系统.我认为 ODE 模式通常通过选择 CVODE 或 LSODAR 激活,而 DAE 模式通过选择 IDA 或 DASSL 激活.但也建议在这里和那里挖掘文档.

Some simulation environments differentiate between two simulation modes which can influence the simulation runtime: the ODE Mode and DAE Mode. In the first mode, the system is reduced to an ODE system with potentially additional cascaded blocks of nonlinear equation systems. In the DAE mode, the system is reduced to a DAE system of index one. The former mode would be beneficial for dense systems exhibiting such large cascaded blocks of nonlinear equations to be solved using s.c. Tearing methods instead of numerical integration. The DAE mode would be beneficial for large-scale sparse systems solved using sparse solvers. I think the ODE mode is usually activated by choosing CVODE or LSODAR while DAE mode is activated by choosing IDA or DASSL. But digging the documentation here and there is also recommended.

还有一些关于所谓的多速率数值积分求解器的已发表作品.这里,在每个数值积分步骤中,仅积分方程系统的数值重要部分,而不是整个方程系统.因此,这对大规模刚性系统非常有益.

There are also some published works regarding so called multirate numerical integration solvers. Here, in each numerical integration step, only the numerically-significant portion of the equation system and not the entire equation system is integrated. Hence, this is significantly beneficial for large-scale stiff systems.

x....

V.并行化

显然,利用多核/GPU 并行执行数值积分,以及应用并行化的其他方法可以加快计算速度.

Obviously, making use of multicore / GPUs for executing numerical integration in parallel, among other approaches for applying parallelization can speed-up computations.

六.非常非常高级的主题

为了关注一些优秀的研究尝试,其中一些可用于加速大规模(松散耦合)混合网络模型的仿真运行时性能,我也在这里列出.通过使用混合范式、基于代理的建模范式和/或多模式范式,可以获得加速.背后的想法是可以在几个较小的子系统中描述一个松散耦合的系统,并仅在必要时进行子系统之间的通信.这可能是有益的,并且可以通过搜索相关出版物来追溯原因.在提到的一些方向上已经有一些出色的工作,如果是这种情况,值得在他们停止的地方继续他们.

In order to pay attention at some excellent research attempts some of which can be exploited for speeding up the simulation runtime performance of large-scale (loosely-coupled) hybrid networked models, I am listing this here as well. Speed-up can be obtained by making use of hybrid paradigms, agent-based modeling paradigm and/or multimode paradigm. The idea behind is that it is possible to describe a loosely coupled system in several smaller subsystems and conduct the communication among subsystems only when necessary. This can be beneficial and the reasons can be traced by searching for relevant publications. There have been some excellent work in some of the mentioned directions, and it is worth to continue them where they have stopped if this is the case.

备注:上述任何求解器不一定出现在所有可能的 Modelica 仿真环境中.如果没有提供求解器作为选择,人们仍然可以生成 FMU-ME(用于模型交换的功能模型单元)并编写代码,将该 FMU 与所需的求解器进行数值集成.

Remark: Any of the mentioned solvers is not necessarily present in all possible Modelica simulation environments. If a solver is not provided as a choice, one would still be able to produce an FMU-ME (Functional mockup unit for model exchange) and write code that numerically integrate this FMU with a desired solver.

警告:上述某些方面基于特定类型模型的个人经验,不一定适用于所有模型类型.

Warning: Some of the above aspects are based on personal experiences for a particular type of models and are not necessarily true for all model types.

很少有人推荐阅读,而且我肯定错过了很多重要的出版物:

Few suggested reading and I am definitely missing a lot of key publications:

这篇关于什么会影响 Modelica 中的仿真运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆