diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index 486aed2ea..af10af236 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -39,10 +39,10 @@ module subroutine fraggle_generate_fragments(self, colliders, system, param, lfa associate(frag => self, nfrag => self%nbody, pl => system%pl) write(message,*) nfrag - call fraggle_io_log_one_message("Fraggle generating " // trim(adjustl(message)) // " fragments.") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle generating " // trim(adjustl(message)) // " fragments.") if (nfrag < NFRAG_MIN) then write(message,*) "Fraggle needs at least ",NFRAG_MIN," fragments, but only ",nfrag," were given." - call fraggle_io_log_one_message(message) + call io_log_one_message(FRAGGLE_LOG_OUT, message) lfailure = .true. return end if @@ -64,7 +64,7 @@ module subroutine fraggle_generate_fragments(self, colliders, system, param, lfa try = 1 do while (try < MAXTRY) write(message,*) try - call fraggle_io_log_one_message("Fraggle try " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle try " // trim(adjustl(message))) if (lfailure) then call frag%restructure(colliders, try, f_spin, r_max_start) call frag%reset() @@ -87,19 +87,19 @@ module subroutine fraggle_generate_fragments(self, colliders, system, param, lfa call fraggle_generate_spins(frag, colliders, f_spin, lfailure) if (lfailure) then - call fraggle_io_log_one_message("Fraggle failed to find spins") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle failed to find spins") cycle end if call fraggle_generate_tan_vel(frag, colliders, lfailure) if (lfailure) then - call fraggle_io_log_one_message("Fraggle failed to find tangential velocities") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle failed to find tangential velocities") cycle end if call fraggle_generate_rad_vel(frag, colliders, lfailure) if (lfailure) then - call fraggle_io_log_one_message("Fraggle failed to find radial velocities") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle failed to find radial velocities") cycle end if @@ -110,14 +110,14 @@ module subroutine fraggle_generate_fragments(self, colliders, system, param, lfa lfailure = ((abs(dEtot + frag%Qloss) > FRAGGLE_ETOL) .or. (dEtot > 0.0_DP)) if (lfailure) then write(message, *) dEtot, abs(dEtot + frag%Qloss) / FRAGGLE_ETOL - call fraggle_io_log_one_message("Fraggle failed due to high energy error: " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle failed due to high energy error: " // trim(adjustl(message))) cycle end if lfailure = ((abs(dLmag) / (.mag.frag%Ltot_before)) > FRAGGLE_LTOL) if (lfailure) then write(message,*) dLmag / (.mag.frag%Ltot_before(:)) - call fraggle_io_log_one_message("Fraggle failed due to high angular momentum error: " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle failed due to high angular momentum error: " // trim(adjustl(message))) cycle end if @@ -126,14 +126,14 @@ module subroutine fraggle_generate_fragments(self, colliders, system, param, lfa lfailure = any(fpe_flag) if (.not.lfailure) exit write(message,*) "Fraggle failed due to a floating point exception: ", fpe_flag - call fraggle_io_log_one_message(message) + call io_log_one_message(FRAGGLE_LOG_OUT, message) end do write(message,*) try if (lfailure) then - call fraggle_io_log_one_message("Fraggle fragment generation failed after " // trim(adjustl(message)) // " tries") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle fragment generation failed after " // trim(adjustl(message)) // " tries") else - call fraggle_io_log_one_message("Fraggle fragment generation succeeded after " // trim(adjustl(message)) // " tries") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fraggle fragment generation succeeded after " // trim(adjustl(message)) // " tries") call fraggle_io_log_generate(frag) end if @@ -254,16 +254,16 @@ subroutine fraggle_generate_spins(frag, colliders, f_spin, lfailure) lfailure = ((frag%ke_budget - frag%ke_spin - frag%ke_orbit) < 0.0_DP) if (lfailure) then - call fraggle_io_log_one_message(" ") - call fraggle_io_log_one_message("Spin failure diagnostics") + call io_log_one_message(FRAGGLE_LOG_OUT, " ") + call io_log_one_message(FRAGGLE_LOG_OUT, "Spin failure diagnostics") write(message, *) frag%ke_budget - call fraggle_io_log_one_message("ke_budget : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_budget : " // trim(adjustl(message))) write(message, *) frag%ke_spin - call fraggle_io_log_one_message("ke_spin : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_spin : " // trim(adjustl(message))) write(message, *) frag%ke_orbit - call fraggle_io_log_one_message("ke_orbit : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_orbit : " // trim(adjustl(message))) write(message, *) frag%ke_budget - frag%ke_spin - frag%ke_orbit - call fraggle_io_log_one_message("ke_remainder : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_remainder : " // trim(adjustl(message))) end if end associate @@ -355,20 +355,20 @@ subroutine fraggle_generate_tan_vel(frag, colliders, lfailure) ! If we are over the energy budget, flag this as a failure so we can try again lfailure = ((frag%ke_budget - frag%ke_spin - frag%ke_orbit) < 0.0_DP) if (lfailure) then - call fraggle_io_log_one_message(" ") - call fraggle_io_log_one_message("Tangential velocity failure diagnostics") + call io_log_one_message(FRAGGLE_LOG_OUT, " ") + call io_log_one_message(FRAGGLE_LOG_OUT, "Tangential velocity failure diagnostics") call frag%get_ang_mtm() L_frag_tot = frag%L_spin(:) + frag%L_orbit(:) write(message, *) .mag.(frag%L_budget(:) - L_frag_tot(:)) / (.mag.frag%Ltot_before(:)) - call fraggle_io_log_one_message("|L_remainder| : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "|L_remainder| : " // trim(adjustl(message))) write(message, *) frag%ke_budget - call fraggle_io_log_one_message("ke_budget : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_budget : " // trim(adjustl(message))) write(message, *) frag%ke_spin - call fraggle_io_log_one_message("ke_spin : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_spin : " // trim(adjustl(message))) write(message, *) frag%ke_orbit - call fraggle_io_log_one_message("ke_tangential : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_tangential : " // trim(adjustl(message))) write(message, *) frag%ke_budget - frag%ke_spin - frag%ke_orbit - call fraggle_io_log_one_message("ke_radial : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_radial : " // trim(adjustl(message))) end if end associate @@ -515,16 +515,16 @@ subroutine fraggle_generate_rad_vel(frag, colliders, lfailure) lfailure = abs((frag%ke_budget - (frag%ke_orbit + frag%ke_spin)) / frag%ke_budget) > FRAGGLE_ETOL if (lfailure) then - call fraggle_io_log_one_message(" ") - call fraggle_io_log_one_message("Radial velocity failure diagnostics") + call io_log_one_message(FRAGGLE_LOG_OUT, " ") + call io_log_one_message(FRAGGLE_LOG_OUT, "Radial velocity failure diagnostics") write(message, *) frag%ke_budget - call fraggle_io_log_one_message("ke_budget : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_budget : " // trim(adjustl(message))) write(message, *) frag%ke_spin - call fraggle_io_log_one_message("ke_spin : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_spin : " // trim(adjustl(message))) write(message, *) frag%ke_orbit - call fraggle_io_log_one_message("ke_orbit : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_orbit : " // trim(adjustl(message))) write(message, *) frag%ke_budget - (frag%ke_orbit + frag%ke_spin) - call fraggle_io_log_one_message("ke_remainder : " // trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, "ke_remainder : " // trim(adjustl(message))) end if end associate diff --git a/src/fraggle/fraggle_io.f90 b/src/fraggle/fraggle_io.f90 index dbd721216..9d7af73f1 100644 --- a/src/fraggle/fraggle_io.f90 +++ b/src/fraggle/fraggle_io.f90 @@ -61,24 +61,24 @@ module subroutine fraggle_io_log_generate(frag) end subroutine fraggle_io_log_generate - module subroutine fraggle_io_log_one_message(message) - !! author: David A. Minton - !! - !! Writes a single message to the fraggle log file - implicit none - ! Arguments - character(len=*), intent(in) :: message - ! Internals - character(STRMAX) :: errmsg - - open(unit=FRAGGLE_LOG_UNIT, file=FRAGGLE_LOG_OUT, status = 'OLD', position = 'APPEND', form = 'FORMATTED', err = 667, iomsg = errmsg) - write(FRAGGLE_LOG_UNIT, *) trim(adjustl(message)) - close(FRAGGLE_LOG_UNIT) - - return - 667 continue - write(*,*) "Error writing Fraggle message to log file: " // trim(adjustl(errmsg)) - end subroutine fraggle_io_log_one_message + ! module subroutine io_log_one_message(FRAGGLE_LOG_OUT, message) + ! !! author: David A. Minton + ! !! + ! !! Writes a single message to the fraggle log file + ! implicit none + ! ! Arguments + ! character(len=*), intent(in) :: message + ! ! Internals + ! character(STRMAX) :: errmsg + + ! open(unit=FRAGGLE_LOG_UNIT, file=FRAGGLE_LOG_OUT, status = 'OLD', position = 'APPEND', form = 'FORMATTED', err = 667, iomsg = errmsg) + ! write(FRAGGLE_LOG_UNIT, *) trim(adjustl(message)) + ! close(FRAGGLE_LOG_UNIT) + + ! return + ! 667 continue + ! write(*,*) "Error writing Fraggle message to log file: " // trim(adjustl(errmsg)) + ! end subroutine fraggle_io_log_one_message module subroutine fraggle_io_log_pl(pl, param) @@ -228,28 +228,28 @@ module subroutine fraggle_io_log_regime(colliders, frag) end subroutine fraggle_io_log_regime - module subroutine fraggle_io_log_start(param) - !! author: David A. Minton - !! - !! Checks to see if the Fraggle log file needs to be replaced if this is a new run, or appended if this is a restarted run - implicit none - ! Arguments - class(swiftest_parameters), intent(in) :: param - ! Internals - character(STRMAX) :: errmsg - logical :: fileExists - - inquire(file=FRAGGLE_LOG_OUT, exist=fileExists) - if (.not.param%lrestart .or. .not.fileExists) then - open(unit=FRAGGLE_LOG_UNIT, file=FRAGGLE_LOG_OUT, status="REPLACE", err = 667, iomsg = errmsg) - write(FRAGGLE_LOG_UNIT, *, err = 667, iomsg = errmsg) "Fraggle logfile" - end if - close(FRAGGLE_LOG_UNIT) - - return - - 667 continue - write(*,*) "Error writing Fraggle log file: " // trim(adjustl(errmsg)) - end subroutine fraggle_io_log_start + ! module subroutine fraggle_io_log_start(param) + ! !! author: David A. Minton + ! !! + ! !! Checks to see if the Fraggle log file needs to be replaced if this is a new run, or appended if this is a restarted run + ! implicit none + ! ! Arguments + ! class(swiftest_parameters), intent(in) :: param + ! ! Internals + ! character(STRMAX) :: errmsg + ! logical :: fileExists + + ! inquire(file=FRAGGLE_LOG_OUT, exist=fileExists) + ! if (.not.param%lrestart .or. .not.fileExists) then + ! open(unit=FRAGGLE_LOG_UNIT, file=FRAGGLE_LOG_OUT, status="REPLACE", err = 667, iomsg = errmsg) + ! write(FRAGGLE_LOG_UNIT, *, err = 667, iomsg = errmsg) "Fraggle logfile" + ! end if + ! close(FRAGGLE_LOG_UNIT) + + ! return + + ! 667 continue + ! write(*,*) "Error writing Fraggle log file: " // trim(adjustl(errmsg)) + ! end subroutine fraggle_io_log_start end submodule s_fraggle_io \ No newline at end of file diff --git a/src/fraggle/fraggle_regime.f90 b/src/fraggle/fraggle_regime.f90 index df9265ae7..f53888df5 100644 --- a/src/fraggle/fraggle_regime.f90 +++ b/src/fraggle/fraggle_regime.f90 @@ -182,7 +182,7 @@ subroutine fraggle_regime_collresolve(Mcb, m1, m2, rad1, rad2, xh1, xh2, vb1, vb Mlr = Mtot Mslr = 0.0_DP Qloss = 0.0_DP - call fraggle_io_log_one_message("Fragments would have mass below the minimum. Converting this collision into a merger.") + call io_log_one_message(FRAGGLE_LOG_OUT, "Fragments would have mass below the minimum. Converting this collision into a merger.") else if( Vimp < Vescp) then regime = COLLRESOLVE_REGIME_MERGE !perfect merging regime diff --git a/src/io/io.f90 b/src/io/io.f90 index ef3f682d2..b0f30d802 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -101,7 +101,6 @@ module subroutine io_dump_param(self, param_file_name) class(swiftest_parameters),intent(in) :: self !! Output collection of parameters character(len=*), intent(in) :: param_file_name !! Parameter input file name (i.e. param.in) ! Internals - integer(I4B), parameter :: LUN = 7 !! Unit number of output file character(STRMAX) :: errmsg !! Error message in UDIO procedure integer(I4B) :: ierr @@ -160,7 +159,6 @@ module subroutine io_dump_particle_info_base(self, param, idx) ! Internals logical, save :: lfirst = .true. - integer(I4B), parameter :: LUN = 22 integer(I4B) :: i character(STRMAX) :: errmsg @@ -228,7 +226,6 @@ module subroutine io_dump_base(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: ierr !! Error code - integer(I4B),parameter :: LUN = 7 !! Unit number for dump file integer(I4B) :: iu = LUN character(len=:), allocatable :: dump_file_name character(STRMAX) :: errmsg @@ -395,7 +392,6 @@ module function io_get_old_t_final_system(self, param) result(old_t_final) ! Internals class(swiftest_nbody_system), allocatable :: tmpsys class(swiftest_parameters), allocatable :: tmpparam - integer(I4B), parameter :: LUN = 76 integer(I4B) :: ierr, iu = LUN character(len=STRMAX) :: errmsg @@ -411,6 +407,7 @@ module function io_get_old_t_final_system(self, param) result(old_t_final) end do if (is_iostat_end(ierr)) then old_t_final = tmpparam%t + close(iu) return end if @@ -468,6 +465,53 @@ module function io_get_token(buffer, ifirst, ilast, ierr) result(token) return end function io_get_token + module subroutine io_log_one_message(file, message) + !! author: David A. Minton + !! + !! Writes a single message to a log file + implicit none + ! Arguments + character(len=*), intent(in) :: file !! Name of file to log + character(len=*), intent(in) :: message + ! Internals + character(STRMAX) :: errmsg + + open(unit=LUN, file=file, status = 'OLD', position = 'APPEND', form = 'FORMATTED', err = 667, iomsg = errmsg) + write(LUN, *) trim(adjustl(message)) + close(LUN) + + return + 667 continue + write(*,*) "Error writing message to log file: " // trim(adjustl(errmsg)) + end subroutine io_log_one_message + + + module subroutine io_log_start(param, file, header) + !! author: David A. Minton + !! + !! Checks to see if a log file needs to be created if this is a new run, or appended if this is a restarted run + implicit none + ! Arguments + class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters + character(len=*), intent(in) :: file !! Name of file to log + character(len=*), intent(in) :: header !! Header to print at top of log file + ! Internals + character(STRMAX) :: errmsg + logical :: fileExists + + inquire(file=file, exist=fileExists) + if (.not.param%lrestart .or. .not.fileExists) then + open(unit=LUN, file=file, status="REPLACE", err = 667, iomsg = errmsg) + write(LUN, *, err = 667, iomsg = errmsg) trim(adjustl(header)) + end if + close(LUN) + + return + + 667 continue + write(*,*) "Error writing log file: " // trim(adjustl(errmsg)) + end subroutine io_log_start + module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott @@ -766,12 +810,22 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) end associate select case(trim(adjustl(param%interaction_loops))) - case("ADAPTIVE", "FLAT", "TRIANGULAR") + case("ADAPTIVE") + param%ladaptive_interactions = .true. + param%lflatten_interactions = .true. + case("TRIANGULAR") + param%ladaptive_interactions = .false. + param%lflatten_interactions = .false. + case("FLAT") + param%ladaptive_interactions = .false. + param%lflatten_interactions = .true. case default write(*,*) "Unknown value for parameter INTERACTION_LOOPS: -> ",trim(adjustl(param%interaction_loops)) write(*,*) "Must be one of the following: TRIANGULAR, FLAT, or ADAPTIVE" write(*,*) "Using default value of ADAPTIVE" param%interaction_loops = "ADAPTIVE" + param%ladaptive_interactions = .true. + param%lflatten_interactions = .true. end select iostat = 0 @@ -1092,7 +1146,6 @@ module subroutine io_read_in_body(self, param) class(swiftest_body), intent(inout) :: self !! Swiftest particle object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B), parameter :: LUN = 7 !! Unit number of input file integer(I4B) :: iu = LUN integer(I4B) :: i, nbody logical :: is_ascii, is_pl @@ -1157,7 +1210,6 @@ module subroutine io_read_in_cb(self, param) class(swiftest_cb), intent(inout) :: self class(swiftest_parameters), intent(inout) :: param ! Internals - integer(I4B), parameter :: LUN = 7 !! Unit number of input file integer(I4B) :: iu = LUN character(len=STRMAX) :: errmsg integer(I4B) :: ierr, idold @@ -1225,7 +1277,6 @@ function io_read_encounter(t, id1, id2, Gmass1, Gmass2, radius1, radius2, & integer(I4B) :: ierr ! Internals logical , save :: lfirst = .true. - integer(I4B), parameter :: lun = 30 integer(I4B), save :: iu = lun if (lfirst) then @@ -1561,7 +1612,6 @@ module subroutine io_read_in_param(self, param_file_name) class(swiftest_parameters),intent(inout) :: self !! Current run configuration parameters character(len=*), intent(in) :: param_file_name !! Parameter input file name (i.e. param.in) ! Internals - integer(I4B), parameter :: LUN = 7 !! Unit number of input file integer(I4B) :: ierr = 0 !! Input error code character(STRMAX) :: errmsg !! Error message in UDIO procedure @@ -1619,8 +1669,7 @@ module subroutine io_read_particle_info_system(self, param) class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B), parameter :: LUN = 22 - integer(I4B) :: i, id, idx + integer(I4B) :: i, id, idx logical :: lmatch character(STRMAX) :: errmsg type(swiftest_particle_info), allocatable :: tmpinfo @@ -1715,7 +1764,6 @@ module subroutine io_write_discard(self, param) class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B), parameter :: LUN = 40 integer(I4B) :: i logical, save :: lfirst = .true. real(DP), dimension(:,:), allocatable :: vh @@ -1800,7 +1848,6 @@ module subroutine io_write_encounter(self, pl, encbody, param) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals logical , save :: lfirst = .true. - integer(I4B), parameter :: LUN = 30 integer(I4B) :: k, ierr character(len=STRMAX) :: errmsg diff --git a/src/kick/kick.f90 b/src/kick/kick.f90 index 0e90e73ee..2626c6d34 100644 --- a/src/kick/kick.f90 +++ b/src/kick/kick.f90 @@ -17,9 +17,7 @@ module subroutine kick_getacch_int_pl(self, param) type(interaction_timer), save :: itimer logical, save :: lfirst - if (lfirst) then - call itimer%reset(param) - end if + if (lfirst) call itimer%reset(param) if (param%lflatten_interactions) then call kick_getacch_int_all_flat_pl(self%nbody, self%nplpl, self%k_plpl, self%xh, self%Gmass, self%radius, self%ah) else diff --git a/src/modules/fraggle_classes.f90 b/src/modules/fraggle_classes.f90 index 63440383f..7fefe652b 100644 --- a/src/modules/fraggle_classes.f90 +++ b/src/modules/fraggle_classes.f90 @@ -113,12 +113,6 @@ module subroutine fraggle_io_log_generate(frag) class(fraggle_fragments), intent(in) :: frag end subroutine fraggle_io_log_generate - module subroutine fraggle_io_log_one_message(message) - implicit none - character(len=*), intent(in) :: message - character(STRMAX) :: errmsg - end subroutine fraggle_io_log_one_message - module subroutine fraggle_io_log_pl(pl, param) implicit none class(swiftest_pl), intent(in) :: pl !! Swiftest massive body object (only the new bodies generated in a collision) @@ -131,11 +125,6 @@ module subroutine fraggle_io_log_regime(colliders, frag) class(fraggle_fragments), intent(in) :: frag end subroutine fraggle_io_log_regime - module subroutine fraggle_io_log_start(param) - implicit none - class(swiftest_parameters), intent(in) :: param - end subroutine fraggle_io_log_start - !> The following interfaces are placeholders intended to satisfy the required abstract methods given by the parent class module subroutine fraggle_placeholder_accel(self, system, param, t, lbeg) use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 89c5ef238..46cf56369 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -123,6 +123,9 @@ module swiftest_classes real(DP) :: inv_c2 = -1.0_DP !! Inverse speed of light squared in the system units character(STRMAX) :: energy_out = "" !! Name of output energy and momentum report file character(NAMELEN) :: interaction_loops = "ADAPTIVE" !! Method used to compute interaction loops. Options are "TRIANGULAR", "FLAT", or "ADAPTIVE" + ! The following are used internally, and are not set by the user, but instead are determined by the input value of INTERACTION_LOOPS + logical :: lflatten_interactions = .false. !! Use the flattened upper triangular matrix for pl-pl interaction loops + logical :: ladaptive_interactions = .false. !! Adaptive interaction loop is turned on ! Logical flags to turn on or off various features of the code logical :: lrhill_present = .false. !! Hill radii are given as an input rather than calculated by the code (can be used to inflate close encounter regions manually) @@ -133,7 +136,6 @@ module swiftest_classes logical :: loblatecb = .false. !! Calculate acceleration from oblate central body (automatically turns true if nonzero J2 is input) logical :: lrotation = .false. !! Include rotation states of big bodies logical :: ltides = .false. !! Include tidal dissipation - logical :: lflatten_interactions = .false. !! Use the flattened upper triangular matrix for pl-pl interactions (turning this on improves the speed but uses more memory) ! Initial values to pass to the energy report subroutine (usually only used in the case of a restart, otherwise these will be updated with initial conditions values) real(DP) :: Eorbit_orig = 0.0_DP !! Initial orbital energy @@ -707,6 +709,19 @@ module function io_get_token(buffer, ifirst, ilast, ierr) result(token) character(len=:), allocatable :: token !! Returned token string end function io_get_token + module subroutine io_log_one_message(file, message) + implicit none + character(len=*), intent(in) :: file !! Name of file to log + character(len=*), intent(in) :: message + end subroutine io_log_one_message + + module subroutine io_log_start(param, file, header) + implicit none + class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters + character(len=*), intent(in) :: file !! Name of file to log + character(len=*), intent(in) :: header !! Header to print at top of log file + end subroutine io_log_start + module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) implicit none class(swiftest_parameters), intent(inout) :: self !! Collection of parameters diff --git a/src/modules/swiftest_globals.f90 b/src/modules/swiftest_globals.f90 index 1f9c6028c..b7fe1a0db 100644 --- a/src/modules/swiftest_globals.f90 +++ b/src/modules/swiftest_globals.f90 @@ -113,9 +113,9 @@ module swiftest_globals !> Standard file names integer(I4B), parameter :: NDUMPFILES = 2 - character(*), dimension(2), parameter :: DUMP_CB_FILE = ['dump_cb1.bin', 'dump_cb2.bin' ] - character(*), dimension(2), parameter :: DUMP_PL_FILE = ['dump_pl1.bin', 'dump_pl2.bin' ] - character(*), dimension(2), parameter :: DUMP_TP_FILE = ['dump_tp1.bin', 'dump_tp2.bin' ] + character(*), dimension(2), parameter :: DUMP_CB_FILE = ['dump_cb1.bin', 'dump_cb2.bin' ] + character(*), dimension(2), parameter :: DUMP_PL_FILE = ['dump_pl1.bin', 'dump_pl2.bin' ] + character(*), dimension(2), parameter :: DUMP_TP_FILE = ['dump_tp1.bin', 'dump_tp2.bin' ] character(*), dimension(2), parameter :: DUMP_PARAM_FILE = ['dump_param1.in', 'dump_param2.in'] !> Default file names that can be changed by the user in the parameters file @@ -126,6 +126,7 @@ module swiftest_globals integer(I4B), parameter :: BINUNIT = 20 !! File unit number for the binary output file character(*), parameter :: PARTICLE_OUTFILE = 'particle.dat' integer(I4B), parameter :: PARTICLEUNIT = 44 !! File unit number for the binary particle info output file + integer(I4B), parameter :: LUN = 42 !! File unit number for files that are opened and closed within a single subroutine call, and therefore should not collide !> Miscellaneous constants: integer(I4B), parameter :: NDIM = 3 !! Number of dimensions in our reality diff --git a/src/modules/walltime_classes.f90 b/src/modules/walltime_classes.f90 index 76600660d..c353328d8 100644 --- a/src/modules/walltime_classes.f90 +++ b/src/modules/walltime_classes.f90 @@ -27,11 +27,25 @@ module walltime_classes integer(I4B) :: step_counter integer(I8B) :: count_previous character(len=NAMELEN) :: current_style + logical :: lflatten_interaction_old contains - + procedure :: reset => walltime_interaction_reset !! Resets the interaction loop timer, and saves the current value of the array flatten parameter end type interaction_timer interface + module subroutine walltime_interaction_reset(self, param) + use swiftest_classes, only : swiftest_parameters + implicit none + class(interaction_timer), intent(inout) :: self !! Walltimer object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + end subroutine walltime_interaction_reset + + module subroutine walltime_interaction_io_log_start(param) + use swiftest_classes, only : swiftest_parameters + implicit none + class(swiftest_parameters), intent(in) :: param + end subroutine walltime_interaction_io_log_start + module subroutine walltime_finish(self, nsubsteps, message, param) use swiftest_classes, only : swiftest_parameters implicit none @@ -58,6 +72,23 @@ end subroutine walltime_start contains + module subroutine walltime_interaction_reset(self, param) + !! author: David A. Minton + !! + !! Resets the interaction loop timer, and saves the current value of the array flatten parameter + use swiftest_classes, only : swiftest_parameters + implicit none + ! Arguments + class(interaction_timer), intent(inout) :: self !! Walltimer object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + + self%lflatten_interaction_old = param%lflatten_interactions + call walltime_reset(self, param) + + return + end subroutine walltime_interaction_reset + + module subroutine walltime_finish(self, nsubsteps, message, param) !! author: David A. Minton !! diff --git a/src/rmvs/rmvs_io.f90 b/src/rmvs/rmvs_io.f90 index b85ce2202..51f077852 100644 --- a/src/rmvs/rmvs_io.f90 +++ b/src/rmvs/rmvs_io.f90 @@ -19,7 +19,6 @@ module subroutine rmvs_io_write_encounter(t, id1, id2, Gmass1, Gmass2, radius1, character(*), intent(in) :: enc_out ! Internals logical , save :: lfirst = .true. - integer(I4B), parameter :: LUN = 30 integer(I4B) :: ierr if (enc_out == "") return diff --git a/src/symba/symba_collision.f90 b/src/symba/symba_collision.f90 index 864eaa723..baa51485a 100644 --- a/src/symba/symba_collision.f90 +++ b/src/symba/symba_collision.f90 @@ -28,7 +28,7 @@ module function symba_collision_casedisruption(system, param, colliders, frag) message = "Supercatastrophic disruption between" end select call symba_collision_collider_message(system%pl, colliders%idx, message) - call fraggle_io_log_one_message(message) + call io_log_one_message(FRAGGLE_LOG_OUT, message) ! Collisional fragments will be uniformly distributed around the pre-impact barycenter call frag%set_mass_dist(colliders, param) @@ -37,7 +37,7 @@ module function symba_collision_casedisruption(system, param, colliders, frag) call frag%generate_fragments(colliders, system, param, lfailure) if (lfailure) then - call fraggle_io_log_one_message("No fragment solution found, so treat as a pure hit-and-run") + call io_log_one_message(FRAGGLE_LOG_OUT, "No fragment solution found, so treat as a pure hit-and-run") status = ACTIVE nfrag = 0 select type(pl => system%pl) @@ -50,7 +50,7 @@ module function symba_collision_casedisruption(system, param, colliders, frag) ! Populate the list of new bodies nfrag = frag%nbody write(message, *) nfrag - call fraggle_io_log_one_message("Generating " // trim(adjustl(message)) // " fragments") + call io_log_one_message(FRAGGLE_LOG_OUT, "Generating " // trim(adjustl(message)) // " fragments") select case(frag%regime) case(COLLRESOLVE_REGIME_DISRUPTION) status = DISRUPTION @@ -87,7 +87,7 @@ module function symba_collision_casehitandrun(system, param, colliders, frag) r message = "Hit and run between" call symba_collision_collider_message(system%pl, colliders%idx, message) - call fraggle_io_log_one_message(trim(adjustl(message))) + call io_log_one_message(FRAGGLE_LOG_OUT, trim(adjustl(message))) if (colliders%mass(1) > colliders%mass(2)) then jtarg = 1 @@ -98,7 +98,7 @@ module function symba_collision_casehitandrun(system, param, colliders, frag) r end if if (frag%mass_dist(2) > 0.9_DP * colliders%mass(jproj)) then ! Pure hit and run, so we'll just keep the two bodies untouched - call fraggle_io_log_one_message("Pure hit and run. No new fragments generated.") + call io_log_one_message(FRAGGLE_LOG_OUT, "Pure hit and run. No new fragments generated.") nfrag = 0 lpure = .true. else ! Imperfect hit and run, so we'll keep the largest body and destroy the other @@ -109,12 +109,12 @@ module function symba_collision_casehitandrun(system, param, colliders, frag) r call frag%generate_fragments(colliders, system, param, lpure) if (lpure) then - call fraggle_io_log_one_message("Should have been a pure hit and run instead") + call io_log_one_message(FRAGGLE_LOG_OUT, "Should have been a pure hit and run instead") nfrag = 0 else nfrag = frag%nbody write(message, *) nfrag - call fraggle_io_log_one_message("Generating " // trim(adjustl(message)) // " fragments") + call io_log_one_message(FRAGGLE_LOG_OUT, "Generating " // trim(adjustl(message)) // " fragments") end if end if if (lpure) then ! Reset these bodies back to being active so that nothing further is done to them @@ -164,7 +164,7 @@ module function symba_collision_casemerge(system, param, colliders, frag) resul message = "Merging" call symba_collision_collider_message(system%pl, colliders%idx, message) - call fraggle_io_log_one_message(message) + call io_log_one_message(FRAGGLE_LOG_OUT, message) select type(pl => system%pl) class is (symba_pl) @@ -358,7 +358,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec write(message, *) "Particle " // trim(adjustl(tp%info(j)%name)) // " (" // trim(adjustl(idstrj)) // ")" & // " collided with massive body " // trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstri)) // ")" & // " at t = " // trim(adjustl(timestr)) - call fraggle_io_log_one_message(message) + call io_log_one_message(FRAGGLE_LOG_OUT, message) end if end if end do @@ -984,10 +984,10 @@ module subroutine symba_collision_resolve_plplenc(self, system, param, t, dt, ir do write(timestr,*) t - call fraggle_io_log_one_message("") - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message("Collision between massive bodies detected at time t = " // trim(adjustl(timestr))) - call fraggle_io_log_one_message("***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, "") + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, "Collision between massive bodies detected at time t = " // trim(adjustl(timestr))) + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") allocate(tmp_param, source=param) tmp_param%t = t if (param%lfragmentation) then diff --git a/src/symba/symba_discard.f90 b/src/symba/symba_discard.f90 index 704d11f85..592b146b8 100644 --- a/src/symba/symba_discard.f90 +++ b/src/symba/symba_discard.f90 @@ -37,11 +37,11 @@ subroutine symba_discard_cb_pl(pl, system, param) write(idstr, *) pl%id(i) write(timestr, *) param%t write(message, *) trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstr)) // ")" // " too far from the central body at t = " // trim(adjustl(timestr)) - call fraggle_io_log_one_message("") - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message(message) - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message("") + call io_log_one_message(FRAGGLE_LOG_OUT, "") + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, message) + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, "") call pl%info(i)%set_value(status="DISCARDED_RMAX", discard_time=param%t, discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i)) else if ((param%rmin >= 0.0_DP) .and. (rh2 < rmin2)) then pl%ldiscard(i) = .true. @@ -50,11 +50,11 @@ subroutine symba_discard_cb_pl(pl, system, param) write(idstr, *) pl%id(i) write(timestr, *) param%t write(message, *) trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstr)) // ")" // " too close to the central body at t = " // trim(adjustl(timestr)) - call fraggle_io_log_one_message("") - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message(message) - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message("") + call io_log_one_message(FRAGGLE_LOG_OUT, "") + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, message) + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, "") call pl%info(i)%set_value(status="DISCARDED_RMIN", discard_time=param%t, discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), discard_body_id=cb%id) else if (param%rmaxu >= 0.0_DP) then rb2 = dot_product(pl%xb(:,i), pl%xb(:,i)) @@ -67,11 +67,11 @@ subroutine symba_discard_cb_pl(pl, system, param) write(idstr, *) pl%id(i) write(timestr, *) param%t write(message, *) trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstr)) // ")" // " is unbound and too far from barycenter at t = " // trim(adjustl(timestr)) - call fraggle_io_log_one_message("") - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message(message) - call fraggle_io_log_one_message("***********************************************************************************************************************") - call fraggle_io_log_one_message("") + call io_log_one_message(FRAGGLE_LOG_OUT, "") + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, message) + call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************************************************************************") + call io_log_one_message(FRAGGLE_LOG_OUT, "") call pl%info(i)%set_value(status="DISCARDED_RMAXU", discard_time=param%t, discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i)) end if end if diff --git a/src/symba/symba_io.f90 b/src/symba/symba_io.f90 index 2e5e87941..3f481d9b4 100644 --- a/src/symba/symba_io.f90 +++ b/src/symba/symba_io.f90 @@ -96,7 +96,7 @@ module subroutine symba_io_param_reader(self, unit, iotype, v_list, iostat, ioms end if ! All reporting of collision information in SyMBA (including mergers) is now recorded in the Fraggle logfile - call fraggle_io_log_start(param) + call io_log_start(param, FRAGGLE_LOG_OUT, "Fraggle logfile") ! Call the base method (which also prints the contents to screen) call io_param_reader(param, unit, iotype, v_list, iostat, iomsg) @@ -155,7 +155,6 @@ module subroutine symba_io_write_discard(self, param) class(symba_nbody_system), intent(inout) :: self !! SyMBA nbody system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I4B), parameter :: LUN = 40 integer(I4B) :: iadd, isub, j, nsub, nadd logical, save :: lfirst = .true. real(DP), dimension(:,:), allocatable :: vh