---
url: /dyad/dev/stdlib/MediaComponents/tests/Tests.TestReducedComposition.md
description: >-
  Dyad Tests.TestReducedComposition docs.  This component extends from
  MediaComponents.Interfaces.PartialMedium
---

# `Tests.TestReducedComposition` {#Tests.TestReducedComposition}

This component extends from [`MediaComponents.Interfaces.PartialMedium`](../types/PartialMedium.md)

## Usage {#Usage}

`MediaComponents.Tests.TestReducedComposition()`

## Parameters: {#Parameters:}

|                      Name | Description | Units |             Default value |
| -------------------------:| -----------:| -----:| -------------------------:|
|             `medium_data` |             |     – |       partial_medium_data |
|        `dyad_medium_type` |             |     – | MediaCompon...edium_data) |
|            `ThermoStates` |             |     – | MediaCompon...edium_data) |
|             `singleState` |             |     – | MediaCompon...edium_data) |
|                      `nS` |             |     – | MediaCompon...edium_data) |
|                      `nX` |             |     – | MediaCompon...edium_data) |
|                `reducedX` |             |     – | MediaCompon...edium_data) |
|                  `fixedX` |             |     – | MediaCompon...edium_data) |
|                     `nXi` |             |     – | MediaCompon...edium_data) |
|                      `nC` |             |     – | MediaCompon...edium_data) |
|   `preferredMediumStates` |             |     – |                     false |
| `standardOrderComponents` |             |     – |                      true |
|        `p_state_priority` |             |     – | ((preferred... (10) : (0) |
|        `T_state_priority` |             |     – | ((preferred... (10) : (0) |
|        `h_state_priority` |             |     – | ((preferred... (10) : (0) |
|        `d_state_priority` |             |     – | ((preferred... (10) : (0) |
|       `Xi_state_priority` |             |     – | ((preferred... (10) : (0) |
|     `partial_medium_data` |             |     – | MediaCompon...ed_X=false) |

## Variables {#Variables}

|     Name | Description |    Units |
| --------:| -----------:| --------:|
|      `p` |             |       Pa |
|     `Xi` |             |    kg/kg |
|      `h` |             |     J/kg |
|      `d` |             |    kg/m3 |
|      `T` |             |        K |
|      `X` |             |    kg/kg |
|      `u` |             |     J/kg |
|    `R_s` |             | J/(kg.K) |
|     `MM` |             |   kg/mol |
| `T_degC` |             |     degC |
|  `p_bar` |             |      bar |
|  `probe` |             |        – |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{T_degC}\left( t \right) &= -273.15 + T\left( t \right) \\
\mathtt{p_bar}\left( t \right) &= \frac{p\left( t \right)}{1 \cdot 10^{5}} \\
\mathtt{thermodynamic_state.p}\left( t \right) &= p\left( t \right) \\
\mathtt{thermodynamic_state.T}\left( t \right) &= T\left( t \right) \\
\mathtt{thermodynamic_state.d}\left( t \right) &= d\left( t \right) \\
\mathtt{thermodynamic_state.h}\left( t \right) &= h\left( t \right) \\
\mathtt{thermodynamic_state.X}\_{1}\left( t \right) &= X\_{1}\left( t \right) \\
\mathtt{thermodynamic_state.X}\_{2}\left( t \right) &= X\_{2}\left( t \right) \\
\mathtt{thermodynamic_state.X}\_{3}\left( t \right) &= X\_{3}\left( t \right) \\
\mathtt{Xi}\_{1}\left( t \right) &= 0.2 \\
\mathtt{Xi}\_{2}\left( t \right) &= 0.3 \\
p\left( t \right) &= 100000 \\
h\left( t \right) &= 1000 \\
d\left( t \right) &= 1 \\
T\left( t \right) &= 300 \\
u\left( t \right) &= 700 \\
\mathtt{R_s}\left( t \right) &= 287 \\
\mathtt{MM}\left( t \right) &= 0.029 \\
\frac{\mathrm{d}\mathtt{probe}\left( t \right)}{\mathrm{d}t} &= 0 \\
\mathtt{Xi}\_{1}\left( t \right) &= X\_{1}\left( t \right) \\
\mathtt{Xi}\_{2}\left( t \right) &= X\_{2}\left( t \right) \\
X\_{3}\left( t \right) &= 1 - SymbolicUtils.Mapreducer{typeof(identity), typeof(Base.add_sum), Colon, Nothing}(identity, Base.add_sum, Colon(), nothing)\left( \mathtt{Xi}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
test component TestReducedComposition
  extends MediaComponents.Interfaces.PartialMedium(partial_medium_data = MediaComponents.Tests.TestPartialMediumData(reduced_X = true, fixed_X = false), standardOrderComponents = true)
  # Observed composition value [-]
  variable probe::Real
relations
  Xi = [0.2, 0.3]
  p = 100000
  h = 1000
  d = 1
  T = 300
  u = 700
  R_s = 287
  MM = 0.029
  initial probe = X[3]
  der(probe) = 0
metadata {
  "Dyad": {
    "tests": {
      "case1": {"stop": 1, "expect": {"initial": {"probe": 0.5}, "final": {"probe": 0.5}}}
    }
  }
}
end
```

```dyad
test component TestReducedComposition
  # Immutable medium definition selected at model construction [-]
  structural parameter medium_data::MediaComponents.Interfaces.AbstractMediumData
  # Structural medium family derived from medium_data [-]
  final structural parameter dyad_medium_type::MediaComponents.Interfaces.MediumType = MediaComponents.Interfaces.medium_data_to_dyad_type(medium_data)
  # Choice of independent thermodynamic variables [-]
  final structural parameter ThermoStates::MediaComponents.Interfaces.Choices.IndependentVariables = MediaComponents.Interfaces.medium_thermo_states(medium_data)
  # Whether internal energy and density are independent of pressure [-]
  final structural parameter singleState::Boolean = MediaComponents.Interfaces.medium_single_state(medium_data)
  # Number of substances [-]
  final structural parameter nS::Integer = MediaComponents.Interfaces.medium_nS(medium_data)
  # Number of mass fractions [-]
  final structural parameter nX::Integer = MediaComponents.Interfaces.medium_nX(medium_data)
  # Whether the mass fractions sum to one [-]
  final structural parameter reducedX::Boolean = MediaComponents.Interfaces.medium_reducedX(medium_data)
  # Whether composition is fixed to the reference composition [-]
  final structural parameter fixedX::Boolean = MediaComponents.Interfaces.medium_fixedX(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)
  # Prefer independent medium properties as states [-]
  structural parameter preferredMediumStates::Boolean = false
  # Use the standard component-ordering equations [-]
  structural parameter standardOrderComponents::Boolean = true
  # State-selection priority for pressure [-]
  final structural parameter p_state_priority::Integer = preferredMediumStates and (case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.pT) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.ph) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.pTX) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.phX)) ? 10 : 0
  # State-selection priority for temperature [-]
  final structural parameter T_state_priority::Integer = preferredMediumStates and (case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.T) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.pT) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.pTX) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.dTX)) ? 10 : 0
  # State-selection priority for specific enthalpy [-]
  final structural parameter h_state_priority::Integer = preferredMediumStates and (case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.ph) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.phX)) ? 10 : 0
  # State-selection priority for density [-]
  final structural parameter d_state_priority::Integer = preferredMediumStates and case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.dTX) ? 10 : 0
  # State-selection priority for independent composition [-]
  final structural parameter Xi_state_priority::Integer = preferredMediumStates and (case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.pTX) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.phX) or case(ThermoStates, MediaComponents.Interfaces.Choices.IndependentVariables.dTX)) ? 10 : 0
  "Wide thermodynamic state represented as a composed component."
  thermodynamic_state = MediaComponents.Interfaces.ThermodynamicState(medium_data = medium_data)
  # Absolute pressure [Pa]
  variable p::MediaComponents.Types.AbsolutePressure(statePriority = p_state_priority)
  # Independent mass fractions [kg/kg]
  variable Xi::MediaComponents.Types.MassFraction(statePriority = Xi_state_priority)[nXi] if nXi > 0
  # Specific enthalpy [J/kg]
  variable h::MediaComponents.Types.SpecificEnthalpy(statePriority = h_state_priority)
  # Density [kg/m3]
  variable d::MediaComponents.Types.Density(statePriority = d_state_priority)
  # Temperature [K]
  variable T::MediaComponents.Types.Temperature(statePriority = T_state_priority)
  # Mass fractions [kg/kg]
  variable X::MediaComponents.Types.MassFraction[nX]
  # Specific internal energy [J/kg]
  variable u::MediaComponents.Types.SpecificInternalEnergy
  # Specific gas constant [J/(kg.K)]
  variable R_s::MediaComponents.Types.SpecificHeatCapacity
  # Molar mass [kg/mol]
  variable MM::MediaComponents.Types.MolarMass
  # Temperature in degrees Celsius [degC]
  variable T_degC::Real(units = "degC")
  # Absolute pressure in bar [bar]
  variable p_bar::Real(units = "bar")
  # Immutable medium definition selected at model construction [-]
  structural parameter partial_medium_data::MediaComponents.Interfaces.AbstractPartialMediumData
  # Observed composition value [-]
  variable probe::Real
relations
  if nXi > 0
    guess Xi = MediaComponents.Interfaces.independent_mass_fraction_guess(MediaComponents.Interfaces.medium_reference_X(medium_data), nXi)
  end
  guess X = MediaComponents.Interfaces.medium_reference_X(medium_data)
  if standardOrderComponents
    for i in 1:nXi
      Xi[i] = X[i]
    end
    if fixedX
      X = MediaComponents.Interfaces.medium_reference_X(medium_data)
    end
    if reducedX and !fixedX
      X[nX] = 1 - sum(Xi)
    end
  end
  assert(MediaComponents.Interfaces.mass_fractions_in_valid_range(standardOrderComponents, X), "A medium mass fraction is outside the permitted range.")
  assert(p >= 0, "The absolute pressure of the medium is negative.")
  T_degC = T - 273.15
  p_bar = p / 1e5
  thermodynamic_state.p = p
  thermodynamic_state.T = T
  thermodynamic_state.d = d
  thermodynamic_state.h = h
  thermodynamic_state.X = X
  if case(dyad_medium_type, MediaComponents.Interfaces.MediumType.PartialSimpleMediumType)
    h = MediaComponents.Interfaces.specificEnthalpy_pTX(medium_data, p, T, X)
    u = MediaComponents.Interfaces.specificInternalEnergy(medium_data, p, T)
    d = MediaComponents.Interfaces.density(medium_data, p, T)
    R_s = 0
    MM = MediaComponents.Interfaces.molarMass(medium_data, p, T)
  end
  Xi = [0.2, 0.3]
  p = 100000
  h = 1000
  d = 1
  T = 300
  u = 700
  R_s = 287
  MM = 0.029
  initial probe = X[3]
  der(probe) = 0
metadata {
  "Dyad": {
    "tests": {
      "case1": {"stop": 1, "expect": {"initial": {"probe": 0.5}, "final": {"probe": 0.5}}}
    }
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`ThermodynamicState`](Tests.TestReducedComposition.md)
