SimpleCylinder

model SimpleCylinder
    import HydraulicsByFluidon.Media.Base.FluidInterface;
    import SI = Modelica.SIunits;

    extends PartialCylinder;

    parameter Boolean forwardFluidProperties = false "Forward fluid properties between ports"
        annotation (Dialog(tab = "Fluid Properties"));
    SI.AbsolutePressure pB(start = environment.pAmbient, stateSelect = StateSelect.default, nominal = 100000) "Pressure in chamber B";
    SI.Volume volumeB;
    HydraulicsByFluidon.Interfaces.FluidPort fluidPortB "Hydraulic port B"
        annotation (Placement(
            visible = true,
            transformation(
                extent = {
                    {70, -90}, 
                    {90, -110}},
                rotation = 0),
            iconTransformation(
                extent = {
                    {70, -50}, 
                    {90, -70}},
                rotation = 0)));
protected
    Real rhoB;
    SI.MassFlowRate mFlowSumB(nominal = 1e-5);
    SI.MassFlowRate mFlowInternalB(nominal = 1e-5);
equation
    if forwardFluidProperties then 
        fluidPortA.fluidTemperature = fluidPortB.fluidTemperature;
        fluidPortA.fluidId = fluidPortB.fluidId;
        fluidPortA.proportionUndissolvedAir = fluidPortB.proportionUndissolvedAir;
        fluidPortA.polytropicExponent = fluidPortB.polytropicExponent;
    end if;
    fHydA = pA * areaA + environment.pAmbient * areaRodA;
    fHydB = pB * areaB + environment.pAmbient * areaRodB;
    mFlowSumB = mFlowInternalB + fluidPortB.mFlow;
    mFluid = volumeA * rhoA + volumeB * rhoB;
    rhoB = FluidInterface.calcRho(fluidPortB.fluidId, pB, fluidPortB.fluidTemperature);
    volumeA = stroke * areaA + deadVolume;
    volumeB = (cylinderLength - stroke) * areaB + deadVolume;
    mFlowInternalB = relVelocity * areaB * rhoB;
    fluidPortB.p = pB;
    der(pB) = FluidInterface.calcKtCorrection(FluidInterface.calcKt(fluidPortB.fluidId, pB, fluidPortB.fluidTemperature), fluidPortB.proportionUndissolvedAir, fluidPortB.polytropicExponent, pB) / volumeB * (mFlowSumB / FluidInterface.calcRho(fluidPortB.fluidId, pB, fluidPortB.fluidTemperature));

    annotation (
        defaultComponentName = "simpleCylinder",
        Documentation(info = "<html>\n                                  <p>Simple model of a cylinder with Stribeck friction.</p>                                  \n                              </html>"),
        Icon(
            coordinateSystem(
                extent = {
                    {-190, -80}, 
                    {210, 120}},
                initialScale = 0.1),
            graphics = {
                Line(points = {
                    {80, -40}, 
                    {80, -60}})}));
end SimpleCylinder;