Elbow

model Elbow "Elbow"
    outer HydraulicsByFluidon.Media.Environment environment;
    parameter Modelica.SIunits.Length Diameter = 0.032 "Diameter";
    parameter Modelica.SIunits.Angle Angle(min = 0.005555555555556 * (30 * Modelica.Constants.pi), max = 0.005555555555556 * (120 * Modelica.Constants.pi)) = 0.5 * Modelica.Constants.pi "Elbow angle";
    parameter Modelica.SIunits.Volume deadVolume(final min = 1e-9) = 1e-6 "Dead volume at ports";
    parameter Boolean forwardFluidProperties = true "Forward fluid properties between ports"
        annotation (
            Dialog(tab = "Fluid Properties"),
            choices(checkBox = true));
    parameter Boolean enableZetaOutput = false "Enable zeta output"
        annotation (choices(checkBox = true));
    Modelica.Blocks.Interfaces.RealOutput Zeta if enableZetaOutput "Zeta"
        annotation (Placement(transformation(
            origin = {40, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    parameter Boolean enableReOutput = false "Enable Re output"
        annotation (choices(checkBox = true));
    Modelica.Blocks.Interfaces.RealOutput Re if enableReOutput "Re"
        annotation (Placement(transformation(
            origin = {40, 40},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Interfaces.FluidPort fluidPortA(p(start = environment.pAmbient, nominal = 100000)) "Hydraulic port A"
        annotation (Placement(transformation(extent = {
            {-110, -10}, 
            {-90, 10}})));
    HydraulicsByFluidon.Interfaces.FluidPort fluidPortB(p(start = environment.pAmbient, nominal = 100000)) "Hydraulic port B"
        annotation (Placement(transformation(extent = {
            {-10, 110}, 
            {10, 90}})));
    HydraulicsByFluidon.Components.Lines.Base.SimpleElbow simpleElbow(forwardFluidProperties = false, Diameter = Diameter, Angle = Angle) annotation (Placement(
        visible = true,
        transformation(
            origin = {-3, 3},
            extent = {
                {-12, -10}, 
                {12, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.Volume volumeB(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {0, 70},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.Volume volumeA(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {-70, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    Modelica.SIunits.AbsolutePressure pA(start = environment.pAmbient, nominal = 100000) "Pressure at port A";
    Modelica.SIunits.AbsolutePressure pB(start = environment.pAmbient, nominal = 100000) "Pressure at port B";
equation
    if enableReOutput then 
        Re = simpleElbow.re;
    end if;
    if enableZetaOutput then 
        Zeta = simpleElbow.zeta;
    end if;
    if forwardFluidProperties then 
        fluidPortA.fluidTemperature = fluidPortB.fluidTemperature;
        fluidPortA.fluidId = fluidPortB.fluidId;
        fluidPortA.proportionUndissolvedAir = fluidPortB.proportionUndissolvedAir;
        fluidPortA.polytropicExponent = fluidPortB.polytropicExponent;
    end if;
    connect(fluidPortA,volumeA.fluidPort) annotation (Line(
        points = {
            {-100, 0}, 
            {-70, 0}},
        color = {0, 93, 152}));
    connect(volumeA.fluidPort,simpleElbow.fluidPortA) annotation (Line(
        points = {
            {-70, 0}, 
            {-18, 0}},
        color = {0, 93, 152}));
    connect(volumeB.fluidPort,fluidPortB) annotation (Line(
        points = {
            {0, 70}, 
            {0, 100}},
        color = {0, 93, 152}));
    connect(simpleElbow.fluidPortB,volumeB.fluidPort) annotation (Line(
        points = {
            {0, 14}, 
            {0, 70}},
        color = {0, 93, 152}));
    volumeA.p = pA;
    volumeB.p = pB;

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -40}, 
                    {40, 100}}),
            graphics = {
                Polygon(
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {-90, -30}, 
                        {30, -30}, 
                        {30, 90}, 
                        {-30, 90}, 
                        {-30, 30}, 
                        {-90, 30}, 
                        {-90, -30}}), 
                Line(points = {
                    {30, -30}, 
                    {-30, 30}})}),
        Documentation(info = "<html>\n            <p>\n                The component Elbow is a valid model for <var>Elbow angle</var> between 30° and 120°.\n            </p>\n            <p>\n                <center><img align=\"middle\" src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Lines/ElbowSketch.png\"></center>\n            </p>\n            <p>\n                <b>Please consider:</b> The component was modeled in order to consider the pressure losses of sharp edged elbows. However, the use of \n                the component can lead to extremely long simulation times, since a small stepsize must be selected due to  \n                the low resistance of an elbow.\n            </p>\n            <p>\n                Formulas are taken from W. Wagner, Strömung und Druckverlust, 7. Auflage 2012, and Will, D., Hydraulik, Grundlagen, Komponenten, Schaltungen, 5. Auflage 2011.\n            </p></html>"));
end Elbow;