Efficient calculations of magnetic fields of solenoids for simulations