英文:
OpenModelica inconsistent initial condistions for DAEs
问题
我正在尝试使用OpenModelica解决类似平面摆的简单DAE问题。我遇到了一个简单的问题,我不知道如何解决。我正在为摆的x和y坐标施加初始条件。x0 = 0.5和y0 = 0可以工作,因为摆的长度是0.5。然而,当我想要使用x0 = -0.5时,它出现错误并告诉我初始条件不一致,但我不明白为什么,因为x^2 + y^2 = L^2。
我还尝试了其他负的初始条件,例如x0 = -0.013437983982246和y0 = -0.499819387965786,但出现相同的错误代码。但是,当我使x0的值为正(去掉减号)时,Modelica可以顺利运行,没有任何错误。
英文:
I'm trying to use openmodelica to solve simple DAEs like for a planar pendulum. I am running into a simple problem that I don't now how to solve. I am imposing an initial condition for the x and y coordinate of the pendulum. x0 = 0.5 and y0 = 0 works since the length of the pendulum is 0.5. However, when I want to use x0 = -0.5, it breaks and tells me that the init conditions are incosistent but I don't understand why since x^2 + y^2 = L^2.
Error with negative x initial condition
I have also tried other negative init conditions like x0 = -0.013437983982246 and y0 = -0.499819387965786 but with the same error code. However when I make the x0 value positive (by removing minus-sign), modelica runs smoothly without any errors.
答案1
得分: 1
As you may have already found out, your model has a differentiation index higher than one. Unfortunately, solution algorithms like dassl and ida are only capable of solving index one problems. This is no shortcoming of dassl and ida but is a structural problem of high index.
你可能已经发现,你的模型具有高于一的微分指数。不幸的是,像dassl和ida这样的解决方案算法只能解决一阶问题。这并不是dassl和ida的缺点,而是高阶问题的结构性问题。
How to find out the index of a DAE system? The index is the minimum number of times the algebraic equations of your DAE-system must be differentiated with respect to time in order to receive a pure ODE system. In your case that has to be done three times. In order to check if your system is of index one, there is a simple algorithm: You can try to locate in each equation of your system exactly one "variable" that should be virtually calculated with that equation. "Variables" are all algebraic variables and the first order derivatives of the state variables (the states itself are no variables since they are given as initial values or provided by the integrator). If this works for a DAE system, then the index is one. Just repeat the differentiation step until you reach an index one problem.
如何确定DAE系统的指数?指数是您的DAE系统的代数方程相对于时间必须进行微分以获得纯ODE系统的最小次数。在您的情况下,这必须做三次。为了检查您的系统是否具有一阶指数,有一个简单的算法:您可以尝试在系统的每个方程中找到一个“变量”,该变量应该在该方程中虚拟计算。 "变量"包括所有代数变量和状态变量的一阶导数(状态本身不是变量,因为它们是初始值或由积分器提供的)。如果对于DAE系统有效,那么指数为一。只需重复微分步骤,直到达到一阶问题。
For the numerical solution of high index problems several methods are available. Modelica introduces dummy variables (--> your favorite search engine), you can use projection methods and you can also transform your problem to a lower index by differentiation of the algebraic variables with respect to time.
对于高阶问题的数值解决方法有几种可用方法。Modelica引入了虚拟变量(--> 您喜欢的搜索引擎),您可以使用投影方法,还可以通过相对于时间对代数变量进行微分将问题转换为较低指数的问题。
The automatic introduction of dummy variables by openmodelica changes your equation system in the background, these changes are not visible (as long as you do not take a look at the generated c-code) and can and will have influence on the convergence of your nonlinear equation system. Just by chance I found out that after introducing the new variable Real L_test and the equation L_test = sqrt(x^2+y^2) your system solves for x0 = -0.5. Although this has nothing to do with the original equation, the additional equation changes Newton's iteration path. It seems, that your error message is caused more or less because openmodelica did not converge due to the new, extended structure of the nonlinear equation system. Why did I introduce this new variable? See below...
openmodelica自动引入虚拟变量会改变您的方程系统,这些更改是不可见的(只要您不查看生成的c代码),并且会影响您的非线性方程系统的收敛性。偶然间,我发现在引入新变量Real L_test和方程L_test = sqrt(x^2+y^2)之后,您的系统求解x0 = -0.5。尽管这与原始方程无关,但附加方程会改变牛顿迭代路径。似乎您的错误消息更多或多少是因为openmodelica由于非线性方程系统的新扩展结构而没有收敛。为什么我引入这个新变量?见下文...
How can we transform your problem to a lower index? There is only one algebraic equation
我们如何将问题转换为较低的指数?只有一个代数方程
x^2 + y^2 = L^2;
which can be differentiated one time for receiving an index two problem
可以对其进行一次微分以获得指数为二的问题
2xder(x) + 2yder(y) = 0;
and a second time for an index one problem:
并且再一次以获得指数为一的问题:
2der(x)^2 + 2xder(vx) + 2der(y)^2 + 2yder(vy) = 0
(Of course the factor 2, for the sake of completeness, is not necessary in both equations)
(当然,出于完整性考虑,在两个方程中都不需要因子2)
If you use the first derivative (instead of x^2+y^2=L^2) your system is of index 2, Openmmodelica introduces one dummy variable and has no problem. You can also use the second derivative for index one without additional dummy variables. In both cases the system solves for your initial conditions x0 = -0.5 and x0 = 0.5.
如果您使用一阶导数(而不是x^2+y^2=L^2),您的系统为二阶指数,Openmmodelica引入一个虚拟变量并且没有问题。您还可以使用二阶导数进行一阶索引,而无需额外的虚拟变量。在这两种情况下,系统都可以解决您的初始条件x0 = -0.5和x0 = 0.5。
Be aware of two points:
注意两个问题:
- After differentiating x^2 + y^2 = L^2 the physical meaning of this equation that the length is L is lost! You have to choose your initial conditions such that length-constraint is fulfilled.
- 在对x^2 + y^2 = L^2进行微分后,该方程的物理含义即长度为L被丢失!您必须选择初始条件,以使长度约束得以满足。
- For the original
英文:
As you may have already found out, your model has a differentiation index higher than one. Unfortunately, solution algorithms like dassl and ida are only capable of solving index one problems. This is no shortcoming of dassl and ida but is a structural problem of high index.
How to find out the index of a DAE system? The index is the minimum number of times the algebraic equations of your DAE-system must
be differentiated with respect to time in order to receive a pure ODE system. In your case that has to be done three times. In order to check if your system is of index one, there is a simple algorithm: You can try to locate in each equation of your system exactly one "variable" that should be virtually calculated with that equation. "Variables" are all algebraic variables and the first order derivatives of the state variables (the states itself are no variables since they are given as initial values or provided by the integrator). If this works for a DAE system, then the index is one. Just repeat the differentiation step until you reach an index one problem.
For the numerical solution of high index problems several methods are available. Modelica introduces dummy variables (--> your favorite search engine), you can use projection methods and you can also transform your problem to a lower index by differentiation of the algebraic variables with respect to time.
The automatic introduction of dummy variables by openmodelica changes your equation system in the background, these changes are not visible (as long as you do not take a look at the generated c-code) and can and will have influence on the convergence of your nonlinear equation system. Just by chance I found out that after introducing the new variable Real L_test and the equation L_test = sqrt(x^2+y^2) your system solves for x0 = -0.5. Although this has nothing to do with the original equation, the additional equation changes Newtons's iteration path. It seems, that your error message is caused more or less because openmodelica did not converge due to the new, extended structure of the nonlinear equation system. Why did I introduce this new variable? See below...
How can we transform your problem to a lower index? There is only one algebraic equation
x^2 + y^2 = L^2;
which can be differentiated one time for receiving an index two problem
2*x*der(x) + 2*y*der(y) = 0;
and a second time for an index one problem:
2*der(x)^2 + 2*x*der(vx) + 2*der(y)^2 + 2*y*der(vy) = 0
(Of course the factor 2, for the sake of completeness, is not necessary in both equations)
If you use the first derivative (instead of x^2+y^2=L^2) your system is of index 2, Openmmodelica introduces one dummy variable and has no problem. You can also use the second derivative for index one without additional dummy variables. In both cases the system solves for your initial conditions x0 = -0.5 and x0 = 0.5.
Be aware of two points:
- After differentiating x^2 + y^2 = L^2 the physical meaning of this equation that the length is L is lost! You have to choose your initial conditions such that length-constraint is fulfilled.
- For the original DAE system the constraint on the length is always fulfilled. For the transformed system (index two or index one) this is not the case! How well the constraint is fulfilled depends on the integration accuracy. The longer the simulation time, the larger the error will be. That was the reason for introducing L_test = x^2 + y^2.
BTW: Your system has two degrees of freedom (x and y) and one constraint on the length L such that only one degree of freedom remains (which causes all the trouble). If you directly understand your system as having only one degree of freedom and expressing this by choosing polar coordinates, things are much easier.
PS: Next time please post the original model as source code, not as a picture.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论