Commit b684512a authored by Francesco Montanari's avatar Francesco Montanari

Merge branch 'devel'

* devel:
  Complete age and lookback time
  Extend cosmic calculator
  Add age of the Universe
  Add lookback time
parents a0d90d23 bc9b6ea4
......@@ -93,6 +93,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# List all interactive commands:
# (apropos-command "cosmo-")
- cosmo-age :: Display age of the Universe in mini-buffer.
- cosmo-angular-diameter-distance :: Display angular diameter
distance in mini-buffer.
......@@ -126,6 +128,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
- cosmo-hubble-time :: Display Hubble distance 1/H0 [Gyr] in
mini-buffer.
- cosmo-lookback-time :: Display lookback time in mini-buffer.
- cosmo-los-comoving-distance :: Display line-of-sight comoving
distance in mini-buffer.
......
......@@ -237,7 +237,7 @@ Optional argument JMAX maximum number of steps."
(/ 3.0e5 H0)))
(defun cosmo-hubble-distance ()
"Display Hubble distance c/H0 [Mpc] in mini-buffer."
"Display Hubble distance c/H0 in mini-buffer."
(interactive)
(message (format "%s Mpc" (cosmo-get-hubble-distance))))
......@@ -247,7 +247,7 @@ Optional argument JMAX maximum number of steps."
(/ 9.78e2 H0)))
(defun cosmo-hubble-time ()
"Display Hubble distance 1/H0 [yr] in mini-buffer."
"Display Hubble time 1/H0 in mini-buffer."
(interactive)
(message (format "%s Gyr" (cosmo-get-hubble-time))))
......@@ -358,6 +358,43 @@ Argument OCURVATURE curvature density parameter."
(message (format "%s Mpc^3"
(cosmo-get-comoving-volume z)))))
(defun cosmo--age-integrand (redshift)
"Universe age integrand at a given REDSHIFT."
(/ (cosmo-inv-efunc redshift) (1+ redshift)))
(defun cosmo-get-lookback-time (redshift)
"Lookback time [Gyr] for Lambda-CDM at a given REDSHIFT."
(let ((tH (cosmo-get-hubble-time))
(int (cosmo-qsimp #'cosmo--age-integrand 0.0 redshift
cosmo-int-prec cosmo-int-maxsteps)))
(* tH int)))
(defun cosmo-lookback-time ()
"Display lookback time in mini-buffer."
(interactive)
(let ((z (cosmo--read-param "redshift")))
(message (format "%s Gyr"
(cosmo-get-lookback-time z)))))
(defun cosmo-get-age (redshift)
;; This is much slower than other functions.
"Age of the Universe [Gyr] for Lambda-CDM at a given REDSHIFT.
This is approximated as the age since equality redshift."
(let* ((tH (cosmo-get-hubble-time))
(omatter (gethash "omatter" cosmo--params))
(H0 (gethash "H0 [Km/s/Mpc]" cosmo--params))
(zeq (* 2.5 1e4 omatter (expt (/ H0 100.0) 2.0)))
(int (cosmo-qsimp #'cosmo--age-integrand redshift zeq
cosmo-int-prec cosmo-int-maxsteps)))
(* tH int)))
(defun cosmo-age ()
"Display age of the Universe in mini-buffer."
(interactive)
(let ((z (cosmo--read-param "redshift")))
(message (format "%s Gyr"
(cosmo-get-age z)))))
;;; Handle output.
(defun cosmo--write-calc-header ()
......@@ -370,7 +407,8 @@ Argument OCURVATURE curvature density parameter."
(defun cosmo--write-calc (redshift H0 omatter olambda orel hubble
los-dist transverse-dist
luminosity-dist angular-dist
parallax-dist comoving-vol)
parallax-dist comoving-vol
lookback-time)
"Format and insert cosmological table in buffer.
Argument REDSHIFT redshift.
Argument H0 Hubble parameter today.
......@@ -383,7 +421,8 @@ Argument TRANSVERSE-DIST transverse comoving distance at given redshift.
Argument LUMINOSITY-DIST luminosity distance at given redshift.
Argument ANGULAR-DIST angular diameter distance at given redshift.
Argument PARALLAX-DIST parallax distance at given redshift.
Argument COMOVING-VOL comoving volume at given redshift."
Argument COMOVING-VOL comoving volume at given redshift.
Argument LOOKBACK-TIME lookback time at given redshift."
;; Input parameters.
(cosmo--write-calc-header)
......@@ -426,7 +465,9 @@ Argument COMOVING-VOL comoving volume at given redshift."
(format "- Parallax distance [Mpc]: %s\n"
parallax-dist)
(format "- Comoving volume [Mpc^3]: %s\n"
comoving-vol))
comoving-vol)
(format "- Lookback time [Gyr]: %s\n"
lookback-time))
nil)
(defun cosmo-calculator ()
......@@ -444,12 +485,14 @@ Argument COMOVING-VOL comoving volume at given redshift."
(luminosity-dist (cosmo-get-luminosity-distance redshift))
(angular-dist (cosmo-get-angular-diameter-distance redshift))
(parallax-dist (cosmo-get-parallax-distance redshift))
(comoving-vol (cosmo-get-comoving-volume redshift)))
(with-output-to-temp-buffer cosmo-buffer
(comoving-vol (cosmo-get-comoving-volume redshift))
(lookback-time (cosmo-get-lookback-time redshift)))
(with-output-to-temp-buffer cosmo-buffer
(pop-to-buffer cosmo-buffer)
(cosmo--write-calc redshift H0 omatter olambda orel hubble
los-dist transverse-dist luminosity-dist
angular-dist parallax-dist comoving-vol))))
angular-dist parallax-dist comoving-vol
lookback-time))))
(provide 'cosmo)
......
......@@ -52,6 +52,10 @@ def print_curves(reds, cosmo):
name='angular-diameter-distance [Mpc]')
sexp_print(reds, cosmo.comoving_volume(reds).value,
name='comoving-volume [Mpc^3]')
sexp_print(reds, cosmo.lookback_time(reds).value,
name='lookback-time [Gyr]')
sexp_print(reds, cosmo.age(reds).value,
name='age [Gyr]')
def print_open_cosmo():
......
......@@ -127,6 +127,14 @@ Argument OREL relativistic density parameter today."
(assert (cosmo-almost-eq
(cosmo-get-comoving-volume 1000.0) 1.00014515316e+13 3e-3)))
(defun cosmo-test-lookback-time ()
(assert (cosmo-almost-eq
(cosmo-get-lookback-time 1000.0) 13.3803575903 4e-3)))
(defun cosmo-test-age ()
(assert (cosmo-almost-eq
(cosmo-get-age 0.0) 13.3807781911 3e-3)))
(cosmo-test-efunc)
(cosmo-test-inv-efunc)
(cosmo-test-hubble)
......@@ -137,6 +145,8 @@ Argument OREL relativistic density parameter today."
(cosmo-test-luminosity-distance)
(cosmo-test-angular-diameter-distance)
(cosmo-test-comoving-volume)
(cosmo-test-lookback-time)
(cosmo-test-age)
;;; Close cosmology.
......@@ -157,8 +167,18 @@ Argument OREL relativistic density parameter today."
(assert (cosmo-almost-eq
(cosmo-get-comoving-volume 1000.0) 1.24288502093e+13 3e-3)))
(defun cosmo-test-lookback-time ()
(assert (cosmo-almost-eq
(cosmo-get-lookback-time 1000.0) 13.7206066124 4e-3)))
(defun cosmo-test-age ()
(assert (cosmo-almost-eq
(cosmo-get-age 0.0) 13.7210465251 3e-3)))
(cosmo-test-transverse-comoving-distance-close)
(cosmo-test-comoving-volume)
(cosmo-test-lookback-time)
(cosmo-test-age)
;;; Flat cosmology.
......@@ -178,9 +198,18 @@ Argument OREL relativistic density parameter today."
(assert (cosmo-almost-eq
(cosmo-get-comoving-volume 1000.0) 1.06780313213e+13 3e-3)))
(defun cosmo-test-lookback-time ()
(assert (cosmo-almost-eq
(cosmo-get-lookback-time 1000.0) 13.4664471061 4e-3)))
(defun cosmo-test-age ()
(assert (cosmo-almost-eq
(cosmo-get-age 0.0) 13.466983947 3e-3)))
(cosmo-test-transverse-comoving-distance-flat)
(cosmo-test-comoving-volume)
(cosmo-test-lookback-time)
(cosmo-test-age)
;;; Benchmarks
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment