“Modelica playground” 模型场 "Internal error function lexer failed"

huangapple go评论50阅读模式
英文:

Modelica playground "Internal error function lexer failed"

问题

I'm trying to use the Modelica playground to build a double pendulum model but it is erroring with "Internal error function lexer failed". How do I fix this? I assume it's a problem with my model but perhaps it's a problem with the playground? I don't know.

英文:

I'm trying to use the Modelica playground to build a double pendulum model but it is erroring with "Internal error function lexer failed". How do I fix this? I assume it's a problem with my model but perhaps it's a problem with the playground? I don't know.

  constant Real speed=0.2;
  constant Real gravity(unit="m/s2")=9.8 * speed;
  constant Real length(unit="m")=1;
  constant Real length2(unit="m")=1;
  constant Real mass(unit="kg")=1;
  constant Real mass2(unit="kg")=1;
  Real angle(unit="rad");
  Real momentum(unit="kg m/s");
  Real angle2(unit="rad");
  Real momentum2(unit="kg m/s");

initial equation
  angle = 130 * (3.142 / 180);
  momentum = 0;
  angle2 = 0; // relative to vertical
  momentum2 = 0;
equation
  der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));

  der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));

  //annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works

Link to playground

答案1

得分: 1

我认为错误在于“momentum”变量的单位定义。应该是unit="kg.m/s"而不是unit="kg m/s"。修复后的代码如下:

  constant Real speed=0.2;
  constant Real gravity(unit="m/s2")=9.8 * speed;
  constant Real length(unit="m")=1;
  constant Real length2(unit="m")=1;
  constant Real mass(unit="kg")=1;
  constant Real mass2(unit="kg")=1;
  Real angle(unit="rad");
  Real momentum(unit="kg.m/s");
  Real angle2(unit="rad");
  Real momentum2(unit="kg.m/s");

initial equation
  angle = 130 * (3.142 / 180);
  momentum = 0;
  angle2 = 0; // relative to vertical
  momentum2 = 0;
equation
  der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));

  der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));

  //annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works

看起来错误信息有改进的空间...

英文:

I think the error is in the unit definition of the "momentum" variables. It should be unit="kg.m/s" instead of unit="kg m/s". The fixed code is:

  constant Real speed=0.2;
  constant Real gravity(unit="m/s2")=9.8 * speed;
  constant Real length(unit="m")=1;
  constant Real length2(unit="m")=1;
  constant Real mass(unit="kg")=1;
  constant Real mass2(unit="kg")=1;
  Real angle(unit="rad");
  Real momentum(unit="kg.m/s");
  Real angle2(unit="rad");
  Real momentum2(unit="kg.m/s");

initial equation
  angle = 130 * (3.142 / 180);
  momentum = 0;
  angle2 = 0; // relative to vertical
  momentum2 = 0;
equation
  der(angle) = (6/(mass * length^2)) * ((2 * momentum - 3 * cos(angle - angle2) * momentum2)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum) = -0.5 * mass * length^2 * (der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length) * sin(angle)));

  der(angle2) = (6/(mass2 * length2^2)) * ((8 * momentum2 - 3 * cos(angle - angle2) * momentum)/(16 - 9 * cos(angle - angle2)^2));
  der(momentum2) = -0.5 * mass2 * length2^2 * (-der(angle) * der(angle2) * sin(angle - angle2) + (3 * (gravity / length2) * sin(angle2)));

  //annotation(experiment(StartTime=0,StopTime=200)); // todo find out how this works

Seems there is room for improvement in the error message...

huangapple
  • 本文由 发表于 2023年5月24日 20:22:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323488.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定