Two-level modeling of lithium-ion batteries