Skip to content

Commit

Permalink
add min_l_logl_sampling to set_accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed May 24, 2023
1 parent 8201bb1 commit 53ab02f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion camb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__author__ = "Antony Lewis"
__contact__ = "antony at cosmologist dot info"
__url__ = "https://camb.readthedocs.io"
__version__ = "1.4.1"
__version__ = "1.4.2"

from . import baseconfig

Expand Down
Binary file modified camb/cambdll.dll
Binary file not shown.
8 changes: 7 additions & 1 deletion camb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class in model.py to add the new parameter in the corresponding location of the
("Log_lvalues", c_bool, "Use log spacing for sampling in L"),
("use_cl_spline_template", c_bool,
"When interpolating use a fiducial spectrum shape to define ratio to spline"),
("min_l_logl_sampling", c_int, "Minimum L to use log sampling for L"),
("SourceWindows", AllocatableObjectArray(SourceWindow)),
("CustomSources", CustomSources)
]
Expand All @@ -262,7 +263,8 @@ def validate(self):
"""
return self.f_Validate() != 0

def set_accuracy(self, AccuracyBoost=1., lSampleBoost=1., lAccuracyBoost=1., DoLateRadTruncation=True):
def set_accuracy(self, AccuracyBoost=1., lSampleBoost=1., lAccuracyBoost=1., DoLateRadTruncation=True,
min_l_logl_sampling=None):
"""
Set parameters determining overall calculation accuracy (large values may give big slow down).
For finer control you can set individual accuracy parameters by changing CAMBParams.Accuracy
Expand All @@ -273,12 +275,16 @@ def set_accuracy(self, AccuracyBoost=1., lSampleBoost=1., lAccuracyBoost=1., DoL
:param lSampleBoost: increase lSampleBoost to increase density of L sampling for CMB
:param lAccuracyBoost: increase lAccuracyBoost to increase the maximum L included in the Boltzmann hierarchies
:param DoLateRadTruncation: If True, use approximation to radiation perturbation evolution at late times
:param min_l_logl_sampling: at L>min_l_logl_sampling uses sparser log sampling for L interpolation;
increase above 5000 for better accuracy at L > 5000
:return: self
"""
self.Accuracy.lSampleBoost = lSampleBoost
self.Accuracy.AccuracyBoost = AccuracyBoost
self.Accuracy.lAccuracyBoost = lAccuracyBoost
self.DoLateRadTruncation = DoLateRadTruncation
if min_l_logl_sampling:
self.min_l_logl_sampling = min_l_logl_sampling
return self

def set_initial_power_function(self, P_scalar, P_tensor=None, kmin=1e-6, kmax=100., N_min=200, rtol=5e-5,
Expand Down
2 changes: 1 addition & 1 deletion fortran/config.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module config
use constants, only: const_twopi
implicit none

character(LEN=*), parameter :: version = '1.4.1'
character(LEN=*), parameter :: version = '1.4.2'

integer :: FeedbackLevel = 0 !if >0 print out useful information about the model

Expand Down
7 changes: 4 additions & 3 deletions fortran/model.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module model
!Reionization settings - used if Reion%Reionization=.true.
logical :: AccurateReionization = .true.
!Do you care about pecent level accuracy on EE signal from reionization?

!The following allow separate tweaking (all also affected by AccuracyBoost above)

real(dl) :: TimeStepBoost = 1._dl !sampling timesteps
Expand Down Expand Up @@ -182,8 +182,9 @@ module model
logical :: Do21cm = .false.
logical :: transfer_21cm_cl = .false.
logical :: Log_lvalues = .false. !useful for smooth results at very high L
logical :: use_cl_spline_template = .true.

logical :: use_cl_spline_template = .true.
integer :: min_l_logl_sampling = 5000 ! increase to use linear sampling for longer

Type(TSourceWindowHolder), allocatable :: SourceWindows(:)

Type(TCustomSourceParams) :: CustomSources
Expand Down
9 changes: 5 additions & 4 deletions fortran/results.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1329,14 +1329,15 @@ subroutine lSamples_init(this, State, lmin, max_l)
class(lSamples) :: this
class(CAMBdata), target :: State
integer, intent(IN) :: lmin,max_l
integer lind, lvar, step, top, bot
integer lind, lvar, step, top, bot, lmin_log
integer, allocatable :: ls(:)
real(dl) AScale

allocate(ls(max_l))
if (allocated(this%l)) deallocate(this%l)
this%lmin = lmin
this%use_spline_template = State%CP%use_cl_spline_template
lmin_log = State%CP%min_l_logl_sampling
associate(Accuracy => State%CP%Accuracy)
Ascale=State%scale/Accuracy%lSampleBoost

Expand Down Expand Up @@ -1457,14 +1458,14 @@ subroutine lSamples_init(this, State, lmin, max_l)
step=max(nint(50*Ascale),7)
end if
bot=ls(lind)+step
top=min(5000,max_l)
top=min(lmin_log,max_l)

do lvar = bot,top,step
lind=lind+1
ls(lind)=lvar
end do

if (max_l > 5000) then
if (max_l > lmin_log) then
!Should be pretty smooth or tiny out here
step=max(nint(400*Ascale),50)
lvar = ls(lind)
Expand All @@ -1488,7 +1489,7 @@ subroutine lSamples_init(this, State, lmin, max_l)
lind=lind+1
ls(lind)=max_l
end if
if (.not. State%flat .and. max_l<=5000) ls(lind-1)=int(max_l+ls(lind-2))/2
if (.not. State%flat .and. max_l<=lmin_log) ls(lind-1)=int(max_l+ls(lind-2))/2
!Not in flat case so interpolation table is the same when using lower l_max
end if
end if
Expand Down

0 comments on commit 53ab02f

Please sign in to comment.