Initial guesses for nonlinear algebraic eqtns

喜你入骨 提交于 2019-12-02 02:03:16

问题


I have a system of nonlinear algebraic equations to solve. How can I use computed values (with continuous-time variability) as initial guess for the variables of solution instead of using parameters as start values? Can initial equation section be used for this purpose?

I have created a test model to explain the issue:

model Teststartvalue
  Real value1=1000;//calculated by some model
  Real value2=-1000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  Real StartValue=if InputValue < value2 then 1.8 elseif InputValue > value1 then 2.8 else 0.5;
  Real x(start=0.5);
//Desired code
//  Real x(start=StartValue);
equation
  (x-1)*(x-2)*(x-3)=0;
//  x^3-(6*x^2)+(11*x)-6=0;
end Teststartvalue;

The intention is to provide the initial guess for “x” based on some calculation. How can I achieve this in openmodelica?


回答1:


As far as I know the start attribute can only take expression with either constant- or parameter variability (see Modelica Specification 3.4 Section 3.8). Therefore the only real solution that comes to my mind is a bit of a hack:

  • Set the fixed attribute of the parameter used for the start value (StartValue in your example) to false and
  • compute the value in the initial equation

This would result in:

model TestStartValue
  Real value1=1000;//calculated by some model
  Real value2=-1000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  final parameter Real StartValue(fixed=false);
  Real x(start=StartValue);

initial equation 
  StartValue=if InputValue < value2 then 1.8 elseif InputValue > value1 then 2.8 else 0.5;

equation 
  (x-1)*(x-2)*(x-3)=0;
end TestStartValue;

Not sure this will work in all tools and in future versions thereof! I actually don't think this is intended to be used this way. Also this could cause problems later on as parameters are usually assumed to be set before the simulation starts, not during its initialization...

Another alternative would be to use the initial equation, which should give something like:

model TestStartValueInitEq
  Real value1=1000;//calculated by some model
  Real value2=2000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  Real x;

initial equation 
  if InputValue < value2 then
    pre(x)-2=0;
  elseif InputValue > value1 then
    pre(x)-3=0;
  else
    pre(x)-1=0;
  end if;

equation 
  (x-1)*(x-2)*(x-3)=0;
end TestStartValueInitEq;

The drawback with this solution is, that an initial equation is actually intended to set the value for state variables. For these the initial value can be chosen freely (more or less) as there is no equation determining it at the initialization. This is not the case here, which will give multiple equations for x during initialization which will brake the model. To avoid this in Dymola the pre() helps (not sure it does in other tools). This then results in "Redundant consistent initial conditions." which Dymola can handle. For the equations to be redundant, they need give the same result. Hence you cannot use estimates for the result as in you original code, which is why I changed them for the second example.

Still both solutions seem imperfect to me. If there is any other solution please add it...



来源:https://stackoverflow.com/questions/55417019/initial-guesses-for-nonlinear-algebraic-eqtns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!