Simulating Scalar Fields in Astrophysical and Cosmological Settings