[英]Modelica - How to use units in equations
How can i use units directly in equations in Modelica?如何在 Modelica 的方程中直接使用单位? Is that possible at all?这可能吗? Simple example, a parameter, that should be made dependant (as default value) to another parameter of a different unit.一个简单的例子,一个参数,它应该依赖于(作为默认值)不同单位的另一个参数。 In the example below it would give a unit warning (naturally).在下面的例子中,它会给出一个单位警告(自然)。 How do i say i just want the nominal value of the variable and not the value+unit ?我怎么说我只想要变量的标称值而不是值+单位?
model customspringdamper
import SI = Modelica.SIunits;
parameter SI.TranslationalSpringConstant c =100;
parameter SI.TranslationalDampingConstant d= 0.01*c;
... < rest of stuff > ...
end customspringdamper;
Of course i could define another parameter with a unit and value 1 but this feels more laborous than neccessary?当然,我可以用单位和值 1 定义另一个参数,但这感觉比必要更费力吗?
I can see three ways:我可以看到三种方式:
parameter Real c =100;
将参数声明为 Real 不带单位: parameter Real c =100;
You lose the unit-checking, but it doesn't seem that you use it.你失去了单元检查,但你似乎没有使用它。 import SI = Modelica.SIunits; parameter SI.TranslationalSpringConstant c= 100; parameter SI.TranslationalDampingConstant d= 0.01*(c/unitSpring)*unitDamping; constant SI.TranslationalSpringConstant unitSpring=1; constant SI.TranslationalDampingConstant unitDamping=1;
Tools should be able to simplify the code to remove those constants.工具应该能够简化代码以删除这些常量。 However, you circumvent unit-checking which makes your code more error-prone.但是,您绕过了单元检查,这会使您的代码更容易出错。
There are some cases where it is legitimate to remove units in this way - but not in cases like this.在某些情况下,以这种方式移除单元是合法的——但在这种情况下则不然。
Basically the same as 2, but you put the units on 0.01
;基本上与 2 相同,但您将单位放在0.01
; and give it an actual physical meaning:并赋予它实际的物理意义:
import SI = Modelica.SIunits; parameter SI.TranslationalSpringConstant c= 100; parameter SI.Time SpringTime=0.01; parameter SI.TranslationalDampingConstant d= SpringTime*c;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.