Libyan officials say clashes have broken out between armed groups in a western city, trapping residents in their homes and causing fires in the country’s second largest oil refinery.