Skip to content

Commit

Permalink
Add restartability to random sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
rjfarmer committed Mar 13, 2023
1 parent 0edcfa4 commit 3d48602
Show file tree
Hide file tree
Showing 19 changed files with 1,114 additions and 324 deletions.
5 changes: 5 additions & 0 deletions defaults/random.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@

! Force a fle sync every this many steps if this is > 0
sync_freq = -1

! Whether the code should be restartable
! If true and bbq detects the output files then we will append new rows to the output
! instead of creating new files
restartable = .false.
3 changes: 2 additions & 1 deletion src/ctrls.f90
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ subroutine load_random_inputs(inlist, options, ierr)
log_rho_min, log_rho_max, log_xa_min, log_xa_max, &
neut_prot_limit_frac, &
output_starting_filename, output_ending_filename,&
num_samples, seed, sync_freq
num_samples, seed, sync_freq, restartable


include '../defaults/random.defaults'
Expand All @@ -151,6 +151,7 @@ subroutine load_random_inputs(inlist, options, ierr)
options% num_samples = num_samples
options% seed = seed
options% sync_freq = sync_freq
options% restartable = restartable

end subroutine load_random_inputs

Expand Down
1 change: 1 addition & 0 deletions src/lib_hydrostatic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ subroutine run_hydrostatic(bbq_in)

do j=1,num_lines
in(j)% xa = out% xa
! write(*,*) in(j)% xa
call do_hydrostatic_burn(in(j), out, bbq_in, total_time, fout, ierr )
if(ierr/=0) return
end do
Expand Down
54 changes: 35 additions & 19 deletions src/lib_random.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ subroutine run_random(bbq_in)

real(dp) :: r,sum
integer :: total, ierr, n, species, j, fin, i
integer :: seed_val, fout
integer :: seed_val, fout, fseed, iostat
logical :: exists

call load_random_inputs(bbq_in% inlist, random_in, ierr)

Expand All @@ -30,21 +31,32 @@ subroutine run_random(bbq_in)
call get_seed_for_random(seed_val)
end if

! Burn in random number generator
do i=1,10
r = get_dp_uniform_01(seed_val)
end do
total = 0

if(random_in% restartable) then
inquire(file=random_in% output_starting_filename,exist=exists)
if(exists) then
! Count lines to adjust total
open(newunit=fin,file=random_in% output_starting_filename,status='old', action='read')
do
read(fin,*,iostat=iostat)
total=total+1
if(IS_IOSTAT_END(iostat)) exit
end do
close(fin)
total=total-2
end if
end if


call random_setup(bbq_in, random_in)

total = 0
species = bbq_in% state% species
allocate(in% xa(species))

open(newunit=fin,file=random_in% output_starting_filename,status='old', position="append", action="write")
open(newunit=fout,file=random_in% output_ending_filename,status='old', position="append", action="write")


do
if(random_in% num_samples>0 .and. total>= random_in% num_samples) exit
total = total+1
Expand Down Expand Up @@ -88,7 +100,6 @@ subroutine run_random(bbq_in)

end if
end if

end do

end subroutine run_random
Expand All @@ -106,21 +117,26 @@ subroutine random_setup(bbq_in, random_in)
type(random_t) :: random_in
integer :: fin, fout
integer :: fisos, species
logical :: exists

open(newunit=fin,file=random_in% output_starting_filename,status='replace',action='write')
open(newunit=fout,file=random_in% output_ending_filename,status='replace',action='write')
inquire(file=random_in% output_starting_filename,exist=exists)

species = bbq_in% state% species
if(.not. exists .or. .not. random_in% restartable) then
open(newunit=fin,file=random_in% output_starting_filename,status='replace',action='write')
open(newunit=fout,file=random_in% output_ending_filename,status='replace',action='write')

species = bbq_in% state% species

!Write header
write(fout,'(A)',advance='no') '# id eps_nuc eps_neu '
call write_iso_names(bbq_in, fout)
close(fout)
!Write header
write(fout,'(A)',advance='no') '# id eps_nuc eps_neu '
call write_iso_names(bbq_in, fout)
close(fout)

!Write header
write(fin,'(A)',advance='no') '# id dt logt logrho '
call write_iso_names(bbq_in, fin)
close(fin)
!Write header
write(fin,'(A)',advance='no') '# id dt logt logrho '
call write_iso_names(bbq_in, fin)
close(fin)
end if


end subroutine random_setup
Expand Down
1 change: 1 addition & 0 deletions src/private/random.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ real(dp) :: log_xa_min, log_xa_max
real(dp) :: neut_prot_limit_frac
character(len=strlen) :: output_starting_filename,output_ending_filename
integer :: num_samples, seed, sync_freq
logical :: restartable
Loading

0 comments on commit 3d48602

Please sign in to comment.