SimpleDisplacementMachineTwoDir

model SimpleDisplacementMachineTwoDir
    import HydraulicsByFluidon.Media;
    import HydraulicsByFluidon.Media.Base.FluidInterface;

    extends HydraulicsByFluidon.Components.Pumps.Interfaces.PartialPump;
    extends Modelica.Mechanics.Rotational.Interfaces.PartialTwoFlanges;

    parameter Modelica.SIunits.Volume dispVolume = 5e-5 "Displacement volume of the machine";
protected
    Real n;
    Modelica.SIunits.Volume volume;
    Modelica.SIunits.Pressure dp;
    Modelica.SIunits.VolumeFlowRate QA;
    parameter Boolean flagIntVol = true;
    Real rho(start = 847);
equation
    if flagIntVol then 
        volume = dispVolume;
    end if;
    flange_a.tau + flange_b.tau = volume * dp / (2 * Modelica.Constants.pi);
    fluidPortA.mFlow + fluidPortB.mFlow = 0;
    n = der(flange_a.phi) / (2 * Modelica.Constants.pi);
    QA = volume * n;
    dp = fluidPortB.p - fluidPortA.p;
    rho = FluidInterface.calcRho(fluidId, 0.5 * abs(fluidPortA.p + fluidPortB.p), 0.5 * (fluidPortA.fluidTemperature + fluidPortB.fluidTemperature));
    flange_a.phi = flange_b.phi;
    fluidPortA.mFlow = QA * rho;

    annotation (
        Documentation(info = "<html>\n              <p>Model of a simple displacement machine without losses.\n              </p>\n              <p>The displacement machine is parameterised by providing its displacement volume <b>dispVolume</b>.\n              </p>\n              </html>"),
        Icon(
            graphics = {
                Line(points = {
                    {-100, 10}, 
                    {-59, 10}}), 
                Line(points = {
                    {-100, -10}, 
                    {-59, -10}}), 
                Line(points = {
                    {59, 10}, 
                    {100, 10}}), 
                Line(points = {
                    {59, -10}, 
                    {100, -10}})},
            coordinateSystem(initialScale = 0.1)));
end SimpleDisplacementMachineTwoDir;