简体   繁体   English

Modelica - 如何在方程中使用单位

[英]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:我可以看到三种方式:

  1. Declare the parameter as Real without the unit: parameter Real c =100;将参数声明为 Real 不带单位: parameter Real c =100; You lose the unit-checking, but it doesn't seem that you use it.你失去了单元检查,但你似乎没有使用它。
  2. Use constants to convert the value to a different unit:使用常量将值转换为不同的单位:

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.在某些情况下,以这种方式移除单元是合法的——但在这种情况下则不然。

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

相关问题 Modelica 中的计算参数 - Computed parameter in Modelica FMU输入用于Modelica中的参数 - FMU inputs for parameters in Modelica 如何在R中求解具有时间相关参数的常微分方程? - How to solve ordinary differential equations with time dependent parameters in R? 如何在tensorflow示例上发布的示例中更改DNNRegressor中的hidden_​​units? - How to change hidden_units in DNNRegressor in the example posted on tensorflow example? Modelica - 指定模拟默认参数 - Modelica - Specify simulation default parameters Modelica:检查可替换 package 或 model 的相等性 - Modelica: check equality of replaceable package or model Modelica (OpenModelica) 中参数的单位定义,在参数文件的范围内找不到 - Definition of unit in Modelica (OpenModelica) for parameters, cannot be found in scope of parameters file 使用方程列表创建 R function - Creating an R function with a list of equations 一个参数单位=N 的 LSTM 是否等同于 N 个单位=1 的并行 LSTM? - Is a LSTM with Argument units=N equivalent to N parallel LSTMs with units=1? R 曲线拟合 [REAT]:非线性函数的方程是什么? - R curvefit [REAT]: What are the equations of the nonlinear functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM