# Path: proptools/constants.py



import numpy as np
from scipy.optimize import minimize
from proptools.constants import charge, amu_kg, g
        discharge_loss (scalar, optional): The discharge loss per ion [units: volt].
        m_ion (scalar, optional): Ion mass [units: kilogram].

    Returns:
        scalar: Optimal specific impulse [units: second].
    """
    v_ch = stuhlinger_velocity(total_efficiency, t_m, specific_mass)
    v_L = 0
    if discharge_loss is not None and m_ion is not None:
        v_L = (2 * (charge / m_ion) * discharge_loss)**0.5

    def mass_fraction(c):
        """Optimization objective function.

        Payload + structure mass fraction.

        Reference: Lozano equation 3-13

        Arguments:
            c : effective exhaust velocity, I_sp * g.
        """
        return np.exp(-dv / c) - (c**2 + v_L**2) / (v_ch**2) * (1 - np.exp(-dv / c))

    # Scale factor to avoid numerical problems with minimize.
    scale_factor = 10e3

    # Find the c which maximizes the mass fraction.
    result = minimize(lambda c: -mass_fraction(c * scale_factor), 1.)
    c = result.x[0] * scale_factor


# Path: proptools/constants.py



# Path: proptools/electric/generic.py
import numpy as np
from scipy.optimize import minimize
from proptools.constants import charge, amu_kg, g

        discharge_loss (scalar, optional): The discharge loss per ion [units: volt].
        m_ion (scalar, optional): Ion mass [units: kilogram].

    Returns:
        scalar: Optimal specific impulse [units: second].
    """
    v_ch = stuhlinger_velocity(total_efficiency, t_m, specific_mass)
    v_L = 0
    if discharge_loss is not None and m_ion is not None:
        v_L = (2 * (charge / m_ion) * discharge_loss)**0.5

    def mass_fraction(c):
        """Optimization objective function.

        Payload + structure mass fraction.

        Reference: Lozano equation 3-13

        Arguments:
            c : effective exhaust velocity, I_sp * g.
        """
        return np.exp(-dv / c) - (c**2 + v_L**2) / (v_ch**2) * (1 - np.exp(-dv / c))

    # Scale factor to avoid numerical problems with minimize.
    scale_factor = 10e3

    # Find the c which maximizes the mass fraction.
    result = minimize(lambda c: -mass_fraction(c * scale_factor), 1.)
    c = result.x[0] * scale_factor


    return c / g