---
url: /dyad/dev/stdlib/FluidComponents/types/Valves.BaseClasses.PartialValve.md
description: >-
  Dyad Valves.BaseClasses.PartialValve docs.  Base class for valves that
  transport fluid without storing mass or energy.
---

# `Valves.BaseClasses.PartialValve` {#Valves.BaseClasses.PartialValve}

Base class for valves that transport fluid without storing mass or energy.

The valve flow coefficient can be supplied as Av, Kv, Cv, or inferred from a nominal operating point. An optional critically damped actuator model filters the commanded valve opening.

This component extends from [`FluidComponents.Interfaces.PartialTwoPortTransport`](./PartialTwoPortTransport.md)

## Usage {#Usage}

`FluidComponents.Valves.BaseClasses.PartialValve(showDesignFlowDirection=true, dp_start=dp_nominal, m_flow_start=m_flow_nominal, m_flow_small, Av=m_flow_nominal / sqrt(rho_nominal * dp_nominal) * FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal), Kv=0, Cv=0, dp_nominal, m_flow_nominal, rho_nominal=MediaComponents.Interfaces.density_pTX(medium_data, MediaComponents.Interfaces.medium_p_default(medium_data), MediaComponents.Interfaces.medium_T_default(medium_data), MediaComponents.Interfaces.medium_X_default(medium_data)), opening_nominal=1, riseTime=1, leakageOpening=1e-3, dp_small, Kv2Av=27.7e-6, Cv2Av=24.0e-6, effective_Av=__dyad_isa_variant(CvData, FluidComponents.Types.CvTypes.Av) ? Av : (__dyad_isa_variant(CvData, FluidComponents.Types.CvTypes.Kv) ? Kv * Kv2Av : (__dyad_isa_variant(CvData, FluidComponents.Types.CvTypes.Cv) ? Cv * Cv2Av : m_flow_nominal / (FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal) * sqrt(rho_nominal) * FluidComponents.regRoot(dp_nominal, dp_small)))))`

## Parameters: {#Parameters:}

|                      Name | Description | Units |             Default value |
| -------------------------:| -----------:| -----:| -------------------------:|
|             `medium_data` |             |     – |                           |
|       `allowFlowReversal` |             |     – |                           |
|     `port_a_exposesState` |             |     – |                     false |
|     `port_b_exposesState` |             |     – |                     false |
|                      `nX` |             |     – | FluidCompon...edium_data) |
|                     `nXi` |             |     – | FluidCompon...edium_data) |
|                      `nC` |             |     – | FluidCompon...edium_data) |
|                `reducedX` |             |     – | FluidCompon...edium_data) |
|                  `fixedX` |             |     – | FluidCompon...edium_data) |
|                  `show_T` |             |     – |                      true |
|             `show_V_flow` |             |     – |                      true |
|                  `CvData` |             |     – | FluidCompon...s.OpPoint() |
|         `filteredOpening` |             |     – |                     false |
|              `checkValve` |             |     – |                     false |
|     `valveCharacteristic` |             |     – | FluidCompon...ic.linear() |
| `showDesignFlowDirection` |             |     – |                      true |
|                `dp_start` |             |    Pa |                dp_nominal |
|            `m_flow_start` |             |  kg/s |            m_flow_nominal |
|            `m_flow_small` |             |  kg/s |                           |
|                      `Av` |             |    m2 | m_flow_nomi...ng_nominal) |
|                      `Kv` |             |     – |                         0 |
|                      `Cv` |             |     – |                         0 |
|              `dp_nominal` |             |    Pa |                           |
|          `m_flow_nominal` |             |  kg/s |                           |
|             `rho_nominal` |             | kg/m3 | MediaCompon...dium_data)) |
|         `opening_nominal` |             |     – |                         1 |
|                `riseTime` |             |     s |                         1 |
|          `leakageOpening` |             |     – |                      1e-3 |
|                `dp_small` |             |    Pa |                           |

## Connectors {#Connectors}

* `port_a` - Generic fluid connector at the design inlet. ([`FluidPort_a`](@ref))

* `port_b` - Generic fluid connector at the design outlet. ([`FluidPort_b`](@ref))

* `opening` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `opening_filtered` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

## Variables {#Variables}

|               Name | Description | Units |
| ------------------:| -----------:| -----:|
|           `m_flow` |             |  kg/s |
|               `dp` |             |    Pa |
|           `V_flow` |             |  m3/s |
|         `port_a_T` |             |     K |
|         `port_b_T` |             |     K |
| `port_a_outflow_X` |             | kg/kg |
| `port_b_outflow_X` |             | kg/kg |
|  `opening_limited` |             |     – |
|   `opening_actual` |             |     – |

## Source {#Source}

```dyad
"""
Base class for valves that transport fluid without storing mass or energy.

The valve flow coefficient can be supplied as Av, Kv, Cv, or inferred from a
nominal operating point. An optional critically damped actuator model filters
the commanded valve opening.
"""
partial component PartialValve
  extends FluidComponents.Interfaces.PartialTwoPortTransport(dp_start = dp_nominal, m_flow_start = m_flow_nominal)
  # Selection of the valve flow-coefficient representation [-]
  structural parameter CvData::FluidComponents.Types.CvTypes = FluidComponents.Types.CvTypes.OpPoint()
  # Metric flow coefficient [m2]
  parameter Av::Area = m_flow_nominal / sqrt(rho_nominal * dp_nominal) * FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal)
  # Metric Kv flow coefficient [m3/h]
  parameter Kv::Real = 0
  # US Cv flow coefficient [USG/min]
  parameter Cv::Real = 0
  # Nominal pressure drop [Pa]
  parameter dp_nominal::Pressure
  # Nominal mass flow rate [kg/s]
  parameter m_flow_nominal::MediaComponents.Types.MassFlowRate
  # Nominal inlet density [kg/m3]
  parameter rho_nominal::MediaComponents.Types.Density = MediaComponents.Interfaces.density_pTX(medium_data, MediaComponents.Interfaces.medium_p_default(medium_data), MediaComponents.Interfaces.medium_T_default(medium_data), MediaComponents.Interfaces.medium_X_default(medium_data))
  # Nominal valve opening [-]
  parameter opening_nominal::Real(min = 0, max = 1) = 1
  # Whether the opening command is filtered [-]
  structural parameter filteredOpening::Boolean = false
  # Time for a filtered opening step to reach 99.6 percent [s]
  parameter riseTime::Time = 1
  # Minimum opening supplied to the actuator filter [-]
  parameter leakageOpening::Real(min = 0, max = 1) = 1e-3
  # Whether reverse flow is stopped [-]
  structural parameter checkValve::Boolean = false
  # Inherent valve-flow characteristic [-]
  structural parameter valveCharacteristic::FluidComponents.Valves.BaseClasses.ValveCharacteristic = FluidComponents.Valves.BaseClasses.ValveCharacteristic.linear()
  # Pressure-drop regularization scale [Pa]
  parameter dp_small::Pressure
  # Conversion factor from Kv to Av [m2]
  final parameter Kv2Av::Area = 27.7e-6
  # Conversion factor from Cv to Av [m2]
  final parameter Cv2Av::Area = 24.0e-6
  # Effective metric flow coefficient [m2]
  final parameter effective_Av::Area = case(CvData, FluidComponents.Types.CvTypes.Av) ? Av : (case(CvData, FluidComponents.Types.CvTypes.Kv) ? Kv * Kv2Av : (case(CvData, FluidComponents.Types.CvTypes.Cv) ? Cv * Cv2Av : m_flow_nominal / (FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal) * sqrt(rho_nominal) * FluidComponents.regRoot(dp_nominal, dp_small))))
  "Commanded valve opening in the range zero to one."
  opening = RealInput(min = 0, max = 1) {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 90}
      }
    }
  }
  "Filtered valve opening."
  opening_filtered = RealOutput(min = 0, max = 1) if filteredOpening {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 750, "y1": 150, "x2": 850, "y2": 250, "rot": 0}
      }
    }
  }
  "Critically damped second-order valve actuator."
  opening_filter = BlockComponents.Continuous.SecondOrder(k = 1, w = 5 / riseTime, d = 1) if filteredOpening
  # Valve opening after leakage limiting [-]
  variable opening_limited::Real if filteredOpening
  # Valve opening used by the flow characteristic [-]
  variable opening_actual::Real
relations
  port_a.h_outflow = instream(port_b.h_outflow)
  port_b.h_outflow = instream(port_a.h_outflow)
  if filteredOpening
    opening_limited = max(leakageOpening, opening)
    opening_filter.u = opening_limited
    opening_filtered = opening_filter.y
    opening_actual = opening_filter.y
    initial der(opening_filter.x) = 0
    initial der(opening_filter.xd) = 0
  else
    opening_actual = opening
  end
end
```

```dyad
"""
Base class for valves that transport fluid without storing mass or energy.

The valve flow coefficient can be supplied as Av, Kv, Cv, or inferred from a
nominal operating point. An optional critically damped actuator model filters
the commanded valve opening.
"""
partial component PartialValve
  # Immutable medium definition selected at model construction [-]
  structural parameter medium_data::MediaComponents.Interfaces.AbstractPartialMediumData
  # Whether flow may reverse from the positive design direction [-]
  structural parameter allowFlowReversal::Boolean
  # Fluid connector at the design inlet [-]
  port_a = FluidComponents.Interfaces.FluidPort_a(medium_data = medium_data) {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      }
    }
  }
  # Fluid connector at the design outlet [-]
  port_b = FluidComponents.Interfaces.FluidPort_b(medium_data = medium_data) {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      }
    }
  }
  # Whether port_a exposes the state of an internal fluid volume [-]
  structural parameter port_a_exposesState::Boolean = false
  # Whether port_b exposes the state of an internal fluid volume [-]
  structural parameter port_b_exposesState::Boolean = false
  # Whether to show the positive design-flow direction [-]
  parameter showDesignFlowDirection::Boolean = true
  # Number of mass fractions [-]
  final structural parameter nX::Integer = MediaComponents.Interfaces.medium_nX(medium_data)
  # Number of independent mass fractions [-]
  final structural parameter nXi::Integer = MediaComponents.Interfaces.medium_nXi(medium_data)
  # Number of extra transported properties [-]
  final structural parameter nC::Integer = MediaComponents.Interfaces.medium_nC(medium_data)
  # Whether the medium mass fractions sum to one [-]
  final structural parameter reducedX::Boolean = MediaComponents.Interfaces.medium_reducedX(medium_data)
  # Whether the medium composition is fixed [-]
  final structural parameter fixedX::Boolean = MediaComponents.Interfaces.medium_fixedX(medium_data)
  # Start value of the pressure difference [Pa]
  parameter dp_start::Pressure
  # Start value of the mass flow rate [kg/s]
  parameter m_flow_start::MediaComponents.Types.MassFlowRate
  # Small mass flow rate used to regularize flow-direction changes [kg/s]
  parameter m_flow_small::MediaComponents.Types.MassFlowRate
  # Whether port temperatures are computed for diagnostics [-]
  structural parameter show_T::Boolean = true
  # Whether volume flow rate is computed for diagnostics [-]
  structural parameter show_V_flow::Boolean = true
  "Thermodynamic state of fluid entering through port_a."
  state_a = MediaComponents.Interfaces.ThermodynamicState(medium_data = medium_data)
  "Thermodynamic state of fluid entering through port_b."
  state_b = MediaComponents.Interfaces.ThermodynamicState(medium_data = medium_data)
  # Mass flow rate in the design-flow direction [kg/s]
  variable m_flow::MediaComponents.Types.MassFlowRate(min = allowFlowReversal ? -Inf : 0)
  # Pressure difference between port_a and port_b [Pa]
  variable dp::Pressure
  # Volume flow rate at the inflowing port [m3/s]
  variable V_flow::VolumeFlowRate if show_V_flow
  # Temperature close to port_a [K]
  variable port_a_T::Temperature if show_T
  # Temperature close to port_b [K]
  variable port_b_T::Temperature if show_T
  # Outflow composition used by the port_a temperature diagnostic [kg/kg]
  variable port_a_outflow_X::MediaComponents.Types.MassFraction[nX] if show_T
  # Outflow composition used by the port_b temperature diagnostic [kg/kg]
  variable port_b_outflow_X::MediaComponents.Types.MassFraction[nX] if show_T
  # Selection of the valve flow-coefficient representation [-]
  structural parameter CvData::FluidComponents.Types.CvTypes = FluidComponents.Types.CvTypes.OpPoint()
  # Metric flow coefficient [m2]
  parameter Av::Area = m_flow_nominal / sqrt(rho_nominal * dp_nominal) * FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal)
  # Metric Kv flow coefficient [m3/h]
  parameter Kv::Real = 0
  # US Cv flow coefficient [USG/min]
  parameter Cv::Real = 0
  # Nominal pressure drop [Pa]
  parameter dp_nominal::Pressure
  # Nominal mass flow rate [kg/s]
  parameter m_flow_nominal::MediaComponents.Types.MassFlowRate
  # Nominal inlet density [kg/m3]
  parameter rho_nominal::MediaComponents.Types.Density = MediaComponents.Interfaces.density_pTX(medium_data, MediaComponents.Interfaces.medium_p_default(medium_data), MediaComponents.Interfaces.medium_T_default(medium_data), MediaComponents.Interfaces.medium_X_default(medium_data))
  # Nominal valve opening [-]
  parameter opening_nominal::Real(min = 0, max = 1) = 1
  # Whether the opening command is filtered [-]
  structural parameter filteredOpening::Boolean = false
  # Time for a filtered opening step to reach 99.6 percent [s]
  parameter riseTime::Time = 1
  # Minimum opening supplied to the actuator filter [-]
  parameter leakageOpening::Real(min = 0, max = 1) = 1e-3
  # Whether reverse flow is stopped [-]
  structural parameter checkValve::Boolean = false
  # Inherent valve-flow characteristic [-]
  structural parameter valveCharacteristic::FluidComponents.Valves.BaseClasses.ValveCharacteristic = FluidComponents.Valves.BaseClasses.ValveCharacteristic.linear()
  # Pressure-drop regularization scale [Pa]
  parameter dp_small::Pressure
  # Conversion factor from Kv to Av [m2]
  final parameter Kv2Av::Area = 27.7e-6
  # Conversion factor from Cv to Av [m2]
  final parameter Cv2Av::Area = 24.0e-6
  # Effective metric flow coefficient [m2]
  final parameter effective_Av::Area = case(CvData, FluidComponents.Types.CvTypes.Av) ? Av : (case(CvData, FluidComponents.Types.CvTypes.Kv) ? Kv * Kv2Av : (case(CvData, FluidComponents.Types.CvTypes.Cv) ? Cv * Cv2Av : m_flow_nominal / (FluidComponents.Valves.BaseClasses.valveCharacteristic(valveCharacteristic, opening_nominal) * sqrt(rho_nominal) * FluidComponents.regRoot(dp_nominal, dp_small))))
  "Commanded valve opening in the range zero to one."
  opening = RealInput(min = 0, max = 1) {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 450, "y1": -50, "x2": 550, "y2": 50, "rot": 90}
      }
    }
  }
  "Filtered valve opening."
  opening_filtered = RealOutput(min = 0, max = 1) if filteredOpening {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 750, "y1": 150, "x2": 850, "y2": 250, "rot": 0}
      }
    }
  }
  "Critically damped second-order valve actuator."
  opening_filter = BlockComponents.Continuous.SecondOrder(k = 1, w = 5 / riseTime, d = 1) if filteredOpening
  # Valve opening after leakage limiting [-]
  variable opening_limited::Real if filteredOpening
  # Valve opening used by the flow characteristic [-]
  variable opening_actual::Real
relations
  guess m_flow = m_flow_start
  guess dp = dp_start
  state_a.p = port_a.p
  state_a.h = instream(port_a.h_outflow)
  state_b.p = port_b.p
  state_b.h = instream(port_b.h_outflow)
  if fixedX
    state_a.X = MediaComponents.Interfaces.medium_reference_X(medium_data)
    state_b.X = MediaComponents.Interfaces.medium_reference_X(medium_data)
  elseif reducedX
    if nXi > 0
      for j in 1:nXi
        state_a.X[j] = instream(port_a.Xi_outflow[j])
        state_b.X[j] = instream(port_b.Xi_outflow[j])
      end
      state_a.X[nX] = 1 - sum(instream(port_a.Xi_outflow))
      state_b.X[nX] = 1 - sum(instream(port_b.Xi_outflow))
    else
      state_a.X[nX] = 1
      state_b.X[nX] = 1
    end
  else
    for j in 1:nX
      state_a.X[j] = instream(port_a.Xi_outflow[j])
      state_b.X[j] = instream(port_b.Xi_outflow[j])
    end
  end
  state_a.T = MediaComponents.Interfaces.temperature_phX(medium_data, state_a.p, state_a.h, state_a.X)
  state_a.d = MediaComponents.Interfaces.density_phX(medium_data, state_a.p, state_a.h, state_a.X)
  state_b.T = MediaComponents.Interfaces.temperature_phX(medium_data, state_b.p, state_b.h, state_b.X)
  state_b.d = MediaComponents.Interfaces.density_phX(medium_data, state_b.p, state_b.h, state_b.X)
  dp = port_a.p - port_b.p
  m_flow = port_a.m_flow
  port_a.m_flow + port_b.m_flow = 0
  if nXi > 0
    for j in 1:nXi
      port_a.Xi_outflow[j] = instream(port_b.Xi_outflow[j])
      port_b.Xi_outflow[j] = instream(port_a.Xi_outflow[j])
    end
  else
    port_a.Xi_outflow[1] = 0
    port_b.Xi_outflow[1] = 0
  end
  if nC > 0
    for j in 1:nC
      port_a.C_outflow[j] = instream(port_b.C_outflow[j])
      port_b.C_outflow[j] = instream(port_a.C_outflow[j])
    end
  else
    port_a.C_outflow[1] = 0
    port_b.C_outflow[1] = 0
  end
  if show_V_flow
    V_flow = m_flow / FluidComponents.regStep(m_flow, state_a.d, state_b.d, m_flow_small)
  end
  if show_T
    if fixedX
      port_a_outflow_X = MediaComponents.Interfaces.medium_reference_X(medium_data)
      port_b_outflow_X = MediaComponents.Interfaces.medium_reference_X(medium_data)
    elseif reducedX
      if nXi > 0
        for j in 1:nXi
          port_a_outflow_X[j] = port_a.Xi_outflow[j]
          port_b_outflow_X[j] = port_b.Xi_outflow[j]
        end
        port_a_outflow_X[nX] = 1 - sum(port_a.Xi_outflow)
        port_b_outflow_X[nX] = 1 - sum(port_b.Xi_outflow)
      else
        port_a_outflow_X[nX] = 1
        port_b_outflow_X[nX] = 1
      end
    else
      for j in 1:nX
        port_a_outflow_X[j] = port_a.Xi_outflow[j]
        port_b_outflow_X[j] = port_b.Xi_outflow[j]
      end
    end
    port_a_T = FluidComponents.regStep(port_a.m_flow, state_a.T, MediaComponents.Interfaces.temperature_phX(medium_data, port_a.p, port_a.h_outflow, port_a_outflow_X), m_flow_small)
    port_b_T = FluidComponents.regStep(port_b.m_flow, state_b.T, MediaComponents.Interfaces.temperature_phX(medium_data, port_b.p, port_b.h_outflow, port_b_outflow_X), m_flow_small)
  end
  port_a.h_outflow = instream(port_b.h_outflow)
  port_b.h_outflow = instream(port_a.h_outflow)
  if filteredOpening
    opening_limited = max(leakageOpening, opening)
    opening_filter.u = opening_limited
    opening_filtered = opening_filter.y
    opening_actual = opening_filter.y
    initial der(opening_filter.x) = 0
    initial der(opening_filter.xd) = 0
  else
    opening_actual = opening
  end
metadata {}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
