From 000489a1247fb5e1c14ab1477ef413e35dfa35dc Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 18 Nov 2022 18:42:15 -0500 Subject: [PATCH] Added progress bar! --- examples/Basic_Simulation/.swiftest/param.in | 37 + .../Basic_Simulation/initial_conditions.ipynb | 3006 ++++++++++++++++- python/swiftest/swiftest/simulation_class.py | 7 +- src/io/io.f90 | 72 + src/main/swiftest_driver.f90 | 19 +- src/modules/swiftest_classes.f90 | 27 + 6 files changed, 3142 insertions(+), 26 deletions(-) create mode 100644 examples/Basic_Simulation/.swiftest/param.in diff --git a/examples/Basic_Simulation/.swiftest/param.in b/examples/Basic_Simulation/.swiftest/param.in new file mode 100644 index 000000000..0ee870562 --- /dev/null +++ b/examples/Basic_Simulation/.swiftest/param.in @@ -0,0 +1,37 @@ +! VERSION Swiftest input file +T0 0.0 +TSTART 0.0 +TSTOP 10.0 +DT 0.005 +ISTEP_OUT 200 +ISTEP_DUMP 200 +NC_IN init_cond.nc +IN_TYPE NETCDF_DOUBLE +IN_FORM EL +BIN_OUT bin.nc +OUT_FORM XVEL +OUT_TYPE NETCDF_DOUBLE +OUT_STAT REPLACE +CHK_QMIN 0.004650467260962157 +CHK_RMIN 0.004650467260962157 +CHK_RMAX 10000.0 +CHK_EJECT 10000.0 +CHK_QMIN_COORD HELIO +CHK_QMIN_RANGE 0.004650467260962157 10000.0 +MU2KG 1.988409870698051e+30 +TU2S 31557600.0 +DU2M 149597870700.0 +GMTINY 9.869231602224408e-07 +RESTART NO +CHK_CLOSE YES +GR YES +FRAGMENTATION YES +ROTATION YES +ENERGY NO +EXTRA_FORCE NO +BIG_DISCARD NO +RHILL_PRESENT NO +INTERACTION_LOOPS TRIANGULAR +ENCOUNTER_CHECK TRIANGULAR +TIDES NO +MIN_GMFRAG 9.869231602224408e-10 diff --git a/examples/Basic_Simulation/initial_conditions.ipynb b/examples/Basic_Simulation/initial_conditions.ipynb index cef068fa0..384c55c1d 100644 --- a/examples/Basic_Simulation/initial_conditions.ipynb +++ b/examples/Basic_Simulation/initial_conditions.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "2c4f59ea-1251-49f6-af1e-5695d7e25500", "metadata": {}, "outputs": [], @@ -14,10 +14,100 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "6054c7ab-c748-4b39-9fee-d8b27326f497", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "codename Swiftest\n", + "integrator symba\n", + "param_file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/.swiftest/param.in\n", + "driver_executable /home/daminton/git_debug/swiftest/bin/swiftest_driver\n", + "gmtiny 9.869231602224408e-07 AU^3 / y^2 \n", + "mtiny 2.5e-08 MSun\n", + "t0 0.0 y\n", + "tstart 0.0 y\n", + "tstop 10.0 y\n", + "dt 0.005 y\n", + "istep_out 200 \n", + "istep_dump 200 \n", + "tstep_out 1.0 y\n", + "init_cond_file_type NETCDF_DOUBLE\n", + "init_cond_format EL\n", + "init_cond_file_name init_cond.nc\n", + "output_file_type NETCDF_DOUBLE\n", + "output_file_name bin.nc\n", + "output_format XVEL\n", + "restart REPLACE\n", + "rmin 0.004650467260962157 AU\n", + "rmax 10000.0 AU\n", + "qmin_coord HELIO\n", + "MU: MSun 1.988409870698051e+30 kg / MSun\n", + "DU: AU 149597870700.0 m / AU\n", + "TU: y 31557600.0 s / y\n", + "close_encounter_check True\n", + "fragmentation True\n", + "minimum_fragment_gmass 9.869231602224408e-10 AU^3 / y^2 \n", + "minimum_fragment_mass 2.5e-11 MSun\n", + "rotation True\n", + "general_relativity True\n", + "compute_conservation_values False\n", + "rhill_present False\n", + "extra_force False\n", + "big_discard False\n", + "interaction_loops TRIANGULAR\n", + "encounter_check_loops TRIANGULAR\n", + "restart False\n", + "ephemeris_date 2027-04-30\n" + ] + }, + { + "data": { + "text/plain": [ + "{'GMTINY': 9.869231602224408e-07,\n", + " 'T0': 0.0,\n", + " 'TSTART': 0.0,\n", + " 'TSTOP': 10.0,\n", + " 'DT': 0.005,\n", + " 'ISTEP_OUT': 200,\n", + " 'ISTEP_DUMP': 200,\n", + " 'IN_TYPE': 'NETCDF_DOUBLE',\n", + " 'IN_FORM': 'EL',\n", + " 'NC_IN': 'init_cond.nc',\n", + " 'OUT_TYPE': 'NETCDF_DOUBLE',\n", + " 'BIN_OUT': 'bin.nc',\n", + " 'OUT_FORM': 'XVEL',\n", + " 'OUT_STAT': 'REPLACE',\n", + " 'CHK_RMIN': 0.004650467260962157,\n", + " 'CHK_RMAX': 10000.0,\n", + " 'CHK_QMIN_COORD': 'HELIO',\n", + " 'CHK_QMIN': 0.004650467260962157,\n", + " 'CHK_QMIN_RANGE': '0.004650467260962157 10000.0',\n", + " 'MU2KG': 1.988409870698051e+30,\n", + " 'DU2M': 149597870700.0,\n", + " 'TU2S': 31557600.0,\n", + " 'CHK_CLOSE': True,\n", + " 'FRAGMENTATION': True,\n", + " 'MIN_GMFRAG': 9.869231602224408e-10,\n", + " 'ROTATION': True,\n", + " 'GR': True,\n", + " 'ENERGY': False,\n", + " 'RHILL_PRESENT': False,\n", + " 'EXTRA_FORCE': False,\n", + " 'BIG_DISCARD': False,\n", + " 'INTERACTION_LOOPS': 'TRIANGULAR',\n", + " 'ENCOUNTER_CHECK': 'TRIANGULAR',\n", + " 'RESTART': False}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Initialize the simulation object as a variable\n", "sim = swiftest.Simulation(tstart=0.0, tstop=10.0, dt=0.005, tstep_out=1.0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)\n", @@ -26,10 +116,459 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "1c122676-bacb-447c-bc37-5ef8019be0d0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Creating the Sun as a central body\n", + "Fetching ephemerides data for Mercury from JPL/Horizons\n", + "Fetching ephemerides data for Venus from JPL/Horizons\n", + "Fetching ephemerides data for Earth from JPL/Horizons\n", + "Fetching ephemerides data for Mars from JPL/Horizons\n", + "Fetching ephemerides data for Jupiter from JPL/Horizons\n", + "Fetching ephemerides data for Saturn from JPL/Horizons\n", + "Fetching ephemerides data for Uranus from JPL/Horizons\n", + "Fetching ephemerides data for Neptune from JPL/Horizons\n", + "Fetching ephemerides data for Pluto from JPL/Horizons\n", + "Writing initial conditions to file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/.swiftest/init_cond.nc\n", + "Writing parameter inputs to file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/.swiftest/param.in\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset>\n",
+       "Dimensions:        (name: 10, time: 1)\n",
+       "Coordinates:\n",
+       "  * name           (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Neptune' 'Pluto'\n",
+       "  * time           (time) float64 0.0\n",
+       "Data variables: (12/20)\n",
+       "    particle_type  (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n",
+       "    id             (name) int64 0 1 2 3 4 5 6 7 8 9\n",
+       "    a              (time, name) float64 nan 0.3871 0.7233 ... 19.24 30.04 39.37\n",
+       "    e              (time, name) float64 nan 0.2056 0.006718 ... 0.008956 0.2487\n",
+       "    inc            (time, name) float64 nan 7.003 3.394 ... 0.773 1.771 17.17\n",
+       "    capom          (time, name) float64 nan 48.3 76.6 ... 74.01 131.8 110.3\n",
+       "    ...             ...\n",
+       "    roty           (time, name) float64 -38.76 -18.38 ... -2.177e+03 261.3\n",
+       "    rotz           (time, name) float64 82.25 34.36 8.703 ... 2.33e+03 -38.57\n",
+       "    j2rp2          (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n",
+       "    j4rp4          (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n",
+       "    ntp            (time) int64 0\n",
+       "    npl            (time) int64 9
" + ], + "text/plain": [ + "\n", + "Dimensions: (name: 10, time: 1)\n", + "Coordinates:\n", + " * name (name) \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset>\n",
+       "Dimensions:        (name: 5, time: 1)\n",
+       "Coordinates:\n",
+       "  * name           (name) <U14 'MassiveBody_01' ... 'MassiveBody_05'\n",
+       "  * time           (time) float64 0.0\n",
+       "Data variables: (12/18)\n",
+       "    particle_type  (name) <U14 'Massive Body' 'Massive Body' ... 'Massive Body'\n",
+       "    id             (name) int64 10 11 12 13 14\n",
+       "    a              (time, name) float64 1.311 0.4269 0.999 0.8757 0.6402\n",
+       "    e              (time, name) float64 0.2241 0.1367 0.1002 0.1051 0.07477\n",
+       "    inc            (time, name) float64 59.21 8.384 79.9 38.54 18.64\n",
+       "    capom          (time, name) float64 248.3 69.55 197.0 300.4 103.7\n",
+       "    ...             ...\n",
+       "    Ip3            (time, name) float64 0.4 0.4 0.4 0.4 0.4\n",
+       "    rotx           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
+       "    roty           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
+       "    rotz           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
+       "    ntp            (time) int64 0\n",
+       "    npl            (time) int64 4
" + ], + "text/plain": [ + "\n", + "Dimensions: (name: 5, time: 1)\n", + "Coordinates:\n", + " * name (name) \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset>\n",
+       "Dimensions:        (name: 10, time: 1)\n",
+       "Coordinates:\n",
+       "  * name           (name) <U15 'TestParticle_01' ... 'TestParticle_10'\n",
+       "  * time           (time) float64 0.0\n",
+       "Data variables:\n",
+       "    particle_type  (name) <U15 'Test Particle' ... 'Test Particle'\n",
+       "    id             (name) int64 15 16 17 18 19 20 21 22 23 24\n",
+       "    a              (time, name) float64 0.5963 0.7501 1.242 ... 0.6646 0.4335\n",
+       "    e              (time, name) float64 0.2692 0.1215 0.144 ... 0.08782 0.1085\n",
+       "    inc            (time, name) float64 31.01 21.79 71.4 ... 49.32 11.98 82.34\n",
+       "    capom          (time, name) float64 14.83 71.52 313.1 ... 55.01 264.6 27.41\n",
+       "    omega          (time, name) float64 263.9 53.24 270.9 ... 129.9 55.52 322.0\n",
+       "    capm           (time, name) float64 203.5 276.4 200.6 ... 296.5 199.3 11.76\n",
+       "    ntp            int64 10\n",
+       "    npl            int64 0
" + ], + "text/plain": [ + "\n", + "Dimensions: (name: 10, time: 1)\n", + "Coordinates:\n", + " * name (name) 4) self%spinner = 1 + select case(self%spinner) + case(1) + self%barstr(pos:pos) = "/" + case(2) + self%barstr(pos:pos) = "-" + case(3) + self%barstr(pos:pos) = "\" + case(4) + self%barstr(pos:pos) = "|" + end select + + write(*,fmt=self%fmt) char(13),self%barstr + + + return + end subroutine io_pbar_update + + + + module subroutine io_conservation_report(self, param, lterminal) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott !! diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 467403269..0eca02509 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -31,6 +31,7 @@ program swiftest_driver real(DP) :: old_t_final = 0.0_DP !! Output time at which writing should start, in order to prevent duplicate lines being written for restarts type(walltimer) :: integration_timer !! Object used for computing elapsed wall time real(DP) :: tfrac + type(progress_bar) :: pbar !! Object used to print out a progress bar character(*), parameter :: statusfmt = '("Time = ", ES12.5, "; fraction done = ", F6.3, ' // & '"; Number of active pl, tp = ", I5, ", ", I5)' character(*), parameter :: symbastatfmt = '("Time = ", ES12.5, "; fraction done = ", F6.3, ' // & @@ -88,6 +89,7 @@ program swiftest_driver !$ write(*,'(a,i3,/)') ' Number of threads = ', nthreads write(*, *) " *************** Main Loop *************** " if (param%lrestart .and. param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.) + call pbar%reset(nloops) do iloop = 1, nloops !> Step the system forward in time call integration_timer%start() @@ -100,6 +102,7 @@ program swiftest_driver call nbody_system%discard(param) !> If the loop counter is at the output cadence value, append the data file with a single frame + call pbar%update(iloop) if (istep_out > 0) then iout = iout - 1 if (iout == 0) then @@ -108,15 +111,15 @@ program swiftest_driver tfrac = (param%t - param%t0) / (param%tstop - param%t0) - select type(pl => nbody_system%pl) - class is (symba_pl) - write(*, symbastatfmt) param%t, tfrac, pl%nplm, pl%nbody, nbody_system%tp%nbody - class default - write(*, statusfmt) param%t, tfrac, pl%nbody, nbody_system%tp%nbody - end select + ! select type(pl => nbody_system%pl) + ! class is (symba_pl) + ! write(*, symbastatfmt) param%t, tfrac, pl%nplm, pl%nbody, nbody_system%tp%nbody + ! class default + ! write(*, statusfmt) param%t, tfrac, pl%nbody, nbody_system%tp%nbody + ! end select if (param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.) - call integration_timer%report(message="Integration steps:", nsubsteps=istep_out) - call integration_timer%reset() + !call integration_timer%report(message="Integration steps:", nsubsteps=istep_out) + !call integration_timer%reset() iout = istep_out end if diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 6c0ac2be3..49735a424 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -414,6 +414,21 @@ module swiftest_classes generic :: read_particle_info => read_particle_info_bin, read_particle_info_netcdf !! Genereric method call for reading in the particle information metadata end type swiftest_nbody_system + type :: progress_bar + !! author: David A. Minton + !! + !! Implements a class for a simple progress bar that can print on the screen. + integer(I4B) :: PBARSIZE = 80 !! Number of characters acros for a whole progress bar + integer(I8B) :: nloops !! The total number of loops that the progrees bar is executing + character(len=:), allocatable :: barstr !! The string that prints out as the progress bar + integer(I4B) :: spinner !! Position of the "spinner" that indicates that progress is being made + character(len=1) :: barchar = "=" !! The progress bar character + character(len=32) :: fmt !! The format string that is used to define the progress bar itself + contains + procedure :: reset => io_pbar_reset !! Resets the progress bar to the beginning + procedure :: update => io_pbar_update !! Updates the progress bar with new values and causes the "spinner" to flip. + end type progress_bar + abstract interface subroutine abstract_accel(self, system, param, t, lbeg) @@ -582,6 +597,18 @@ pure module subroutine gr_vh2pv_body(self, param) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters end subroutine gr_vh2pv_body + module subroutine io_pbar_reset(self, nloops) + implicit none + class(progress_bar),intent(inout) :: self + integer(I8B), intent(in) :: nloops + end subroutine io_pbar_reset + + module subroutine io_pbar_update(self,i) + implicit none + class(progress_bar), intent(inout) :: self + integer(I8B), intent(in) :: i + end subroutine io_pbar_update + module subroutine io_conservation_report(self, param, lterminal) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object