if max=="soft": //use softmax function (makes it differentiable)
min_mass=np.minimum(energy_mass, power_mass)
mass=mass+np.log(1.+np.exp(min_mass-mass)) //write it this way to prevent overflow
battery.mass_properties.mass=mass
battery.max_energy=battery.specific_energy*mass
After Change
power_mass=power/battery.specific_power
mass=np.maximum(energy_mass, power_mass)
if max=="soft": //use softmax function (makes it differentiable)
scaling=10.**(np.floor(np.log10(mass))-1) //make it so the exponentials are taking ~10 (closer numerically, while still differentiable)
mass=scaling*np.log(np.exp(energy_mass/scaling)+np.exp(power_mass/scaling)) //write it this way to prevent overflow
battery.mass_properties.mass=mass
battery.max_energy=battery.specific_energy*mass