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

Setting parameters OMPython

Setting parameters OMPython

Hi everybody
I have this model in OpenModelica:
model BranchA
  inner Modelica.Fluid.System system annotation(
    Placement(visible = true, transformation(origin = {-152, 148}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Fluid.Sources.MassFlowSource_T boundary(redeclare package Medium =
  Modelica.Media.Water.StandardWater, m_flow = 2.376, nPorts = 1)  annotation(
    Placement(visible = true, transformation(origin = {6, 190}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 15.35)  annotation(
    Placement(visible = true, transformation(origin = {-36, 138}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe1(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 15.35)  annotation(
    Placement(visible = true, transformation(origin = {44, 138}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe2(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 1)  annotation(
    Placement(visible = true, transformation(origin = {6, 162}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 50000, m_flow_nominal = 1.188, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {-36, 112}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice1(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 50000, m_flow_nominal = 1.188, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {44, 112}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Sensors.MassFlowRate massFlowRate (redeclare package Medium =
  Modelica.Media.Water.StandardWater) annotation(
    Placement(visible = true, transformation(origin = {-36, 82}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Sensors.MassFlowRate massFlowRate1 (redeclare package Medium =
  Modelica.Media.Water.StandardWater) annotation(
    Placement(visible = true, transformation(origin = {44, 82}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe3(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {-60, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe4(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {-44, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe5(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {-14, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe6(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {-28, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe7(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {48, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe8(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {64, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe9(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {32, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe10(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 13.8e-3, length = 12.8)  annotation(
    Placement(visible = true, transformation(origin = {16, 46}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Sensors.MassFlowRate massFlowRate2 (redeclare package Medium =
  Modelica.Media.Water.StandardWater) annotation(
    Placement(visible = true, transformation(origin = {-36, -76}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Sensors.MassFlowRate massFlowRate3 (redeclare package Medium =
  Modelica.Media.Water.StandardWater) annotation(
    Placement(visible = true, transformation(origin = {44, -76}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice2(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 50000, m_flow_nominal = 1.188, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {-36, -106}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice3(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 50000, m_flow_nominal = 1.188, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {44, -106}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe11(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 15.35)  annotation(
    Placement(visible = true, transformation(origin = {-36, -134}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe12(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 15.35)  annotation(
    Placement(visible = true, transformation(origin = {44, -134}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Pipes.StaticPipe pipe13(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 2.79e-2, length = 1)  annotation(
    Placement(visible = true, transformation(origin = {6, -196}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Sources.FixedBoundary boundary1(redeclare package Medium =
  Modelica.Media.Water.StandardWater,nPorts = 1)  annotation(
    Placement(visible = true, transformation(origin = {6, -228}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice4(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 207833, m_flow_nominal = 2.376, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {6, -166}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice5(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false)  annotation(
    Placement(visible = true, transformation(origin = {-60, 14}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice6(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {-44, 14}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice7(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {-12, 12}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice8(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {-28, 12}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice9(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {48, 12}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice10(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {64, 12}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice11(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {32, 14}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Fittings.SimpleGenericOrifice orifice12(redeclare package Medium =
  Modelica.Media.Water.StandardWater,diameter = 0.2, dp_nominal = 94200, m_flow_nominal = 0.297, use_zeta = false) annotation(
    Placement(visible = true, transformation(origin = {16, 14}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
  connect(boundary.ports[1], pipe2.port_a) annotation(
    Line(points = {{6, 180}, {6, 172}}, color = {0, 127, 255}));
  connect(pipe2.port_b, pipe1.port_a) annotation(
    Line(points = {{6, 152}, {44, 152}, {44, 148}}, color = {0, 127, 255}));
  connect(pipe2.port_b, pipe.port_a) annotation(
    Line(points = {{6, 152}, {-36, 152}, {-36, 148}}, color = {0, 127, 255}));
  connect(pipe.port_b, orifice.port_a) annotation(
    Line(points = {{-36, 128}, {-36, 122}}, color = {0, 127, 255}));
  connect(pipe1.port_b, orifice1.port_a) annotation(
    Line(points = {{44, 128}, {44, 122}}, color = {0, 127, 255}));
  connect(orifice.port_b, massFlowRate.port_a) annotation(
    Line(points = {{-36, 102}, {-36, 92}}, color = {0, 127, 255}));
  connect(orifice1.port_b, massFlowRate1.port_a) annotation(
    Line(points = {{44, 102}, {44, 92}}, color = {0, 127, 255}));
  connect(massFlowRate.port_b, pipe3.port_a) annotation(
    Line(points = {{-36, 72}, {-60, 72}, {-60, 56}}, color = {0, 127, 255}));
  connect(massFlowRate.port_b, pipe4.port_a) annotation(
    Line(points = {{-36, 72}, {-44, 72}, {-44, 56}}, color = {0, 127, 255}));
  connect(massFlowRate.port_b, pipe6.port_a) annotation(
    Line(points = {{-36, 72}, {-28, 72}, {-28, 56}}, color = {0, 127, 255}));
  connect(massFlowRate.port_b, pipe5.port_a) annotation(
    Line(points = {{-36, 72}, {-14, 72}, {-14, 56}}, color = {0, 127, 255}));
  connect(massFlowRate1.port_b, pipe10.port_a) annotation(
    Line(points = {{44, 72}, {16, 72}, {16, 56}}, color = {0, 127, 255}));
  connect(massFlowRate1.port_b, pipe9.port_a) annotation(
    Line(points = {{44, 72}, {32, 72}, {32, 56}}, color = {0, 127, 255}));
  connect(massFlowRate1.port_b, pipe7.port_a) annotation(
    Line(points = {{44, 72}, {48, 72}, {48, 56}}, color = {0, 127, 255}));
  connect(massFlowRate1.port_b, pipe8.port_a) annotation(
    Line(points = {{44, 72}, {64, 72}, {64, 56}}, color = {0, 127, 255}));
  connect(massFlowRate2.port_b, orifice2.port_a) annotation(
    Line(points = {{-36, -86}, {-36, -96}}, color = {0, 127, 255}));
  connect(massFlowRate3.port_b, orifice3.port_a) annotation(
    Line(points = {{44, -86}, {44, -96}}, color = {0, 127, 255}));
  connect(orifice2.port_b, pipe11.port_a) annotation(
    Line(points = {{-36, -116}, {-36, -124}}, color = {0, 127, 255}));
  connect(orifice3.port_b, pipe12.port_a) annotation(
    Line(points = {{44, -116}, {44, -124}}, color = {0, 127, 255}));
  connect(pipe13.port_b, boundary1.ports[1]) annotation(
    Line(points = {{6, -206}, {6, -218}}, color = {0, 127, 255}));
  connect(pipe11.port_b, orifice4.port_a) annotation(
    Line(points = {{-36, -144}, {-36, -156}, {6, -156}}, color = {0, 127, 255}));
  connect(pipe12.port_b, orifice4.port_a) annotation(
    Line(points = {{44, -144}, {23, -144}, {23, -156}, {6, -156}}, color = {0, 127, 255}));
  connect(orifice4.port_b, pipe13.port_a) annotation(
    Line(points = {{6, -176}, {6, -186}}, color = {0, 127, 255}));
  connect(pipe3.port_b, orifice5.port_a) annotation(
    Line(points = {{-60, 36}, {-60, 36}, {-60, 24}, {-60, 24}}, color = {0, 127, 255}));
  connect(pipe4.port_b, orifice6.port_a) annotation(
    Line(points = {{-44, 36}, {-44, 36}, {-44, 24}, {-44, 24}}, color = {0, 127, 255}));
  connect(pipe6.port_b, orifice8.port_a) annotation(
    Line(points = {{-28, 36}, {-28, 36}, {-28, 22}, {-28, 22}}, color = {0, 127, 255}));
  connect(pipe5.port_b, orifice7.port_a) annotation(
    Line(points = {{-14, 36}, {-14, 36}, {-14, 22}, {-12, 22}, {-12, 22}}, color = {0, 127, 255}));
  connect(pipe10.port_b, orifice12.port_a) annotation(
    Line(points = {{16, 36}, {16, 36}, {16, 24}, {16, 24}}, color = {0, 127, 255}));
  connect(pipe9.port_b, orifice11.port_a) annotation(
    Line(points = {{32, 36}, {32, 36}, {32, 24}, {32, 24}}, color = {0, 127, 255}));
  connect(pipe7.port_b, orifice9.port_a) annotation(
    Line(points = {{48, 36}, {48, 36}, {48, 22}, {48, 22}}, color = {0, 127, 255}));
  connect(pipe8.port_b, orifice10.port_a) annotation(
    Line(points = {{64, 36}, {64, 36}, {64, 22}, {64, 22}}, color = {0, 127, 255}));
  connect(orifice5.port_b, massFlowRate2.port_a) annotation(
    Line(points = {{-60, 4}, {-60, -66}, {-36, -66}}, color = {0, 127, 255}));
  connect(orifice6.port_b, massFlowRate2.port_a) annotation(
    Line(points = {{-44, 4}, {-46, 4}, {-46, -66}, {-36, -66}}, color = {0, 127, 255}));
  connect(orifice8.port_b, massFlowRate2.port_a) annotation(
    Line(points = {{-28, 2}, {-28, -66}, {-36, -66}}, color = {0, 127, 255}));
  connect(orifice7.port_b, massFlowRate2.port_a) annotation(
    Line(points = {{-12, 2}, {-14, 2}, {-14, -66}, {-36, -66}}, color = {0, 127, 255}));
  connect(orifice12.port_b, massFlowRate3.port_a) annotation(
    Line(points = {{16, 4}, {16, -66}, {44, -66}}, color = {0, 127, 255}));
  connect(orifice11.port_b, massFlowRate3.port_a) annotation(
    Line(points = {{32, 4}, {32, -66}, {44, -66}}, color = {0, 127, 255}));
  connect(orifice9.port_b, massFlowRate3.port_a) annotation(
    Line(points = {{48, 2}, {48, -66}, {44, -66}}, color = {0, 127, 255}));
  connect(orifice10.port_b, massFlowRate3.port_a) annotation(
    Line(points = {{64, 2}, {62, 2}, {62, -66}, {44, -66}}, color = {0, 127, 255}));

annotation(
    uses(Modelica(version = "3.2.3")));
end BranchA;
I want to simulate this model with OMPython with this code:

import OMPython
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem
omc = OMCSessionZMQ()
omc.sendExpression("instantiateModel(BranchA)")
omc.sendExpression("loadFile(\"C:/Users/loren/Documents/OpenModelica/BranchA.mo\")")
omc.sendExpression("loadModel(BranchA)")


model_path = omc.sendExpression("getInstallationDirectoryPath()")


mod = ModelicaSystem("C:/Users/loren/Documents/OpenModelica/BranchA.mo", "BranchA")


quantities = mod.getQuantities()
parameters = mod.getParameters()
continuous = mod.getContinuous()
setting = mod.setParameters("boundary.m_flow=5")
gettingParameters = mod.getParameters(["orifice5.dp_nominal"])
mod.simulate()
pipeMassFlow = mod.getSolutions(["pipe.port_a.m_flow"])
pipe1MassFlow = mod.getSolutions(["pipe1.port_a.m_flow"])
pipe2MassFlow = mod.getSolutions(["pipe2.port_a.m_flow"])
pipe3MassFlow = mod.getSolutions(["pipe3.port_a.m_flow"])
pipe4MassFlow = mod.getSolutions(["pipe4.port_a.m_flow"])
pipe5MassFlow = mod.getSolutions(["pipe5.port_a.m_flow"])
pipe6MassFlow = mod.getSolutions(["pipe6.port_a.m_flow"])
pipe7MassFlow = mod.getSolutions(["pipe7.port_a.m_flow"])
pipe8MassFlow = mod.getSolutions(["pipe8.port_a.m_flow"])
pipe9MassFlow = mod.getSolutions(["pipe9.port_a.m_flow"])
pipe10MassFlow = mod.getSolutions(["pipe10.port_a.m_flow"])
pipe11MassFlow = mod.getSolutions(["pipe11.port_a.m_flow"])
pipe12MassFlow = mod.getSolutions(["pipe12.port_a.m_flow"])
pipe13MassFlow = mod.getSolutions(["pipe13.port_a.m_flow"])
inletPressurePipe3 = mod.getSolutions(["pipe3.port_a.p"])
outletPressureOrifice5 = mod.getSolutions(["orifice5.port_b.p"])
inletPressurePipe = mod.getSolutions(["pipe.port_a.p"])
outletPressureMassFlowRate = mod.getSolutions(["massFlowRate.port_b.p"])

m_flow = pipeMassFlow.flat[0]
m_flow1 = pipe1MassFlow.flat[0]
m_flow2 = pipe2MassFlow.flat[0]
m_flow3 = pipe3MassFlow.flat[0]
m_flow4 = pipe4MassFlow.flat[0]
m_flow5 = pipe5MassFlow.flat[0]
m_flow6 = pipe6MassFlow.flat[0]
m_flow7 = pipe7MassFlow.flat[0]
m_flow8 = pipe8MassFlow.flat[0]
m_flow9 = pipe9MassFlow.flat[0]
m_flow10 = pipe10MassFlow.flat[0]
m_flow11 = pipe11MassFlow.flat[0]
m_flow12 = pipe12MassFlow.flat[0]
m_flow13 = pipe13MassFlow.flat[0]
inletPressureBeam = inletPressurePipe3.flat[0]
outletPressureBeam = outletPressureOrifice5.flat[0]
PressureDropBeam = inletPressureBeam-outletPressureBeam
inletPressureLosses = inletPressurePipe.flat[0]
outletPressureLosses = outletPressureMassFlowRate.flat[0]
BranchLosses = (inletPressureLosses-outletPressureLosses)*2



print(parameters)
print("\n")
print("m_flowInlet =", m_flow2, "[kg/s]")
print("\n")
print("m_flowInletBranchA2 =", m_flow1, "[kg/s]")
print("\n")
print("m_flowInletBranchA1 =", m_flow, "[kg/s]")
print("\n")
#print("m_flowBeam =", m_flow3, "[kg/s]")
#print("\n")
#print("m_flow4 =", m_flow4, "[kg/s]")
#print("\n")
#print("m_flow5 =", m_flow5, "[kg/s]")
#print("\n")
#print("m_flow6 =", m_flow6, "[kg/s]")
#print("\n")
#print("m_flow7 =", m_flow7, "[kg/s]")
#print("\n")
#print("m_flow8 =", m_flow8, "[kg/s]")
#print("\n")
#print("m_flow9 =", m_flow9, "[kg/s]")
#print("\n")
#print("m_flow10 =", m_flow10, "[kg/s]")
#print("\n")
print("m_flowOutletBranchA1 =", m_flow11, "[kg/s]")
print("\n")
print("m_flowOutletBranchA2 =", m_flow12, "[kg/s]")
print("\n")
print("m_flowOutlet =", m_flow13, "[kg/s]")
print("\n")
print("PressureDropBeam =", PressureDropBeam, "[Pa]")
print("\n")
print("BranchLosses =", BranchLosses, "[Pa]")

I want to set a new parameter but after the simulation the results are the same. How can I set a paramater??? Thanks

There are 0 guests and 0 other users also viewing this topic