from numpy import sqrt


def microhole_formation(formation_rate, age_of_film, area_holes_initial):
    """
    Calculate the area of microholes formed over time.

    Parameters:
    formation_rate (float): The rate at which microholes form per unit time.
    age_of_film (float): The age of the film in the same time units as formation_rate.
    area_holes_initial (float): The initial area of the microholes.

    Returns:
    float: The total area of the microholes after the given age of the film.
    """
    return area_holes_initial + formation_rate * age_of_film


def gas_leakage_micro_holes(
    discharge_coefficient, micro_hole_area, pressure_difference, gas_density, time_step
):
    """
    Calculate the gas leakage through microholes.

    Parameters:
    discharge_coefficient (float): The discharge coefficient, a dimensionless number.
    micro_hole_area (float): The total area of the microholes.
    pressure_difference (float): The pressure difference across the microholes.
    gas_density (float): The density of the gas.
    time_step (float): The time step over which to calculate the leakage.

    Returns:
    float: The amount of gas leaked through the microholes in the given time step.
    """
    return (
        -discharge_coefficient
        * micro_hole_area
        * sqrt(2 * pressure_difference * gas_density)
        * time_step
    )


def gas_leakage_permeability(
    permeability_coefficient,
    pressure_difference,
    time_step,
    balloon_skin_area,
):
    """
    Calculate the gas leakage through the balloon skin due to permeability.

    Parameters:
    permeability_coefficient (float): The permeability coefficient of the balloon skin.
    pressure_difference (float): The pressure difference across the balloon skin.
    time_step (float): The time step over which to calculate the leakage.
    balloon_skin_area (float): The total surface area of the balloon skin.

    Returns:
    float: The amount of gas leaked through the balloon skin in the given time step.
    """
    return (
        -permeability_coefficient * balloon_skin_area * pressure_difference * time_step
    )
