39 #ifdef COSMICFISH_EFTCAMB
57 Type(cambparams) ,
intent(in) :: P
59 real(dl),
dimension(FP%fisher_RD%number_RD_redshifts),
intent(out) :: redrift
60 integer,
intent(out) :: err
70 real(dl),
parameter :: conv_time=3.15e7, conv_mpc=1/(3.09e19)
76 call cambparams_set(p)
79 #ifdef COSMICFISH_EFTCAMB
81 if (p%EFTflag /= 0)
then
82 call eftcamb_initialization(eftsuccess)
83 if (.not. eftsuccess)
then
84 write(*,*)
'EFTCAMB: unstable model'
91 deltat = fp%fisher_RD%obs_time*conv_time
96 do i=1, fp%fisher_RD%number_RD_redshifts
97 redrift(i) =(c*100)*(p%H0*conv_mpc)*deltat*(1.-(hofz(fp%fisher_RD%RD_redshift(i))/(p%H0*1.e+03/c))/(1+fp%fisher_RD%RD_redshift(i)))
113 Type(cambparams) ,
intent(in) :: P
115 real(dl),
dimension(FP%fisher_RD%number_RD_redshifts),
intent(out) :: RDsigma
116 integer,
intent(out) :: err
127 if (fp%fisher_RD%exptype.eq.1)
then
128 if ( fp%cosmicfish_feedback >= 1 )
then
129 write(*,
'(a)')
'**************************************************************'
130 write(*,
'(a)')
'Computing E-ELT errors:'
131 write(*,
'(a)')
'**************************************************************'
133 do i=1, fp%fisher_RD%number_RD_redshifts
134 if (fp%fisher_RD%RD_redshift(i).le.4)
then
139 rdsigma(i) = 1.35*(2370./fp%fisher_RD%signoise)*sqrt(30./fp%fisher_RD%RD_number(i))*(5./(1+fp%fisher_RD%RD_redshift(i)))**pow
141 else if (fp%fisher_RD%exptype.eq.2)
then
142 write(*,*)
'not implemented yet'
144 else if (fp%fisher_RD%exptype.eq.3)
then
145 write(*,*)
'not implemented yet'
148 write(*,*)
'invalid experiment choice'
152 if ( fp%cosmicfish_feedback >= 1 )
then
153 write(*,
'(a)')
'**************************************************************'
154 write(*,
'(a)')
'errors computed'
155 write(*,
'(a)')
'**************************************************************'
167 integer,
intent(in) :: mock_size
168 real(dl),
dimension(mock_size),
intent(in) :: RD_theory
169 real(dl),
dimension(mock_size),
intent(in) :: RD_error
170 character(len=*),
intent(in) :: filename
173 open(unit=42, file=filename, action=
"write", status=
"replace")
175 write(42,
'(a)')
"# redshift, Delta v [cm/s], sigma(Delta v) [cm/s] "
177 write(42,
'(5E15.5)') fp%fisher_RD%RD_redshift(i), rd_theory(i), rd_error(i)
191 subroutine rd_derivativecalc( P, FP, param_num, deltav_derivative, deltav_der_error, deltav_initial, initial_step, num_param, error_code)
194 Type(cambparams) ,
intent(in) :: P
197 integer ,
intent(in) :: param_num
198 integer ,
intent(in) :: num_param
200 real(dl),
dimension(:),
intent(in) :: deltav_initial
201 real(dl),
dimension(:),
intent(out) :: deltav_derivative
202 real(dl),
dimension(:),
intent(out) :: deltav_der_error
206 real(dl),
intent(in) :: initial_step
207 integer ,
intent(out) :: error_code
214 integer :: mock_RD_size
215 real(dl),
dimension(:),
allocatable :: rd_temp_1, rd_temp_2, errt
216 integer ,
dimension(:),
allocatable :: accept_mask
217 real(dl),
dimension(:,:,:),
allocatable :: a
218 real(dl),
dimension(num_param) :: param_vector, fiducial_param_vector, temp_param_vector
220 real(dl),
parameter :: con = 1.4_dl
221 real(dl),
parameter :: big = 1.d+30
222 real(dl),
parameter :: safe = 2._dl
223 integer ,
parameter :: ntab = 30
224 real(dl) :: con2 = con*con
225 integer :: i, j, k, l, m, side, err, AllocateStatus
227 real(dl) :: temp1, temp2, temp3
228 Type(cambparams) :: P_temp
231 real(dl) :: acceptance
232 real(dl),
dimension(:),
allocatable :: redshift, deltav
238 deltav_derivative = 0._dl
239 deltav_der_error = 0._dl
242 if ( initial_step == 0._dl )
then
243 stop
'RD_derivative initial stepsize is zero'
246 mock_rd_size = fp%fisher_RD%number_RD_redshifts
249 if ( fp%adaptivity )
then
260 allocate( rd_temp_1(mock_rd_size), &
261 & rd_temp_2(mock_rd_size), &
262 & stat = allocatestatus )
263 if (allocatestatus /= 0) stop
"RD_Magnitude_derivative: Allocation failed. Not enough memory"
264 allocate( a(1,1, mock_rd_size) , stat = allocatestatus )
265 if (allocatestatus /= 0) stop
"RD_derivative: Allocation failed. Not enough memory for the derivative array"
268 allocate( redshift(mock_rd_size), &
269 & deltav(mock_rd_size), &
270 & stat = allocatestatus )
273 redshift(:) = fp%fisher_RD%RD_redshift(:)
282 fiducial_param_vector = param_vector
283 temp_param_vector = param_vector
287 deltav_der_error = big
289 if ( fp%adaptivity ) accept_mask = 0
292 param_vector(param_num) = fiducial_param_vector(param_num) + hh
296 if ( err /= 0 ) side = 1
298 temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
304 if ( side == 1 )
then
306 deltav_der_error = 0.0_dl
307 deltav_derivative = 0.0_dl
309 else if ( side == 0 )
then
316 a(1,1,:) = (rd_temp_1(:) - rd_temp_2(:))/(2.0_dl*hh)
317 else if (side == 1)
then
318 a(1,1,:) = (rd_temp_2(:) - deltav_initial(:))/(-hh)
319 else if (side == 2)
then
320 a(1,1,:) = (rd_temp_1(:) - deltav_initial(:))/(hh)
324 if ( .not. fp%adaptivity )
then
325 deltav_derivative(:) = a(1,1,:)
326 deltav_der_error = 0.0_dl
327 deallocate( rd_temp_1, rd_temp_2, a )
335 if ( fp%cosmicfish_feedback >= 2 )
then
336 accepted = sum(accept_mask)
337 acceptance =
REAL(accepted)/
REAL(mock_rd_size)
338 print*,
'iteration:', i
339 print*,
' stepsize:', hh
340 print*,
' accepted elements', accepted,
'accepted ratio', acceptance
348 param_vector(param_num) = fiducial_param_vector(param_num) + hh
349 temp_param_vector(param_num) = fiducial_param_vector(param_num) - hh
355 deltav_der_error = 0.0_dl
356 deltav_derivative = 0.0_dl
364 deltav_der_error = 0.0_dl
365 deltav_derivative = 0.0_dl
369 a(1,i,:) = (rd_temp_1(:) - rd_temp_2(:))/(2.0_dl*hh)
370 else if (side==1)
then
371 param_vector(param_num) = fiducial_param_vector(param_num) - hh
376 deltav_der_error = 0.0_dl
377 deltav_derivative = 0.0_dl
381 a(1,i,:) = (rd_temp_1(:) - deltav_initial(:))/(-hh)
382 else if (side==2)
then
383 param_vector(param_num) = fiducial_param_vector(param_num) + hh
388 deltav_der_error = 0.0_dl
389 deltav_derivative = 0.0_dl
393 a(1,i,:) = (rd_temp_1(:) - deltav_initial(:))/(hh)
400 forall ( k = 1:mock_rd_size, accept_mask(k) == 0 )
402 a(j,i,k) = (a(j-1,i,k)*fac-a(j-1,i-1,k))/(fac-1._dl)
404 errt(k) = max( abs(a(j,i,k)-a(j-1,i,k)), &
405 & abs(a(j,i,k)-a(j-1,i-1,k)))
412 forall ( k = 1:mock_rd_size, &
413 & errt(k) .le. deltav_der_error(k) .and. accept_mask(k) == 0 )
415 deltav_der_error(k) = errt(k)
416 deltav_derivative(k) = a(j,i,k)
422 forall ( k = 1:mock_rd_size, &
423 & accept_mask(k) == 0 .and. &
424 & (a(i,i,k) - a(i-1,i-1,k)) .ge. safe*deltav_der_error(k) )
430 if ( sum(accept_mask) == mock_rd_size )
exit
435 if ( sum(accept_mask) /= mock_rd_size )
then
440 if ( fp%adaptivity )
then
456 subroutine fisher_rd(P, FP, num_param, Fisher_Matrix, outroot)
459 Type(cambparams) ,
intent(in) :: P
461 real(dl),
allocatable,
dimension(:) :: redrift,RDsigma
463 integer ,
intent(in) :: num_param
464 real(dl),
dimension(num_param,num_param),
intent(out) :: Fisher_Matrix
465 character(len=*),
intent(in),
optional :: outroot
467 real(dl) :: time_1, time_2
468 real(dl) :: initial_step, temp, temp1, temp2
469 integer :: err, AllocateStatus, ind, ind2
470 integer :: i, j, k, l
471 real(dl),
allocatable :: param_array(:)
472 real(dl),
dimension(:),
allocatable :: rd_fiducial, rd_derivative, rd_temp, rd_error
473 real(dl),
dimension(:,:),
allocatable :: rd_derivative_array
477 allocate( param_array(num_param) )
484 allocate(rd_fiducial(fp%fisher_RD%number_RD_redshifts), stat = allocatestatus)
485 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate rd_fiducial"
486 allocate(rd_temp(fp%fisher_RD%number_RD_redshifts), stat = allocatestatus)
487 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate rd_temp"
488 allocate(rd_derivative(fp%fisher_RD%number_RD_redshifts), stat = allocatestatus)
489 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate rd_derivative"
490 allocate(rd_error(fp%fisher_RD%number_RD_redshifts), stat = allocatestatus)
491 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate rd_derivative"
494 time_1 = omp_get_wtime()
497 time_2 = omp_get_wtime() - time_1
499 if (
present(outroot) )
call save_rd_mock_to_file(fp, fp%fisher_RD%number_RD_redshifts, rd_fiducial, rd_error, filename=trim(outroot)//
'fiducial.dat')
502 else if ( err == 4 )
then
503 write(*,*)
'Fiducial model unstable. Calculation cannot proceed.'
506 write(*,*)
'Error in computing the fiducial. Calculation cannot proceed.'
511 if ( fp%cosmicfish_feedback >= 1 )
then
512 write(*,
'(a)')
'**************************************************************'
513 write(*,
'(a,i10)')
'Some more feedback to be added '
514 write(*,
'(a,i10)')
'Number of parameters : ', num_param
515 write(*,
'(a,f10.3,a)')
'Time taken for RD calculation: ', time_2,
' (s)'
516 write(*,
'(a,i10)')
'Number of omp processes : ', omp_get_max_threads()
517 if ( fp%adaptivity )
then
518 write(*,
'(a,f10.3,a)')
'Estimated completion time : ', time_2*20._dl*num_param,
' (s)'
520 write(*,
'(a,f10.3,a)')
'Estimated completion time : ', time_2*2._dl*num_param,
' (s)'
522 write(*,
'(a)')
'**************************************************************'
526 if ( fp%cosmicfish_feedback >= 1 )
then
527 write(*,
'(a)')
'**************************************************************'
528 write(*,
'(a)')
'Computation of the delta v derivatives'
529 write(*,
'(a)')
'**************************************************************'
532 allocate(rd_derivative_array(num_param,fp%fisher_RD%number_RD_redshifts), stat = allocatestatus)
533 if (allocatestatus /= 0) stop
"Allocation failed. Not enough memory to allocate rd_derivative_array"
535 time_1 = omp_get_wtime()
536 do ind = 1, num_param
538 if ( fp%cosmicfish_feedback >= 1 )
then
539 write(*,
'(a,i5,a,E15.5)')
'Doing parameter number: ', ind,
' value: ', param_array(ind)
542 if ( param_array(ind) /= 0._dl )
then
543 initial_step = param_array(ind)*3.0_dl/100._dl
545 initial_step = 3.0_dl/100._dl
548 call rd_derivativecalc( p, fp, ind, rd_derivative, rd_temp, rd_fiducial, initial_step, num_param, err)
550 if (err /= 0) print*,
'WARNING: something went wrong with the delta v derivative of parameter:', ind
552 if (
present(outroot) .and. fp%cosmicfish_feedback >= 2 )
then
556 rd_derivative_array(ind,:) = rd_derivative(:)
559 time_2 = omp_get_wtime() - time_1
561 if ( fp%cosmicfish_feedback >= 1 )
then
563 write(*,
'(a,f8.3,a)')
'Time to compute all the derivatives:', time_2,
' (s)'
568 do ind = 1, num_param
569 do ind2 = 1, num_param
573 do i = 1, fp%fisher_RD%number_RD_redshifts
574 temp = (1./rd_error(i)**2.)*rd_derivative_array(ind,i)*rd_derivative_array(ind2,i)
578 fisher_matrix(ind, ind2) = temp2
582 time_2 = omp_get_wtime() - time_1
584 if ( fp%cosmicfish_feedback >= 1 )
then
585 write(*,
'(a,f8.3,a)')
'Time to compute the Fisher matrix:', time_2,
' (s)'
subroutine, public rd_error_calc(P, FP, RDsigma, err)
subroutine, public rd_theo_calc(P, FP, redrift, err)
This subroutine returns the theoretical prediction of redshift drift given the input cosmological par...
subroutine, public params_array_to_camb_param(P, FP, num_param, params_array)
This subroutine updates the values of the parameters P and FP based on the values contained in the pa...
subroutine, public fisher_rd(P, FP, num_param, Fisher_Matrix, outroot)
This subroutine computes the Fisher matrix for redshift drift.
subroutine, public camb_params_to_params_array(P, FP, num_param, params_array)
This subroutine updates the values of the parameters array based on the values of P and FP...
This module contains the definitions of derived data types used to store the informations about the f...
This module contains the subroutine and functions to manipulate and modify matrices.
This module contains the interface layer between CosmicFish and CAMB.
This module contains several general purpose utilities.
subroutine, public save_rd_mock_to_file(FP, mock_size, RD_theory, RD_error, filename)
This subroutine outputs to file a SN covariance.
This module contains the code to compute the noise for CMB lensing.
character(10) function, public integer_to_string(number)
This function converts an integer to a string. Usefull for numbered files output. ...
This module contains the code that computes the Fisher matrix for Redshift Drift. ...
subroutine, public rd_derivativecalc(P, FP, param_num, deltav_derivative, deltav_der_error, deltav_initial, initial_step, num_param, error_code)
This subroutine computes the derivative of the observed redshift drift signal. The calculation is car...
This derived data type contains all the informations that the cosmicfish code needs to run...