FlowSensor

model FlowSensor
    import HydraulicsByFluidon.Media.Base.FluidInterface;

    parameter HydraulicsByFluidon.Types.TFlowTypes sensorType = HydraulicsByFluidon.Types.TFlowTypes.volumeFlow "Sensor type";

    extends HydraulicsByFluidon.Components.Sensors.Base.SensorTwoPort;
equation
    if sensorType == HydraulicsByFluidon.Types.TFlowTypes.massFlow then 
        value = fluidPortA.mFlow;
    else 
        value = volumeFlowA;
    end if;
    0 = fluidPortA.mFlow + fluidPortB.mFlow;
    fluidPortA.p = fluidPortB.p;

    annotation (
        Icon(
            coordinateSystem(initialScale = 0.1),
            graphics = {
                Line(
                    origin = {-58.2973, 0.518199},
                    points = {
                        {0, 25}, 
                        {0, -25}}), 
                Polygon(
                    origin = {-58, -52},
                    rotation = 45,
                    fillPattern = FillPattern.Solid,
                    points = {
                        {59, 59}, 
                        {45, 51}, 
                        {51, 45}, 
                        {59, 59}}), 
                Line(points = {
                    {-29, 28}, 
                    {-18, 21}, 
                    {-14, 15}, 
                    {-12, 11}, 
                    {-10, 3}, 
                    {-10, -3}, 
                    {-12, -11}, 
                    {-14, -15}, 
                    {-18, -21}, 
                    {-29, -28}}), 
                Line(points = {
                    {29, 28}, 
                    {18, 21}, 
                    {14, 15}, 
                    {12, 11}, 
                    {10, 3}, 
                    {10, -3}, 
                    {12, -11}, 
                    {14, -15}, 
                    {18, -21}, 
                    {29, -28}})}),
        Documentation(info = "<html>\n            <p>\n                FlowSensor acts either as volume flow or mass flow sensor, depending on the parameter <var>Sensor type</var>.\n                The sensor is lossless and causes no pressure drop.\n            </p>\n            <p>\n                <var>Sensor type</var> = massFlow: Measured value = Mass flow rate through sensor</br>\n                <var>Sensor type</var> = volumeFlow: Measured value = Volume flow through sensor\n            </p></html>"));
end FlowSensor;