I am trying to model a system where gain is variable. I have created a simple two block model to first investigate the possibility of using a variable as the gain parameter. If this works, I would like to add blocks to compute the gain.
The first block is a sinusoidal source with an amplitude of 10 and offset of 5 and a frequency of 1.
The second block is a gain block. The input is connected to the sinusoidal source. The gain parameter is set to a variable named gainValue
.
The variable named gainValue
with an initial value of 1 and the Fixed property set to False.
The code is below:
model ExploratoryModelForVariableGain "Sandbox model to use a variable as the gain parameter"
Modelica.Blocks.Sources.Sine V1(amplitude = 10, freqHz = 1, offset = 5) "Simple AC Voltage with DC Offset" annotation(Placement(visible = true, transformation(origin = {-97.915, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.Gain Amp1(k = gainValue) annotation(Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Real gainValue(start = 1, fixed = false) = 1 annotation(Dialog(group = "Variables", showStartAttribute = true));
equation
connect(V1.y, Amp1.u) annotation(Line(visible = true, origin = {-74.457, 0}, points = {{-12.457, -0}, {12.457, 0}}, color = {1, 37, 163}));
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end ExploratoryModelForVariableGain;
The Error: "Component Amp1.k of variability PARAM has a binding gainValue of higher variability VAR" appears during Validation.
Note: Changing the variable to a parameter removes this error, but leaves warnings that initial values are not set (even though an Initial Value is specified for the parameter on the Parameters tab).
I am also seeing Internal Errors thrown whenever component modifications are attempted.