Model-based predictive diagnostics for primary and secondary batteries