Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Parametric Modeling with a variable number of models

Parametric Modeling with a variable number of models

Hello!
I'm trying to generate a model that consist of a varying number of thermal resistances. I can create these by:

Code:


model testcase
  parameter Integer n_res = 5;
 

 
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature(T(displayUnit = "K") = 298.15)  annotation(
    Placement(visible = true, transformation(origin = {-76, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow fixedHeatFlow(Q_flow = 1)  annotation(
    Placement(visible = true, transformation(origin = {60, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermalResistors[n_res](each R=10) annotation(
    Placement(visible = true, transformation(origin = {-12, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

equation
for i in 1:(n_res-1) loop
    connect(thermalResistors[i].port_a, thermalResistors[i+1].port_b);
  end for;
  connect(thermalResistors[1].port_b, fixedTemperature.port);

  connect(fixedHeatFlow.port, thermalResistors[n_res].port_b)
  annotation(
    uses(Modelica(version = "4.0.0")));
end testcase;

right now all of these have the same restitance R, that i specify with the "each" command.
I want every of these to have a different R, something like R={1,2,3,4,5}.

When i try to assign these in a for loop in the equation section I have more equations than variables and the model does not compile.

Can someone help me with that?

Thanks you in advance!
Sebastian

There are 0 guests and 0 other users also viewing this topic
You are here: