Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Division by zero depending on parameter

I am using the FixedRotation component and get a division by zero error. This happens in a translated expression of the form

var = nominator/fixedRotation.R_rel_inv.T[1,3]

because T[1,3] is 0 for the chosen parameters:

  • n={0,1,0}
  • angle=180 deg.

It seems that Openmodelica keeps the symbolic variable and tries to be generic but in this case this leads to division by zero because it chooses to put T[1,3] in the denominator.

What are the modifications in order to tell the compiler that the evaluated values T[1,3] for the compilation shall be considered as if the values were hard coded? R_rel is internally in fixedRotation not defined with Evaluate=true...

Should I use custom version of this block? (when I copy paste the source code to a new model and set the parameters R_rel and R_rel_inv to Evalute=true then the simulation works without division by zero)...

BUT is there a modifier to tell from outside that a parameter shall be Evaluate=true without the need to make a new model?

Any other way to prevent division by zero?

like image 587
Cimi Avatar asked Jan 21 '26 11:01

Cimi


1 Answers

Try propagating the parameter at a higher level and setting annotation(Evaluate=true) on this.

For example:

model A
  parameter Real a=1;
end A;

model B
  parameter Real aPropagated = 2 annotation(Evaluate=true);
  A Ainstance(a=aPropagated);
end B;
like image 175
user2024223 Avatar answered Jan 27 '26 01:01

user2024223



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!