Initial guesses for nonlinear algebraic eqtns

前端 未结 1 925
忘掉有多难
忘掉有多难 2021-01-22 11:03

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 instea

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 11:58

    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...

    0 讨论(0)
提交回复
热议问题