from numpy import nan

from .gas_base import GasTwoPort
from .._internal import BaseAsset


class Compressor(GasTwoPort, BaseAsset):
    """
    A gas compressor increases the pressure level of the flow.
    """

    def __init__(self, name, **modifiers):
        super().__init__(name, **modifiers)

        self.component_type = "compressor"
        self.min_head = 30.0

        self.Q_nominal_in = nan
        self.Q_nominal_out = nan

        self.density_in = 2.5e3  # H2 density [g/m3] at 30bar
        self.density_out = 2.5e3  # H2 density [g/m3] at 30bar

        self.add_equation(
            (
                (self.GasIn.Q * self.density_in - self.GasOut.Q * self.density_out)
                / (self.Q_nominal_in * self.density_in * self.Q_nominal_out * self.density_out)
                ** 0.5
            )
        )
