【发布时间】:2021-11-26 13:12:54
【问题描述】:
我正在努力计算我的 Modelica 模型中连续信号的平均值。问题是我只对计算稳态的平均值感兴趣。例如,在附加的模型(最小,可重现示例)中,我想计算 40 到 60 秒之间的平均值。因此,我首先尝试使用Modelica.Blocks.Math.ContinuousMean,但t_0是受保护的,所以我在我的个人库中写了一个类似的代码(也附上)。
但是,有一个错误,我无法弄清楚发生了什么。有人可以对这个简单的问题有所了解吗?提前谢谢!!!
型号:
model MeanExampleStackOverFlow
parameter Modelica.SIunits.Time period=3;
final parameter Real angularFrecuency=(2*Modelica.Constants.pi)/period;
parameter Real amplitude=2;
Real signal;
Real mean;
PersonalLibrary.Utilities.ContinuosMeanStartTime meanBlock(t_0=40);
equation
signal = amplitude*sin(angularFrecuency*time) + log(time*100 + 1);
meanBlock.u = signal;
meanBlock.y = mean;
end MeanExampleStackOverFlow;
块保存在个人库中:
block ContinuosMeanStartTime "Similar block as Continuos Mean in MSL but with unprotected Start time (t_0)"
extends Modelica.Blocks.Icons.Block;
parameter Modelica.SIunits.Time t_eps(min=0.0) = 1e-7 "Mean value calculation starts at startTime + t_eps";
parameter Modelica.SIunits.Time t_0(min=0.0) = 0 "Start time";
Modelica.Blocks.Interfaces.RealInput u "Noisy input signal";
Modelica.Blocks.Interfaces.RealOutput y "Expectation (mean) value of the input signal";
protected
Real mu "Internal integrator variable";
initial equation
mu = u;
equation
der(mu) = noEvent(if time >= t_0 + t_eps then (u - mu)/(time - t_0) else 0);
y = noEvent(if time >= t_0 + t_eps then mu else u);
end ContinuosMeanStartTime;
最后,这里有一些结果显示了我想要实现的目标(已经用其他软件编辑了结果)。 最好的问候。
注意:顺便问一下,有没有其他方法可以访问 MSL 中的受保护参数而不是编写新块?
【问题讨论】:
-
你能提供一个最小的、可重现的例子吗?从您的绘图中重新创建模型需要工作,并且不能保证会发生相同的错误。 stackoverflow.com/help/minimal-reproducible-example
-
感谢您的评论。我已经编辑了帖子。让我们看看现在是否更容易理解。提前致谢!
标签: modelica dymola openmodelica