simulateModel("Buildings.Fluid.HydronicConfigurations.ActiveNetworks.Examples.DiversionOpenLoop", method="CVode", stopTime=300, tolerance=1e-06, resultFile="DiversionOpenLoop");


createPlot(id=1, position={15, 15, 1184, 744},y={"ope.y[1]", "ope.y[2]"}, patterns={LinePattern.Solid, LinePattern.Dash}, autoscale=true, grid=true, autoerase=true, color=true);

createPlot(id=2, position={616, 16, 1183, 972}, y={"pum.m_flow", "con.val.m1_flow", "con.val.m2_flow", "con.val.m3_flow", "mPum_flow_nominal", "con.m2_flow_nominal"}, subPlot=1, autoscale=true, grid=true, autoerase=true, color=true);
createPlot(id=2, position={616, 16, 1183, 972}, y={"pum.m_flow", "con1.val.m1_flow", "con1.val.m2_flow", "con1.val.m3_flow", "mPum_flow_nominal", "con1.m2_flow_nominal"}, subPlot=2, autoscale=true, grid=true, autoerase=true, color=true);

createPlot(id=3, position={1214, 15, 1184, 744}, y={"pum.dpMachine", "dp.p_rel", "dp1.p_rel", "con.val.dp1", "con1.val.dp1"}, autoerase=true, range={0.0, 1.0, 0.0, 5E4}, grid=true, color=true);

createPlot(id=4, position={169, 245, 1184, 744}, y={"ope.y[1]", "ope.y[2]", "loa.yLoa_actual", "loa1.yLoa_actual"}, autoscale=true, grid=true, autoerase=true, color=true);

// Plot pump characteristic and design operating point
createPlot(id=5, position={1384, 242, 1184, 744}, x="pum.m_flow", y={"pum.dpMachine"}, autoscale=true, autoerase=true, grid=true, color=true, leftTitle="pum.dpMachine [Pa]", patterns={LinePattern.None}, markers={MarkerStyle.Dot});
nPoints = readTrajectorySize("DiversionOpenLoop.mat");

dp_nom = readTrajectory("DiversionOpenLoop.mat", {"dpPum_nominal"}, 1);
m_flow_nom = readTrajectory("DiversionOpenLoop.mat", {"mPum_flow_nominal"}, 1);

mValues = {0.1 * i for i in 1:40};
coefValues = {-631.30252101,  -1712.18487395,  -1050.42016807, 114000.} * dp_nom[1,1] * 1e-5 ;
dpValues = {coefValues[1] * mValues[i]^3 for i in 1:40} + {coefValues[2] * mValues[i]^2 for i in 1:40} + coefValues[3] .* mValues + fill(coefValues[4], 40);
plotArray(mValues, dpValues, id=5, erase=false, legend="Characteristic");
plotArray({m_flow_nom[1, 1]}, {dp_nom[1, 1]}, id=5, erase=false, legend="Design operating point");

// Delta-T function of the load
q_flow_nom = readTrajectory("DiversionOpenLoop.mat", {"loa.Q_flow_nominal"}, 1);
q1_flow_nom = readTrajectory("DiversionOpenLoop.mat", {"loa1.Q_flow_nominal"}, 1);
q_flow = readTrajectory("DiversionOpenLoop.mat", {"loa.Q_flow"}, nPoints);
q1_flow = readTrajectory("DiversionOpenLoop.mat", {"loa1.Q_flow"}, nPoints);
dT = readTrajectory("DiversionOpenLoop.mat", {"dT1.y"}, nPoints);
ratQTot_flow = (q_flow[1] + q1_flow[1]) / (q_flow_nom[1, 1] + q1_flow_nom[1, 1]);

createPlot(id=6, position={730, 245, 1184, 744}, autoscale=true, autoerase=true, grid=true, color=true, leftTitle="delta-T [K]", bottomTitle="QTot_flow/QTot_flow_nominal [-]");
plotArray(ratQTot_flow, dT[1], id=6, erase=false, legend="dT1.y", pattern=LinePattern.None, marker=MarkerStyle.Dot);
plotArray({1}, {dT[1, 1]}, id=6, erase=false, legend="Design operating point", color={238,46,47});
plotArray({0,1}, {0,dT[1, 1]}, id=6, erase=false, legend="Linear trend", color={0,140,72}, pattern=LinePattern.Dash);