Modelica中的正则化
我想知道Modelica中是否存在其他正则化技术(例如双曲正切)而不是Modelica中的正则化,modelica,smoothing,regularized,Modelica,Smoothing,Regularized,我想知道Modelica中是否存在其他正则化技术(例如双曲正切)而不是smoothStep函数。我处理一个复杂的代码,我多次使用smoothStep,以避免模型中的抖动;然而,我在模型的结果中看到了这个函数的一些副作用,我宁愿采用其他技术。为了进一步澄清,我只包含了代码的一部分,如下所示: model MassFlow import Modelica.SIunits.MassFlowRate; import Modelica.Media.Common.smoothStep; Real
smoothStep
函数。我处理一个复杂的代码,我多次使用smoothStep
,以避免模型中的抖动;然而,我在模型的结果中看到了这个函数的一些副作用,我宁愿采用其他技术。为了进一步澄清,我只包含了代码的一部分,如下所示:
model MassFlow
import Modelica.SIunits.MassFlowRate;
import Modelica.Media.Common.smoothStep;
Real c1[15];
parameter MassFlowRate mDotSource[15]={0.00,-0.10,0.10,1.00,2.00,0.00,0.10,0.01,0.09,-0.20,-0.30,0.00,-0.10,-0.03,0.06};
parameter MassFlowRate smallFlow = 0.01 "Small flow value used to avoid chattering problems";
equation
c1 = smoothStep(mDotSource, 1, 0, smallFlow);
end MassFlow;
function spliceFun "Spline interpolation of two functions"
extends Modelica.Icons.Function;
input Real pos "Returned value for x-deltax >= 0";
input Real neg "Returned value for x+deltax <= 0";
input Real x "Function argument";
input Real deltax=1 "Region around x with spline interpolation";
output Real out;
protected
Real scaledX;
Real scaledX1;
Real y;
algorithm
scaledX1 := x/deltax;
scaledX := scaledX1*Modelica.Math.asin(1);
if scaledX1 <= -0.00000001 then
y := 0;
elseif scaledX1 >= 0.999999 then
y := 1;
else
y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2;
end if;
out := pos*y + (1 - y)*neg;
annotation (derivative=spliceFun_der);
end spliceFun;
因此,目标是在mDotSource
的正则化中获得更精确的近似。如果你能帮我,我将不胜感激
根据@matth的有用评论,我使用了这个函数。为了在输入负值时返回0,我对函数进行了如下修改:
model MassFlow
import Modelica.SIunits.MassFlowRate;
import Modelica.Media.Common.smoothStep;
Real c1[15];
parameter MassFlowRate mDotSource[15]={0.00,-0.10,0.10,1.00,2.00,0.00,0.10,0.01,0.09,-0.20,-0.30,0.00,-0.10,-0.03,0.06};
parameter MassFlowRate smallFlow = 0.01 "Small flow value used to avoid chattering problems";
equation
c1 = smoothStep(mDotSource, 1, 0, smallFlow);
end MassFlow;
function spliceFun "Spline interpolation of two functions"
extends Modelica.Icons.Function;
input Real pos "Returned value for x-deltax >= 0";
input Real neg "Returned value for x+deltax <= 0";
input Real x "Function argument";
input Real deltax=1 "Region around x with spline interpolation";
output Real out;
protected
Real scaledX;
Real scaledX1;
Real y;
algorithm
scaledX1 := x/deltax;
scaledX := scaledX1*Modelica.Math.asin(1);
if scaledX1 <= -0.00000001 then
y := 0;
elseif scaledX1 >= 0.999999 then
y := 1;
else
y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2;
end if;
out := pos*y + (1 - y)*neg;
annotation (derivative=spliceFun_der);
end spliceFun;
然而,当我试图在复杂代码中应用修改后的拼接函数(StipeFun)时,模拟运行是无止境的。它既不停止也不出错。
我必须在这里补充一点,在我的复杂代码中,我使用了6倍的拼接乐趣,当我用smoothStep
函数替换其中的5个,并且只使用1个拼接乐趣时,它是有效的,但我没有收到我期望的准确度的结果。请您就这个问题提供建议好吗?您可以使用一些其他的正则化,而不仅仅是简单的正则化,但有两个要求:
- 边缘平滑度
- 正确导数
scaledX
,我们有:
(Modelica.Math.tanh(Modelica.Math.tan(scaledX1*asin(1))) + 1)/2;
对于scaledX1=0
给出y=0.5,对于scaledX1=1给出y=1;完全不规则,并且0处的坡度不是0。基本上,你似乎有一个转变,你想要的是:
scaledX := (scaledX1-0.5)*Modelica.Math.asin(1);
...
y:= Modelica.Math.tan(scaledX)) + 1)/2;
因此,scaledX1=0
给出了scaledX=-0.5*Modelica.Math.asin(1)
,它给出了y=0
,但不幸的是,在边缘没有零导数。有了tanh,情况变得更加混乱,但仍然需要scaledX=0和1的限制相匹配
这个主意是怎么用的
scaledX := (2*scaledX1-1)*Modelica.Math.asin(1);
...
y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2;
好像边在-1和1而不是0和1?这个变量似乎从0变为1,并且在过渡时是平滑的
第二部分很容易通过编写来更正:
注释(smoothOrder=2)代码>并且不尝试编写导数。搜索函数,它基于tanh。还有其他功能,请检查FluidDisposition或IBPSA库中的正则化。相关出版物: