TeeJunctionVolume

model TeeJunctionVolume "Splitting/joining component with static balances for a dynamic control volume"
    extends Modelica.Fluid.Fittings.BaseClasses.PartialTeeJunction;
    extends Modelica.Fluid.Interfaces.PartialLumpedVolume(final fluidVolume = V);

    parameter SI.Volume V "Mixing volume inside junction";
equation
    assert(cardinality(port_1) <= 1, "\nport_1 of volume can at most be connected to one component.\nIf two or more connections are present, ideal mixing takes\nplace with these connections which is usually not the intention\nof the modeller.\n");
    assert(cardinality(port_2) <= 1, "\nport_2 of volume can at most be connected to one component.\nIf two or more connections are present, ideal mixing takes\nplace with these connections which is usually not the intention\nof the modeller.\n");
    assert(cardinality(port_3) <= 1, "\nport_3 of volume can at most be connected to one component.\nIf two or more connections are present, ideal mixing takes\nplace with these connections which is usually not the intention\nof the modeller.\n");
    Hb_flow = port_1.m_flow * actualStream(port_1.h_outflow) + port_2.m_flow * actualStream(port_2.h_outflow) + port_3.m_flow * actualStream(port_3.h_outflow);
    Qb_flow = 0;
    Wb_flow = 0;
    port_1.p = medium.p;
    port_1.C_outflow = C;
    port_1.h_outflow = medium.h;
    port_1.Xi_outflow = medium.Xi;
    port_2.p = medium.p;
    port_2.C_outflow = C;
    port_2.h_outflow = medium.h;
    port_2.Xi_outflow = medium.Xi;
    port_3.p = medium.p;
    port_3.C_outflow = C;
    port_3.h_outflow = medium.h;
    port_3.Xi_outflow = medium.Xi;
    mbC_flow = port_1.m_flow * actualStream(port_1.C_outflow) + port_2.m_flow * actualStream(port_2.C_outflow) + port_3.m_flow * actualStream(port_3.C_outflow) "Trace substance mass balances";
    mbXi_flow = port_1.m_flow * actualStream(port_1.Xi_outflow) + port_2.m_flow * actualStream(port_2.Xi_outflow) + port_3.m_flow * actualStream(port_3.Xi_outflow) "Component mass balances";
    mb_flow = port_1.m_flow + port_2.m_flow + port_3.m_flow "Mass balance";

    annotation (
        Documentation(info = "<html>\n  This model introduces a mixing volume into a junction.\n  This might be useful to examine the non-ideal mixing taking place in a real junction.</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Ellipse(
                    extent = {
                        {-9, 10}, 
                        {11, -10}},
                    fillPattern = FillPattern.Solid)}));
end TeeJunctionVolume;