Modelica用记录设置多个参数
Modelica set multiple parameters with record
要用 DcPermanentMagnetData 记录的内容覆盖永磁直流电机的多个参数,我使用以下结构:
Modelica.Electrical.Machines.Utilities.ParameterRecords.DcPermanentMagnetData dcpmData(
IaNominal = 1,
VaNominal = 2,
wNominal = 3);
Modelica.Electrical.Machines.BasicMachines.DCMachines.DC_PermanentMagnet dcpm(
IaNominal = dcpmData.IaNominal,
VaNominal = dcpmData.VaNominal,
wNominal = dcpmData.wNominal);
是否可以使用单个命令设置模型的多个参数值?
MWE:
model MWE
record Rec
parameter Real x_init;
parameter Real y_init;
end Rec;
model HelloWorld
parameter Real x_init;
parameter Real y_init;
Real x;
Real y;
initial equation
x = x_init;
y = y_init;
equation
der(x)=-x;
der(y)=-y;
end HelloWorld;
Rec r (x_init = 1, y_init = 2);
HelloWorld hi (x_init = r.x_init, y_init = r.y_init); // this works
//HelloWorld hi ( allValuesFrom(r) ); // <--- something like this
end MWE;
您可以将整个记录传递给模型。为此,您必须用记录实例替换参数:
model MWE
record Rec
parameter Real x_init;
parameter Real y_init;
end Rec;
model HelloWorld
input Rec r;
Real x;
Real y;
initial equation
x = r.x_init;
y = r.y_init;
equation
der(x)=-x;
der(y)=-y;
end HelloWorld;
Rec r( x_init = 1, y_init = 2);
HelloWorld hi(r=r);
end MWE;
要用 DcPermanentMagnetData 记录的内容覆盖永磁直流电机的多个参数,我使用以下结构:
Modelica.Electrical.Machines.Utilities.ParameterRecords.DcPermanentMagnetData dcpmData(
IaNominal = 1,
VaNominal = 2,
wNominal = 3);
Modelica.Electrical.Machines.BasicMachines.DCMachines.DC_PermanentMagnet dcpm(
IaNominal = dcpmData.IaNominal,
VaNominal = dcpmData.VaNominal,
wNominal = dcpmData.wNominal);
是否可以使用单个命令设置模型的多个参数值?
MWE:
model MWE
record Rec
parameter Real x_init;
parameter Real y_init;
end Rec;
model HelloWorld
parameter Real x_init;
parameter Real y_init;
Real x;
Real y;
initial equation
x = x_init;
y = y_init;
equation
der(x)=-x;
der(y)=-y;
end HelloWorld;
Rec r (x_init = 1, y_init = 2);
HelloWorld hi (x_init = r.x_init, y_init = r.y_init); // this works
//HelloWorld hi ( allValuesFrom(r) ); // <--- something like this
end MWE;
您可以将整个记录传递给模型。为此,您必须用记录实例替换参数:
model MWE
record Rec
parameter Real x_init;
parameter Real y_init;
end Rec;
model HelloWorld
input Rec r;
Real x;
Real y;
initial equation
x = r.x_init;
y = r.y_init;
equation
der(x)=-x;
der(y)=-y;
end HelloWorld;
Rec r( x_init = 1, y_init = 2);
HelloWorld hi(r=r);
end MWE;