From e0dcf9ba8c286604e93a34b95cb28e7aba3be5e3 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:01:20 -0400 Subject: [PATCH 01/77] Converted CMAKE_INSTALL_PREFIX to be a cache variable so that it gets set properly via flags --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44cbb743e..6451c20da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,8 +79,9 @@ SET(PY "${CMAKE_SOURCE_DIR}/swiftest") IF(WIN32) SET(CMAKE_INSTALL_PREFIX "C:\\Program Files\\swiftest") FILE(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX) + SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path for install") ELSE() - SET(CMAKE_INSTALL_PREFIX /usr/local) + SET(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Path for install") ENDIF(WIN32) # Make sure paths are correct for Unix or Windows style From 8adb5a2fcc7bd1eda8a329cb4fb7dc73523fa2a6 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:35:40 -0400 Subject: [PATCH 02/77] Made a number of formatting changes to better conform to standard line lengths. Also now include the version number in the log output --- pyproject.toml | 2 +- src/globals/globals_module.f90 | 2 +- src/swiftest/swiftest_io.f90 | 916 ++++++++++++++++++++++----------- version.txt | 2 +- 4 files changed, 616 insertions(+), 306 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3e59ce1c6..cf00e16ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "swiftest" -version = "2023.9.3" +version = "2023.9.4" authors=[ {name = 'David A. Minton', email='daminton@purdue.edu'}, {name = 'Carlisle Wishard'}, diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index d826bbb1c..93ed3ac1e 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -48,7 +48,7 @@ module globals integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper !! conversion - offset between upper and lower - character(*), parameter :: VERSION = "2023.9.3" !! Swiftest version + character(*), parameter :: VERSION = "2023.9.4" !! Swiftest version !> Symbolic name for integrator types character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR" diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 9a8095116..56fa50d7f 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -22,14 +22,16 @@ module subroutine swiftest_io_compact_output(self, param, timer) interface fmt !! author: David Minton !! - !! Formats a pair of variables and corresponding values for the compact display output. Generic interface for different variable types to format. + !! Formats a pair of variables and corresponding values for the compact display output. Generic interface for different + !! variable types to format. procedure :: fmt_I4B, fmt_I8B, fmt_DP end interface ! Arguments class(swiftest_nbody_system), intent(in) :: self !! Swiftest nbody system object class(swiftest_parameters), intent(in) :: param !! Input colleciton of user-defined parameters - class(*), intent(in) :: timer !! Object used for computing elapsed wall time (must be unlimited polymorphic because the walltimer module requires base) + class(*), intent(in) :: timer !! Object used for computing elapsed wall time (must be unlimited + !! polymorphic because the walltimer module requires base) ! Internals character(len=:), allocatable :: formatted_output @@ -41,17 +43,20 @@ module subroutine swiftest_io_compact_output(self, param, timer) formatted_output = formatted_output // fmt("NPLM",pl%nplm) end select if (param%lenergy) then - formatted_output = formatted_output // fmt("LTOTERR",self%L_total_error) // fmt("ETOTERR",self%te_error) // fmt("MTOTERR",self%Mtot_error) & - // fmt("KEOERR",self%ke_orbit_error) // fmt("PEERR",self%pe_error) // fmt("EORBERR",self%E_orbit_error) & - // fmt("EUNTRERR",self%E_untracked_error) // fmt("LESCERR",self%L_escape_error) // fmt("MESCERR",self%Mescape_error) + formatted_output = formatted_output // fmt("LTOTERR",self%L_total_error) // fmt("ETOTERR",self%te_error) & + // fmt("MTOTERR",self%Mtot_error) // fmt("KEOERR",self%ke_orbit_error) // fmt("PEERR",self%pe_error) & + // fmt("EORBERR",self%E_orbit_error) // fmt("EUNTRERR",self%E_untracked_error) & + // fmt("LESCERR",self%L_escape_error) // fmt("MESCERR",self%Mescape_error) if (param%lclose) formatted_output = formatted_output // fmt("ECOLLERR",self%Ecoll_error) - if (param%lrotation) formatted_output = formatted_output // fmt("KESPINERR",self%ke_spin_error) // fmt("LSPINERR",self%L_spin_error) + if (param%lrotation) formatted_output = formatted_output // fmt("KESPINERR",self%ke_spin_error) & + // fmt("LSPINERR",self%L_spin_error) end if if (.not. timer%main_is_started) then ! This is the start of a new run formatted_output = formatted_output // fmt("WT",0.0_DP) // fmt("IWT",0.0_DP) // fmt("WTPS",0.0_DP) else - formatted_output = formatted_output // fmt("WT",timer%wall_main) // fmt("IWT",timer%wall_step) // fmt("WTPS",timer%wall_per_substep) + formatted_output = formatted_output // fmt("WT",timer%wall_main) // fmt("IWT",timer%wall_step) & + // fmt("WTPS",timer%wall_per_substep) end if write(*,*) formatted_output end select @@ -123,12 +128,13 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) real(DP), dimension(NDIM) :: L_total_now, L_orbit_now, L_spin_now real(DP) :: ke_orbit_now, ke_spin_now, pe_now, E_orbit_now, be_now, be_cb_now, be_cb_orig, te_now real(DP) :: GMtot_now - character(len=*), parameter :: EGYTERMFMT = '(" DL/L0 = ", ES12.5, "; DE_orbit/|E0| = ", ES12.5, "; DE_total/|E0| = ", ES12.5, "; DM/M0 = ", ES12.5)' + character(len=*), parameter :: EGYTERMFMT = '(" DL/L0 = ", ES12.5, "; DE_orbit/|E0| = ", ES12.5, ";"' & + //'" DE_total/|E0| = ", ES12.5, "; DM/M0 = ", ES12.5)' associate(nbody_system => self, pl => self%pl, cb => self%cb, npl => self%pl%nbody, display_unit => param%display_unit) select type(self) - class is (helio_nbody_system) ! Don't convert vh to vb for Helio-based integrators, because they are already have that calculated + class is (helio_nbody_system) ! Don't convert vh to vb for Helio-based integrators, because it's already calculated class is (whm_nbody_system) call pl%vh2vb(cb) end select @@ -168,12 +174,14 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) nbody_system%pe_error = (pe_now - nbody_system%pe_orig) / abs(nbody_system%E_orbit_orig) be_cb_orig = -(3 * cb%GM0**2 / param%GU) / (5 * cb%R0) - nbody_system%be_error = (be_now - nbody_system%be_orig) / abs(nbody_system%te_orig) + (be_cb_now - be_cb_orig) / abs(nbody_system%te_orig) + nbody_system%be_error = (be_now - nbody_system%be_orig) / abs(nbody_system%te_orig) + (be_cb_now - be_cb_orig) & + / abs(nbody_system%te_orig) nbody_system%E_orbit_error = (E_orbit_now - nbody_system%E_orbit_orig) / abs(nbody_system%E_orbit_orig) nbody_system%Ecoll_error = nbody_system%E_collisions / abs(nbody_system%te_orig) nbody_system%E_untracked_error = nbody_system%E_untracked / abs(nbody_system%te_orig) - nbody_system%te_error = (nbody_system%te - nbody_system%te_orig - nbody_system%E_collisions - nbody_system%E_untracked) / abs(nbody_system%te_orig) + (be_cb_now - be_cb_orig) / abs(nbody_system%te_orig) + nbody_system%te_error = (nbody_system%te - nbody_system%te_orig - nbody_system%E_collisions - nbody_system%E_untracked)& + / abs(nbody_system%te_orig) + (be_cb_now - be_cb_orig) / abs(nbody_system%te_orig) nbody_system%L_orbit_error = norm2(L_orbit_now(:) - nbody_system%L_orbit_orig(:)) / norm2(nbody_system%L_total_orig(:)) nbody_system%L_spin_error = norm2(L_spin_now(:) - nbody_system%L_spin_orig(:)) / norm2(nbody_system%L_total_orig(:)) @@ -185,7 +193,8 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) if (this_image() == 1 .or. param%log_output) then #endif if (lterminal) then - write(display_unit, EGYTERMFMT) nbody_system%L_total_error, nbody_system%E_orbit_error, nbody_system%te_error,nbody_system%Mtot_error + write(display_unit, EGYTERMFMT) nbody_system%L_total_error, nbody_system%E_orbit_error, nbody_system%te_error, & + nbody_system%Mtot_error if (param%log_output) flush(display_unit) end if @@ -251,9 +260,11 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t #endif if (phase_val == 0) then if (param%lrestart) then - write(param%display_unit, *) " *************** Swiftest restart " // trim(adjustl(param%integrator)) // " *************** " + write(param%display_unit, *) " *************** Swiftest " // VERSION // " restart " // & + trim(adjustl(param%integrator)) // " *************** " else - write(param%display_unit, *) " *************** Swiftest start " // trim(adjustl(param%integrator)) // " *************** " + write(param%display_unit, *) " *************** Swiftest " // VERSION // " start " // & + trim(adjustl(param%integrator)) // " *************** " end if if (param%display_style == "PROGRESS") then call pbar%reset(param%nloops) @@ -360,13 +371,17 @@ module subroutine swiftest_io_dump_system(self, param, system_history) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters class(swiftest_storage), intent(inout) :: system_history !! Stores the system history between output dumps ! Internals - class(swiftest_parameters), allocatable :: param_restart !! Local parameters variable used to parameters change input file names - !! to dump file-specific values without changing the user-defined values + class(swiftest_parameters), allocatable :: param_restart !! Local parameters variable used to parameters change input file + !! names to dump file-specific values without changing the + !! user-defined values character(len=:), allocatable :: param_file_name character(len=STRMAX) :: time_text ! Dump the encounter history if necessary - if (param%lenc_save_trajectory .or. param%lenc_save_closest .and. allocated(self%encounter_history)) call self%encounter_history%dump(param) + if (param%lenc_save_trajectory & + .or. param%lenc_save_closest & + .and. allocated(self%encounter_history)) & + call self%encounter_history%dump(param) if (allocated(self%collision_history)) call self%collision_history%dump(param) ! Dump the nbody_system history to file @@ -454,8 +469,10 @@ module subroutine swiftest_io_get_args(integrator, param_file_name, display_styl ! Arguments character(len=:), intent(inout), allocatable :: integrator !! Symbolic code of the requested integrator character(len=:), intent(inout), allocatable :: param_file_name !! Name of the input parameters file - character(len=:), intent(inout), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD" - logical, intent(in) :: from_cli !! If true, get command-line arguments. Otherwise, use the values of the input variables + character(len=:), intent(inout), allocatable :: display_style !! Style of the output display + !! {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD" + logical, intent(in) :: from_cli !! If true, get command-line arguments. Otherwise, use the + !! values of the input variables ! Internals character(len=STRMAX), dimension(:), allocatable :: arg character(len=STRMAX), dimension(3) :: tmp_arg @@ -543,7 +560,7 @@ end subroutine swiftest_io_get_args module function swiftest_io_get_token(buffer, ifirst, ilast, ierr) result(token) !! author: David A. Minton !! - !! Retrieves a character token from an input string. Here a token is defined as any set of contiguous non-blank characters not + !! Retrieves a character token from an input string. Here a token is defined as any set of contiguous non-blank characters not !! beginning with or containing "!". If "!" is present, any remaining part of the buffer including the "!" is ignored !! !! Adapted from David E. Kaufmann's Swifter routine swiftest_io_get_token.f90 @@ -675,35 +692,44 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) associate (cb => self%cb) call nc%open(param, readonly=.true.) call nc%find_tslot(param%t0, tslot) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, len=itmax), "netcdf_io_get_t0_values_system time_dimid" ) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%name_dimid, len=idmax), "netcdf_io_get_t0_values_system name_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, len=itmax), "netcdf_io_get_t0_values_system time_dimid") + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%name_dimid, len=idmax), "netcdf_io_get_t0_values_system name_dimid") allocate(vals(idmax)) - call netcdf_io_check( nf90_get_var(nc%id, nc%time_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system time_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%time_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system time_varid" ) if (param%lenergy) then - call netcdf_io_check( nf90_get_var(nc%id, nc%KE_orb_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system KE_orb_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%KE_orb_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system KE_orb_varid" ) self%ke_orbit_orig = rtemp(1) - call netcdf_io_check( nf90_get_var(nc%id, nc%KE_spin_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system KE_spin_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%KE_spin_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system KE_spin_varid" ) self%ke_spin_orig = rtemp(1) - call netcdf_io_check( nf90_get_var(nc%id, nc%PE_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system PE_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%PE_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system PE_varid" ) self%pe_orig = rtemp(1) - call netcdf_io_check( nf90_get_var(nc%id, nc%BE_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system BE_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%BE_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system BE_varid" ) self%be_orig = rtemp(1) - call netcdf_io_check( nf90_get_var(nc%id, nc%TE_varid, rtemp, start=[tslot], count=[1]), "netcdf_io_get_t0_values_system TE_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%TE_varid, rtemp, start=[tslot], count=[1]), & + "netcdf_io_get_t0_values_system TE_varid" ) self%te_orig = rtemp(1) self%E_orbit_orig = self%ke_orbit_orig + self%pe_orig - call netcdf_io_check( nf90_get_var(nc%id, nc%L_orbit_varid, self%L_orbit_orig(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_get_t0_values_system L_orbit_varid" ) - call netcdf_io_check( nf90_get_var(nc%id, nc%L_spin_varid, self%L_spin_orig(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_get_t0_values_system L_spin_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%L_orbit_varid, self%L_orbit_orig(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_get_t0_values_system L_orbit_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%L_spin_varid, self%L_spin_orig(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_get_t0_values_system L_spin_varid" ) self%L_total_orig(:) = self%L_orbit_orig(:) + self%L_spin_orig(:) - call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, vals, start=[1,tslot], count=[idmax,1]), "netcdf_io_get_t0_values_system Gmass_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, vals, start=[1,tslot], count=[idmax,1]), & + "netcdf_io_get_t0_values_system Gmass_varid" ) call nc%get_valid_masks(plmask,tpmask) self%GMtot_orig = vals(1) + sum(vals(2:idmax), plmask(:)) @@ -711,13 +737,16 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) cb%dGM = cb%Gmass - cb%GM0 mass0 = cb%GM0 / param%GU - call netcdf_io_check( nf90_get_var(nc%id, nc%radius_varid, rtemp, start=[1,tslot], count=[1,1]), "netcdf_io_get_t0_values_system radius_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%radius_varid, rtemp, start=[1,tslot], count=[1,1]), & + "netcdf_io_get_t0_values_system radius_varid" ) cb%R0 = rtemp(1) if (param%lrotation) then - call netcdf_io_check( nf90_get_var(nc%id, nc%rot_varid, rot0, start=[1,1,tslot], count=[NDIM,1,1]), "netcdf_io_get_t0_values_system rot_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%rot_varid, rot0, start=[1,1,tslot], count=[NDIM,1,1]), & + "netcdf_io_get_t0_values_system rot_varid" ) rot0(:) = rot0(:) * DEG2RAD - call netcdf_io_check( nf90_get_var(nc%id, nc%Ip_varid, Ip0, start=[1,1,tslot], count=[NDIM,1,1]), "netcdf_io_get_t0_values_system Ip_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%Ip_varid, Ip0, start=[1,1,tslot], count=[NDIM,1,1]), & + "netcdf_io_get_t0_values_system Ip_varid" ) cb%L0(:) = Ip0(3) * mass0 * cb%R0**2 * rot0(:) L(:) = cb%Ip(3) * cb%mass * cb%radius**2 * cb%rot(:) cb%dL(:) = L(:) - cb%L0 @@ -725,10 +754,14 @@ module subroutine swiftest_io_netcdf_get_t0_values_system(self, nc, param) ! Retrieve the current bookkeeping variables call nc%find_tslot(self%t, tslot) - call netcdf_io_check( nf90_get_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_get_t0_values_system L_escape_varid" ) - call netcdf_io_check( nf90_get_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_get_t0_values_system GMescape_varid" ) - call netcdf_io_check( nf90_get_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_get_t0_values_system E_collisions_varid" ) - call netcdf_io_check( nf90_get_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), "netcdf_io_get_t0_values_system E_untracked_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_get_t0_values_system L_escape_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), & + "netcdf_io_get_t0_values_system GMescape_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), & + "netcdf_io_get_t0_values_system E_collisions_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), & + "netcdf_io_get_t0_values_system E_untracked_varid" ) end if @@ -784,115 +817,194 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param) nc%lfile_is_open = .true. ! Dimensions - call netcdf_io_check( nf90_def_dim(nc%id, nc%time_dimname, NF90_UNLIMITED, nc%time_dimid), "netcdf_io_initialize_output nf90_def_dim time_dimid" ) ! Simulation time dimension - call netcdf_io_check( nf90_def_dim(nc%id, nc%space_dimname, NDIM, nc%space_dimid), "netcdf_io_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension - call netcdf_io_check( nf90_def_dim(nc%id, nc%name_dimname, NF90_UNLIMITED, nc%name_dimid), "netcdf_io_initialize_output nf90_def_dim name_dimid" ) ! dimension to store particle id numbers - call netcdf_io_check( nf90_def_dim(nc%id, nc%str_dimname, NAMELEN, nc%str_dimid), "netcdf_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) + call netcdf_io_check( nf90_def_dim(nc%id, nc%time_dimname, NF90_UNLIMITED, nc%time_dimid), & + "netcdf_io_initialize_output nf90_def_dim time_dimid" ) ! Simulation time dimension + call netcdf_io_check( nf90_def_dim(nc%id, nc%space_dimname, NDIM, nc%space_dimid), & + "netcdf_io_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension + call netcdf_io_check( nf90_def_dim(nc%id, nc%name_dimname, NF90_UNLIMITED, nc%name_dimid), & + "netcdf_io_initialize_output nf90_def_dim name_dimid" ) ! dimension to store particle id numbers + call netcdf_io_check( nf90_def_dim(nc%id, nc%str_dimname, NAMELEN, nc%str_dimid), & + "netcdf_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables ! Dimension coordinates - call netcdf_io_check( nf90_def_var(nc%id, nc%time_dimname, nc%out_type, nc%time_dimid, nc%time_varid), "netcdf_io_initialize_output nf90_def_var time_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%space_dimname, NF90_CHAR, nc%space_dimid, nc%space_varid), "netcdf_io_initialize_output nf90_def_var space_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%name_dimname, NF90_CHAR, [nc%str_dimid, nc%name_dimid], nc%name_varid), "netcdf_io_initialize_output nf90_def_var name_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%time_dimname, nc%out_type, nc%time_dimid, nc%time_varid), & + "netcdf_io_initialize_output nf90_def_var time_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%space_dimname, NF90_CHAR, nc%space_dimid, nc%space_varid), & + "netcdf_io_initialize_output nf90_def_var space_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%name_dimname, NF90_CHAR, [nc%str_dimid, nc%name_dimid], nc%name_varid), & + "netcdf_io_initialize_output nf90_def_var name_varid" ) ! Variables - call netcdf_io_check( nf90_def_var(nc%id, nc%id_varname, NF90_INT, nc%name_dimid, nc%id_varid), "netcdf_io_initialize_output nf90_def_var id_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%status_varname, NF90_INT, [nc%name_dimid, nc%time_dimid], nc%status_varid), "netcdf_io_initialize_output nf90_def_var status_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%npl_varname, NF90_INT, nc%time_dimid, nc%npl_varid), "netcdf_io_initialize_output nf90_def_var npl_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%ntp_varname, NF90_INT, nc%time_dimid, nc%ntp_varid), "netcdf_io_initialize_output nf90_def_var ntp_varid" ) - if (param%lmtiny_pl) call netcdf_io_check( nf90_def_var(nc%id, nc%nplm_varname, NF90_INT, nc%time_dimid, nc%nplm_varid), "netcdf_io_initialize_output nf90_def_var nplm_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%ptype_varname, NF90_CHAR, [nc%str_dimid, nc%name_dimid], nc%ptype_varid), "netcdf_io_initialize_output nf90_def_var ptype_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%id_varname, NF90_INT, nc%name_dimid, nc%id_varid), & + "netcdf_io_initialize_output nf90_def_var id_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%status_varname, NF90_INT, [nc%name_dimid, nc%time_dimid], nc%status_varid), & + "netcdf_io_initialize_output nf90_def_var status_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%npl_varname, NF90_INT, nc%time_dimid, nc%npl_varid), & + "netcdf_io_initialize_output nf90_def_var npl_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%ntp_varname, NF90_INT, nc%time_dimid, nc%ntp_varid), & + "netcdf_io_initialize_output nf90_def_var ntp_varid" ) + if (param%lmtiny_pl) call netcdf_io_check( nf90_def_var(nc%id, nc%nplm_varname, NF90_INT, nc%time_dimid, nc%nplm_varid), & + "netcdf_io_initialize_output nf90_def_var nplm_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%ptype_varname, NF90_CHAR, [nc%str_dimid, nc%name_dimid], nc%ptype_varid), & + "netcdf_io_initialize_output nf90_def_var ptype_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_def_var(nc%id, nc%rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%rh_varid), "netcdf_io_initialize_output nf90_def_var rh_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%vh_varid), "netcdf_io_initialize_output nf90_def_var vh_varid" ) - - !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, otherwise - !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors during the conversion. + call netcdf_io_check( nf90_def_var(nc%id, nc%rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], & + nc%rh_varid), "netcdf_io_initialize_output nf90_def_var rh_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], & + nc%vh_varid), "netcdf_io_initialize_output nf90_def_var vh_varid" ) + + !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, + !! otherwise !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors + !! during the conversion. if (param%lgr) then - call netcdf_io_check( nf90_def_var(nc%id, nc%gr_pseudo_vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%gr_pseudo_vh_varid), "netcdf_io_initialize_output nf90_def_var gr_psuedo_vh_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%gr_pseudo_vh_varname, nc%out_type, & + [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%gr_pseudo_vh_varid), & + "netcdf_io_initialize_output nf90_def_var gr_psuedo_vh_varid" ) nc%lpseudo_vel_exists = .true. end if end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_def_var(nc%id, nc%a_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%a_varid), "netcdf_io_initialize_output nf90_def_var a_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%e_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%e_varid), "netcdf_io_initialize_output nf90_def_var e_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%inc_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%inc_varid), "netcdf_io_initialize_output nf90_def_var inc_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%capom_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%capom_varid), "netcdf_io_initialize_output nf90_def_var capom_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%omega_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%omega_varid), "netcdf_io_initialize_output nf90_def_var omega_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%capm_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%capm_varid), "netcdf_io_initialize_output nf90_def_var capm_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%varpi_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%varpi_varid), "netcdf_io_initialize_output nf90_def_var varpi_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%lam_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%lam_varid), "netcdf_io_initialize_output nf90_def_var lam_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%f_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%f_varid), "netcdf_io_initialize_output nf90_def_var f_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%cape_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%cape_varid), "netcdf_io_initialize_output nf90_def_var cape_varid" ) - end if - - call netcdf_io_check( nf90_def_var(nc%id, nc%Gmass_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%Gmass_varid), "netcdf_io_initialize_output nf90_def_var Gmass_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%mass_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%mass_varid), "netcdf_io_initialize_output nf90_def_var mass_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%rhill_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%rhill_varid), "netcdf_io_initialize_output nf90_def_var rhill_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%a_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%a_varid), & + "netcdf_io_initialize_output nf90_def_var a_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%e_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%e_varid), & + "netcdf_io_initialize_output nf90_def_var e_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%inc_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%inc_varid), & + "netcdf_io_initialize_output nf90_def_var inc_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%capom_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], & + nc%capom_varid), & + "netcdf_io_initialize_output nf90_def_var capom_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%omega_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], & + nc%omega_varid), & + "netcdf_io_initialize_output nf90_def_var omega_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%capm_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], & + nc%capm_varid), & + "netcdf_io_initialize_output nf90_def_var capm_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%varpi_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], & + nc%varpi_varid), & + "netcdf_io_initialize_output nf90_def_var varpi_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%lam_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%lam_varid), & + "netcdf_io_initialize_output nf90_def_var lam_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%f_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%f_varid), & + "netcdf_io_initialize_output nf90_def_var f_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%cape_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%cape_varid),& + "netcdf_io_initialize_output nf90_def_var cape_varid" ) + end if + + call netcdf_io_check( nf90_def_var(nc%id, nc%Gmass_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%Gmass_varid), & + "netcdf_io_initialize_output nf90_def_var Gmass_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%mass_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%mass_varid), & + "netcdf_io_initialize_output nf90_def_var mass_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%rhill_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%rhill_varid), & + "netcdf_io_initialize_output nf90_def_var rhill_varid" ) if (param%lclose) then - call netcdf_io_check( nf90_def_var(nc%id, nc%radius_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%radius_varid), "netcdf_io_initialize_output nf90_def_var radius_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%radius_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], & + nc%radius_varid), & + "netcdf_io_initialize_output nf90_def_var radius_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%origin_time_varname, nc%out_type, nc%name_dimid, nc%origin_time_varid), "netcdf_io_initialize_output nf90_def_var origin_time_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%origin_time_varname, nc%out_type, nc%name_dimid, nc%origin_time_varid), & + "netcdf_io_initialize_output nf90_def_var origin_time_varid" ) call netcdf_io_check( nf90_def_var(nc%id, nc%origin_type_varname, NF90_CHAR, [nc%str_dimid, nc%name_dimid], & - nc%origin_type_varid), "netcdf_io_initialize_output nf90_create" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%origin_rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], nc%origin_rh_varid), "netcdf_io_initialize_output nf90_def_var origin_rh_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%origin_vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], nc%origin_vh_varid), "netcdf_io_initialize_output nf90_def_var origin_vh_varid" ) - - call netcdf_io_check( nf90_def_var(nc%id, nc%collision_id_varname, NF90_INT, nc%name_dimid, nc%collision_id_varid), "netcdf_io_initialize_output nf90_def_var collision_id_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%discard_time_varname, nc%out_type, nc%name_dimid, nc%discard_time_varid), "netcdf_io_initialize_output nf90_def_var discard_time_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%discard_rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], nc%discard_rh_varid), "netcdf_io_initialize_output nf90_def_var discard_rh_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%discard_vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], nc%discard_vh_varid), "netcdf_io_initialize_output nf90_def_var discard_vh_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%discard_body_id_varname, NF90_INT, nc%name_dimid, nc%discard_body_id_varid), "netcdf_io_initialize_output nf90_def_var discard_body_id_varid" ) + nc%origin_type_varid), & + "netcdf_io_initialize_output nf90_create" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%origin_rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], & + nc%origin_rh_varid), & + "netcdf_io_initialize_output nf90_def_var origin_rh_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%origin_vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], & + nc%origin_vh_varid), & + "netcdf_io_initialize_output nf90_def_var origin_vh_varid" ) + + call netcdf_io_check( nf90_def_var(nc%id, nc%collision_id_varname, NF90_INT, nc%name_dimid, nc%collision_id_varid), & + "netcdf_io_initialize_output nf90_def_var collision_id_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%discard_time_varname, nc%out_type, nc%name_dimid, nc%discard_time_varid), & + "netcdf_io_initialize_output nf90_def_var discard_time_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%discard_rh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], & + nc%discard_rh_varid), & + "netcdf_io_initialize_output nf90_def_var discard_rh_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%discard_vh_varname, nc%out_type, [nc%space_dimid, nc%name_dimid], & + nc%discard_vh_varid), & + "netcdf_io_initialize_output nf90_def_var discard_vh_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%discard_body_id_varname, NF90_INT, nc%name_dimid, & + nc%discard_body_id_varid), & + "netcdf_io_initialize_output nf90_def_var discard_body_id_varid" ) end if if (param%lrotation) then - call netcdf_io_check( nf90_def_var(nc%id, nc%Ip_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%Ip_varid), "netcdf_io_initialize_output nf90_def_var Ip_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%rot_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], nc%rot_varid), "netcdf_io_initialize_output nf90_def_var rot_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%Ip_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], & + nc%Ip_varid), & + "netcdf_io_initialize_output nf90_def_var Ip_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%rot_varname, nc%out_type, [nc%space_dimid, nc%name_dimid, nc%time_dimid], & + nc%rot_varid), & + "netcdf_io_initialize_output nf90_def_var rot_varid" ) end if ! if (param%ltides) then - ! call netcdf_io_check( nf90_def_var(nc%id, nc%k2_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%k2_varid), "netcdf_io_initialize_output nf90_def_var k2_varid" ) - ! call netcdf_io_check( nf90_def_var(nc%id, nc%q_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%Q_varid), "netcdf_io_initialize_output nf90_def_var Q_varid" ) + ! call netcdf_io_check( nf90_def_var(nc%id, nc%k2_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%k2_varid), & + ! "netcdf_io_initialize_output nf90_def_var k2_varid" ) + ! call netcdf_io_check( nf90_def_var(nc%id, nc%q_varname, nc%out_type, [nc%name_dimid, nc%time_dimid], nc%Q_varid), & + ! "netcdf_io_initialize_output nf90_def_var Q_varid" ) ! end if if (param%lenergy) then - call netcdf_io_check( nf90_def_var(nc%id, nc%ke_orb_varname, nc%out_type, nc%time_dimid, nc%KE_orb_varid), "netcdf_io_initialize_output nf90_def_var KE_orb_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%ke_spin_varname, nc%out_type, nc%time_dimid, nc%KE_spin_varid), "netcdf_io_initialize_output nf90_def_var KE_spin_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%pe_varname, nc%out_type, nc%time_dimid, nc%PE_varid), "netcdf_io_initialize_output nf90_def_var PE_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%be_varname, nc%out_type, nc%time_dimid, nc%BE_varid), "netcdf_io_initialize_output nf90_def_var BE_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%te_varname, nc%out_type, nc%time_dimid, nc%TE_varid), "netcdf_io_initialize_output nf90_def_var TE_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%L_orbit_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], nc%L_orbit_varid), "netcdf_io_initialize_output nf90_def_var L_orbit_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%L_spin_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], nc%L_spin_varid), "netcdf_io_initialize_output nf90_def_var L_spin_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%L_escape_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], nc%L_escape_varid), "netcdf_io_initialize_output nf90_def_var L_escape_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%E_collisions_varname, nc%out_type, nc%time_dimid, nc%E_collisions_varid), "netcdf_io_initialize_output nf90_def_var E_collisions_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%E_untracked_varname, nc%out_type, nc%time_dimid, nc%E_untracked_varid), "netcdf_io_initialize_output nf90_def_var E_untracked_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%GMescape_varname, nc%out_type, nc%time_dimid, nc%GMescape_varid), "netcdf_io_initialize_output nf90_def_var GMescape_varid" ) - end if - - call netcdf_io_check( nf90_def_var(nc%id, nc%j2rp2_varname, nc%out_type, nc%time_dimid, nc%j2rp2_varid), "netcdf_io_initialize_output nf90_def_var j2rp2_varid" ) - call netcdf_io_check( nf90_def_var(nc%id, nc%j4rp4_varname, nc%out_type, nc%time_dimid, nc%j4rp4_varid), "netcdf_io_initialize_output nf90_def_var j4rp4_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%ke_orb_varname, nc%out_type, nc%time_dimid, nc%KE_orb_varid), & + "netcdf_io_initialize_output nf90_def_var KE_orb_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%ke_spin_varname, nc%out_type, nc%time_dimid, nc%KE_spin_varid), & + "netcdf_io_initialize_output nf90_def_var KE_spin_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%pe_varname, nc%out_type, nc%time_dimid, nc%PE_varid), & + "netcdf_io_initialize_output nf90_def_var PE_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%be_varname, nc%out_type, nc%time_dimid, nc%BE_varid), & + "netcdf_io_initialize_output nf90_def_var BE_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%te_varname, nc%out_type, nc%time_dimid, nc%TE_varid), & + "netcdf_io_initialize_output nf90_def_var TE_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%L_orbit_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], & + nc%L_orbit_varid), & + "netcdf_io_initialize_output nf90_def_var L_orbit_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%L_spin_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], & + nc%L_spin_varid), & + "netcdf_io_initialize_output nf90_def_var L_spin_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%L_escape_varname, nc%out_type, [nc%space_dimid, nc%time_dimid], & + nc%L_escape_varid), & + "netcdf_io_initialize_output nf90_def_var L_escape_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%E_collisions_varname, nc%out_type, nc%time_dimid, nc%E_collisions_varid), & + "netcdf_io_initialize_output nf90_def_var E_collisions_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%E_untracked_varname, nc%out_type, nc%time_dimid, nc%E_untracked_varid), & + "netcdf_io_initialize_output nf90_def_var E_untracked_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%GMescape_varname, nc%out_type, nc%time_dimid, nc%GMescape_varid), & + "netcdf_io_initialize_output nf90_def_var GMescape_varid" ) + end if + + call netcdf_io_check( nf90_def_var(nc%id, nc%j2rp2_varname, nc%out_type, nc%time_dimid, nc%j2rp2_varid), & + "netcdf_io_initialize_output nf90_def_var j2rp2_varid" ) + call netcdf_io_check( nf90_def_var(nc%id, nc%j4rp4_varname, nc%out_type, nc%time_dimid, nc%j4rp4_varid), & + "netcdf_io_initialize_output nf90_def_var j4rp4_varid" ) ! Set fill mode to NaN for all variables - call netcdf_io_check( nf90_inquire(nc%id, nVariables=nvar), "netcdf_io_initialize_output nf90_inquire nVariables" ) + call netcdf_io_check( nf90_inquire(nc%id, nVariables=nvar), "netcdf_io_initialize_output nf90_inquire nVariables" ) do varid = 1, nvar - call netcdf_io_check( nf90_inquire_variable(nc%id, varid, xtype=vartype, ndims=ndims), "netcdf_io_initialize_output nf90_inquire_variable" ) + call netcdf_io_check( nf90_inquire_variable(nc%id, varid, xtype=vartype, ndims=ndims), & + "netcdf_io_initialize_output nf90_inquire_variable" ) select case(vartype) case(NF90_INT) if (varid == nc%status_varid) then ! Be sure the status variable fill value is the INACTIVE symbolic value - call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, INACTIVE), "netcdf_io_netcdf_initialize_output nf90_def_var_fill status variable" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, INACTIVE), & + "netcdf_io_netcdf_initialize_output nf90_def_var_fill status variable" ) else - call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, NF90_FILL_INT), "netcdf_io_initialize_output nf90_def_var_fill NF90_INT" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, NF90_FILL_INT), & + "netcdf_io_initialize_output nf90_def_var_fill NF90_INT" ) end if case(NF90_FLOAT) - call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, sfill), "netcdf_io_initialize_output nf90_def_var_fill NF90_FLOAT" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, sfill), & + "netcdf_io_initialize_output nf90_def_var_fill NF90_FLOAT" ) case(NF90_DOUBLE) - call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, dfill), "netcdf_io_initialize_output nf90_def_var_fill NF90_DOUBLE" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, dfill), & + "netcdf_io_initialize_output nf90_def_var_fill NF90_DOUBLE" ) case(NF90_CHAR) - call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, 0), "netcdf_io_initialize_output nf90_def_var_fill NF90_CHAR" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, varid, NO_FILL, 0), & + "netcdf_io_initialize_output nf90_def_var_fill NF90_CHAR" ) end select end do @@ -900,9 +1012,11 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param) if (param%lclose) then select case (vartype) case(NF90_FLOAT) - call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_SP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_FLOAT" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_SP)), & + "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_FLOAT" ) case(NF90_DOUBLE) - call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_DP)), "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_DOUBLE" ) + call netcdf_io_check( nf90_def_var_fill(nc%id, nc%discard_time_varid, NO_FILL, huge(1.0_DP)), & + "netcdf_io_initialize_output nf90_def_var_fill discard_time NF90_DOUBLE" ) end select end if @@ -910,7 +1024,8 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param) call netcdf_io_check( nf90_enddef(nc%id), "netcdf_io_initialize_output nf90_enddef" ) ! Add in the space dimension coordinates - call netcdf_io_check( nf90_put_var(nc%id, nc%space_varid, nc%space_coords, start=[1], count=[NDIM]), "netcdf_io_initialize_output nf90_put_var space" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%space_varid, nc%space_coords, start=[1], count=[NDIM]), & + "netcdf_io_initialize_output nf90_put_var space" ) end associate return @@ -945,57 +1060,82 @@ module subroutine swiftest_io_netcdf_open(self, param, readonly) self%lfile_is_open = .true. ! Dimensions - call netcdf_io_check( nf90_inq_dimid(nc%id, nc%time_dimname, nc%time_dimid), "swiftest_io_netcdf_open nf90_inq_dimid time_dimid" ) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, nc%time_dimname, len=nc%max_tslot), "swiftest_io_netcdf_open nf90_inquire_dimension max_tslot" ) - call netcdf_io_check( nf90_inq_dimid(nc%id, nc%space_dimname, nc%space_dimid), "swiftest_io_netcdf_open nf90_inq_dimid space_dimid" ) - call netcdf_io_check( nf90_inq_dimid(nc%id, nc%name_dimname, nc%name_dimid), "swiftest_io_netcdf_open nf90_inq_dimid name_dimid" ) - call netcdf_io_check( nf90_inq_dimid(nc%id, nc%str_dimname, nc%str_dimid), "swiftest_io_netcdf_open nf90_inq_dimid str_dimid" ) + call netcdf_io_check( nf90_inq_dimid(nc%id, nc%time_dimname, nc%time_dimid), & + "swiftest_io_netcdf_open nf90_inq_dimid time_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, nc%time_dimname, len=nc%max_tslot), & + "swiftest_io_netcdf_open nf90_inquire_dimension max_tslot" ) + call netcdf_io_check( nf90_inq_dimid(nc%id, nc%space_dimname, nc%space_dimid), & + "swiftest_io_netcdf_open nf90_inq_dimid space_dimid" ) + call netcdf_io_check( nf90_inq_dimid(nc%id, nc%name_dimname, nc%name_dimid), & + "swiftest_io_netcdf_open nf90_inq_dimid name_dimid" ) + call netcdf_io_check( nf90_inq_dimid(nc%id, nc%str_dimname, nc%str_dimid), & + "swiftest_io_netcdf_open nf90_inq_dimid str_dimid" ) ! Dimension coordinates - call netcdf_io_check( nf90_inq_varid(nc%id, nc%time_dimname, nc%time_varid), "swiftest_io_netcdf_open nf90_inq_varid time_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%space_dimname, nc%space_varid), "swiftest_io_netcdf_open nf90_inq_varid space_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%name_dimname, nc%name_varid), "swiftest_io_netcdf_open nf90_inq_varid name_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%time_dimname, nc%time_varid), & + "swiftest_io_netcdf_open nf90_inq_varid time_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%space_dimname, nc%space_varid), & + "swiftest_io_netcdf_open nf90_inq_varid space_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%name_dimname, nc%name_varid), & + "swiftest_io_netcdf_open nf90_inq_varid name_varid" ) ! Required Variables - call netcdf_io_check( nf90_inq_varid(nc%id, nc%id_varname, nc%id_varid), "swiftest_io_netcdf_open nf90_inq_varid name_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%Gmass_varname, nc%Gmass_varid), "swiftest_io_netcdf_open nf90_inq_varid Gmass_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%id_varname, nc%id_varid), & + "swiftest_io_netcdf_open nf90_inq_varid name_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%Gmass_varname, nc%Gmass_varid), & + "swiftest_io_netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_inq_varid(nc%id, nc%rh_varname, nc%rh_varid), "swiftest_io_netcdf_open nf90_inq_varid rh_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%vh_varname, nc%vh_varid), "swiftest_io_netcdf_open nf90_inq_varid vh_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%rh_varname, nc%rh_varid), & + "swiftest_io_netcdf_open nf90_inq_varid rh_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%vh_varname, nc%vh_varid), & + "swiftest_io_netcdf_open nf90_inq_varid vh_varid" ) if (param%lgr) then - !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. + !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not + !! do the conversion. status = nf90_inq_varid(nc%id, nc%gr_pseudo_vh_varname, nc%gr_pseudo_vh_varid) nc%lpseudo_vel_exists = (status == NF90_NOERR) if (param%lrestart .and. .not.nc%lpseudo_vel_exists) then - write(*,*) "Warning! Pseudovelocity not found in input file for GR enabled run. If this is a restarted run, bit-identical trajectories are not guarunteed!" + write(*,*) "Warning! Pseudovelocity not found in input file for GR enabled run. " & + // "If this is a restarted run, bit-identical trajectories are not guarunteed!" end if end if end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_inq_varid(nc%id, nc%a_varname, nc%a_varid), "swiftest_io_netcdf_open nf90_inq_varid a_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%e_varname, nc%e_varid), "swiftest_io_netcdf_open nf90_inq_varid e_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%inc_varname, nc%inc_varid), "swiftest_io_netcdf_open nf90_inq_varid inc_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%capom_varname, nc%capom_varid), "swiftest_io_netcdf_open nf90_inq_varid capom_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%omega_varname, nc%omega_varid), "swiftest_io_netcdf_open nf90_inq_varid omega_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%capm_varname, nc%capm_varid), "swiftest_io_netcdf_open nf90_inq_varid capm_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%a_varname, nc%a_varid), & + "swiftest_io_netcdf_open nf90_inq_varid a_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%e_varname, nc%e_varid), & + "swiftest_io_netcdf_open nf90_inq_varid e_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%inc_varname, nc%inc_varid), & + "swiftest_io_netcdf_open nf90_inq_varid inc_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%capom_varname, nc%capom_varid), & + "swiftest_io_netcdf_open nf90_inq_varid capom_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%omega_varname, nc%omega_varid), & + "swiftest_io_netcdf_open nf90_inq_varid omega_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%capm_varname, nc%capm_varid), & + "swiftest_io_netcdf_open nf90_inq_varid capm_varid" ) end if if (param%lclose) then - call netcdf_io_check( nf90_inq_varid(nc%id, nc%radius_varname, nc%radius_varid), "swiftest_io_netcdf_open nf90_inq_varid radius_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%radius_varname, nc%radius_varid), & + "swiftest_io_netcdf_open nf90_inq_varid radius_varid" ) end if if (param%lrotation) then - call netcdf_io_check( nf90_inq_varid(nc%id, nc%Ip_varname, nc%Ip_varid), "swiftest_io_netcdf_open nf90_inq_varid Ip_varid" ) - call netcdf_io_check( nf90_inq_varid(nc%id, nc%rot_varname, nc%rot_varid), "swiftest_io_netcdf_open nf90_inq_varid rot_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%Ip_varname, nc%Ip_varid), & + "swiftest_io_netcdf_open nf90_inq_varid Ip_varid" ) + call netcdf_io_check( nf90_inq_varid(nc%id, nc%rot_varname, nc%rot_varid), & + "swiftest_io_netcdf_open nf90_inq_varid rot_varid" ) end if ! if (param%ltides) then - ! call netcdf_io_check( nf90_inq_varid(nc%id, nc%k2_varname, nc%k2_varid), "swiftest_io_netcdf_open nf90_inq_varid k2_varid" ) - ! call netcdf_io_check( nf90_inq_varid(nc%id, nc%q_varname, nc%Q_varid), "swiftest_io_netcdf_open nf90_inq_varid Q_varid" ) + ! call netcdf_io_check( nf90_inq_varid(nc%id, nc%k2_varname, nc%k2_varid), & + ! "swiftest_io_netcdf_open nf90_inq_varid k2_varid" ) + ! call netcdf_io_check( nf90_inq_varid(nc%id, nc%q_varname, nc%Q_varid), & + ! "swiftest_io_netcdf_open nf90_inq_varid Q_varid" ) ! end if ! Optional variables The User Doesn't Need to Know About @@ -1049,17 +1189,22 @@ end subroutine swiftest_io_netcdf_open module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask, plmmask, Gmtiny) !! author: David A. Minton !! - !! Given an open NetCDF, returns logical masks indicating which bodies in the body arrays are active pl and tp type at the current time. - !! Uses the value of tslot stored in the NetCDF parameter object as the definition of current time + !! Given an open NetCDF, returns logical masks indicating which bodies in the body arrays are active pl and tp type at the + !! current time. Uses the value of tslot stored in the NetCDF parameter object as the definition of current time use, intrinsic :: ieee_exceptions use, intrinsic :: ieee_arithmetic implicit none ! Arguments - class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive bodies - logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test particles - logical, dimension(:), allocatable, intent(out), optional :: plmmask !! Logical mask indicating which bodies are fully interacting massive bodies - real(DP), intent(in), optional :: Gmtiny !! The cutoff G*mass between semi-interacting and fully interacting massive bodies + class(swiftest_netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF + !! dataset + logical, dimension(:), allocatable, intent(out) :: plmask !! Logical mask indicating which bodies are massive + !! bodies + logical, dimension(:), allocatable, intent(out) :: tpmask !! Logical mask indicating which bodies are test + !! particles + logical, dimension(:), allocatable, intent(out), optional :: plmmask !! Logical mask indicating which bodies are fully + !! interacting massive bodies + real(DP), intent(in), optional :: Gmtiny !! The cutoff G*mass between semi-interacting and fully + !! interacting massive bodies ! Internals real(DP), dimension(:), allocatable :: Gmass, a real(DP), dimension(:,:), allocatable :: rh @@ -1071,7 +1216,8 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask, plmma call ieee_get_halting_mode(IEEE_ALL,fpe_halting_modes) ! Save the current halting modes so we can turn them off temporarily call ieee_set_halting_mode(IEEE_ALL,.false.) - call netcdf_io_check( nf90_inquire_dimension(self%id, self%name_dimid, len=idmax), "swiftest_io_netcdf_get_valid_masks nf90_inquire_dimension name_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(self%id, self%name_dimid, len=idmax), & + "swiftest_io_netcdf_get_valid_masks nf90_inquire_dimension name_dimid" ) allocate(Gmass(idmax)) allocate(tpmask(idmax)) @@ -1079,24 +1225,28 @@ module subroutine swiftest_io_netcdf_get_valid_masks(self, plmask, tpmask, plmma allocate(lvalid(idmax)) associate(tslot => self%tslot) - call netcdf_io_check( nf90_get_var(self%id, self%Gmass_varid, Gmass, start=[1,tslot], count=[idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar Gmass_varid" ) + call netcdf_io_check( nf90_get_var(self%id, self%Gmass_varid, Gmass, start=[1,tslot], count=[idmax,1]), & + "swiftest_io_netcdf_get_valid_masks nf90_getvar Gmass_varid" ) status = nf90_inq_varid(self%id, self%status_varname, self%status_varid) if (status == NF90_NOERR) then allocate(body_status(idmax)) - call netcdf_io_check( nf90_get_var(self%id, self%status_varid, body_status, start=[1, tslot], count=[idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar status_varid" ) + call netcdf_io_check( nf90_get_var(self%id, self%status_varid, body_status, start=[1, tslot], count=[idmax,1]), & + "swiftest_io_netcdf_get_valid_masks nf90_getvar status_varid" ) lvalid(:) = body_status(:) /= INACTIVE else status = nf90_inq_varid(self%id, self%rh_varname, self%rh_varid) if (status == NF90_NOERR) then allocate(rh(NDIM,idmax)) - call netcdf_io_check( nf90_get_var(self%id, self%rh_varid, rh, start=[1, 1, tslot], count=[NDIM,idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar rh_varid" ) + call netcdf_io_check( nf90_get_var(self%id, self%rh_varid, rh, start=[1, 1, tslot], count=[NDIM,idmax,1]), & + "swiftest_io_netcdf_get_valid_masks nf90_getvar rh_varid" ) lvalid(:) = ieee_is_normal(rh(1,:)) else status = nf90_inq_varid(self%id, self%a_varname, self%a_varid) if (status == NF90_NOERR) then allocate(a(idmax)) - call netcdf_io_check( nf90_get_var(self%id, self%a_varid, a, start=[1, tslot], count=[idmax,1]), "swiftest_io_netcdf_get_valid_masks nf90_getvar a_varid" ) + call netcdf_io_check( nf90_get_var(self%id, self%a_varid, a, start=[1, tslot], count=[idmax,1]), & + "swiftest_io_netcdf_get_valid_masks nf90_getvar a_varid" ) lvalid(:) = ieee_is_normal(a(:)) else lvalid(:) = .false. @@ -1149,7 +1299,8 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier associate(cb => self%cb, pl => self%pl, tp => self%tp, tslot => nc%tslot) call nc%open(param, readonly=.true.) call nc%find_tslot(self%t, tslot) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, len=nc%max_tslot), "netcdf_io_read_frame_system nf90_inquire_dimension time_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%time_dimid, len=nc%max_tslot), & + "netcdf_io_read_frame_system nf90_inquire_dimension time_dimid" ) tslot = min(tslot, nc%max_tslot) call self%read_hdr(nc, param) @@ -1159,12 +1310,14 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier ntp = tp%nbody call pl%setup(npl, param) call tp%setup(ntp, param) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%name_dimid, len=idmax), "netcdf_io_read_frame_system nf90_inquire_dimension name_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%name_dimid, len=idmax), & + "netcdf_io_read_frame_system nf90_inquire_dimension name_dimid" ) allocate(rtemp(idmax)) allocate(vectemp(NDIM,idmax)) allocate(itemp(idmax)) - call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%str_dimid, len=str_max), "netcdf_io_read_frame_system nf90_inquire_dimension str_dimid" ) + call netcdf_io_check( nf90_inquire_dimension(nc%id, nc%str_dimid, len=str_max), & + "netcdf_io_read_frame_system nf90_inquire_dimension str_dimid" ) call nc%get_valid_masks(plmask, tpmask) @@ -1187,20 +1340,24 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier ! Now read in each variable and split the outputs by body type if ((param%in_form == "XV") .or. (param%in_form == "XVEL")) then - call netcdf_io_check( nf90_get_var(nc%id, nc%rh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_io_read_frame_system nf90_getvar rh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%rh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar rh_varid" ) do i = 1, NDIM if (npl > 0) pl%rh(i,:) = pack(vectemp(i,:), plmask(:)) if (ntp > 0) tp%rh(i,:) = pack(vectemp(i,:), tpmask(:)) end do if (param%lgr .and. nc%lpseudo_vel_exists) then - call netcdf_io_check( nf90_get_var(nc%id, nc%gr_pseudo_vh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_io_read_frame_system nf90_getvar gr_pseudo_vh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%gr_pseudo_vh_varid, vectemp, start=[1, 1, tslot], & + count=[NDIM,idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar gr_pseudo_vh_varid" ) do i = 1, NDIM if (npl > 0) pl%vh(i,:) = pack(vectemp(i,:), plmask(:)) if (ntp > 0) tp%vh(i,:) = pack(vectemp(i,:), tpmask(:)) end do else - call netcdf_io_check( nf90_get_var(nc%id, nc%vh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_io_read_frame_system nf90_getvar vh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%vh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar vh_varid" ) do i = 1, NDIM if (npl > 0) pl%vh(i,:) = pack(vectemp(i,:), plmask(:)) if (ntp > 0) tp%vh(i,:) = pack(vectemp(i,:), tpmask(:)) @@ -1209,40 +1366,46 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier end if if ((param%in_form == "EL") .or. (param%in_form == "XVEL")) then - call netcdf_io_check( nf90_get_var(nc%id, nc%a_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar a_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%a_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar a_varid" ) if (.not.allocated(pl%a)) allocate(pl%a(npl)) if (.not.allocated(tp%a)) allocate(tp%a(ntp)) if (npl > 0) pl%a(:) = pack(rtemp, plmask) if (ntp > 0) tp%a(:) = pack(rtemp, tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%e_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar e_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%e_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar e_varid" ) if (.not.allocated(pl%e)) allocate(pl%e(npl)) if (.not.allocated(tp%e)) allocate(tp%e(ntp)) if (npl > 0) pl%e(:) = pack(rtemp, plmask) if (ntp > 0) tp%e(:) = pack(rtemp, tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%inc_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar inc_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%inc_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar inc_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%inc)) allocate(pl%inc(npl)) if (.not.allocated(tp%inc)) allocate(tp%inc(ntp)) if (npl > 0) pl%inc(:) = pack(rtemp, plmask) if (ntp > 0) tp%inc(:) = pack(rtemp, tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%capom_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar capom_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%capom_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar capom_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capom)) allocate(pl%capom(npl)) if (.not.allocated(tp%capom)) allocate(tp%capom(ntp)) if (npl > 0) pl%capom(:) = pack(rtemp, plmask) if (ntp > 0) tp%capom(:) = pack(rtemp, tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%omega_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar omega_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%omega_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar omega_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%omega)) allocate(pl%omega(npl)) if (.not.allocated(tp%omega)) allocate(tp%omega(ntp)) if (npl > 0) pl%omega(:) = pack(rtemp, plmask) if (ntp > 0) tp%omega(:) = pack(rtemp, tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%capm_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar capm_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%capm_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar capm_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capm)) allocate(pl%capm(npl)) if (.not.allocated(tp%capm)) allocate(tp%capm(ntp)) @@ -1251,7 +1414,8 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier end if - call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar Gmass_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%Gmass_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar Gmass_varid" ) cb%Gmass = rtemp(1) cb%mass = cb%Gmass / param%GU @@ -1270,7 +1434,8 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier end if if (param%lclose) then - call netcdf_io_check( nf90_get_var(nc%id, nc%radius_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_io_read_frame_system nf90_getvar radius_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%radius_varid, rtemp, start=[1, tslot], count=[idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar radius_varid" ) cb%radius = rtemp(1) if (npl > 0) pl%radius(:) = pack(rtemp, plmask) @@ -1281,13 +1446,15 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier cb%R0 = cb%radius if (param%lrotation) then - call netcdf_io_check( nf90_get_var(nc%id, nc%Ip_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_io_read_frame_system nf90_getvar Ip_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%Ip_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar Ip_varid" ) cb%Ip(:) = vectemp(:,1) do i = 1, NDIM if (npl > 0) pl%Ip(i,:) = pack(vectemp(i,:), plmask(:)) end do - call netcdf_io_check( nf90_get_var(nc%id, nc%rot_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_io_read_frame_system nf90_getvar rot_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%rot_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), & + "netcdf_io_read_frame_system nf90_getvar rot_varid" ) vectemp(:,:) = vectemp(:,:) * DEG2RAD cb%rot(:) = vectemp(:,1) do i = 1, NDIM @@ -1299,25 +1466,29 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier end if ! if (param%ltides) then - ! call netcdf_io_check( nf90_get_var(nc%id, nc%k2_varid, rtemp, start=[1, tslot]), "netcdf_io_read_frame_system nf90_getvar k2_varid" ) + ! call netcdf_io_check( nf90_get_var(nc%id, nc%k2_varid, rtemp, start=[1, tslot]), & + ! "netcdf_io_read_frame_system nf90_getvar k2_varid" ) ! cb%k2 = rtemp(1) ! if (npl > 0) pl%k2(:) = pack(rtemp, plmask) - ! call netcdf_io_check( nf90_get_var(nc%id, nc%Q_varid, rtemp, start=[1, tslot]), "netcdf_io_read_frame_system nf90_getvar Q_varid" ) + ! call netcdf_io_check( nf90_get_var(nc%id, nc%Q_varid, rtemp, start=[1, tslot]), & + ! "netcdf_io_read_frame_system nf90_getvar Q_varid" ) ! cb%Q = rtemp(1) ! if (npl > 0) pl%Q(:) = pack(rtemp, plmask) ! end if status = nf90_inq_varid(nc%id, nc%j2rp2_varname, nc%j2rp2_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%j2rp2_varid, cb%j2rp2, start=[tslot]), "netcdf_io_read_frame_system nf90_getvar j2rp2_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%j2rp2_varid, cb%j2rp2, start=[tslot]), & + "netcdf_io_read_frame_system nf90_getvar j2rp2_varid" ) else cb%j2rp2 = 0.0_DP end if status = nf90_inq_varid(nc%id, nc%j4rp4_varname, nc%j4rp4_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%j4rp4_varid, cb%j4rp4, start=[tslot]), "netcdf_io_read_frame_system nf90_getvar j4rp4_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%j4rp4_varid, cb%j4rp4, start=[tslot]), & + "netcdf_io_read_frame_system nf90_getvar j4rp4_varid" ) else cb%j4rp4 = 0.0_DP end if @@ -1349,8 +1520,8 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) !! author: David A. Minton !! !! Reads header information (variables that change with time, but not particle id). - !! This subroutine swiftest_significantly improves the output over the original binary file, allowing us to track energy, momentum, and other quantities that - !! previously were handled as separate output files. + !! This subroutine swiftest_significantly improves the output over the original binary file, allowing us to track energy, + !! momentum, and other quantities that previously were handled as separate output files. implicit none ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object @@ -1361,7 +1532,8 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) logical, dimension(:), allocatable :: plmask, tpmask, plmmask associate(tslot => nc%tslot) - call netcdf_io_check( nf90_get_var(nc%id, nc%time_varid, self%t, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar time_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%time_varid, self%t, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar time_varid" ) if (param%lmtiny_pl) then call nc%get_valid_masks(plmask, tpmask, plmmask, param%GMTINY) else @@ -1370,14 +1542,16 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) status = nf90_inq_varid(nc%id, nc%npl_varname, nc%npl_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar npl_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar npl_varid" ) else self%pl%nbody = count(plmask(:)) end if status = nf90_inq_varid(nc%id, nc%ntp_varname, nc%ntp_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar ntp_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar ntp_varid" ) else self%tp%nbody = count(tpmask(:)) end if @@ -1385,7 +1559,8 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) if (param%lmtiny_pl) then status = nf90_inq_varid(nc%id, nc%nplm_varname, nc%nplm_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar nplm_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar nplm_varid" ) else self%pl%nplm = count(plmmask(:)) end if @@ -1393,27 +1568,43 @@ module subroutine swiftest_io_netcdf_read_hdr_system(self, nc, param) if (param%lenergy) then status = nf90_inq_varid(nc%id, nc%ke_orb_varname, nc%KE_orb_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar KE_orb_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar KE_orb_varid" ) status = nf90_inq_varid(nc%id, nc%ke_spin_varname, nc%KE_spin_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar KE_spin_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar KE_spin_varid" ) status = nf90_inq_varid(nc%id, nc%pe_varname, nc%PE_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar PE_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar PE_varid" ) status = nf90_inq_varid(nc%id, nc%be_varname, nc%BE_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%BE_varid, self%be, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar BE_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%BE_varid, self%be, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar BE_varid" ) status = nf90_inq_varid(nc%id, nc%te_varname, nc%TE_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%TE_varid, self%te, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar TE_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%TE_varid, self%te, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar TE_varid" ) status = nf90_inq_varid(nc%id, nc%L_orbit_varname, nc%L_orbit_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_read_hdr_system nf90_getvar L_orbit_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), & + start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_read_hdr_system nf90_getvar L_orbit_varid" ) status = nf90_inq_varid(nc%id, nc%L_spin_varname, nc%L_spin_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_read_hdr_system nf90_getvar L_spin_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], & + count=[NDIM,1]), & + "netcdf_io_read_hdr_system nf90_getvar L_spin_varid" ) status = nf90_inq_varid(nc%id, nc%L_escape_varname, nc%L_escape_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1, tslot], count=[NDIM,1]), "netcdf_io_read_hdr_system nf90_getvar L_escape_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%L_escape_varid, self%L_escape(:), & + start=[1, tslot], count=[NDIM,1]), & + "netcdf_io_read_hdr_system nf90_getvar L_escape_varid" ) status = nf90_inq_varid(nc%id, nc%E_collisions_varname, nc%E_collisions_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar E_collisions_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%E_collisions_varid, self%E_collisions, & + start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar E_collisions_varid" ) status = nf90_inq_varid(nc%id, nc%E_untracked_varname, nc%E_untracked_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar E_untracked_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%E_untracked_varid, self%E_untracked, & + start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar E_untracked_varid" ) status = nf90_inq_varid(nc%id, nc%GMescape_varname, nc%GMescape_varid) - if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_read_hdr_system nf90_getvar GMescape_varid" ) + if (status == NF90_NOERR) call netcdf_io_check( nf90_get_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), & + "netcdf_io_read_hdr_system nf90_getvar GMescape_varid" ) end if end associate @@ -1428,11 +1619,13 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, !! Reads particle information metadata from file implicit none ! Arguments - class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object + class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object class(swiftest_netcdf_parameters), intent(inout) :: nc !! Parameters used to identify a particular NetCDF dataset - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - logical, dimension(:), intent(in) :: plmask !! Logical array indicating which index values belong to massive bodies - logical, dimension(:), intent(in) :: tpmask !! Logical array indicating which index values belong to test particles + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + logical, dimension(:), intent(in) :: plmask !! Logical array indicating which index values belong to massive + !! bodies + logical, dimension(:), intent(in) :: tpmask !! Logical array indicating which index values belong to test + !! particles ! Internals integer(I4B) :: i, idmax, status @@ -1470,7 +1663,7 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, tpind(:) = pack([(i, i = 1, idmax)], tpmask(:)) end if - call netcdf_io_check( nf90_get_var(nc%id, nc%id_varid, itemp), "netcdf_io_read_particle_info_system nf90_getvar id_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%id_varid, itemp), "netcdf_io_read_particle_info_system nf90_getvar id_varid") cb%id = itemp(1) pl%id(:) = pack(itemp, plmask) tp%id(:) = pack(itemp, tpmask) @@ -1478,7 +1671,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, pl%id(:) = pack([(i,i=0,idmax-1)],plmask) tp%id(:) = pack([(i,i=0,idmax-1)],tpmask) - call netcdf_io_check( nf90_get_var(nc%id, nc%name_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_io_read_particle_info_system nf90_getvar name_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%name_varid, ctemp, count=[NAMELEN, idmax]), & + "netcdf_io_read_particle_info_system nf90_getvar name_varid" ) call cb%info%set_value(name=ctemp(1)) do i = 1, npl call pl%info(i)%set_value(name=ctemp(plind(i))) @@ -1517,7 +1711,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, if (param%lclose) then status = nf90_inq_varid(nc%id, nc%origin_type_varname, nc%origin_type_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%origin_type_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_io_read_particle_info_system nf90_getvar origin_type_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%origin_type_varid, ctemp, count=[NAMELEN, idmax]), & + "netcdf_io_read_particle_info_system nf90_getvar origin_type_varid" ) else ctemp = "Initial Conditions" end if @@ -1532,7 +1727,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%origin_time_varname, nc%origin_time_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%origin_time_varid, rtemp), "netcdf_io_read_particle_info_system nf90_getvar origin_time_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%origin_time_varid, rtemp), & + "netcdf_io_read_particle_info_system nf90_getvar origin_time_varid" ) else rtemp = param%t0 end if @@ -1547,9 +1743,11 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%origin_rh_varname, nc%origin_rh_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%origin_rh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar origin_rh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%origin_rh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar origin_rh_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_get_var(nc%id, nc%rh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar rh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%rh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar rh_varid" ) else vectemp(:,:) = 0._DP end if @@ -1563,9 +1761,11 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%origin_vh_varname, nc%origin_vh_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%origin_vh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar origin_vh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%origin_vh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar origin_vh_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_get_var(nc%id, nc%vh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar vh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%vh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar vh_varid" ) else vectemp(:,:) = 0._DP end if @@ -1579,7 +1779,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%collision_id_varname, nc%collision_id_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%collision_id_varid, itemp), "netcdf_io_read_particle_info_system nf90_getvar collision_id_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%collision_id_varid, itemp), & + "netcdf_io_read_particle_info_system nf90_getvar collision_id_varid" ) do i = 1, npl call pl%info(i)%set_value(collision_id=itemp(plind(i))) end do @@ -1590,7 +1791,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%discard_time_varname, nc%discard_time_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%discard_time_varid, rtemp), "netcdf_io_read_particle_info_system nf90_getvar discard_time_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%discard_time_varid, rtemp), & + "netcdf_io_read_particle_info_system nf90_getvar discard_time_varid" ) call cb%info%set_value(discard_time=rtemp(1)) do i = 1, npl call pl%info(i)%set_value(discard_time=rtemp(plind(i))) @@ -1602,7 +1804,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%discard_rh_varname, nc%discard_rh_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%discard_rh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar discard_rh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%discard_rh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar discard_rh_varid" ) do i = 1, npl call pl%info(i)%set_value(discard_rh=vectemp(:,plind(i))) end do @@ -1613,7 +1816,8 @@ module subroutine swiftest_io_netcdf_read_particle_info_system(self, nc, param, status = nf90_inq_varid(nc%id, nc%discard_vh_varname, nc%discard_vh_varid) if (status == NF90_NOERR) then - call netcdf_io_check( nf90_get_var(nc%id, nc%discard_vh_varid, vectemp(:,:)), "netcdf_io_read_particle_info_system nf90_getvar discard_vh_varid" ) + call netcdf_io_check( nf90_get_var(nc%id, nc%discard_vh_varid, vectemp(:,:)), & + "netcdf_io_read_particle_info_system nf90_getvar discard_vh_varid" ) do i = 1, npl call pl%info(i)%set_value(discard_vh=vectemp(:,plind(i))) end do @@ -1642,7 +1846,8 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) ! Internals integer(I4B) :: i, j, idslot, old_mode, tmp integer(I4B), dimension(:), allocatable :: ind - real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs + real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting + !! from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm, varpi, lam, f, cape, capf #ifdef COARRAY integer(I4B) :: ntp @@ -1664,22 +1869,29 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) do i = 1, n j = ind(i) call nc%find_idslot(self%id(j), idslot) - !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity + ! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity if (param%lgr) call swiftest_gr_pseudovel2vel(param, self%mu(j), self%rh(:, j), self%vh(:, j), vh(:)) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call netcdf_io_check( nf90_put_var(nc%id, nc%rh_varid, self%rh(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var rh_varid" ) - if (param%lgr) then !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity - call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, vh(:), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var vh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%gr_pseudo_vh_varid, self%vh(:, j), start=[1,idslot, tslot],count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var gr_pseudo_vhx_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rh_varid, self%rh(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]),& + "netcdf_io_write_frame_body nf90_put_var rh_varid" ) + if (param%lgr) then ! Convert from pseudovelocity to heliocentric without replacing the current value of + ! pseudovelocity + call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, vh(:), start=[1,idslot, tslot], count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var vh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%gr_pseudo_vh_varid, self%vh(:, j), start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var gr_pseudo_vhx_varid" ) else - call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, self%vh(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var vh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%vh_varid, self%vh(:, j), start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var vh_varid" ) end if end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - if (param%lgr) then !! For GR-enabled runs, use the true value of velocity computed above + if (param%lgr) then ! For GR-enabled runs, use the true value of velocity computed above call swiftest_orbel_xv2el(self%mu(j), self%rh(1,j), self%rh(2,j), self%rh(3,j), & vh(1), vh(2), vh(3), & a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) @@ -1688,48 +1900,78 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) self%vh(1,j), self%vh(2,j), self%vh(3,j), & a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) end if - call netcdf_io_check( nf90_put_var(nc%id, nc%a_varid, a, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body a_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%e_varid, e, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body e_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body inc_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body capom_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body omega_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body capm_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%varpi_varid, varpi * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body varpi_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%lam_varid, lam * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body lam_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%f_varid, f * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body f_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%a_varid, a, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body a_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%e_varid, e, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body e_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body inc_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body capom_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body omega_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body capm_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%varpi_varid, varpi * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body varpi_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%lam_varid, lam * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body lam_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%f_varid, f * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body f_varid" ) if (e < 1.0_DP) then - call netcdf_io_check( nf90_put_var(nc%id, nc%cape_varid, cape * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body cape_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%cape_varid, cape * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body cape_varid" ) else if (e > 1.0_DP) then - call netcdf_io_check( nf90_put_var(nc%id, nc%cape_varid, capf * RAD2DEG, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body (capf) cape_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%cape_varid, capf * RAD2DEG, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body (capf) cape_varid" ) end if end if select type(self) class is (swiftest_pl) ! Additional output if the passed polymorphic object is a massive body - call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body Gmass_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, self%mass(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body mass_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body Gmass_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, self%mass(j), start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body mass_varid" ) if (param%lrhill_present) then - call netcdf_io_check( nf90_put_var(nc%id, nc%rhill_varid, self%rhill(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body rhill_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rhill_varid, self%rhill(j), start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body rhill_varid" ) end if - if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body radius_varid" ) + if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, self%radius(j), & + start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body radius_varid" ) if (param%lrotation) then - call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, self%Ip(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var body Ip_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, self%rot(:, j) * RAD2DEG, start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var body rotx_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, self%Ip(:, j), start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var body Ip_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, self%rot(:, j) * RAD2DEG, start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var body rotx_varid" ) end if ! if (param%ltides) then - ! call netcdf_io_check( nf90_put_var(nc%id, nc%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body k2_varid" ) - ! call netcdf_io_check( nf90_put_var(nc%id, nc%Q_varid, self%Q(j), start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body Q_varid" ) + ! call netcdf_io_check( nf90_put_var(nc%id, nc%k2_varid, self%k2(j), start=[idslot, tslot]), & + ! "netcdf_io_write_frame_body nf90_put_var body k2_varid" ) + ! call netcdf_io_check( nf90_put_var(nc%id, nc%Q_varid, self%Q(j), start=[idslot, tslot]), & + ! "netcdf_io_write_frame_body nf90_put_var body Q_varid" ) ! end if class is (swiftest_tp) - call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, 0.0_DP, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body Gmass_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, 0.0_DP, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body mass_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, 0.0_DP, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body Gmass_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, 0.0_DP, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body mass_varid" ) if (param%lrhill_present) then - call netcdf_io_check( nf90_put_var(nc%id, nc%rhill_varid, 0.0_DP, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body rhill_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rhill_varid, 0.0_DP, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body rhill_varid" ) end if - if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, 0.0_DP, start=[idslot, tslot]), "netcdf_io_write_frame_body nf90_put_var body radius_varid" ) + if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, 0.0_DP, start=[idslot, tslot]), & + "netcdf_io_write_frame_body nf90_put_var body radius_varid" ) if (param%lrotation) then - call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, [0.0_DP,0.0_DP,0.0_DP], start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var body Ip_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, [0.0_DP,0.0_DP,0.0_DP], start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_io_write_frame_body nf90_put_var body rotx_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, [0.0_DP,0.0_DP,0.0_DP], start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var body Ip_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, [0.0_DP,0.0_DP,0.0_DP], start=[1,idslot, tslot], & + count=[NDIM,1,1]), & + "netcdf_io_write_frame_body nf90_put_var body rotx_varid" ) end if end select end do @@ -1741,11 +1983,13 @@ module subroutine swiftest_io_netcdf_write_frame_body(self, nc, param) class is (swiftest_tp) call nc%get_valid_masks(plmask, tpmask) ntp = count(tpmask(:)) - call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, ntp, start=[nc%tslot]), "netcdf_io_write_frame_body nf90_put_var ntp_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, ntp, start=[nc%tslot]), & + "netcdf_io_write_frame_body nf90_put_var ntp_varid" ) end select #endif - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), "netcdf_io_write_frame_body nf90_set_fill old_mode" ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), & + "netcdf_io_write_frame_body nf90_set_fill old_mode" ) return end subroutine swiftest_io_netcdf_write_frame_body @@ -1766,23 +2010,35 @@ module subroutine swiftest_io_netcdf_write_frame_cb(self, nc, param) associate(tslot => nc%tslot) call self%write_info(nc, param) - call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), "swiftest_io_netcdf_write_frame_cb nf90_set_fill" ) + call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), & + "swiftest_io_netcdf_write_frame_cb nf90_set_fill" ) call nc%find_idslot(self%id, idslot) - call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb id_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, ACTIVE, start=[idslot, tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb id_varid" ) - - call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, self%Gmass, start=[idslot, tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb Gmass_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, self%mass, start=[idslot, tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb mass_varid" ) - if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, self%radius, start=[idslot, tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb radius_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%j2rp2_varid, self%j2rp2, start=[tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb j2rp2_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%j4rp4_varid, self%j4rp4, start=[tslot]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb j4rp4_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb id_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, ACTIVE, start=[idslot, tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb id_varid" ) + + call netcdf_io_check( nf90_put_var(nc%id, nc%Gmass_varid, self%Gmass, start=[idslot, tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb Gmass_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%mass_varid, self%mass, start=[idslot, tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb mass_varid" ) + if (param%lclose) call netcdf_io_check( nf90_put_var(nc%id, nc%radius_varid, self%radius, start=[idslot, tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb radius_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%j2rp2_varid, self%j2rp2, start=[tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb j2rp2_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%j4rp4_varid, self%j4rp4, start=[tslot]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb j4rp4_varid" ) if (param%lrotation) then - call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, self%Ip(:), start=[1, idslot, tslot], count=[NDIM,1,1]), "swiftest_io_netcdf_write_frame_cb nf90_put_var cb Ip_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, self%rot(:) * RAD2DEG, start=[1, idslot, tslot], count=[NDIM,1,1]), "swiftest_io_netcdf_write_frame_cby nf90_put_var cb rot_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%Ip_varid, self%Ip(:), start=[1, idslot, tslot], count=[NDIM,1,1]), & + "swiftest_io_netcdf_write_frame_cb nf90_put_var cb Ip_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%rot_varid, self%rot(:) * RAD2DEG, start=[1, idslot, tslot], & + count=[NDIM,1,1]), & + "swiftest_io_netcdf_write_frame_cby nf90_put_var cb rot_varid" ) end if - call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), "swiftest_io_netcdf_write_frame_cb nf90_set_fill old_mode" ) + call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp), & + "swiftest_io_netcdf_write_frame_cb nf90_set_fill old_mode" ) end associate return @@ -1818,8 +2074,8 @@ module subroutine swiftest_io_netcdf_write_hdr_system(self, nc, param) !! author: David A. Minton !! !! Writes header information (variables that change with time, but not particle id). - !! This subroutine swiftest_significantly improves the output over the original binary file, allowing us to track energy, momentum, and other quantities that - !! previously were handled as separate output files. + !! This subroutine swiftest_significantly improves the output over the original binary file, allowing us to track energy, + !! momentum, and other quantities that previously were handled as separate output files. implicit none ! Arguments class(swiftest_nbody_system), intent(in) :: self !! Swiftest nbody system object @@ -1829,25 +2085,40 @@ module subroutine swiftest_io_netcdf_write_hdr_system(self, nc, param) integer(I4B) :: tslot call nc%find_tslot(self%t, tslot) - call netcdf_io_check( nf90_put_var(nc%id, nc%time_varid, self%t, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var npl_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%time_varid, self%t, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%npl_varid, self%pl%nbody, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var npl_varid" ) #ifndef COARRAY - call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var ntp_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%ntp_varid, self%tp%nbody, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var ntp_varid" ) #endif - if (param%lmtiny_pl) call netcdf_io_check( nf90_put_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var nplm_varid" ) + if (param%lmtiny_pl) call netcdf_io_check( nf90_put_var(nc%id, nc%nplm_varid, self%pl%nplm, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var nplm_varid" ) if (param%lenergy) then - call netcdf_io_check( nf90_put_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_orb_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var KE_spin_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var PE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%BE_varid, self%be, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var BE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%TE_varid, self%te, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var TE_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_orbit_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_spin_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_io_write_hdr_system nf90_put_var L_escape_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_collisions_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var E_untracked_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_io_write_hdr_system nf90_put_var GMescape_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%KE_orb_varid, self%ke_orbit, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var KE_orb_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%KE_spin_varid, self%ke_spin, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var KE_spin_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%PE_varid, self%pe, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var PE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%BE_varid, self%be, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var BE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%TE_varid, self%te, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var TE_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_orbit_varid, self%L_orbit(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_write_hdr_system nf90_put_var L_orbit_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_spin_varid, self%L_spin(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_write_hdr_system nf90_put_var L_spin_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%L_escape_varid, self%L_escape(:), start=[1,tslot], count=[NDIM,1]), & + "netcdf_io_write_hdr_system nf90_put_var L_escape_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%E_collisions_varid, self%E_collisions, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var E_collisions_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%E_untracked_varid, self%E_untracked, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var E_untracked_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%GMescape_varid, self%GMescape, start=[tslot]), & + "netcdf_io_write_hdr_system nf90_put_var GMescape_varid" ) end if return @@ -1869,7 +2140,8 @@ module subroutine swiftest_io_netcdf_write_info_body(self, nc, param) character(len=NAMELEN) :: charstring character(len=NAMELEN), dimension(self%nbody) :: origin_type - call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), "netcdf_io_write_info_body nf90_set_fill NF90_NOFILL" ) + call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), & + "netcdf_io_write_info_body nf90_set_fill NF90_NOFILL" ) select type(self) class is (swiftest_body) @@ -1881,27 +2153,44 @@ module subroutine swiftest_io_netcdf_write_info_body(self, nc, param) do i = 1, n j = ind(i) call nc%find_idslot(self%id(j), idslot) - call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id(j), start=[idslot]), "netcdf_io_write_info_body nf90_put_var id_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, self%status(j), start=[idslot,tslot]), "netcdf_io_write_info_body nf90_put_var status_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id(j), start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var id_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%status_varid, self%status(j), start=[idslot,tslot]), & + "netcdf_io_write_info_body nf90_put_var status_varid" ) charstring = trim(adjustl(self%info(j)%name)) - call netcdf_io_check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_body nf90_put_var name_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), & + "netcdf_io_write_info_body nf90_put_var name_varid" ) charstring = trim(adjustl(self%info(j)%particle_type)) - call netcdf_io_check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_body nf90_put_var particle_type_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), & + "netcdf_io_write_info_body nf90_put_var particle_type_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info(j)%origin_type)) origin_type(i) = charstring - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_body nf90_put_var origin_type_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_io_write_info_body nf90_put_var origin_time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_rh_varid, self%info(j)%origin_rh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var origin_rh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_vh_varid, self%info(j)%origin_vh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var origin_vh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], & + count=[NAMELEN, 1]), & + "netcdf_io_write_info_body nf90_put_var origin_type_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_time_varid, self%info(j)%origin_time, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var origin_time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_rh_varid, self%info(j)%origin_rh(:), start=[1,idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var origin_rh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_vh_varid, self%info(j)%origin_vh(:), start=[1,idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var origin_vh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_io_write_info_body nf90_put_var collision_id_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_io_write_info_body nf90_put_var discard_time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_rh_varid, self%info(j)%discard_rh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var discard_rh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_vh_varid, self%info(j)%discard_vh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var discard_vh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%collision_id_varid, self%info(j)%collision_id, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var collision_id_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_time_varid, self%info(j)%discard_time, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var discard_time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_rh_varid, self%info(j)%discard_rh(:), start=[1,idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var discard_rh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_vh_varid, self%info(j)%discard_vh(:), start=[1,idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var discard_vh_varid" ) end if end do @@ -1926,30 +2215,44 @@ module subroutine swiftest_io_netcdf_write_info_cb(self, nc, param) character(len=NAMELEN) :: charstring ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables - call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), "netcdf_io_write_info_cb nf90_set_fill NF90_NOFILL" ) + call netcdf_io_check( nf90_set_fill(nc%id, NF90_NOFILL, old_mode), & + "netcdf_io_write_info_cb nf90_set_fill NF90_NOFILL" ) call nc%find_idslot(self%id, idslot) - call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), "netcdf_io_write_info_cb nf90_put_var id_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%id_varid, self%id, start=[idslot]), & + "netcdf_io_write_info_cb nf90_put_var id_varid" ) charstring = trim(adjustl(self%info%name)) - call netcdf_io_check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_cb nf90_put_var name_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), & + "netcdf_io_write_info_cb nf90_put_var name_varid" ) charstring = trim(adjustl(self%info%particle_type)) - call netcdf_io_check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_cb nf90_put_var ptype_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), & + "netcdf_io_write_info_cb nf90_put_var ptype_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info%origin_type)) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_io_write_info_body nf90_put_var cb origin_type_varid" ) - - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_io_write_info_body nf90_put_var cb origin_time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_rh_varid, self%info%origin_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb origin_rh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%origin_vh_varid, self%info%origin_vh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb origin_vh_varid" ) - - call netcdf_io_check( nf90_put_var(nc%id, nc%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_io_write_info_body nf90_put_var cb collision_id_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_io_write_info_body nf90_put_var cb discard_time_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_rh_varid, self%info%discard_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb discard_rh_varid" ) - call netcdf_io_check( nf90_put_var(nc%id, nc%discard_vh_varid, self%info%discard_vh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_io_write_info_body nf90_put_var cb discard_vh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), & + "netcdf_io_write_info_body nf90_put_var cb origin_type_varid" ) + + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_time_varid, self%info%origin_time, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var cb origin_time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_rh_varid, self%info%origin_rh(:), start=[1, idslot], count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var cb origin_rh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%origin_vh_varid, self%info%origin_vh(:), start=[1, idslot], count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var cb origin_vh_varid" ) + + call netcdf_io_check( nf90_put_var(nc%id, nc%collision_id_varid, self%info%collision_id, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var cb collision_id_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_time_varid, self%info%discard_time, start=[idslot]), & + "netcdf_io_write_info_body nf90_put_var cb discard_time_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_rh_varid, self%info%discard_rh(:), start=[1, idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var cb discard_rh_varid" ) + call netcdf_io_check( nf90_put_var(nc%id, nc%discard_vh_varid, self%info%discard_vh(:), start=[1, idslot], & + count=[NDIM,1]), & + "netcdf_io_write_info_body nf90_put_var cb discard_vh_varid" ) end if call netcdf_io_check( nf90_set_fill(nc%id, old_mode, tmp) ) @@ -1990,8 +2293,10 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i ! Arguments class(swiftest_parameters), intent(inout) :: self !! Collection of parameters integer(I4B), intent(in) :: unit !! File unit number - character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the text from the char-literal-constant, prefixed with DT. - !! If you do not include a char-literal-constant, the iotype argument contains only DT. + character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the + !! text from the char-literal-constant, prefixed with DT. + !! If you do not include a char-literal-constant, the iotype + !! argument contains only DT. character(len=*), intent(in) :: v_list(:) !! The first element passes the integrator code to the reader integer(I4B), intent(out) :: iostat !! IO status code character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0 @@ -2195,8 +2500,9 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i if (param_value == "YES" .or. param_value == 'T') param%lcoarray = .true. case("SEED") read(param_value, *) nseeds_from_file - ! Because the number of seeds can vary between compilers/systems, we need to make sure we can handle cases in which the input file has a different - ! number of seeds than the current nbody_system. If the number of seeds in the file is smaller than required, we will use them as a source to fill in the missing elements. + ! Because the number of seeds can vary between compilers/systems, we need to make sure we can handle cases in + ! which the input file has a different number of seeds than the current nbody_system. If the number of seeds in + ! the file is smaller than required, we will use them as a source to fill in the missing elements. ! If the number of seeds in the file is larger than required, we will truncate the seed array. if (nseeds_from_file > nseeds) then nseeds = nseeds_from_file @@ -2447,7 +2753,8 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i select case(param%integrator) case(INT_WHM, INT_RMVS, INT_HELIO) case default - write(iomsg, *) "Coarray-based parallelization of test particles are not compatible with this integrator. This parameter will be ignored." + write(iomsg, *) "Coarray-based parallelization of test particles are not compatible with this integrator. " & + // "This parameter will be ignored." param%lcoarray = .false. end select #else @@ -2496,7 +2803,8 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i function time_stretcher(fstep_out) result(ans) !! author: David A. Minton !! - !! Equation for the time stretchinf function. Solving the roots of this equation gives the time stretching factor for non-linear file output cadence. + !! Equation for the time stretchinf function. Solving the roots of this equation gives the time stretching factor for + !! non-linear file output cadence. implicit none ! Arguments real(DP), intent(in) :: fstep_out @@ -2524,10 +2832,12 @@ module subroutine swiftest_io_param_writer(self, unit, iotype, v_list, iostat, i !! Adapted from Martin Duncan's Swift routine io_param_restart.f implicit none ! Arguments - class(swiftest_parameters),intent(in) :: self !! Collection of parameters + class(swiftest_parameters),intent(in) :: self !! Collection of parameters integer, intent(in) :: unit !! File unit number - character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the text from the char-literal-constant, prefixed with DT. - !! If you do not include a char-literal-constant, the iotype argument contains only DT. + character(len=*), intent(in) :: iotype !! Dummy argument passed to the input/output procedure contains the + !! text from the char-literal-constant, prefixed with DT. + !! If you do not include a char-literal-constant, the iotype + !! argument contains only DT. integer, intent(in) :: v_list(:) !! Not used in this procedure integer, intent(out) :: iostat !! IO status code character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0 @@ -3207,7 +3517,7 @@ module subroutine swiftest_io_initialize_output_file_system(self, nc, param) call nc%open(param) case('NEW') if (fileExists) then - errmsg = trim(adjustl(param%outfile)) // " already exists! You must specify OUT_STAT = APPEND, REPLACE, or UNKNOWN" + errmsg = trim(adjustl(param%outfile))// " already exists! You must specify OUT_STAT = APPEND, REPLACE, or UNKNOWN" goto 667 end if call nc%initialize(param) diff --git a/version.txt b/version.txt index bb764935a..6895b410d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2023.9.3 \ No newline at end of file +2023.9.4 \ No newline at end of file From 837535b39d48459af21c1b6a60307cd406e46b2b Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 15 Sep 2023 16:19:33 -0400 Subject: [PATCH 03/77] Got rid of aarch64 build in Github actions because it's way faster to do it on my M1 than wait on the emulated GA runner --- .github/workflows/build_wheels.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a607e1741..8f2480a9a 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -12,9 +12,6 @@ jobs: matrix: os: [ubuntu-latest, macos-11, macos-12, macos-13] cibw_archs: [x86_64] - include: - - os: ubuntu-latest - cibw_archs: "aarch64" env: SYSTEM_VERSION_COMPAT: 0 From 7aed38d73ab77a47f1592019abb14c4cecd1a035 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 15 Sep 2023 16:52:32 -0400 Subject: [PATCH 04/77] Added a missing close for the log file at the end of a run --- src/swiftest/swiftest_io.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 56fa50d7f..46551788a 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -317,6 +317,7 @@ module subroutine swiftest_io_display_run_information(self, param, integration_t if (phase_val == -1) then write(param%display_unit, *)" *************** Swiftest stop " // trim(adjustl(param%integrator)) // " *************** " if (param%display_style == "COMPACT") write(*,*) "SWIFTEST STOP" // trim(adjustl(param%integrator)) + if (param%log_output) close(param%display_unit) end if #ifdef COARRAY From a2369d44b023aa4f1e39be8179ada467036b0f11 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 15 Sep 2023 16:52:47 -0400 Subject: [PATCH 05/77] Refactored test and added gr test --- tests/.gitignore | 2 +- tests/test_input_output.py | 333 -------------------------------- tests/test_swiftest.py | 380 +++++++++++++++++++++++++++++++++++++ 3 files changed, 381 insertions(+), 334 deletions(-) delete mode 100755 tests/test_input_output.py create mode 100755 tests/test_swiftest.py diff --git a/tests/.gitignore b/tests/.gitignore index bb2dc8eb5..1025d6c0a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,3 +1,3 @@ !.gitignore -!test_*.py +!swiftest_tests.py simdata/** diff --git a/tests/test_input_output.py b/tests/test_input_output.py deleted file mode 100755 index 714104d12..000000000 --- a/tests/test_input_output.py +++ /dev/null @@ -1,333 +0,0 @@ -#!/usr/bin/env python3 - -""" - Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh - This file is part of Swiftest. - Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with Swiftest. - If not, see: https://www.gnu.org/licenses. -""" - -""" -Tests that energy and momentum errors are within tolerances in a Swiftest simulation - -Input ------- - -Output ------- -None -""" - -import swiftest -import unittest -import os -import shutil -import numpy as np -from numpy.random import default_rng - -rng = default_rng(seed=123) - -major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] -param = {} - - -class TestSwiftest(unittest.TestCase): - - def test01_gen_ic(self): - """ - Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised - """ - print("\ntest_gen_ic: Test whether we can generate simulation initial conditions test") - # Files that are expected to be generated: - simdir = "simdata" - file_list = [simdir, os.path.join(simdir,"param.in"), os.path.join(simdir,"init_cond.nc")] - - sim = swiftest.Simulation() - sim.clean() -#!/usr/bin/env python3 - -""" - Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh - This file is part of Swiftest. - Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with Swiftest. - If not, see: https://www.gnu.org/licenses. -""" - -""" -Tests that energy and momentum errors are within tolerances in a Swiftest simulation - -Input ------- - -Output ------- -None -""" - -import swiftest -import unittest -import os -import shutil -import numpy as np -from numpy.random import default_rng - -rng = default_rng(seed=123) - -major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] -param = {} - - -class TestSwiftest(unittest.TestCase): - - def test01_gen_ic(self): - """ - Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised - """ - print("\ntest_gen_ic: Test whether we can generate simulation initial conditions test") - # Files that are expected to be generated: - simdir = "simdata" - file_list = [simdir, os.path.join(simdir,"param.in"), os.path.join(simdir,"init_cond.nc")] - - sim = swiftest.Simulation() - sim.clean() - - # Add the modern planets and the Sun using the JPL Horizons Database. - # Add the modern planets and the Sun using the JPL Horizons Database. - sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) - sim.save() - - for f in file_list: - self.assertTrue(os.path.exists(f)) - - def test02_read_ic(self): - """ - Tests that Swiftest is able to read a set of pre-existing initial conditions files and that they contain the correct data - """ - print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") - sim = swiftest.Simulation(read_param=True) - # Check if all names in Dataset read in from file match the expected list of names - self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") - - # Check to see if all parameter values read in from file match the expected parameters saved when generating the file - self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) - - def test03_integrators(self): - """ - Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators - """ - print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") - sim = swiftest.Simulation(read_param=True) - - # Add 10 user-defined test particles. - ntp = 10 - - name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] - a_tp = rng.uniform(0.3, 1.5, ntp) - e_tp = rng.uniform(0.0, 0.2, ntp) - inc_tp = rng.uniform(0.0, 10, ntp) - capom_tp = rng.uniform(0.0, 360.0, ntp) - omega_tp = rng.uniform(0.0, 360.0, ntp) - capm_tp = rng.uniform(0.0, 360.0, ntp) - - integrators= ["whm","helio","rmvs","symba"] - sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) - sim.set_parameter(tstart=0.0, tstop=0.02, dt=0.01, istep_out=1, dump_cadence=0) - integrators= ["whm","helio","rmvs","symba"] - for i in integrators: - try: - sim.run(integrator=i) - except: - self.fail(f"Failed with integrator {i}") - - - def test04_conservation(self): - """ - Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. - """ - print("\ntest_conservation: Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances.") - - # Error limits - L_slope_limit = 1e-10 - E_slope_limit = 1e-8 - GM_limit = 1e-14 - - sim = swiftest.Simulation() - sim.clean() - - sim.add_solar_system_body(major_bodies) - - dt = 0.01 - nout = 1000 - tstop = 1e4 - tstep_out = tstop / nout - - sim.run(tstart=0.0, tstop=tstop, dt=dt, tstep_out=tstep_out, dump_cadence=0, compute_conservation_values=True, integrator="symba") - - def fit_func(x,slope,b): - """ - Linear function for curve fitting - """ - return slope * x + b - - # Calculate the angular momentum error - sim.data['L_tot'] = sim.data['L_orbit'] + sim.data['L_spin'] + sim.data['L_escape'] - sim.data['DL'] = sim.data['L_tot'] - sim.data['L_tot'].isel(time=0) - L_error = swiftest.tool.magnitude(sim.data,'DL') / swiftest.tool.magnitude(sim.data.isel(time=0), 'L_tot') - - # Calculate the energy error - E_error = (sim.data['TE'] - sim.data['TE'].isel(time=0)) / sim.data['TE'].isel(time=0) - - # Calculate the mass error - sim.data['GMtot'] = sim.data['Gmass'].sum(dim='name',skipna=True) + sim.data['GMescape'] - GM_error = (sim.data['GMtot'] - sim.data['GMtot'].isel(time=0)) / sim.data['GMtot'].isel(time=0) - GM_final = GM_error.isel(time=-1).values - - # Compute the slope of the error vs time fit - E_fit_result = E_error.curvefit("time",fit_func) - L_fit_result = L_error.curvefit("time",fit_func) - - E_slope = E_fit_result['curvefit_coefficients'].sel(param='slope').values - L_slope = L_fit_result['curvefit_coefficients'].sel(param='slope').values - - # Print the final errors - print("\n") - print(f"Angular momentum error slope: {L_slope:.2e}/{sim.TU_name}") - print(f"Energy error slope: {E_slope:.2e}/{sim.TU_name}") - print(f"Final Mass Error: {GM_final:.2e}") - - self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") - -if __name__ == '__main__': - unittest.main() - if os.path.exists("simdir"): - shutil.rmtree("simdir") - - # Add the modern planets and the Sun using the JPL Horizons Database. - # Add the modern planets and the Sun using the JPL Horizons Database. - sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) - sim.save() - - for f in file_list: - self.assertTrue(os.path.exists(f)) - - print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") - sim = swiftest.Simulation(read_param=True) - # Check if all names in Dataset read in from file match the expected list of names - self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") - - # Check to see if all parameter values read in from file match the expected parameters saved when generating the file - self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) - - def test02_integrators(self): - """ - Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators - """ - print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") - sim = swiftest.Simulation() - sim.clean() - - # Add the modern planets and the Sun using the JPL Horizons Database. - # Add the modern planets and the Sun using the JPL Horizons Database. - sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) - sim.save() - - # Add 10 user-defined test particles. - ntp = 10 - - name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] - a_tp = rng.uniform(0.3, 1.5, ntp) - e_tp = rng.uniform(0.0, 0.2, ntp) - inc_tp = rng.uniform(0.0, 10, ntp) - capom_tp = rng.uniform(0.0, 360.0, ntp) - omega_tp = rng.uniform(0.0, 360.0, ntp) - capm_tp = rng.uniform(0.0, 360.0, ntp) - - integrators= ["helio","whm","rmvs","symba"] - sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) - sim.set_parameter(tstart=0.0, tstop=0.10, dt=0.01, istep_out=1, dump_cadence=0) - for i in integrators: - sim.run(integrator=i) - - - def test03_conservation(self): - """ - Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. - """ - print("\ntest_conservation: Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances.") - - # Error limits - L_slope_limit = 1e-10 - E_slope_limit = 1e-8 - GM_limit = 1e-14 - - sim = swiftest.Simulation() - sim.clean() - - sim.add_solar_system_body(major_bodies) - - dt = 0.01 - nout = 1000 - tstop = 1e4 - tstep_out = tstop / nout - - sim.run(tstart=0.0, tstop=tstop, dt=dt, tstep_out=tstep_out, dump_cadence=0, compute_conservation_values=True, integrator="symba") - - def fit_func(x,slope,b): - """ - Linear function for curve fitting - """ - return slope * x + b - - # Calculate the angular momentum error - sim.data['L_tot'] = sim.data['L_orbit'] + sim.data['L_spin'] + sim.data['L_escape'] - sim.data['DL'] = sim.data['L_tot'] - sim.data['L_tot'].isel(time=0) - L_error = swiftest.tool.magnitude(sim.data,'DL') / swiftest.tool.magnitude(sim.data.isel(time=0), 'L_tot') - - # Calculate the energy error - E_error = (sim.data['TE'] - sim.data['TE'].isel(time=0)) / sim.data['TE'].isel(time=0) - - # Calculate the mass error - sim.data['GMtot'] = sim.data['Gmass'].sum(dim='name',skipna=True) + sim.data['GMescape'] - GM_error = (sim.data['GMtot'] - sim.data['GMtot'].isel(time=0)) / sim.data['GMtot'].isel(time=0) - GM_final = GM_error.isel(time=-1).values - - # Compute the slope of the error vs time fit - E_fit_result = E_error.curvefit("time",fit_func) - L_fit_result = L_error.curvefit("time",fit_func) - - E_slope = E_fit_result['curvefit_coefficients'].sel(param='slope').values - L_slope = L_fit_result['curvefit_coefficients'].sel(param='slope').values - - # Print the final errors - print("\n") - print(f"Angular momentum error slope: {L_slope:.2e}/{sim.TU_name}") - print(f"Energy error slope: {E_slope:.2e}/{sim.TU_name}") - print(f"Final Mass Error: {GM_final:.2e}") - - self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") - -if __name__ == '__main__': - unittest.main() - if os.path.exists("simdir"): - shutil.rmtree("simdir") diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py new file mode 100755 index 000000000..ad15189fa --- /dev/null +++ b/tests/test_swiftest.py @@ -0,0 +1,380 @@ +#!/usr/bin/env python3 + +""" + Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +""" +Tests that energy and momentum errors are within tolerances in a Swiftest simulation + +Input +------ + +Output +------ +None +""" + +import swiftest +import unittest +import os +import shutil +import numpy as np +from numpy.random import default_rng +from astroquery.jplhorizons import Horizons +import datetime + + +rng = default_rng(seed=123) + +major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] +param = {} + + +class TestSwiftest(unittest.TestCase): + + def test01_gen_ic(self): + """ + Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised + """ + print("\ntest_gen_ic: Test whether we can generate simulation initial conditions test") + # Files that are expected to be generated: + simdir = "simdata" + file_list = [simdir, os.path.join(simdir,"param.in"), os.path.join(simdir,"init_cond.nc")] + + sim = swiftest.Simulation() + sim.clean() +#!/usr/bin/env python3 + +""" + Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +""" +Tests that energy and momentum errors are within tolerances in a Swiftest simulation + +Input +------ + +Output +------ +None +""" + +import swiftest +import unittest +import os +import shutil +import numpy as np +from numpy.random import default_rng + +rng = default_rng(seed=123) + +major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] +param = {} + + +class TestSwiftest(unittest.TestCase): + + def test01_gen_ic(self): + """ + Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised + """ + print("\ntest_gen_ic: Test whether we can generate simulation initial conditions test") + # Files that are expected to be generated: + simdir = "simdata" + file_list = [simdir, os.path.join(simdir,"param.in"), os.path.join(simdir,"init_cond.nc")] + + sim = swiftest.Simulation() + sim.clean() + + # Add the modern planets and the Sun using the JPL Horizons Database. + # Add the modern planets and the Sun using the JPL Horizons Database. + sim.add_solar_system_body(major_bodies) + + # Display the run configuration parameters. + param = sim.get_parameter(verbose=False) + sim.save() + + for f in file_list: + self.assertTrue(os.path.exists(f)) + + + def test02_read_ic(self): + """ + Tests that Swiftest is able to read a set of pre-existing initial conditions files and that they contain the correct data + """ + print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") + sim = swiftest.Simulation(read_param=True) + # Check if all names in Dataset read in from file match the expected list of names + self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") + + # Check to see if all parameter values read in from file match the expected parameters saved when generating the file + self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) + + + def test03_integrators(self): + """ + Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators + """ + print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") + sim = swiftest.Simulation(read_param=True) + + # Add 10 user-defined test particles. + ntp = 10 + + name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] + a_tp = rng.uniform(0.3, 1.5, ntp) + e_tp = rng.uniform(0.0, 0.2, ntp) + inc_tp = rng.uniform(0.0, 10, ntp) + capom_tp = rng.uniform(0.0, 360.0, ntp) + omega_tp = rng.uniform(0.0, 360.0, ntp) + capm_tp = rng.uniform(0.0, 360.0, ntp) + + integrators= ["whm","helio","rmvs","symba"] + sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) + sim.set_parameter(tstart=0.0, tstop=0.02, dt=0.01, istep_out=1, dump_cadence=0) + integrators= ["whm","helio","rmvs","symba"] + for i in integrators: + try: + sim.run(integrator=i) + except: + self.fail(f"Failed with integrator {i}") + + + def test04_conservation(self): + """ + Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. + """ + print("\ntest_conservation: Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances.") + + # Error limits + L_slope_limit = 1e-10 + E_slope_limit = 1e-8 + GM_limit = 1e-14 + + sim = swiftest.Simulation() + sim.clean() + + sim.add_solar_system_body(major_bodies) + + dt = 0.01 + nout = 1000 + tstop = 1e4 + tstep_out = tstop / nout + + sim.run(tstart=0.0, tstop=tstop, dt=dt, tstep_out=tstep_out, dump_cadence=0, compute_conservation_values=True, integrator="symba") + + def fit_func(x,slope,b): + """ + Linear function for curve fitting + """ + return slope * x + b + + # Calculate the angular momentum error + sim.data['L_tot'] = sim.data['L_orbit'] + sim.data['L_spin'] + sim.data['L_escape'] + sim.data['DL'] = sim.data['L_tot'] - sim.data['L_tot'].isel(time=0) + L_error = swiftest.tool.magnitude(sim.data,'DL') / swiftest.tool.magnitude(sim.data.isel(time=0), 'L_tot') + + # Calculate the energy error + E_error = (sim.data['TE'] - sim.data['TE'].isel(time=0)) / sim.data['TE'].isel(time=0) + + # Calculate the mass error + sim.data['GMtot'] = sim.data['Gmass'].sum(dim='name',skipna=True) + sim.data['GMescape'] + GM_error = (sim.data['GMtot'] - sim.data['GMtot'].isel(time=0)) / sim.data['GMtot'].isel(time=0) + GM_final = GM_error.isel(time=-1).values + + # Compute the slope of the error vs time fit + E_fit_result = E_error.curvefit("time",fit_func) + L_fit_result = L_error.curvefit("time",fit_func) + + E_slope = E_fit_result['curvefit_coefficients'].sel(param='slope').values + L_slope = L_fit_result['curvefit_coefficients'].sel(param='slope').values + + # Print the final errors + print("\n") + print(f"Angular momentum error slope: {L_slope:.2e}/{sim.TU_name}") + print(f"Energy error slope: {E_slope:.2e}/{sim.TU_name}") + print(f"Final Mass Error: {GM_final:.2e}") + + self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") + self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") + self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") + + + def test05_gr(self): + """ + Tests that GR is working correctly by computing the precession of Mercury's longitude of periapsis and comparing it to + values obtained from the JPL/Horizons ephemeris service + """ + print("\ntest_gr: Tests that GR is working correctly.") + + # Error limits + dvarpi_limit = 1e-3 + integrators= ["whm","helio","rmvs","symba"] + + # Initialize the simulation object as a variable. Define the directory in which the output will be placed. + sim = swiftest.Simulation(tstop=1000.0, dt=0.005, tstep_out=10.0, dump_cadence=0,general_relativity=True) + sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) + + # Get the start and end date of the simulation so we can compare with the real solar system. + start_date = sim.ephemeris_date + tstop_d = sim.param['TSTOP'] * sim.param['TU2S'] / swiftest.JD2S + + stop_date = (datetime.datetime.fromisoformat(start_date) + datetime.timedelta(days=tstop_d)).isoformat() + + #Get the ephemerides of Mercury for the same timeframe as the simulation. + obj = Horizons(id='1', location='@sun', + epochs={'start':start_date, 'stop':stop_date, + 'step':'10y'}) + el = obj.elements() + t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25 + varpi_obs = el['w'] + el['Omega'] + dvarpi_obs = np.diff(varpi_obs) / np.diff(t) + dvarpi_obs_mean = np.mean(dvarpi_obs) + + for i in integrators: + sim.run(integrator=i) + varpi_sim = sim.data['varpi'].sel(name="Mercury") + dvarpi_gr = np.diff(varpi_sim) / sim.param['tstep_out'] + dvarpi_err = np.mean(dvarpi_obs - dvarpi_gr) / dvarpi_obs_mean + self.assertLess(np.abs(dvarpi_err),msg=f'Mercury precession rate error of of {dvarpi_err:.2e} "/{sim.TU_name} higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') + + return + + +if __name__ == '__main__': + unittest.main() + if os.path.exists("simdir"): + shutil.rmtree("simdir") + + # Add the modern planets and the Sun using the JPL Horizons Database. + # Add the modern planets and the Sun using the JPL Horizons Database. + sim.add_solar_system_body(major_bodies) + + # Display the run configuration parameters. + param = sim.get_parameter(verbose=False) + sim.save() + + for f in file_list: + self.assertTrue(os.path.exists(f)) + + print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") + sim = swiftest.Simulation(read_param=True) + # Check if all names in Dataset read in from file match the expected list of names + self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") + + # Check to see if all parameter values read in from file match the expected parameters saved when generating the file + self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) + + def test02_integrators(self): + """ + Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators + """ + print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") + sim = swiftest.Simulation() + sim.clean() + + # Add the modern planets and the Sun using the JPL Horizons Database. + # Add the modern planets and the Sun using the JPL Horizons Database. + sim.add_solar_system_body(major_bodies) + + # Display the run configuration parameters. + param = sim.get_parameter(verbose=False) + sim.save() + + # Add 10 user-defined test particles. + ntp = 10 + + name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] + a_tp = rng.uniform(0.3, 1.5, ntp) + e_tp = rng.uniform(0.0, 0.2, ntp) + inc_tp = rng.uniform(0.0, 10, ntp) + capom_tp = rng.uniform(0.0, 360.0, ntp) + omega_tp = rng.uniform(0.0, 360.0, ntp) + capm_tp = rng.uniform(0.0, 360.0, ntp) + + integrators= ["helio","whm","rmvs","symba"] + sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) + sim.set_parameter(tstart=0.0, tstop=0.10, dt=0.01, istep_out=1, dump_cadence=0) + for i in integrators: + sim.run(integrator=i) + + + def test03_conservation(self): + """ + Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. + """ + print("\ntest_conservation: Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances.") + + # Error limits + L_slope_limit = 1e-10 + E_slope_limit = 1e-8 + GM_limit = 1e-14 + + sim = swiftest.Simulation() + sim.clean() + + sim.add_solar_system_body(major_bodies) + + dt = 0.01 + nout = 1000 + tstop = 1e4 + tstep_out = tstop / nout + + sim.run(tstart=0.0, tstop=tstop, dt=dt, tstep_out=tstep_out, dump_cadence=0, compute_conservation_values=True, integrator="symba") + + def fit_func(x,slope,b): + """ + Linear function for curve fitting + """ + return slope * x + b + + # Calculate the angular momentum error + sim.data['L_tot'] = sim.data['L_orbit'] + sim.data['L_spin'] + sim.data['L_escape'] + sim.data['DL'] = sim.data['L_tot'] - sim.data['L_tot'].isel(time=0) + L_error = swiftest.tool.magnitude(sim.data,'DL') / swiftest.tool.magnitude(sim.data.isel(time=0), 'L_tot') + + # Calculate the energy error + E_error = (sim.data['TE'] - sim.data['TE'].isel(time=0)) / sim.data['TE'].isel(time=0) + + # Calculate the mass error + sim.data['GMtot'] = sim.data['Gmass'].sum(dim='name',skipna=True) + sim.data['GMescape'] + GM_error = (sim.data['GMtot'] - sim.data['GMtot'].isel(time=0)) / sim.data['GMtot'].isel(time=0) + GM_final = GM_error.isel(time=-1).values + + # Compute the slope of the error vs time fit + E_fit_result = E_error.curvefit("time",fit_func) + L_fit_result = L_error.curvefit("time",fit_func) + + E_slope = E_fit_result['curvefit_coefficients'].sel(param='slope').values + L_slope = L_fit_result['curvefit_coefficients'].sel(param='slope').values + + # Print the final errors + print("\n") + print(f"Angular momentum error slope: {L_slope:.2e}/{sim.TU_name}") + print(f"Energy error slope: {E_slope:.2e}/{sim.TU_name}") + print(f"Final Mass Error: {GM_final:.2e}") + + self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") + self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") + self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") + +if __name__ == '__main__': + unittest.main() + if os.path.exists("simdir"): + shutil.rmtree("simdir") From 98edde5ee8067026739cae56ac40202814ddcf4b Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 15 Sep 2023 17:24:29 -0400 Subject: [PATCH 06/77] Fixed typo in unit test --- tests/test_swiftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index ad15189fa..8f06cae1e 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -228,7 +228,8 @@ def test05_gr(self): integrators= ["whm","helio","rmvs","symba"] # Initialize the simulation object as a variable. Define the directory in which the output will be placed. - sim = swiftest.Simulation(tstop=1000.0, dt=0.005, tstep_out=10.0, dump_cadence=0,general_relativity=True) + tstep_out = 10.0 + sim = swiftest.Simulation(tstop=1000.0, dt=0.005, tstep_out=tstep_out, dump_cadence=0,general_relativity=True) sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) # Get the start and end date of the simulation so we can compare with the real solar system. @@ -250,7 +251,7 @@ def test05_gr(self): for i in integrators: sim.run(integrator=i) varpi_sim = sim.data['varpi'].sel(name="Mercury") - dvarpi_gr = np.diff(varpi_sim) / sim.param['tstep_out'] + dvarpi_gr = np.diff(varpi_sim) / tstep_out dvarpi_err = np.mean(dvarpi_obs - dvarpi_gr) / dvarpi_obs_mean self.assertLess(np.abs(dvarpi_err),msg=f'Mercury precession rate error of of {dvarpi_err:.2e} "/{sim.TU_name} higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') From 4192711e15612c7b78c8eaf9f1609ec963ab0c77 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 15 Sep 2023 17:25:53 -0400 Subject: [PATCH 07/77] Added missing argument --- tests/test_swiftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index 8f06cae1e..e6d1cf4c9 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -253,7 +253,7 @@ def test05_gr(self): varpi_sim = sim.data['varpi'].sel(name="Mercury") dvarpi_gr = np.diff(varpi_sim) / tstep_out dvarpi_err = np.mean(dvarpi_obs - dvarpi_gr) / dvarpi_obs_mean - self.assertLess(np.abs(dvarpi_err),msg=f'Mercury precession rate error of of {dvarpi_err:.2e} "/{sim.TU_name} higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') + self.assertLess(np.abs(dvarpi_err),dvarpi_limit,msg=f'Mercury precession rate error of of {dvarpi_err:.2e} "/{sim.TU_name} higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') return From 511d0fb2c0eb0ae802d11a81fd3ec36f8fabf2c3 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 17 Sep 2023 09:39:04 -0400 Subject: [PATCH 08/77] Changed helio_gr_test.py to be executable --- examples/helio_gr_test/helio_gr_test.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 examples/helio_gr_test/helio_gr_test.py diff --git a/examples/helio_gr_test/helio_gr_test.py b/examples/helio_gr_test/helio_gr_test.py old mode 100644 new mode 100755 From 6889de2da71b813dfa7d1fd0d6c6fa82116212c8 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 17 Sep 2023 22:25:29 -0400 Subject: [PATCH 09/77] Added C flags to the compiler flags so that the cython code can get debugging flags --- CMakeLists.txt | 5 + buildscripts/install_editable_debug.sh | 15 + ...tranFlags.cmake => SetSwiftestFlags.cmake} | 264 +++++++++--------- src/CMakeLists.txt | 7 - 4 files changed, 145 insertions(+), 146 deletions(-) create mode 100755 buildscripts/install_editable_debug.sh rename cmake/Modules/{SetFortranFlags.cmake => SetSwiftestFlags.cmake} (82%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6451c20da..da029328d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,11 @@ FILE(TO_CMAKE_PATH ${PY} PY) # Set the name of the swiftest library SET(SWIFTEST_LIBRARY ${SKBUILD_PROJECT_NAME}) + +# This INCLUDE statement executes code that sets the compile flags for DEBUG, +# RELEASE, PROFILING, and TESTING. +INCLUDE(SetSwiftestFlags) + # The source for the SWIFTEST binary and have it placed in the bin folder ADD_SUBDIRECTORY(${SRC} ${CMAKE_INSTALL_BINDIR}) ADD_SUBDIRECTORY(${PY}) diff --git a/buildscripts/install_editable_debug.sh b/buildscripts/install_editable_debug.sh new file mode 100755 index 000000000..29c606257 --- /dev/null +++ b/buildscripts/install_editable_debug.sh @@ -0,0 +1,15 @@ +#!/bin/zsh +# installs an editable (local) package in debug mode +set -a +SCRIPT_DIR=$(realpath $(dirname $0)) +ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) +cd ${ROOT_DIR} +python3 -m pip install --upgrade pip --user +pip install scikit-build-core pyproject-metadata pathspec ninja --user +pip install --config-settings=editable.rebuild=true \ + --config-settings=build-dir="build/{wheel_tag}" \ + --config-settings=cmake.build-type="Debug" \ + --config-settings=cmake.args="-DUSE_SIMD=ON" \ + --config-settings=cmake.args="-DUSE_OPENMP=ON" \ + --no-build-isolation \ + -ve . --user \ No newline at end of file diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetSwiftestFlags.cmake similarity index 82% rename from cmake/Modules/SetFortranFlags.cmake rename to cmake/Modules/SetSwiftestFlags.cmake index c5514e749..e6166d787 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetSwiftestFlags.cmake @@ -46,14 +46,13 @@ ELSE() MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE not valid! ${BUILD_TYPE_MSG}") ENDIF(BT STREQUAL "RELEASE") - ######################################################### # If the compiler flags have already been set, return now ######################################################### IF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE ) RETURN () -ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fortran_FLAGS_DEBUG AND CMAKE_Fortran_FLAGS_PROFILE) +ENDIF() ######################################################################## # Determine the appropriate flags for this compiler for each build type. @@ -72,13 +71,11 @@ ENDIF () ### GENERAL FLAGS ### ##################### - # Free form IF (COMPILER_OPTIONS STREQUAL "GNU") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-ffree-form" # GNU ) - # Don't add underscores in symbols for C-compatability SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-fno-underscoring" # GNU @@ -88,12 +85,10 @@ IF (COMPILER_OPTIONS STREQUAL "GNU") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-fsignaling-nans " # GNU ) - # Allows for lines longer than 80 characters without truncation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-ffree-line-length-512" # GNU (gfortran) ) - # Sets the dialect standard SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-std=f2018" @@ -131,7 +126,6 @@ IF (NOT BUILD_SHARED_LIBS AND NOT WINOPT) SET_COMPILE_FLAG(CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS}" Fortran "-fPIC" ) - IF (COMPILER_OPTIONS STREQUAL "Intel") # Use static Intel libraries SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" @@ -141,27 +135,27 @@ IF (NOT BUILD_SHARED_LIBS AND NOT WINOPT) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-static_mpi" # Intel ) - IF (USE_OPENMP) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-qopenmp-link=static" # Intel ) ENDIF (USE_OPENMP) - ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") - # # Set GNU static libraries - # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - # Fortran "-static-libgfortran" - # ) - # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - # Fortran "-static-libgcc" - # ) - # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - # Fortran "-static-libstdc++" - # ) - # SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" - # Fortran "-static-libquadmath" - # ) + IF (NOT BUILD_SHARED_LIBS) + # Set GNU static libraries + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static-libgfortran" + ) + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static-libgcc" + ) + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static-libstdc++" + ) + SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" + Fortran "-static-libquadmath" + ) + ENDIF () IF (USE_OPENMP) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-lomp" @@ -194,55 +188,52 @@ IF (USE_SIMD) # Optimize for an old enough processor that it should run on most computers IF (WINOPT) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "/Qx${MACHINE_CODE_VALUE}" # Intel - ) - # Generate an extended set of vector functions - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + ) + # Generate an extended set of vector functions + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "/Qvecabi:cmdtarget" # Intel Windows - ) + ) ELSE () - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-x${MACHINE_CODE_VALUE}" # Intel - ) - # Generate an extended set of vector functions - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + ) + # Generate an extended set of vector functions + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-vecabi=cmdtarget" # Intel - ) + ) ENDIF () ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") SET(MACHINE_CODE_VALUE "native" CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") - # Enables OpenMP SIMD compilation when OpenMP parallelization is disabled. IF (NOT USE_OPENMP) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-fno-openmp -fopenmp-simd" # GNU - ) + ) ENDIF (NOT USE_OPENMP) IF (MACHINE_CODE_VALUE STREQUAL "Host") - SET(MACHINE_CODE_VALUE "native" CACHE STRING "native is the GNU equivalent of Host" FORCE) + SET(MACHINE_CODE_VALUE "native" CACHE STRING "native is the GNU equivalent of Host" FORCE) ENDIF () IF (APPLE) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-mtune=${MACHINE_CODE_VALUE}" - ) + ) ELSE () - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-march=${MACHINE_CODE_VALUE}" - ) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" + ) + SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" Fortran "-mtune=${MACHINE_CODE_VALUE}" - ) + ) ENDIF () - ENDIF () SET(MACHINE_CODE_VALUE ${MACHINE_CODE_VALUE} CACHE STRING "Tells the compiler which processor features it may target, including which instruction sets and optimizations it may generate.") ENDIF (USE_SIMD) - ################### ### DEBUG FLAGS ### ################### @@ -253,32 +244,35 @@ IF (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "TESTING" ) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran REQUIRED "/Od" # Intel Windows ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C REQUIRED "/0d" + ) # Turn on all warnings SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/warn:all" # Intel Windows ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "/warn:all" # Intel Windows + ) # Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/stand:f18" # Intel Windows ) - # Traceback SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/traceback" # Intel Windows ) - # Check everything SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/check:all" # Intel Windows ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "/check:all" # Intel Windows + ) # Initializes matrices/arrays with NaN values SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/Qinit:snan,arrays" # Intel Windows ) - # Does not generate an interface block for each routine in a source file SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/nogen-interfaces" # Intel Windows @@ -288,27 +282,25 @@ IF (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "TESTING" ) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/Qftz-" # Intel Windows ) - # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/fpe-all:0" # Intel Windows ) - # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/fpe:0" # Intel Windows ) - # Enables debug info SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/debug:all" # Intel Windows ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "/debug:all" # Intel Windows + ) # Disables additional interprocedural optimizations for a single file compilation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/Qip-" # Intel Windows ) - # Disables prefetch insertion optimization SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "/Qopt-prefetch-" # Intel Windows @@ -317,145 +309,166 @@ IF (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "TESTING" ) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran REQUIRED "-O0" # All compilers not on Windows ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C REQUIRED "-O0" # All compilers not on Windows + ) # Turn on all warnings SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-warn all" # Intel ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-Wall" # Intel + ) # Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-stand f18" # Intel ) - # Traceback SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-traceback" # Intel Group ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-traceback" # Intel Group + ) # Check everything SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-check all" # Intel ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-check=conversions,stack,uninit" # Intel + ) # Initializes matrices/arrays with NaN values SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-init=snan,arrays" # Intel ) - # Does not generate an interface block for each routine in a source file SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-nogen-interfaces" # Intel ) - # Does not generate aposition independent executable SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-no-pie" # Intel ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-no-pie" # Intel + ) # Does not set denormal results from floating-point calculations to zero SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-no-ftz" # Intel ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-no-ftz" # Intel + ) # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-fpe-all=0" # Intel ) - # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-fpe0" # Intel ) - # Enables debug info SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-debug all" # Intel ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-debug all" # Intel + ) # Disables additional interprocedural optimizations for a single file compilation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-no-ip" # Intel ) - # Disables prefetch insertion optimization SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran "-qno-opt-prefetch" # Intel ) - ENDIF () - ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" Fortran REQUIRED "-Og" # GNU (gfortran) ) - + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C REQUIRED "-Og" # GNU (gfortran) + ) # Turn on all warnings SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-Wall" # GNU + Fortran "-Wall" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-Wall" # GNU ) # This enables some extra warning flags that are not enabled by -Wall SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-Wextra" # GNU + Fortran "-Wextra" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-Wextra" # GNU ) - # Disable the warning that arrays may be uninitialized, which comes up due to a known bug in gfortran SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-Wno-maybe-uninitialized" # GNU + Fortran "-Wno-maybe-uninitialized" # GNU ) # Disable the warning about unused dummy arguments. These primarily occur due to interface rules for type-bound procedures used in extendable types. SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-Wno-unused-dummy-argument" # GNU + Fortran "-Wno-unused-dummy-argument" # GNU ) - # Tells the compiler to issue compile-time messages for nonstandard language elements (Fortran 2018). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fstd=f2018" # GNU + Fortran "-fstd=f2018" # GNU ) - # Traceback SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fbacktrace" # GNU (gfortran) + Fortran "-fbacktrace" # GNU (gfortran) ) - # Sanitize SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fsanitize=address, undefined" # Gnu + Fortran "-fsanitize=address, undefined" # Gnu + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-fsanitize=address, undefined" # Gnu ) - # Check everything SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fcheck=all" # GNU + Fortran "-fcheck=all" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-fcheck=all" # GNU ) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fstack-check" # GNU + Fortran "-fstack-check" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-fstack-check" # GNU ) - # Initializes matrices/arrays with NaN values SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-finit-real=snan" # GNU + Fortran "-finit-real=snan" # GNU ) - # Generates non position-independent code SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fno-PIE" # GNU + Fortran "-fno-PIE" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-fno-PIE" # GNU ) - # Enables floating-point invalid, divide-by-zero, and overflow exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-ffpe-trap=zero,overflow,underflow" # GNU + Fortran "-ffpe-trap=zero,overflow,underflow" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-ffpe-trap=zero,overflow,underflow" # GNU ) - # List of floating-point exceptions, whose flag status is printed to ERROR_UNIT when invoking STOP and ERROR STOP SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-ffpe-summary=all" # GNU + Fortran "-ffpe-summary=all" # GNU ) - SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" - Fortran "-fstack-check" # GNU + Fortran "-fstack-check" # GNU + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" + C "-fstack-check" # GNU ) ENDIF () - ENDIF () ##################### @@ -463,15 +476,20 @@ ENDIF () ##################### IF (CMAKE_BUILD_TYPE STREQUAL "TESTING" ) - # Optimizations IF (WINOPT) SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_DEBUG}" - REQUIRED "/O3" # Intel Windows + Fortran REQUIRED "/O3" # Intel Windows + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_TESTING "${CMAKE_C_FLAGS_DEBUG}" + C REQUIRED "/O3" # Intel Windows ) ELSE () SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_DEBUG}" - REQUIRED "-O3" # All compilers not on Windows + Fortran REQUIRED "-O3" # All compilers not on Windows + ) + SET_COMPILE_FLAG(CMAKE_C_FLAGS_TESTING "${CMAKE_C_FLAGS_DEBUG}" + C REQUIRED "-O3" # All compilers not on Windows ) ENDIF () ENDIF () @@ -481,47 +499,38 @@ ENDIF () ##################### # NOTE: agressive optimizations (-O3) are already turned on by default - IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") - IF (COMPILER_OPTIONS STREQUAL "Intel") IF (WINOPT) # Unroll loops SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/unroll" # Intel Windows ) - # Inline functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/Qinline" # Intel Windows ) - # Calls the Matrix Multiply library SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/Qopt-matmul" # Intel Windows ) - # Aligns a variable to a specified boundary and offset SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/align:all" # Intel Windows ) - # No floating-point exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/fp:no-except" # Intel Windows ) - # Generate fused multiply-add instructions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/Qfma" # Intel Windows ) - # Tells the compiler to link to certain libraries in the Intel oneAPI Math Kernel Library (oneMKL). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/Qmkl:cluster" # Intel Windows "/Qmkl" # Intel Windows ) - # Enables additional interprocedural optimizations for a single file compilation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "/Qip" # Intel Windows @@ -531,7 +540,6 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-unroll" # Intel ) - # Inline functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-inline" # Intel @@ -541,12 +549,10 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-qopt-matmul" # Intel ) - # Aligns a variable to a specified boundary and offset SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-align all" # Intel ) - # No floating-point exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-fp-model no-except" # Intel @@ -554,15 +560,13 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") # Generate fused multiply-add instructions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-fma" # Intel + Fortran "-fma" # Intel ) - # Tells the compiler to link to certain libraries in the Intel oneAPI Math Kernel Library (oneMKL). SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-qmkl=cluster" # Intel "-qmkl" # Intel ) - # Enables additional interprocedural optimizations for a single file compilation SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" Fortran "-ip" # Intel @@ -572,45 +576,37 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") ELSEIF(COMPILER_OPTIONS STREQUAL "GNU") # Unroll loops SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-funroll-loops" # GNU - ) - + Fortran "-funroll-loops" # GNU + ) # Inline functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "-finline-functions" # GNU - ) + Fortran "-finline-functions" # GNU + ) ENDIF () - ENDIF () ##################### ### MATH FLAGS ### ##################### IF (COMPILER_OPTIONS STREQUAL "Intel") - IF (WINOPT) # Some subroutines require more strict floating point operation optimizations for repeatability SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "/fp:precise" # Intel Windows ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "/Qprec-div" # Intel Windows ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "/Qprec-sqrt" # Intel Windows ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "/assume:protect-parens" # Intel Windows ) - # Improves floating-point precision and consistency SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "/Qprec" # Intel Windows ) - # Most subroutines can use aggressive optimization of floating point operations without problems. SET_COMPILE_FLAG(FASTMATH_FLAGS "${FASTMATH_FLAGS}" Fortran "/fp:fast" # Intel Windows @@ -620,46 +616,37 @@ IF (COMPILER_OPTIONS STREQUAL "Intel") SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-fp-module=precise" # Intel ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-prec-div" # Intel ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-prec-sqrt" # Intel ) - SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-assume protect-parens" # Intel ) - # Improves floating-point precision and consistency SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-mp1" # Intel Windows ) - # Most subroutines can use aggressive optimization of floating point operations without problems. SET_COMPILE_FLAG(FASTMATH_FLAGS "${FASTMATH_FLAGS}" Fortran "-fp-model=fast" # Intel Windows ) - ENDIF () - ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") - # Some subroutines require more strict floating point operation optimizations for repeatability SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-fno-unsafe-math-optimizations" # GNU - ) + ) # Disable transformations and optimizations that assume default floating-point rounding behavior. SET_COMPILE_FLAG(STRICTMATH_FLAGS "${STRICTMATH_FLAGS}" Fortran "-frounding-math" - ) - + ) # Most subroutines can use aggressive optimization of floating point operations without problems. SET_COMPILE_FLAG(FASTMATH_FLAGS "${FASTMATH_FLAGS}" Fortran "-ffast-math" # GNU - ) + ) ENDIF () # Debug mode always uses strict math @@ -671,7 +658,6 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}" ### PROFILE FLAGS ### ##################### IF (CMAKE_BUILD_TYPE STREQUAL "PROFILE") - IF (COMPILER_OPTIONS STREQUAL "Intel") # Enables the optimization reports to be generated IF (WINOPT) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e6c638d33..88b197744 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,10 +22,6 @@ IF (COMPILER_OPTIONS STREQUAL "Intel" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Window INCLUDE(SetMKL) ENDIF () -# This INCLUDE statement executes code that sets the compile flags for DEBUG, -# RELEASE, PROFILING, and TESTING. -INCLUDE(SetFortranFlags) - # Add the source files SET(STRICT_MATH_FILES ${SRC}/collision/collision_generate.f90 @@ -136,9 +132,6 @@ ENDIF() SET(SWIFTEST_DRIVER swiftest_driver) ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src}) -# Be sure the executable gets packaged with the wheel -#SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${SKBUILD_SCRIPTS_DIR}) - ##################################################### # Add the needed libraries ##################################################### From 97d949344508d8f41ab93b95b54414a76a8ab749 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 18 Sep 2023 07:45:42 -0400 Subject: [PATCH 10/77] Switched the editable install script to use a venv instead of a local python install --- .gitignore | 4 +++- buildscripts/install_editable_debug.sh | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8135a42d5..ea3fe2120 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,6 @@ netcdf-c-* netcdf-fortran-* zlib-* -actions-runner* \ No newline at end of file +actions-runner* + +env/** \ No newline at end of file diff --git a/buildscripts/install_editable_debug.sh b/buildscripts/install_editable_debug.sh index 29c606257..4a8a8d8cb 100755 --- a/buildscripts/install_editable_debug.sh +++ b/buildscripts/install_editable_debug.sh @@ -3,13 +3,16 @@ set -a SCRIPT_DIR=$(realpath $(dirname $0)) ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) +VENV_DIR=${ROOT_DIR}/env cd ${ROOT_DIR} -python3 -m pip install --upgrade pip --user -pip install scikit-build-core pyproject-metadata pathspec ninja --user +python3 -m venv ${VENV_DIR} +. ${VENV_DIR}/bin/activate +python3 -m pip install --upgrade pip +pip install scikit-build-core pyproject-metadata pathspec ninja pip install --config-settings=editable.rebuild=true \ --config-settings=build-dir="build/{wheel_tag}" \ --config-settings=cmake.build-type="Debug" \ --config-settings=cmake.args="-DUSE_SIMD=ON" \ --config-settings=cmake.args="-DUSE_OPENMP=ON" \ --no-build-isolation \ - -ve . --user \ No newline at end of file + -ve . \ No newline at end of file From f341a783969dd44d409067233c83b97acac25fa2 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 18 Sep 2023 09:08:04 -0400 Subject: [PATCH 11/77] Added policy statement to get rid of warning when doing a distclean --- distclean.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/distclean.cmake b/distclean.cmake index c0ce74642..19d766f08 100644 --- a/distclean.cmake +++ b/distclean.cmake @@ -12,6 +12,7 @@ # We want to start from the top of the source dir, so if we are in build # we want to start one directory up +CMAKE_POLICY(SET CMP0009 NEW) GET_FILENAME_COMPONENT(BASEDIR ${CMAKE_SOURCE_DIR} NAME) IF(${BASEDIR} STREQUAL "build") SET(TOPDIR "${CMAKE_SOURCE_DIR}/..") From ba23e4f6416a18e631193c699c69c4c8f5dbf7d1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 18 Sep 2023 11:27:07 -0400 Subject: [PATCH 12/77] Fixed issue that was causing the wrong cython executable from being called when building the editable wheel --- buildscripts/install_editable_debug.sh | 2 +- swiftest/CMakeLists.txt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/buildscripts/install_editable_debug.sh b/buildscripts/install_editable_debug.sh index 4a8a8d8cb..62abedf5d 100755 --- a/buildscripts/install_editable_debug.sh +++ b/buildscripts/install_editable_debug.sh @@ -8,7 +8,7 @@ cd ${ROOT_DIR} python3 -m venv ${VENV_DIR} . ${VENV_DIR}/bin/activate python3 -m pip install --upgrade pip -pip install scikit-build-core pyproject-metadata pathspec ninja +pip install scikit-build-core pyproject-metadata pathspec ninja cython pip install --config-settings=editable.rebuild=true \ --config-settings=build-dir="build/{wheel_tag}" \ --config-settings=cmake.build-type="Debug" \ diff --git a/swiftest/CMakeLists.txt b/swiftest/CMakeLists.txt index 1925932b4..4ffc024d8 100644 --- a/swiftest/CMakeLists.txt +++ b/swiftest/CMakeLists.txt @@ -9,7 +9,15 @@ SET(SWIFTEST_BINDINGS _bindings) -FIND_PROGRAM(CYTHON "cython") +# Find the Cython executable, but don't look in the cmake root directory (due how cmake and cython are installed on the RCAC system) +FIND_PROGRAM(CYTHON + NAMES "cython" + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_FIND_ROOT_PATH + ) +MESSAGE(STATUS "Cython executable path: ${CYTHON}") ADD_CUSTOM_COMMAND( OUTPUT "${SWIFTEST_BINDINGS}.c" DEPENDS "${SWIFTEST_BINDINGS}.pyx" From c7d49423ff7df1d20555fe8a5173320668642036 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Mon, 18 Sep 2023 12:25:19 -0400 Subject: [PATCH 13/77] Added debug arguments to cython call when in debug build type --- pyproject.toml | 1 + swiftest/CMakeLists.txt | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cf00e16ee..a66de5da9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,7 @@ build-backend = "scikit_build_core.build" cmake.args = ["-DUSE_SIMD=OFF"] sdist.include = ["src/globals/globals_module.f90.in","swiftest/*.py","swiftest/*.pyx","swiftest/*.h"] build-dir = "build/{wheel_tag}" +cmake.verbose = true [tool.cibuildwheel] test-command = "pytest {package}/tests" diff --git a/swiftest/CMakeLists.txt b/swiftest/CMakeLists.txt index 4ffc024d8..31114fd6d 100644 --- a/swiftest/CMakeLists.txt +++ b/swiftest/CMakeLists.txt @@ -18,12 +18,16 @@ FIND_PROGRAM(CYTHON NO_CMAKE_FIND_ROOT_PATH ) MESSAGE(STATUS "Cython executable path: ${CYTHON}") +SET(CYTHON_ARGS "${CMAKE_CURRENT_SOURCE_DIR}/${SWIFTEST_BINDINGS}.pyx" "--output-file" "${CMAKE_CURRENT_BINARY_DIR}/${SWIFTEST_BINDINGS}.c") +STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT) +IF (BT STREQUAL "DEBUG") + LIST(APPEND CYTHON_ARGS "--gdb") +endif () ADD_CUSTOM_COMMAND( OUTPUT "${SWIFTEST_BINDINGS}.c" DEPENDS "${SWIFTEST_BINDINGS}.pyx" VERBATIM - COMMAND "${CYTHON}" "${CMAKE_CURRENT_SOURCE_DIR}/${SWIFTEST_BINDINGS}.pyx" --output-file - "${CMAKE_CURRENT_BINARY_DIR}/${SWIFTEST_BINDINGS}.c") + COMMAND "${CYTHON}" ${CYTHON_ARGS} ) PYTHON_ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE "${CMAKE_CURRENT_BINARY_DIR}/${SWIFTEST_BINDINGS}.c" WITH_SOABI) From 42edf8c263e9efb88a0c9faf0be5b7d58a872f17 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:15:58 -0400 Subject: [PATCH 14/77] Pulled in changes from other branch --- cmake/Modules/FindNETCDF.cmake | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index 05f91e77c..cee2fabad 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -51,7 +51,6 @@ IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") ENDIF() ENDIF() -MESSAGE(STATUS "\nNETCDF_INCLUDE: $ENV{NETCDF_INCLUDE}\nNETCDF_FORTRAN_HOME: $ENV{NETCDF_FORTRAN_HOME}\n") FIND_PATH(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS @@ -66,8 +65,6 @@ FIND_PATH(NETCDF_INCLUDE_DIR REQUIRED ) -MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_INCLUDE_DIR}") - IF (BUILD_SHARED_LIBS) SET(NETCDFF "netcdff") ELSE () @@ -102,8 +99,6 @@ FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY REQUIRED ) -MESSAGE(STATUS "NetCDF-Fortran Library: ${NETCDF_FORTRAN_LIBRARY}") - IF (BUILD_SHARED_LIBS) SET(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} CACHE STRING "NetCDF Fortran library") ELSE () @@ -119,7 +114,6 @@ ELSE () REQUIRED ) - MESSAGE(STATUS "NetCDF-C Library: ${NETCDF_LIBRARY}") IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") FIND_LIBRARY(HDF5_LIBRARY NAMES ${HDF5} @@ -201,7 +195,8 @@ ELSE () # Note for posterity: When building static libraries, NETCDF_FORTRAN_LIBRARY must come *before* NETCDF_LIBRARY. Otherwise you get a bunch of "undefined reference to" errors SET(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${EXTRA_FLAGS} CACHE STRING "NetCDF Fortran and dependant static libraries") ENDIF () -MESSAGE(STATUS "NetCDF dependencies: ${NETCDF_LIBRARIES}") +MESSAGE(STATUS "NetCDF libraries: ${NETCDF_LIBRARIES}") +MESSAGE(STATUS "NetCDF include directory: ${NETCDF_INCLUDE_DIR}") SET(NETCDF_FOUND TRUE) MARK_AS_ADVANCED(NETCDF_LIBRARIES NETCDF_INCLUDE_DIR) \ No newline at end of file From 24464485d7c7a16422b7296db64728c592f823b9 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 19 Sep 2023 22:26:28 -0400 Subject: [PATCH 15/77] Updated cmake module for Windows --- CMakeLists.txt | 2 +- cmake/Modules/FindNETCDF.cmake | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da029328d..8b17c19a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ ENDIF () # Have the .mod files placed in the include folder SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod) -# Add our local modules to the module path +# Add our local modules to the module ldpath FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH) LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH}) diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index cee2fabad..91a7cf706 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -66,7 +66,11 @@ FIND_PATH(NETCDF_INCLUDE_DIR ) IF (BUILD_SHARED_LIBS) - SET(NETCDFF "netcdff") + IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + SET(NETCDFF "netcdff.dll") + ELSE () + SET(NETCDFF "netcdff") + ENDIF () ELSE () SET(NCPREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided NetCDF-C dependencies") SET(H5PREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided HDF5 dependencies") @@ -95,6 +99,7 @@ FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY ENV LD_LIBRARY_PATH PATH_SUFFIXES lib + bin ${CMAKE_LIBRARY_ARCHITECTURE} REQUIRED ) From 6cfa241f2f67126a1d41e8f0b4c3350f8d654143 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 20 Sep 2023 10:09:53 -0400 Subject: [PATCH 16/77] Updated compiler flag checks. Now use built in check_fortran_compiler_flag function and fixed Windows options --- CMakeLists.txt | 12 +++++++++--- cmake/Modules/FindOpenMP_Fortran.cmake | 2 +- cmake/Modules/SetCompileFlag.cmake | 22 ++-------------------- cmake/Modules/SetSwiftestFlags.cmake | 6 +++--- src/CMakeLists.txt | 11 +---------- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b17c19a1..adc5c9436 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,9 +91,15 @@ FILE(TO_CMAKE_PATH ${PY} PY) # Set the name of the swiftest library SET(SWIFTEST_LIBRARY ${SKBUILD_PROJECT_NAME}) - -# This INCLUDE statement executes code that sets the compile flags for DEBUG, -# RELEASE, PROFILING, and TESTING. +# Determine compiler options +IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) + MESSAGE(FATAL_ERROR "Fortran compiler does not support F90") +ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) +INCLUDE(SetParallelizationLibrary) + +IF (COMPILER_OPTIONS STREQUAL "Intel" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + INCLUDE(SetMKL) +ENDIF () INCLUDE(SetSwiftestFlags) # The source for the SWIFTEST binary and have it placed in the bin folder diff --git a/cmake/Modules/FindOpenMP_Fortran.cmake b/cmake/Modules/FindOpenMP_Fortran.cmake index 33eda8f5b..2b5b80ef4 100644 --- a/cmake/Modules/FindOpenMP_Fortran.cmake +++ b/cmake/Modules/FindOpenMP_Fortran.cmake @@ -34,7 +34,7 @@ IF (COMPILER_OPTIONS STREQUAL "Intel") ) ELSE () SET (OpenMP_Fortran_FLAG_CANDIDATES - "/Qopenmp-simd-" # Intel Windows + "/Qopenmp /Qopenmp-simd-" # Intel Windows ) ENDIF (USE_SIMD) ELSE () diff --git a/cmake/Modules/SetCompileFlag.cmake b/cmake/Modules/SetCompileFlag.cmake index 69e3526f8..f5644e266 100644 --- a/cmake/Modules/SetCompileFlag.cmake +++ b/cmake/Modules/SetCompileFlag.cmake @@ -36,6 +36,7 @@ INCLUDE(${CMAKE_ROOT}/Modules/CheckCCompilerFlag.cmake) INCLUDE(${CMAKE_ROOT}/Modules/CheckCXXCompilerFlag.cmake) +INCLUDE(${CMAKE_ROOT}/Modules/CheckFortranCompilerFlag.cmake) FUNCTION(SET_COMPILE_FLAG FLAGVAR FLAGVAL LANG) @@ -79,26 +80,7 @@ FUNCTION(SET_COMPILE_FLAG FLAGVAR FLAGVAL LANG) ELSEIF(LANG STREQUAL "CXX") CHECK_CXX_COMPILER_FLAG("${flag}" FLAG_WORKS) ELSEIF(LANG STREQUAL "Fortran") - # There is no nice function to do this for FORTRAN, so we must manually - # create a test program and check if it compiles with a given flag. - SET(TESTFILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}") - SET(TESTFILE "${TESTFILE}/CMakeTmp/testFortranFlags.f90") - FILE(WRITE "${TESTFILE}" -" -program dummyprog - i = 5 -end program dummyprog -") - TRY_COMPILE(FLAG_WORKS ${CMAKE_BINARY_DIR} ${TESTFILE} - COMPILE_DEFINITIONS "${flag}" OUTPUT_VARIABLE OUTPUT) - - # Check that the output message doesn't match any errors - FOREACH(rx ${FAIL_REGEX}) - IF("${OUTPUT}" MATCHES "${rx}") - SET(FLAG_WORKS FALSE) - ENDIF("${OUTPUT}" MATCHES "${rx}") - ENDFOREACH(rx ${FAIL_REGEX}) - + CHECK_Fortran_COMPILER_FLAG("${flag}" FLAG_WORKS) ELSE() MESSAGE(FATAL_ERROR "Unknown language in SET_COMPILE_FLAGS: ${LANG}") ENDIF(LANG STREQUAL "C") diff --git a/cmake/Modules/SetSwiftestFlags.cmake b/cmake/Modules/SetSwiftestFlags.cmake index e6166d787..470f5c210 100644 --- a/cmake/Modules/SetSwiftestFlags.cmake +++ b/cmake/Modules/SetSwiftestFlags.cmake @@ -504,11 +504,11 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") IF (WINOPT) # Unroll loops SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "/unroll" # Intel Windows + Fortran "/Qunroll" # Intel Windows ) # Inline functions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "/Qinline" # Intel Windows + Fortran "/inline" # Intel Windows ) # Calls the Matrix Multiply library SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" @@ -520,7 +520,7 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE") ) # No floating-point exceptions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" - Fortran "/fp:no-except" # Intel Windows + Fortran "/fp:except-" # Intel Windows ) # Generate fused multiply-add instructions SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88b197744..a35d9a9ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,16 +12,6 @@ set(GLOBAL_MODULE_IN ${SRC}/globals/globals_module.f90.in) set(GLOBAL_MODULE_OUT ${SRC}/globals/globals_module.f90) CONFIGURE_FILE(${GLOBAL_MODULE_IN} ${GLOBAL_MODULE_OUT}) -IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) - MESSAGE(FATAL_ERROR "Fortran compiler does not support F90") -ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90) - -INCLUDE(SetParallelizationLibrary) -INCLUDE(SetUpNetCDF) -IF (COMPILER_OPTIONS STREQUAL "Intel" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") - INCLUDE(SetMKL) -ENDIF () - # Add the source files SET(STRICT_MATH_FILES ${SRC}/collision/collision_generate.f90 @@ -136,6 +126,7 @@ ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src}) # Add the needed libraries ##################################################### # Create a library from the source files, except the driver +INCLUDE(SetUpNetCDF) ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src}) IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE) From 0cb455fd058cf5590209a52553a3d6b5efbd005d Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 20 Sep 2023 11:25:40 -0400 Subject: [PATCH 17/77] Made more changes to get the NetCDF-Fortran library finding to work without too much user intervention --- cmake/Modules/FindNETCDF.cmake | 55 ++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index 91a7cf706..4be53ace5 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -8,9 +8,48 @@ # If not, see: https://www.gnu.org/licenses. # - Finds the NetCDF libraries +# Begin searches with "typical" install locations of dependent libraries. These can be overrided in the cache or supplemented +# with environment variables +IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") + SET(NFPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "/usr/local/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + SET(NCPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "/usr/local" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "/usr/local" CACHE PATH "Location of provided zlib dependencies") + ENDIF () +ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + IF (DEFINED ENV{HOMEBREW_PREFIX}) + SET(LIBPREFIX "$ENV{HOMEBREW_PREFIX}") + ELSE () + SET(LIBPREFIX "/usr/local") + ENDIF() + + SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") + ENDIF () +ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") + LIST(SORT LIBDIRS) + LIST(GET LIBDIRS -1 LIBPREFIX) + SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + # Assumes that the dependency libraries are packaged with NetCDF-C. + FILE(GLOB LIBDIRS "C:/Program Files*/netCDF*") + LIST(SORT LIBDIRS) + LIST(GET LIBDIRS -1 LIBPREFIX) + SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") + ENDIF () +ENDIF () +MESSAGE(STATUS "NFPREFIX_DIR: ${NFPREFIX_DIR}") -SET(NFPREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided NetCDF-Fortran dependencies") -SET(NFINCLUDE_DIR "${NFPREFIX_DIR}/include" CACHE PATH "Location of provided netcdf.mod") IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") FIND_PATH(NFBIN NAMES nf-config @@ -66,15 +105,8 @@ FIND_PATH(NETCDF_INCLUDE_DIR ) IF (BUILD_SHARED_LIBS) - IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - SET(NETCDFF "netcdff.dll") - ELSE () - SET(NETCDFF "netcdff") - ENDIF () + SET(NETCDFF "netcdff") ELSE () - SET(NCPREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided NetCDF-C dependencies") - SET(H5PREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided HDF5 dependencies") - SET(ZPREFIX_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Location of provided zlib dependencies") IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") SET(NETCDFF "netcdff.lib") SET(NETCDF "netcdf.lib") @@ -92,14 +124,13 @@ ENDIF() FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY NAMES ${NETCDFF} - HINTS + PATHS ${NFPREFIX_DIR} ENV NETCDF_FORTRAN_HOME ENV NETCDF_HOME ENV LD_LIBRARY_PATH PATH_SUFFIXES lib - bin ${CMAKE_LIBRARY_ARCHITECTURE} REQUIRED ) From 11ef7a396d2f7ea6b996d49f68d07dacb1bdbcb3 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 20 Sep 2023 11:27:27 -0400 Subject: [PATCH 18/77] Removed testing message --- cmake/Modules/FindNETCDF.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF.cmake index 4be53ace5..bb69254e2 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF.cmake @@ -48,7 +48,6 @@ ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Windows") SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") ENDIF () ENDIF () -MESSAGE(STATUS "NFPREFIX_DIR: ${NFPREFIX_DIR}") IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") FIND_PATH(NFBIN From 9a628b526f4bfa676ead333707400b9da2568799 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 20 Sep 2023 16:58:55 -0400 Subject: [PATCH 19/77] Rearranged cmake files --- CMakeLists.txt | 19 +-- ...dNETCDF.cmake => FindNETCDF_Fortran.cmake} | 136 +++++------------- cmake/Modules/SetUpNetCDF.cmake | 15 -- src/CMakeLists.txt | 10 +- swiftest/CMakeLists.txt | 2 +- 5 files changed, 49 insertions(+), 133 deletions(-) rename cmake/Modules/{FindNETCDF.cmake => FindNETCDF_Fortran.cmake} (60%) delete mode 100644 cmake/Modules/SetUpNetCDF.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index adc5c9436..b55b4c73c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,12 @@ IF (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") CMAKE_POLICY(SET CMP0148 OLD) ENDIF () +# Set some options the user may choose +OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF) +OPTION(USE_OPENMP "Use OpenMP for parallelization" ON) +OPTION(USE_SIMD "Use SIMD vectorization" ON) +OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON) + INCLUDE(GNUInstallDirs) IF (SKBUILD) SET(INSTALL_BINDIR ${SKBUILD_PLATLIB_DIR}/${SKBUILD_PROJECT_NAME}) @@ -55,17 +61,13 @@ ELSE () MESSAGE(FATAL_ERROR "Compiler ${CMAKE_Fortran_COMPILER_ID} not recognized!") ENDIF () -# Set some options the user may choose -OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF) -OPTION(USE_OPENMP "Use OpenMP for parallelization" ON) -OPTION(USE_SIMD "Use SIMD vectorization" ON) -OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON) - # The following section is modified from Numpy f2py documentation IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n") ENDIF() +FIND_PACKAGE(NETCDF_FORTRAN REQUIRED) + # Ensure scikit-build modules FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED) @@ -76,13 +78,14 @@ SET(PY "${CMAKE_SOURCE_DIR}/swiftest") ##################################### # Tell how to install this executable ##################################### -IF(WIN32) +IF(CMAKE_SYSTEM_NAME STREQUAL "Windows") SET(CMAKE_INSTALL_PREFIX "C:\\Program Files\\swiftest") FILE(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX) SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path for install") ELSE() SET(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Path for install") -ENDIF(WIN32) +ENDIF() + # Make sure paths are correct for Unix or Windows style FILE(TO_CMAKE_PATH ${SRC} SRC) diff --git a/cmake/Modules/FindNETCDF.cmake b/cmake/Modules/FindNETCDF_Fortran.cmake similarity index 60% rename from cmake/Modules/FindNETCDF.cmake rename to cmake/Modules/FindNETCDF_Fortran.cmake index bb69254e2..3a0e648f5 100644 --- a/cmake/Modules/FindNETCDF.cmake +++ b/cmake/Modules/FindNETCDF_Fortran.cmake @@ -50,7 +50,7 @@ ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Windows") ENDIF () IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") - FIND_PATH(NFBIN + FIND_FILE(NFBIN NAMES nf-config HINTS NFPREFIX_DIR @@ -61,7 +61,7 @@ IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") ) IF (NFBIN) - SET(CMD "${NFBIN}/nf-config") + SET(CMD "${NFBIN}") LIST(APPEND CMD "--includedir") MESSAGE(STATUS "Searching for NetCDF-Fortran include directory using ${CMD}") EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFINCLUDE_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -74,7 +74,7 @@ IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") MESSAGE(STATUS "ERROR : ${ERR}") ENDIF () - SET(CMD "${NFBIN}/nf-config") + SET(CMD "${NFBIN}") LIST(APPEND CMD "--prefix") MESSAGE(STATUS "Searching for NetCDF-Fortran library directory using ${CMD}") EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFPREFIX_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -89,7 +89,7 @@ IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") ENDIF() ENDIF() -FIND_PATH(NETCDF_INCLUDE_DIR +FIND_PATH(NETCDF_FORTRAN_INCLUDE_DIR NAMES netcdf.mod HINTS ${NFINCLUDE_DIR} @@ -121,7 +121,7 @@ ELSE () ENDIF() ENDIF() -FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY +FIND_LIBRARY(NFLIB NAMES ${NETCDFF} PATHS ${NFPREFIX_DIR} @@ -133,105 +133,33 @@ FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY ${CMAKE_LIBRARY_ARCHITECTURE} REQUIRED ) - -IF (BUILD_SHARED_LIBS) - SET(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} CACHE STRING "NetCDF Fortran library") -ELSE () - FIND_LIBRARY(NETCDF_LIBRARY - NAMES ${NETCDF} - HINTS - ${NCPREFIX_DIR} - ENV NETCDF_HOME - ENV LD_LIBRARY_PATH +ADD_LIBRARY(NETCDF_FORTRAN_LIBRARY SHARED IMPORTED) +IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + # Get the DLL added in + FIND_FILE(NFDLL + NAMES "netcdff.dll" + HINTS + NFPREFIX_DIR + ENV NETCDF_FORTRAN_HOME + ENV PATH PATH_SUFFIXES - lib - ${CMAKE_LIBRARY_ARCHITECTURE} - REQUIRED + bin ) + SET_TARGET_PROPERTIES(NETCDF_FORTRAN_LIBRARY PROPERTIES + IMPORTED_IMPLIB "${NFLIB}" + IMPORTED_LOCATION "${NFDLL}" + INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" + ) + MESSAGE(STATUS "NetCDF-Fortran dll: ${NFDLL}") +ELSE () + SET_TARGET_PROPERTIES(NETCDF_FORTRAN_LIBRARY PROPERTIES + IMPORTED_LOCATION "${NFLIB}" + INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" + ) +ENDIF() + +MESSAGE(STATUS "NetCDF-Fortran library: ${NFLIB}") +MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_FORTRAN_INCLUDE_DIR}") - IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - FIND_LIBRARY(HDF5_LIBRARY - NAMES ${HDF5} - HINTS - ${H5PREFIX_DIR} - ENV HDF5_ROOT - ENV LD_LIBRARY_PATH - PATH_SUFFIXES - lib - ${CMAKE_LIBRARY_ARCHITECTURE} - REQUIRED - ) - - FIND_LIBRARY(HDF5_HL_LIBRARY - NAMES ${HDF5_HL} - HINTS - ${H5PREFIX_DIR} - ENV HDF5_ROOT - ENV LD_LIBRARY_PATH - PATH_SUFFIXES - lib - ${CMAKE_LIBRARY_ARCHITECTURE} - REQUIRED - ) - - FIND_LIBRARY(Z_LIBRARY - NAMES ${ZLIB} - HINTS - ${ZPREFIX_DIR} - ENV ZLIB_ROOT - ENV LD_LIBRARY_PATH - PATH_SUFFIXES - lib - ${CMAKE_LIBRARY_ARCHITECTURE} - REQUIRED - ) - - LIST(APPEND EXTRA_FLAGS ${HDF5_LIBRARY} ${HDF5_HL_LIBRARY} ${Z_LIBRARY}) - - ELSE () - FIND_PATH(NCBIN - NAMES nc-config - HINTS - ENV NETCDF_HOME - ENV PATH - PATH_SUFFIXES - bin - ) - - IF (NCBIN) # The nc-config utility is available. Parse its output for unique flags - SET(CMD "${NCBIN}/nc-config") - LIST(APPEND CMD "--libs") - LIST(APPEND CMD "--static") - MESSAGE(STATUS "NetCDF configuration command: ${CMD}") - EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE EXTRA_FLAGS ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) - IF (EXTRA_FLAGS) - SEPARATE_ARGUMENTS(EXTRA_FLAGS NATIVE_COMMAND "${EXTRA_FLAGS}") - LIST(REMOVE_DUPLICATES EXTRA_FLAGS) - LIST(FILTER EXTRA_FLAGS EXCLUDE REGEX "netcdf+") - MESSAGE(STATUS "Extra library flags: ${EXTRA_FLAGS}") - ELSE () - MESSAGE(STATUS "Cannot execute ${CMD}") - MESSAGE(STATUS "OUTPUT: ${EXTRA_FLAGS}") - MESSAGE(STATUS "RESUL : ${RES}") - MESSAGE(STATUS "ERROR : ${ERR}") - MESSAGE(FATAL_ERROR "Cannot configure NetCDF for static") - ENDIF () - ELSE () - MESSAGE(FATAL_ERROR "Cannot find nc-config") - ENDIF () - ENDIF() - - IF (DEFINED ENV{LIBS}) - STRING(STRIP "$ENV{LIBS}" LIBS) - SEPARATE_ARGUMENTS(LIBS NATIVE_COMMAND "${LIBS}") - LIST(APPEND EXTRA_FLAGS ${LIBS}) - ENDIF() - - # Note for posterity: When building static libraries, NETCDF_FORTRAN_LIBRARY must come *before* NETCDF_LIBRARY. Otherwise you get a bunch of "undefined reference to" errors - SET(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} ${EXTRA_FLAGS} CACHE STRING "NetCDF Fortran and dependant static libraries") -ENDIF () -MESSAGE(STATUS "NetCDF libraries: ${NETCDF_LIBRARIES}") -MESSAGE(STATUS "NetCDF include directory: ${NETCDF_INCLUDE_DIR}") - -SET(NETCDF_FOUND TRUE) -MARK_AS_ADVANCED(NETCDF_LIBRARIES NETCDF_INCLUDE_DIR) \ No newline at end of file +SET(NETCDF_FORTRAN_FOUND TRUE) +MARK_AS_ADVANCED(NETCDF_FORTRAN_LIBRARY NETCDF_FORTRAN_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/Modules/SetUpNetCDF.cmake b/cmake/Modules/SetUpNetCDF.cmake deleted file mode 100644 index fad06d4f5..000000000 --- a/cmake/Modules/SetUpNetCDF.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh -# This file is part of Swiftest. -# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# You should have received a copy of the GNU General Public License along with Swiftest. -# If not, see: https://www.gnu.org/licenses. - -# Find NetCDF if not already found -IF(NOT NETCDF_FOUND) - ENABLE_LANGUAGE(C) # Some libraries need a C compiler to find - FIND_PACKAGE(NETCDF REQUIRED) -ENDIF(NOT NETCDF_FOUND) - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a35d9a9ba..548ea7b83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -126,16 +126,16 @@ ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src}) # Add the needed libraries ##################################################### # Create a library from the source files, except the driver -INCLUDE(SetUpNetCDF) + ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src}) IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE) ENDIF () -TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_INCLUDE_DIR}) -TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_INCLUDE_DIR}) -TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_LIBRARIES}) -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_LIBRARIES}) +TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) +TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) +TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_LIBRARY}) +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARY}) IF(USE_OPENMP OR USE_SIMD) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") diff --git a/swiftest/CMakeLists.txt b/swiftest/CMakeLists.txt index 31114fd6d..243cf93fb 100644 --- a/swiftest/CMakeLists.txt +++ b/swiftest/CMakeLists.txt @@ -33,7 +33,7 @@ PYTHON_ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE "${CMAKE_CURRENT_BINARY_DIR}/${SW IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_BINDINGS} PROPERTY POSITION_INDEPENDENT_CODE) - TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_LIBRARIES}) + TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARY}) ELSE () TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY}) ENDIF () From 4611302da7fc7d0583e02f61f2858a418a9f2dde Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:37:25 -0400 Subject: [PATCH 20/77] More tweaks to cmake files to try to get cross-platform consistency --- cmake/Modules/FindNETCDF_Fortran.cmake | 6 +++--- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/FindNETCDF_Fortran.cmake b/cmake/Modules/FindNETCDF_Fortran.cmake index 3a0e648f5..7baec7972 100644 --- a/cmake/Modules/FindNETCDF_Fortran.cmake +++ b/cmake/Modules/FindNETCDF_Fortran.cmake @@ -121,7 +121,7 @@ ELSE () ENDIF() ENDIF() -FIND_LIBRARY(NFLIB +FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY NAMES ${NETCDFF} PATHS ${NFPREFIX_DIR} @@ -133,7 +133,7 @@ FIND_LIBRARY(NFLIB ${CMAKE_LIBRARY_ARCHITECTURE} REQUIRED ) -ADD_LIBRARY(NETCDF_FORTRAN_LIBRARY SHARED IMPORTED) +ADD_LIBRARY(NETCDF_FORTRAN_LIBRARY UNKNOWN IMPORTED PUBLIC) IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") # Get the DLL added in FIND_FILE(NFDLL @@ -158,7 +158,7 @@ ELSE () ) ENDIF() -MESSAGE(STATUS "NetCDF-Fortran library: ${NFLIB}") +MESSAGE(STATUS "NetCDF-Fortran library: ${NETCDF_FORTRAN_LIBRARY}") MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_FORTRAN_INCLUDE_DIR}") SET(NETCDF_FORTRAN_FOUND TRUE) diff --git a/pyproject.toml b/pyproject.toml index a66de5da9..de06c6ce6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ LDFLAGS="-Wl,-rpath,${ROOT_DIR}/lib -Wl,-no_compact_unwind -L${PREFIX}/lib -L${ CPATH="/usr/local/include:${PREFIX}/include:${HOMEBREW_PREFIX}/include:${ROOT_DIR}/include" CPPFLAGS="-isystem ${PREFIX}/include -isystem /usr/local/include" LIBS="-lomp" -FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" +FCFLAGS="-mmacos-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" FFFLAGS="${FCFLAGS}" CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype -arch ${ARCH}" CXXFLAGS="${CFLAGS}" From 25dd5ad05eef0aaf733c3dbd6eec8d3dc08a1785 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:38:13 -0400 Subject: [PATCH 21/77] Fixed typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b55b4c73c..4eb00d050 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n") ENDIF() -FIND_PACKAGE(NETCDF_FORTRAN REQUIRED) +FIND_PACKAGE(NETCDF_Fortran REQUIRED) # Ensure scikit-build modules FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED) From d43cab7218791b7108ab3c76f64e52bc06db94de Mon Sep 17 00:00:00 2001 From: David Minton Date: Thu, 21 Sep 2023 08:25:14 -0400 Subject: [PATCH 22/77] Started to simplify the NetCDF library methods using cmake packages instead of hand-coded library finders --- CMakeLists.txt | 9 ++++++++- src/CMakeLists.txt | 8 ++++---- swiftest/CMakeLists.txt | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eb00d050..f1004663a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,14 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n") ENDIF() -FIND_PACKAGE(NETCDF_Fortran REQUIRED) +IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") + LIST(SORT LIBDIRS) + LIST(GET LIBDIRS -1 LIBPREFIX) + SET(netCDF-Fortran_DIR "${LIBPREFIX}/lib/cmake/netCDF" CACHE PATH "Location of provided netCDF-FortranConfig.cmake file") +ENDIF () +MESSAGE(STATUS "Looking for netCDF-FortranConfig.cmake in ${netCDF-Fortran_DIR}") +FIND_PACKAGE(netCDF-Fortran REQUIRED) # Ensure scikit-build modules FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 548ea7b83..ca5e1474f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,10 +132,10 @@ IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE) ENDIF () -TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) -TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) -TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_LIBRARY}) -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARY}) +#TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) +#TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) +TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC netCDF::netcdff) +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff) IF(USE_OPENMP OR USE_SIMD) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") diff --git a/swiftest/CMakeLists.txt b/swiftest/CMakeLists.txt index 243cf93fb..37d232d87 100644 --- a/swiftest/CMakeLists.txt +++ b/swiftest/CMakeLists.txt @@ -33,7 +33,7 @@ PYTHON_ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE "${CMAKE_CURRENT_BINARY_DIR}/${SW IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_BINDINGS} PROPERTY POSITION_INDEPENDENT_CODE) - TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARY}) + TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff) ELSE () TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY}) ENDIF () From e7b86b43c80a1c80fbf7021c117f17d7041d82b7 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:04:16 -0400 Subject: [PATCH 23/77] Made significant changes to build scripts. Now use CMake to build dependencies for speed --- buildscripts/_build_getopts.sh | 8 ++++++-- buildscripts/build_dependencies.sh | 12 +----------- buildscripts/build_hdf5.sh | 29 ++++++++++++++++------------ buildscripts/build_netcdf-c.sh | 23 ++++++++++++++-------- buildscripts/build_netcdf-fortran.sh | 29 +++++++++++++++++++++++----- buildscripts/build_zlib.sh | 19 ++++++++++++++---- buildscripts/set_compilers.sh | 13 ++++++++----- pyproject.toml | 4 +++- 8 files changed, 89 insertions(+), 48 deletions(-) diff --git a/buildscripts/_build_getopts.sh b/buildscripts/_build_getopts.sh index ac9e9586b..329d39ea4 100755 --- a/buildscripts/_build_getopts.sh +++ b/buildscripts/_build_getopts.sh @@ -13,9 +13,14 @@ set -a SCRIPT_DIR=$(realpath $(dirname $0)) ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) +# Get platform and architecture +read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh) + # Parse arguments USTMT="Usage: ${0} [-d /path/to/dependency/source] [-p /prefix/path] [-m MACOSX_DEPLOYMENT_TARGET]" -MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"} +if [ $OS = "MacOSX" ]; then + MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"$(sw_vers --ProductVersion)"} +fi while getopts ":d:p:m:h" ARG; do case "${ARG}" in @@ -44,7 +49,6 @@ while getopts ":d:p:m:h" ARG; do esac done -read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh) BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build.XXXXXXXX)} PREFIX=${PREFIX:-${ROOT_DIR}} DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}} diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 8d8027aa6..ba978214c 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -16,19 +16,9 @@ SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +NPROC=$(nproc) cd $ROOT_DIR -printf "*********************************************************\n" -printf "* STARTING DEPENDENCY BUILD *\n" -printf "*********************************************************\n" -printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" -printf "Installing to ${PREFIX}\n" -printf "\n" - -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi set -e ${SCRIPT_DIR}/build_zlib.sh ${ARGS} diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index d351bd47d..98b3609a2 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -14,6 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +. ${SCRIPT_DIR}/set_compilers.sh +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi + +printf "*********************************************************\n" +printf "* STARTING DEPENDENCY BUILD *\n" +printf "*********************************************************\n" +printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" +printf "Installing to ${PREFIX}\n" +printf "\n" HDF5_VER="1_14_2" printf "*********************************************************\n" @@ -51,20 +63,13 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/hdfsrc -if [ $OS = "MacOSX" ]; then - read -r OS ARCH < <($SCRIPT_DIR/get_platform.sh) - if [ $ARCH = "arm64" ]; then - printf "Manually setting bin/config.sub to arm-apple-darwin\n" - printf "echo arm-apple-darwin" > bin/config.sub - fi -fi -COPTS="--enable-build-mode=production --enable-tests=no --enable-tools=no --disable-fortran --disable-java --disable-cxx --prefix=${PREFIX} --with-zlib=${PREFIX}" -./configure ${COPTS} -make +ZLIB_ROOT=${PREFIX} +cmake -B build -S . -G Ninja +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - make install + cmake --install build --prefix ${PREFIX} else - sudo make install + sudo cmake --install build --prefix ${PREFIX} fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 8f692fac1..addb84ec7 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -11,11 +11,21 @@ # You should have received a copy of the GNU General Public License along with Swiftest. # If not, see: https://www.gnu.org/licenses. SCRIPT_DIR=$(realpath $(dirname $0)) - set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +. ${SCRIPT_DIR}/set_compilers.sh +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi +printf "*********************************************************\n" +printf "* STARTING DEPENDENCY BUILD *\n" +printf "*********************************************************\n" +printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" +printf "Installing to ${PREFIX}\n" +printf "\n" NC_VER="4.9.2" @@ -43,15 +53,12 @@ printf "HDF5_ROOT: ${HDF5_ROOT}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-c-* -COPTS="--disable-testsets --disable-nczarr --prefix=${PREFIX}" -printf "COPTS: ${COPTS}\n" -./configure $COPTS -make && make check - +cmake -B build -S . -G Ninja +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - make install + cmake --install build --prefix ${PREFIX} else - sudo make install + sudo cmake --install build --prefix ${PREFIX} fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index aea5e71aa..42c5b6e7e 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -14,6 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +. ${SCRIPT_DIR}/set_compilers.sh +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi + +printf "*********************************************************\n" +printf "* STARTING DEPENDENCY BUILD *\n" +printf "*********************************************************\n" +printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" +printf "Installing to ${PREFIX}\n" +printf "\n" NF_VER="4.6.1" printf "*********************************************************\n" @@ -24,7 +36,8 @@ if [ ! -d ${DEPENDENCY_DIR}/netcdf-fortran-${NF_VER} ]; then [ -d ${DEPENDENCY_DIR}/netcdf-fortran-* ] && rm -rf ${DEPENDENCY_DIR}/netcdf-fortran-* curl -s -L https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v${NF_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} fi - +CFLAGS="$(nc-config --cflags) $CFLAGS" +LIBS="$(nc-config --libs) $LIBS" printf "\n" printf "*********************************************************\n" printf "* BUILDING NETCDF-FORTRAN LIBRARY *\n" @@ -38,12 +51,18 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-fortran-* -./configure --enable-large-file-tests=no --enable-static=no --enable-filter-test=no --prefix=${PREFIX} -make && make check i + +if [ $OS = "MacOSX" ]; then + netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.dylib" +else + netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.so" +fi +cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}" +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - make install + cmake --install build --prefix ${PREFIX} else - sudo make install + sudo cmake --install build --prefix ${PREFIX} fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_zlib.sh b/buildscripts/build_zlib.sh index e21b75b47..79b145eb3 100755 --- a/buildscripts/build_zlib.sh +++ b/buildscripts/build_zlib.sh @@ -14,7 +14,18 @@ SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +. ${SCRIPT_DIR}/set_compilers.sh +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi +printf "*********************************************************\n" +printf "* STARTING DEPENDENCY BUILD *\n" +printf "*********************************************************\n" +printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" +printf "Installing to ${PREFIX}\n" +printf "\n" ZLIB_VER="1.3" @@ -40,12 +51,12 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/zlib-* -./configure --prefix=${PREFIX} -make +cmake -B build -S . -G Ninja +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - make install + cmake --install build --prefix ${PREFIX} else - sudo make install + sudo cmake --install build --prefix ${PREFIX} fi if [ $? -ne 0 ]; then diff --git a/buildscripts/set_compilers.sh b/buildscripts/set_compilers.sh index 7523628ee..85495b40d 100755 --- a/buildscripts/set_compilers.sh +++ b/buildscripts/set_compilers.sh @@ -13,9 +13,8 @@ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with Swiftest. # If not, see: https://www.gnu.org/licenses. -# Parse arguments case "$OS" in - Linux|MacOSX) + Linux|MacOSX|Intel) ;; *) echo "Unknown compiler type: $OS" @@ -25,7 +24,6 @@ case "$OS" in ;; esac - set -a # Only replace compiler definitions if they are not already set case $OS in @@ -51,6 +49,12 @@ case $OS in RANLIB=${COMPILER_PREFIX}/bin/ranlib LDFLAGS="-Wl,-no_compact_unwind" ;; + Intel) + FC=$(command -v ifx) + CC=$(command -v icx) + CXX=$(command -v icpx) + CPP=$(command -v cpp) + ;; *) printf "Unknown compiler type: ${OS}\n" echo "Valid options are Intel, Linux, or MacOSX" @@ -59,5 +63,4 @@ case $OS in ;; esac F77=${FC} - -printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n\n" \ No newline at end of file +F95=${FC} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index de06c6ce6..b0571eaff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,11 +93,12 @@ CPP="/usr/bin/cpp" AR="/usr/bin/ar" NM="/usr/bin/nm" RANLIB="/usr/bin/ranlib" +netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ "brew install coreutils", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}" + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] @@ -110,6 +111,7 @@ NETCDF_FORTRAN_HOME="/usr/local" NETCDF_INCLUDE="/usr/local/include" LD_LIBRARY_PATH="/usr/local/lib:/project/lib" CPATH="/usr/local/include:/project/include" +netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [[tool.scikit-build.generate]] path = "version.txt" From 00a49854eda8914a30fcf5c304ec9d0c351d3ff4 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:37:00 -0400 Subject: [PATCH 24/77] Fixed the prefix path in the build scripts --- buildscripts/build_hdf5.sh | 6 +++--- buildscripts/build_netcdf-c.sh | 6 +++--- buildscripts/build_netcdf-fortran.sh | 6 +++--- buildscripts/build_zlib.sh | 6 +++--- pyproject.toml | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 98b3609a2..f6c5a2938 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -64,12 +64,12 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/hdfsrc ZLIB_ROOT=${PREFIX} -cmake -B build -S . -G Ninja +cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - cmake --install build --prefix ${PREFIX} + cmake --install build else - sudo cmake --install build --prefix ${PREFIX} + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index addb84ec7..91be2b04c 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -53,12 +53,12 @@ printf "HDF5_ROOT: ${HDF5_ROOT}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-c-* -cmake -B build -S . -G Ninja +cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - cmake --install build --prefix ${PREFIX} + cmake --install build else - sudo cmake --install build --prefix ${PREFIX} + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 42c5b6e7e..8214ed8fe 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -57,12 +57,12 @@ if [ $OS = "MacOSX" ]; then else netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.so" fi -cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}" +cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}" -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - cmake --install build --prefix ${PREFIX} + cmake --install build else - sudo cmake --install build --prefix ${PREFIX} + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_zlib.sh b/buildscripts/build_zlib.sh index 79b145eb3..93275a8e8 100755 --- a/buildscripts/build_zlib.sh +++ b/buildscripts/build_zlib.sh @@ -51,12 +51,12 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/zlib-* -cmake -B build -S . -G Ninja +cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - cmake --install build --prefix ${PREFIX} + cmake --install build else - sudo cmake --install build --prefix ${PREFIX} + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/pyproject.toml b/pyproject.toml index b0571eaff..790bd6e11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,7 +98,7 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ "brew install coreutils", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] From 58b7997a52a020aec542336914b14421042ce992 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:41:49 -0400 Subject: [PATCH 25/77] Added Ninja to the linux build --- buildscripts/build_dependencies.sh | 19 +++++++++++++++++++ pyproject.toml | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index ba978214c..704aa1e28 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -19,6 +19,25 @@ ARGS=$@ NPROC=$(nproc) cd $ROOT_DIR +NINJA_VER="1.11.1" + +printf "*********************************************************\n" +printf "* FETCHING NINJA SOURCE *\n" +printf "*********************************************************\n" +printf "Copying files to ${DEPENDENCY_DIR}\n" +mkdir -p ${DEPENDENCY_DIR} +if [ ! -d ${DEPENDENCY_DIR}/ninja-${NINJA_VER} ]; then + [ -d ${DEPENDENCY_DIR}/zlib-* ] && rm -rf ${DEPENDENCY_DIR}/zlib-* + curl -L https://github.com/ninja-build/ninja/archive/refs/tags/v${NINJA_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} +fi +cd ${DEPENDENCY_DIR}/ninja-* +cmake -B build -S . -DCMAKE_INSTALL_PREFIX=${PREFIX} +cmake --build build +if [ -w ${PREFIX} ]; then + cmake --install build +else + sudo cmake --install build +fi set -e ${SCRIPT_DIR}/build_zlib.sh ${ARGS} diff --git a/pyproject.toml b/pyproject.toml index 790bd6e11..e10f0aadf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,12 +98,14 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ "brew install coreutils", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}" + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${TMPDIR}/build -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", + "wget https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip", + "unzip ninja-linux.zip -d /usr/local/bin", "buildscripts/build_dependencies.sh -p /usr/local" ] [tool.cibuildwheel.linux.environment] From e16b9c8309d83d7e2316c2d05eea201479c765d1 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:53:45 -0400 Subject: [PATCH 26/77] Adjustments to netcdf-fortran build script to to get working in cibuildwheel --- buildscripts/build_netcdf-fortran.sh | 5 +++-- pyproject.toml | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 8214ed8fe..283e9aa66 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -52,10 +52,11 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-fortran-* +NCLIBDIR=$(${PREFIX}/bin/nc-config --libdir) if [ $OS = "MacOSX" ]; then - netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.dylib" + netCDF_LIBRARIES="${NCLIBDIR}/ibnetcdf.dylib" else - netCDF_LIBRARIES="${PREFIX}/lib/libnetcdf.so" + netCDF_LIBRARIES="${NCLIBDIR}/libnetcdf.so" fi cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}" -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} diff --git a/pyproject.toml b/pyproject.toml index e10f0aadf..80fd491eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,8 +104,6 @@ before-all = [ [tool.cibuildwheel.linux] before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", - "wget https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip", - "unzip ninja-linux.zip -d /usr/local/bin", "buildscripts/build_dependencies.sh -p /usr/local" ] [tool.cibuildwheel.linux.environment] From 4f5973c1596d7bf494a7ada127d74f46eb01c3f2 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:58:29 -0400 Subject: [PATCH 27/77] More changes to get the cibuildwheel linux to work --- .github/workflows/build_wheels.yml | 3 +++ pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 8f2480a9a..a607e1741 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -12,6 +12,9 @@ jobs: matrix: os: [ubuntu-latest, macos-11, macos-12, macos-13] cibw_archs: [x86_64] + include: + - os: ubuntu-latest + cibw_archs: "aarch64" env: SYSTEM_VERSION_COMPAT: 0 diff --git a/pyproject.toml b/pyproject.toml index 80fd491eb..28a89269d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,7 +111,7 @@ NETCDF_FORTRAN_HOME="/usr/local" NETCDF_INCLUDE="/usr/local/include" LD_LIBRARY_PATH="/usr/local/lib:/project/lib" CPATH="/usr/local/include:/project/include" -netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" +netCDF-Fortran_DIR="${PREFIX}/lib64/cmake/netCDF" [[tool.scikit-build.generate]] path = "version.txt" From bca834e18293d93fc622be0c1fbe6a439b7a5b50 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:01:10 -0400 Subject: [PATCH 28/77] fixed bad environment variable --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 28a89269d..a18e44fb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,7 +111,7 @@ NETCDF_FORTRAN_HOME="/usr/local" NETCDF_INCLUDE="/usr/local/include" LD_LIBRARY_PATH="/usr/local/lib:/project/lib" CPATH="/usr/local/include:/project/include" -netCDF-Fortran_DIR="${PREFIX}/lib64/cmake/netCDF" +netCDF-Fortran_DIR="/usr/local/lib64/cmake/netCDF" [[tool.scikit-build.generate]] path = "version.txt" From 0adbccfe6de9fe85759fd9c0739c1db6442e6fab Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:10:06 -0400 Subject: [PATCH 29/77] Changes to get the macos build working again --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a18e44fb2..8be59d57a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ build-verbosity = 1 [tool.cibuildwheel.macos.environment] ROOT_DIR="$(pwd)" MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion)" -PREFIX="${ROOT_DIR}" +PREFIX="/usr/local" HOMEBREW_PREFIX="$(brew --prefix)" ARCH="$(uname -m)" LD_LIBRARY_PATH="/usr/local/lib:${PREFIX}/lib:${HOMEBREW_PREFIX}/lib" @@ -98,7 +98,7 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ "brew install coreutils", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${TMPDIR}/build -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" + "LIBS=\"\" sudo buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] @@ -109,7 +109,7 @@ before-all = [ [tool.cibuildwheel.linux.environment] NETCDF_FORTRAN_HOME="/usr/local" NETCDF_INCLUDE="/usr/local/include" -LD_LIBRARY_PATH="/usr/local/lib:/project/lib" +LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/project/lib" CPATH="/usr/local/include:/project/include" netCDF-Fortran_DIR="/usr/local/lib64/cmake/netCDF" From 89b21681e7532cbd2d1fbcf01b9126adb6a867c4 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:36:44 -0400 Subject: [PATCH 30/77] Added HDF5 library to link stage --- CMakeLists.txt | 1 + src/CMakeLists.txt | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1004663a..0e8d4b256 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") ENDIF () MESSAGE(STATUS "Looking for netCDF-FortranConfig.cmake in ${netCDF-Fortran_DIR}") FIND_PACKAGE(netCDF-Fortran REQUIRED) +FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED) # Ensure scikit-build modules FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca5e1474f..925d70005 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,10 +132,8 @@ IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE) ENDIF () -#TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) -#TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_FORTRAN_INCLUDE_DIR}) -TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC netCDF::netcdff) -TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff) +TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC netCDF::netcdff HDF5::HDF5) +TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff HDF5::HDF5) IF(USE_OPENMP OR USE_SIMD) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ") From 311e667b07bdf4b2f287be3c43ee8b5a518b708f Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:43:42 -0400 Subject: [PATCH 31/77] fixed typos in build scripts --- buildscripts/build_netcdf-fortran.sh | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 283e9aa66..fbbd3930a 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -54,7 +54,7 @@ cd ${DEPENDENCY_DIR}/netcdf-fortran-* NCLIBDIR=$(${PREFIX}/bin/nc-config --libdir) if [ $OS = "MacOSX" ]; then - netCDF_LIBRARIES="${NCLIBDIR}/ibnetcdf.dylib" + netCDF_LIBRARIES="${NCLIBDIR}/libnetcdf.dylib" else netCDF_LIBRARIES="${NCLIBDIR}/libnetcdf.so" fi diff --git a/pyproject.toml b/pyproject.toml index 8be59d57a..d80530429 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,7 +98,7 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ "brew install coreutils", - "LIBS=\"\" sudo buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] From d4c8dcbce6b61a7b82ba579c7077d0b6f0c22440 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:17:23 -0400 Subject: [PATCH 32/77] Major update to build scripts. Now use CMake for all dependencies and attempted to simplify the FindNETCDF_Fortran package finder --- CMakeFiles/3.27.0/CMakeCCompiler.cmake | 74 +++++ CMakeFiles/3.27.0/CMakeFortranCompiler.cmake | 64 ++++ CMakeFiles/3.27.0/CMakeSystem.cmake | 15 + CMakeLists.txt | 9 +- buildscripts/build_dependencies.sh | 44 +-- buildscripts/build_hdf5.sh | 40 ++- buildscripts/build_libaec.sh | 69 +++++ buildscripts/build_netcdf-c.sh | 21 +- buildscripts/build_netcdf-fortran.sh | 13 +- buildscripts/set_environment.sh | 7 +- cmake/Modules/FindNETCDF_Fortran.cmake | 290 ++++++++++--------- pyproject.toml | 10 +- 12 files changed, 473 insertions(+), 183 deletions(-) create mode 100644 CMakeFiles/3.27.0/CMakeCCompiler.cmake create mode 100644 CMakeFiles/3.27.0/CMakeFortranCompiler.cmake create mode 100644 CMakeFiles/3.27.0/CMakeSystem.cmake create mode 100755 buildscripts/build_libaec.sh diff --git a/CMakeFiles/3.27.0/CMakeCCompiler.cmake b/CMakeFiles/3.27.0/CMakeCCompiler.cmake new file mode 100644 index 000000000..a1b553d9c --- /dev/null +++ b/CMakeFiles/3.27.0/CMakeCCompiler.cmake @@ -0,0 +1,74 @@ +set(CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang") +set(CMAKE_C_COMPILER_ARG1 "") +set(CMAKE_C_COMPILER_ID "AppleClang") +set(CMAKE_C_COMPILER_VERSION "15.0.0.15000040") +set(CMAKE_C_COMPILER_VERSION_INTERNAL "") +set(CMAKE_C_COMPILER_WRAPPER "") +set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "17") +set(CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT "ON") +set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert;c_std_17;c_std_23") +set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") +set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") +set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") +set(CMAKE_C17_COMPILE_FEATURES "c_std_17") +set(CMAKE_C23_COMPILE_FEATURES "c_std_23") + +set(CMAKE_C_PLATFORM_ID "Darwin") +set(CMAKE_C_SIMULATE_ID "") +set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU") +set(CMAKE_C_SIMULATE_VERSION "") + + + + +set(CMAKE_AR "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar") +set(CMAKE_C_COMPILER_AR "") +set(CMAKE_RANLIB "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib") +set(CMAKE_C_COMPILER_RANLIB "") +set(CMAKE_LINKER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld") +set(CMAKE_MT "") +set(CMAKE_TAPI "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/tapi") +set(CMAKE_COMPILER_IS_GNUCC ) +set(CMAKE_C_COMPILER_LOADED 1) +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_C_ABI_COMPILED TRUE) + +set(CMAKE_C_COMPILER_ENV_VAR "CC") + +set(CMAKE_C_COMPILER_ID_RUN 1) +set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) +set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_C_LINKER_PREFERENCE 10) +set(CMAKE_C_LINKER_DEPFILE_SUPPORTED FALSE) + +# Save compiler ABI information. +set(CMAKE_C_SIZEOF_DATA_PTR "8") +set(CMAKE_C_COMPILER_ABI "") +set(CMAKE_C_BYTE_ORDER "LITTLE_ENDIAN") +set(CMAKE_C_LIBRARY_ARCHITECTURE "") + +if(CMAKE_C_SIZEOF_DATA_PTR) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_C_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") +endif() + +if(CMAKE_C_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "") +endif() + +set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") +if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) + set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") +endif() + + + + + +set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/local/include;/opt/homebrew/include;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include;/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include") +set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") +set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/local/lib;/opt/homebrew/lib") +set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/CMakeFiles/3.27.0/CMakeFortranCompiler.cmake b/CMakeFiles/3.27.0/CMakeFortranCompiler.cmake new file mode 100644 index 000000000..12e12ebd9 --- /dev/null +++ b/CMakeFiles/3.27.0/CMakeFortranCompiler.cmake @@ -0,0 +1,64 @@ +set(CMAKE_Fortran_COMPILER "/opt/homebrew/bin/gfortran-12") +set(CMAKE_Fortran_COMPILER_ARG1 "") +set(CMAKE_Fortran_COMPILER_ID "GNU") +set(CMAKE_Fortran_COMPILER_VERSION "12.3.0") +set(CMAKE_Fortran_COMPILER_WRAPPER "") +set(CMAKE_Fortran_PLATFORM_ID "") +set(CMAKE_Fortran_SIMULATE_ID "") +set(CMAKE_Fortran_COMPILER_FRONTEND_VARIANT "GNU") +set(CMAKE_Fortran_SIMULATE_VERSION "") + + +set(CMAKE_Fortran_COMPILER_SYSROOT "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr") +set(CMAKE_COMPILER_SYSROOT "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr") + +set(CMAKE_AR "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar") +set(CMAKE_Fortran_COMPILER_AR "/opt/homebrew/bin/gcc-ar-12") +set(CMAKE_RANLIB "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib") +set(CMAKE_TAPI "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/tapi") +set(CMAKE_Fortran_COMPILER_RANLIB "/opt/homebrew/bin/gcc-ranlib-12") +set(CMAKE_COMPILER_IS_GNUG77 1) +set(CMAKE_Fortran_COMPILER_LOADED 1) +set(CMAKE_Fortran_COMPILER_WORKS TRUE) +set(CMAKE_Fortran_ABI_COMPILED TRUE) + +set(CMAKE_Fortran_COMPILER_ENV_VAR "FC") + +set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) + +set(CMAKE_Fortran_COMPILER_ID_RUN 1) +set(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;fpp;FPP;f77;F77;f90;F90;for;For;FOR;f95;F95;f03;F03;f08;F08) +set(CMAKE_Fortran_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_Fortran_LINKER_PREFERENCE 20) +set(CMAKE_Fortran_LINKER_DEPFILE_SUPPORTED FALSE) +if(UNIX) + set(CMAKE_Fortran_OUTPUT_EXTENSION .o) +else() + set(CMAKE_Fortran_OUTPUT_EXTENSION .obj) +endif() + +# Save compiler ABI information. +set(CMAKE_Fortran_SIZEOF_DATA_PTR "8") +set(CMAKE_Fortran_COMPILER_ABI "") +set(CMAKE_Fortran_LIBRARY_ARCHITECTURE "") + +if(CMAKE_Fortran_SIZEOF_DATA_PTR AND NOT CMAKE_SIZEOF_VOID_P) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_Fortran_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_Fortran_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_Fortran_COMPILER_ABI}") +endif() + +if(CMAKE_Fortran_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "") +endif() + + +set(CMAKE_Fortran_SYSROOT_FLAG "-isysroot") +set(CMAKE_Fortran_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=") + +set(CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES "/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc/aarch64-apple-darwin22/12/finclude;/usr/local/include;/opt/homebrew/include;/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc/aarch64-apple-darwin22/12/include;/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc/aarch64-apple-darwin22/12/include-fixed;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include") +set(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "gfortran;emutls_w;gcc;quadmath;emutls_w;gcc;gcc") +set(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "/usr/local/lib;/opt/homebrew/lib;/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc/aarch64-apple-darwin22/12;/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc;/opt/homebrew/Cellar/gcc@12/12.3.0/lib/gcc/12") +set(CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/CMakeFiles/3.27.0/CMakeSystem.cmake b/CMakeFiles/3.27.0/CMakeSystem.cmake new file mode 100644 index 000000000..ac5601a0f --- /dev/null +++ b/CMakeFiles/3.27.0/CMakeSystem.cmake @@ -0,0 +1,15 @@ +set(CMAKE_HOST_SYSTEM "Darwin-22.6.0") +set(CMAKE_HOST_SYSTEM_NAME "Darwin") +set(CMAKE_HOST_SYSTEM_VERSION "22.6.0") +set(CMAKE_HOST_SYSTEM_PROCESSOR "arm64") + + + +set(CMAKE_SYSTEM "Darwin-22.6.0") +set(CMAKE_SYSTEM_NAME "Darwin") +set(CMAKE_SYSTEM_VERSION "22.6.0") +set(CMAKE_SYSTEM_PROCESSOR "arm64") + +set(CMAKE_CROSSCOMPILING "FALSE") + +set(CMAKE_SYSTEM_LOADED 1) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e8d4b256..ee14a5b37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,14 +66,7 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n") ENDIF() -IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") - LIST(SORT LIBDIRS) - LIST(GET LIBDIRS -1 LIBPREFIX) - SET(netCDF-Fortran_DIR "${LIBPREFIX}/lib/cmake/netCDF" CACHE PATH "Location of provided netCDF-FortranConfig.cmake file") -ENDIF () -MESSAGE(STATUS "Looking for netCDF-FortranConfig.cmake in ${netCDF-Fortran_DIR}") -FIND_PACKAGE(netCDF-Fortran REQUIRED) +FIND_PACKAGE(NETCDF_Fortran REQUIRED) FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED) # Ensure scikit-build modules diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 704aa1e28..11e3bdbdc 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -16,30 +16,34 @@ SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} -NPROC=$(nproc) - +set -e cd $ROOT_DIR -NINJA_VER="1.11.1" -printf "*********************************************************\n" -printf "* FETCHING NINJA SOURCE *\n" -printf "*********************************************************\n" -printf "Copying files to ${DEPENDENCY_DIR}\n" -mkdir -p ${DEPENDENCY_DIR} -if [ ! -d ${DEPENDENCY_DIR}/ninja-${NINJA_VER} ]; then - [ -d ${DEPENDENCY_DIR}/zlib-* ] && rm -rf ${DEPENDENCY_DIR}/zlib-* - curl -L https://github.com/ninja-build/ninja/archive/refs/tags/v${NINJA_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} -fi -cd ${DEPENDENCY_DIR}/ninja-* -cmake -B build -S . -DCMAKE_INSTALL_PREFIX=${PREFIX} -cmake --build build -if [ -w ${PREFIX} ]; then - cmake --install build -else - sudo cmake --install build +if ! command -v ninja &> /dev/null; then + NINJA_VER="1.11.1" + + printf "*********************************************************\n" + printf "* FETCHING NINJA SOURCE *\n" + printf "*********************************************************\n" + printf "Copying files to ${DEPENDENCY_DIR}\n" + mkdir -p ${DEPENDENCY_DIR} + if [ ! -d ${DEPENDENCY_DIR}/ninja-${NINJA_VER} ]; then + [ -d ${DEPENDENCY_DIR}/zlib-* ] && rm -rf ${DEPENDENCY_DIR}/zlib-* + curl -L https://github.com/ninja-build/ninja/archive/refs/tags/v${NINJA_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} + fi + cd ${DEPENDENCY_DIR}/ninja-* + cmake -B build -S . -DCMAKE_INSTALL_PREFIX=${PREFIX} + cmake --build build + if [ -w ${PREFIX} ]; then + cmake --install build + else + sudo cmake --install build + fi fi -set -e +NPROC=$(nproc) + +${SCRIPT_DIR}/build_libaec.sh ${ARGS} ${SCRIPT_DIR}/build_zlib.sh ${ARGS} ${SCRIPT_DIR}/build_hdf5.sh ${ARGS} ${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS} diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index f6c5a2938..43308cc5e 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -10,6 +10,12 @@ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with Swiftest. # If not, see: https://www.gnu.org/licenses. + +HDF5_VER="1_14_2" +PLUGIN_VER="1.14.0" +ZLIB_VER="1.3" +AEC_VER="1.0.6" + SCRIPT_DIR=$(realpath $(dirname $0)) set -a ARGS=$@ @@ -27,7 +33,6 @@ printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" printf "Installing to ${PREFIX}\n" printf "\n" -HDF5_VER="1_14_2" printf "*********************************************************\n" printf "* FETCHING HDF5 SOURCE *\n" printf "*********************************************************\n" @@ -63,8 +68,39 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/hdfsrc +ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" +ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" +LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" +LIBAEC_TGZ_ORIGPATH="https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/" + +HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" ZLIB_ROOT=${PREFIX} -cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} +SZIP_ROOT=${PREFIX} +if [ $OS = "MacOSX" ]; then + ZLIB_LIBRARY="${ZLIB_ROOT}/lib/libz.dylib" + SZIP_LIBRARY="${SZIP_ROOT}/lib/libsz.dylib" +else + ZLIB_LIBRARY="${ZLIB_ROOT}/lib/libz.so" + SZIP_LIBRARY="${SZIP_ROOT}/lib/libsz.so" +fi + +cmake -B build -C ./config/cmake/cacheinit.cmake -G Ninja \ + -DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ + -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ" \ + -DBUILD_ZLIB_WITH_FETCHCONTENT:BOOL=ON \ + -DZLIB_USE_LOCALCONTENT:BOOL=OFF \ + -DZLIB_TGZ_ORIGNAME:STRING="${ZLIB_TGZ_NAME}" \ + -DZLIB_TGZ_ORIGPATH:STRING="${ZLIB_TGZ_ORIGPATH}" \ + -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \ + -DBUILD_SZIP_WITH_FETCHCONTENT:BOOL=ON \ + -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \ + -DLIBAEC_TGZ_ORIGNAME:STRING="${LIBAEC_TGZ_NAME}" \ + -DLIBAEC_TGZ_ORIGPATH:STRING="${LIBAEC_TGZ_ORIGPATH}" \ + -DHDF5_ENABLE_PLUGIN_SUPPORT:BOOL=OFF \ + -DHDF5_BUILD_CPP_LIB:BOOL=OFF \ + -DHDF5_BUILD_FORTRAN:BOOL=OFF \ + -DHDF5_BUILD_JAVA:BOOL=OFF . + cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then cmake --install build diff --git a/buildscripts/build_libaec.sh b/buildscripts/build_libaec.sh new file mode 100755 index 000000000..8e2f4d0d2 --- /dev/null +++ b/buildscripts/build_libaec.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# This script will build all of the dependency libraries needed by Swiftest. Builds the following from source: +# Zlib, hdf5, netcdf-c, netcdf-fortran +# +# Copyright 2023 - David Minton +# This file is part of Swiftest. +# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with Swiftest. +# If not, see: https://www.gnu.org/licenses. +SCRIPT_DIR=$(realpath $(dirname $0)) +set -a +ARGS=$@ +. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} +. ${SCRIPT_DIR}/set_compilers.sh +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi + +printf "*********************************************************\n" +printf "* STARTING DEPENDENCY BUILD *\n" +printf "*********************************************************\n" +printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" +printf "Installing to ${PREFIX}\n" +printf "\n" + +AEC_VER="1.0.6" +LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" + +printf "*********************************************************\n" +printf "* FETCHING AEC SOURCE *\n" +printf "*********************************************************\n" +printf "Copying files to ${DEPENDENCY_DIR}\n" +mkdir -p ${DEPENDENCY_DIR} +if [ ! -d ${DEPENDENCY_DIR}/aec-${ZLIB_VER} ]; then + [ -d ${DEPENDENCY_DIR}/aec-* ] && rm -rf ${DEPENDENCY_DIR}/aec-* + + curl -L https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/${LIBAEC_TGZ_NAME}| tar xvz -C ${DEPENDENCY_DIR} +fi + +printf "*********************************************************\n" +printf "* BUILDING AEC LIBRARY *\n" +printf "*********************************************************\n" +printf "LIBS: ${LIBS}\n" +printf "CFLAGS: ${CFLAGS}\n" +printf "CPPFLAGS: ${CPPFLAGS}\n" +printf "CPATH: ${CPATH}\n" +printf "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}\n" +printf "LDFLAGS: ${LDFLAGS}\n" +printf "*********************************************************\n" + +cd ${DEPENDENCY_DIR}/libaec-* +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PREFIX} +cmake --build build -j${NPROC} +if [ -w ${PREFIX} ]; then + make install +else + sudo make install +fi + +if [ $? -ne 0 ]; then + printf "libaec could not be compiled.\n" + exit 1 +fi \ No newline at end of file diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 91be2b04c..3eafa0d7e 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -53,12 +53,25 @@ printf "HDF5_ROOT: ${HDF5_ROOT}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-c-* -cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} -cmake --build build -j${NPROC} +NCDIR="${PREFIX}" +ZLIB_ROOT=${PREFIX} +cmake -B build -S . -G Ninja \ + -DCMAKE_BUILD_TYPE:STRING="Release" \ + -DHDF5_DIR:PATH=${HDF5_ROOT}/cmake \ + -DCMAKE_INSTALL_PREFIX:STRING="${NCDIR}" \ + -DENABLE_DAP:BOOL=OFF \ + -DENABLE_BYTERANGE:BOOL=OFF \ + -DENABLE_NCZARR:BOOL=OFF \ + -DENABLE_NCZARR_FILTERS:BOOL=OFF \ + -DENABLE_NCZARR_FILTER_TESTING:BOOL=OFF \ + -DENABLE_NCZARR_FILTERS_TESTING:BOOL=OFF \ + -DENABLE_LIBXML2:BOOL=OFF \ + +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then - cmake --install build + cmake --install build else - sudo cmake --install build + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index fbbd3930a..0f920a8e1 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -51,19 +51,22 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-fortran-* - -NCLIBDIR=$(${PREFIX}/bin/nc-config --libdir) +NFDIR="${PREFIX}" +NCLIBDIR=$(${NCDIR}/bin/nc-config --libdir) if [ $OS = "MacOSX" ]; then netCDF_LIBRARIES="${NCLIBDIR}/libnetcdf.dylib" else netCDF_LIBRARIES="${NCLIBDIR}/libnetcdf.so" fi -cmake -B build -S . -G Ninja -DnetCDF_INCLUDE_DIR="${PREFIX}/include" -DnetCDF_LIBRARIES="${netCDF_LIBRARIES}" -DCMAKE_INSTALL_PREFIX=${PREFIX} -cmake --build build -j${NPROC} +cmake -B build -S . -G Ninja \ + -DnetCDF_INCLUDE_DIR:PATH="${NCDIR}/include" \ + -DnetCDF_LIBRARIES:FILEPATH="${netCDF_LIBRARIES}" \ + -DCMAKE_INSTALL_PREFIX:PATH=${NFDIR} +cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then cmake --install build else - sudo cmake --install build + sudo cmake --install build fi if [ $? -ne 0 ]; then diff --git a/buildscripts/set_environment.sh b/buildscripts/set_environment.sh index e1cffbc64..bf1775978 100755 --- a/buildscripts/set_environment.sh +++ b/buildscripts/set_environment.sh @@ -11,18 +11,19 @@ LDFLAGS="-Wl,-rpath,${ROOT_DIR}/lib -Wl,-no_compact_unwind -L${PREFIX}/lib -L${ CPATH="/usr/local/include:${PREFIX}/include:${HOMEBREW_PREFIX}/include:${ROOT_DIR}/include" CPPFLAGS="-isystem ${PREFIX}/include -isystem /usr/local/include -Xclang -fopenmp" LIBS="-lomp" +CFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wno-deprecated-non-prototype -arch ${ARCH}" FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" FFFLAGS="${FCFLAGS}" CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype" CXXFLAGS="${CFLAGS}" -HDF5_ROOT="${PREFIX}" +HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" HDF5_LIBDIR="${HDF5_ROOT}/lib" HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" -NETCDF_FORTRAN_HOME="${PREFIX}" -NETCDF_INCLUDE="${PREFIX}" NCDIR="${PREFIX}" NFDIR="${PREFIX}" +NETCDF_FORTRAN_HOME="${NFDIR}" +NETCDF_FORTRAN_INCLUDE="${NFDIR}/include" FC="$(command -v gfortran-12)" F77="${FC}" CC="/usr/bin/clang" diff --git a/cmake/Modules/FindNETCDF_Fortran.cmake b/cmake/Modules/FindNETCDF_Fortran.cmake index 7baec7972..5a74b488a 100644 --- a/cmake/Modules/FindNETCDF_Fortran.cmake +++ b/cmake/Modules/FindNETCDF_Fortran.cmake @@ -8,158 +8,176 @@ # If not, see: https://www.gnu.org/licenses. # - Finds the NetCDF libraries -# Begin searches with "typical" install locations of dependent libraries. These can be overrided in the cache or supplemented -# with environment variables -IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") - SET(NFPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-Fortran dependencies") - SET(NFINCLUDE_DIR "/usr/local/include" CACHE PATH "Location of provided netcdf.mod") - IF (NOT BUILD_SHARED_LIBS) - SET(NCPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-C dependencies") - SET(H5PREFIX_DIR "/usr/local" CACHE PATH "Location of provided HDF5 dependencies") - SET(ZPREFIX_DIR "/usr/local" CACHE PATH "Location of provided zlib dependencies") - ENDIF () -ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - IF (DEFINED ENV{HOMEBREW_PREFIX}) - SET(LIBPREFIX "$ENV{HOMEBREW_PREFIX}") - ELSE () - SET(LIBPREFIX "/usr/local") - ENDIF() +# Tries to find the cmake config files first. Otherwise, try to find the libraries and headers by hand - SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") - SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") - IF (NOT BUILD_SHARED_LIBS) - SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") - SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") - SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") - ENDIF () -ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") - LIST(SORT LIBDIRS) - LIST(GET LIBDIRS -1 LIBPREFIX) - SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") - SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") - IF (NOT BUILD_SHARED_LIBS) - # Assumes that the dependency libraries are packaged with NetCDF-C. - FILE(GLOB LIBDIRS "C:/Program Files*/netCDF*") +IF (NOT netCDF-Fortran_DIR) + IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") + LIST(SORT LIBDIRS) + LIST(GET LIBDIRS -1 LIBPREFIX) + SET(netCDF-Fortran_DIR "${LIBPREFIX}/lib/cmake/netCDF" CACHE PATH "Location of provided netCDF-FortranConfig.cmake file") + ELSE() + SET(netCDF-Fortran_DIR "/usr/local/lib/cmake/netCDF" CACHE PATH "Location of provided netCDF-FortranConfig.cmake file") + ENDIF () +ENDIF() + +MESSAGE(STATUS "Looking for netCDF-FortranConfig.cmake in ${netCDF-Fortran_DIR}") +FIND_PACKAGE(netCDF-Fortran QUIET) +IF (netCDF-Fortran_FOUND) + MESSAGE(STATUS "Found the NetCDF library via cmake configuration files") +ELSE () + MESSAGE(STATUS "No cmake configuration files detected. Searching for library files manually.") + IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") + SET(NFPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "/usr/local/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + SET(NCPREFIX_DIR "/usr/local" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "/usr/local" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "/usr/local" CACHE PATH "Location of provided zlib dependencies") + ENDIF () + ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + IF (DEFINED ENV{HOMEBREW_PREFIX}) + SET(LIBPREFIX "$ENV{HOMEBREW_PREFIX}") + ELSE () + SET(LIBPREFIX "/usr/local") + ENDIF() + + SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") + ENDIF () + ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + FILE(GLOB LIBDIRS "C:/Program Files*/NC4F") LIST(SORT LIBDIRS) LIST(GET LIBDIRS -1 LIBPREFIX) - SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") - SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") - SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") + SET(NFPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-Fortran dependencies") + SET(NFINCLUDE_DIR "${LIBPREFIX}/include" CACHE PATH "Location of provided netcdf.mod") + IF (NOT BUILD_SHARED_LIBS) + # Assumes that the dependency libraries are packaged with NetCDF-C. + FILE(GLOB LIBDIRS "C:/Program Files*/netCDF*") + LIST(SORT LIBDIRS) + LIST(GET LIBDIRS -1 LIBPREFIX) + SET(NCPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided NetCDF-C dependencies") + SET(H5PREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided HDF5 dependencies") + SET(ZPREFIX_DIR "${LIBPREFIX}" CACHE PATH "Location of provided zlib dependencies") + ENDIF () ENDIF () -ENDIF () -IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") - FIND_FILE(NFBIN - NAMES nf-config - HINTS - NFPREFIX_DIR - ENV NETCDF_FORTRAN_HOME - ENV PATH - PATH_SUFFIXES - bin - ) + IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + FIND_FILE(NFBIN + NAMES nf-config + HINTS + NFPREFIX_DIR + ENV NETCDF_FORTRAN_HOME + ENV PATH + PATH_SUFFIXES + bin + ) - IF (NFBIN) - SET(CMD "${NFBIN}") - LIST(APPEND CMD "--includedir") - MESSAGE(STATUS "Searching for NetCDF-Fortran include directory using ${CMD}") - EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFINCLUDE_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) - IF (NFINCLUDE_DIR) - MESSAGE(STATUS "Found in ${NFINCLUDE_DIR}") - ELSE () - MESSAGE(STATUS "Cannot execute ${CMD}") - MESSAGE(STATUS "OUTPUT: ${NFINCLUDE_DIR}") - MESSAGE(STATUS "RESULT: ${RES}") - MESSAGE(STATUS "ERROR : ${ERR}") - ENDIF () + IF (NFBIN) + SET(CMD "${NFBIN}") + LIST(APPEND CMD "--includedir") + MESSAGE(STATUS "Searching for NetCDF-Fortran include directory using ${CMD}") + EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFINCLUDE_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) + IF (NFINCLUDE_DIR) + MESSAGE(STATUS "Found in ${NFINCLUDE_DIR}") + ELSE () + MESSAGE(STATUS "Cannot execute ${CMD}") + MESSAGE(STATUS "OUTPUT: ${NFINCLUDE_DIR}") + MESSAGE(STATUS "RESULT: ${RES}") + MESSAGE(STATUS "ERROR : ${ERR}") + ENDIF () - SET(CMD "${NFBIN}") - LIST(APPEND CMD "--prefix") - MESSAGE(STATUS "Searching for NetCDF-Fortran library directory using ${CMD}") - EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFPREFIX_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) - IF (NFPREFIX_DIR) - MESSAGE(STATUS "Found in ${NFPREFIX_DIR}") - ELSE () - MESSAGE(STATUS "Cannot execute ${CMD}") - MESSAGE(STATUS "OUTPUT: ${NFPREFIX_DIR}") - MESSAGE(STATUS "RESULT: ${RES}") - MESSAGE(STATUS "ERROR : ${ERR}") - ENDIF () + SET(CMD "${NFBIN}") + LIST(APPEND CMD "--prefix") + MESSAGE(STATUS "Searching for NetCDF-Fortran library directory using ${CMD}") + EXECUTE_PROCESS(COMMAND ${CMD} OUTPUT_VARIABLE NFPREFIX_DIR ERROR_VARIABLE ERR RESULT_VARIABLE RES OUTPUT_STRIP_TRAILING_WHITESPACE) + IF (NFPREFIX_DIR) + MESSAGE(STATUS "Found in ${NFPREFIX_DIR}") + ELSE () + MESSAGE(STATUS "Cannot execute ${CMD}") + MESSAGE(STATUS "OUTPUT: ${NFPREFIX_DIR}") + MESSAGE(STATUS "RESULT: ${RES}") + MESSAGE(STATUS "ERROR : ${ERR}") + ENDIF () + ENDIF() ENDIF() -ENDIF() -FIND_PATH(NETCDF_FORTRAN_INCLUDE_DIR - NAMES netcdf.mod - HINTS - ${NFINCLUDE_DIR} - ENV NETCDF_INCLUDE - ENV NETCDF_FORTRAN_HOME - ENV CPATH - PATH_SUFFIXES - include - modules - mod - REQUIRED -) + FIND_PATH(NETCDF_FORTRAN_INCLUDE_DIR + NAMES netcdf.mod + HINTS + ${NFINCLUDE_DIR} + ENV NETCDF_INCLUDE + ENV NETCDF_FORTRAN_HOME + ENV CPATH + PATH_SUFFIXES + include + modules + mod + REQUIRED + ) -IF (BUILD_SHARED_LIBS) - SET(NETCDFF "netcdff") -ELSE () - IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - SET(NETCDFF "netcdff.lib") - SET(NETCDF "netcdf.lib") - SET(HDF5 "libhdf5.lib") - SET(HDF5_HL "libhdf5_hl.lib") - SET(ZLIB "zlibstatic.lib") + IF (BUILD_SHARED_LIBS) + SET(NETCDFF "netcdff") ELSE () - SET(NETCDFF "libnetcdff.a") - SET(NETCDF "libnetcdf.a") - SET(HDF5 "libhdf5.a") - SET(HDF5_HL "libhdf5_hl.a") - SET(ZLIB "libz.a") + IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + SET(NETCDFF "netcdff.lib") + SET(NETCDF "netcdf.lib") + SET(HDF5 "libhdf5.lib") + SET(HDF5_HL "libhdf5_hl.lib") + SET(ZLIB "zlibstatic.lib") + ELSE () + SET(NETCDFF "libnetcdff.a") + SET(NETCDF "libnetcdf.a") + SET(HDF5 "libhdf5.a") + SET(HDF5_HL "libhdf5_hl.a") + SET(ZLIB "libz.a") + ENDIF() ENDIF() -ENDIF() -FIND_LIBRARY(NETCDF_FORTRAN_LIBRARY - NAMES ${NETCDFF} - PATHS - ${NFPREFIX_DIR} - ENV NETCDF_FORTRAN_HOME - ENV NETCDF_HOME - ENV LD_LIBRARY_PATH - PATH_SUFFIXES - lib - ${CMAKE_LIBRARY_ARCHITECTURE} - REQUIRED -) -ADD_LIBRARY(NETCDF_FORTRAN_LIBRARY UNKNOWN IMPORTED PUBLIC) -IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") - # Get the DLL added in - FIND_FILE(NFDLL - NAMES "netcdff.dll" - HINTS - NFPREFIX_DIR + FIND_LIBRARY(netCDF::netcdff + NAMES ${NETCDFF} + PATHS + ${NFPREFIX_DIR} ENV NETCDF_FORTRAN_HOME - ENV PATH + ENV NETCDF_HOME + ENV LD_LIBRARY_PATH PATH_SUFFIXES - bin + lib + ${CMAKE_LIBRARY_ARCHITECTURE} + REQUIRED ) - SET_TARGET_PROPERTIES(NETCDF_FORTRAN_LIBRARY PROPERTIES - IMPORTED_IMPLIB "${NFLIB}" - IMPORTED_LOCATION "${NFDLL}" - INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" - ) - MESSAGE(STATUS "NetCDF-Fortran dll: ${NFDLL}") -ELSE () - SET_TARGET_PROPERTIES(NETCDF_FORTRAN_LIBRARY PROPERTIES - IMPORTED_LOCATION "${NFLIB}" - INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" - ) -ENDIF() - -MESSAGE(STATUS "NetCDF-Fortran library: ${NETCDF_FORTRAN_LIBRARY}") -MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_FORTRAN_INCLUDE_DIR}") + ADD_LIBRARY(netCDF::netcdff UNKNOWN IMPORTED PUBLIC) + IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + # Get the DLL added in + FIND_FILE(NFDLL + NAMES "netcdff.dll" + HINTS + NFPREFIX_DIR + ENV NETCDF_FORTRAN_HOME + ENV PATH + PATH_SUFFIXES + bin + ) + SET_TARGET_PROPERTIES(netCDF::netcdff PROPERTIES + IMPORTED_IMPLIB "${NFLIB}" + IMPORTED_LOCATION "${NFDLL}" + INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" + ) + MESSAGE(STATUS "NetCDF-Fortran dll: ${NFDLL}") + ELSE () + SET_TARGET_PROPERTIES(netCDF::netcdff PROPERTIES + IMPORTED_LOCATION "${NFLIB}" + INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_FORTRAN_INCLUDE_DIR}" + ) + ENDIF() + + MESSAGE(STATUS "NetCDF-Fortran library: ${NFLIB}") + MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_FORTRAN_INCLUDE_DIR}") +ENDIF () SET(NETCDF_FORTRAN_FOUND TRUE) MARK_AS_ADVANCED(NETCDF_FORTRAN_LIBRARY NETCDF_FORTRAN_INCLUDE_DIR) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d80530429..be5fc1ed1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,14 +77,14 @@ FCFLAGS="-mmacos-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" FFFLAGS="${FCFLAGS}" CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype -arch ${ARCH}" CXXFLAGS="${CFLAGS}" -HDF5_ROOT="${PREFIX}" +HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" HDF5_LIBDIR="${HDF5_ROOT}/lib" HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" -NETCDF_FORTRAN_HOME="${PREFIX}" -NETCDF_INCLUDE="${PREFIX}" -NCDIR="${PREFIX}" -NFDIR="${PREFIX}" +NCDIR="${PREFIX}/netCDF-C" +NFDIR="${PREFIX}/netCDF-Fortran" +NETCDF_FORTRAN_HOME="${NFDIR}" +NETCDF_FORTRAN_INCLUDE="${NFDIR}/include" FC="$(command -v gfortran-12)" F77="${FC}" CC="/usr/bin/clang" From 2aab08784f7fc8bc8b6f30131f09720eebd3924e Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:24:16 -0400 Subject: [PATCH 33/77] Fixed a few lingering issues with the Mac build --- buildscripts/build_hdf5.sh | 22 ++++++++++++++-------- pyproject.toml | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 43308cc5e..9653f7cd0 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -84,22 +84,28 @@ else SZIP_LIBRARY="${SZIP_ROOT}/lib/libsz.so" fi -cmake -B build -C ./config/cmake/cacheinit.cmake -G Ninja \ - -DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ - -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ" \ +ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ + -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ \ -DBUILD_ZLIB_WITH_FETCHCONTENT:BOOL=ON \ -DZLIB_USE_LOCALCONTENT:BOOL=OFF \ - -DZLIB_TGZ_ORIGNAME:STRING="${ZLIB_TGZ_NAME}" \ - -DZLIB_TGZ_ORIGPATH:STRING="${ZLIB_TGZ_ORIGPATH}" \ + -DZLIB_TGZ_ORIGNAME:STRING=${ZLIB_TGZ_NAME} \ + -DZLIB_TGZ_ORIGPATH:STRING=${ZLIB_TGZ_ORIGPATH} \ -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \ -DBUILD_SZIP_WITH_FETCHCONTENT:BOOL=ON \ -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \ - -DLIBAEC_TGZ_ORIGNAME:STRING="${LIBAEC_TGZ_NAME}" \ - -DLIBAEC_TGZ_ORIGPATH:STRING="${LIBAEC_TGZ_ORIGPATH}" \ + -DLIBAEC_TGZ_ORIGNAME:STRING=${LIBAEC_TGZ_NAME} \ + -DLIBAEC_TGZ_ORIGPATH:STRING=${LIBAEC_TGZ_ORIGPATH} \ -DHDF5_ENABLE_PLUGIN_SUPPORT:BOOL=OFF \ -DHDF5_BUILD_CPP_LIB:BOOL=OFF \ -DHDF5_BUILD_FORTRAN:BOOL=OFF \ - -DHDF5_BUILD_JAVA:BOOL=OFF . + -DHDF5_BUILD_JAVA:BOOL=OFF" + + +if [ $OS = "MacOSX" ]; then + ARGLIST="${ARGLIST} -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF" +fi + +cmake -B build -C ./config/cmake/cacheinit.cmake -G Ninja ${ARGLIST} . cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then diff --git a/pyproject.toml b/pyproject.toml index be5fc1ed1..5412396b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,8 +81,8 @@ HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" HDF5_LIBDIR="${HDF5_ROOT}/lib" HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" -NCDIR="${PREFIX}/netCDF-C" -NFDIR="${PREFIX}/netCDF-Fortran" +NCDIR="${PREFIX}" +NFDIR="${PREFIX}" NETCDF_FORTRAN_HOME="${NFDIR}" NETCDF_FORTRAN_INCLUDE="${NFDIR}/include" FC="$(command -v gfortran-12)" From cb2ad733d5596eb2831c7f851532df7b730494f3 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:27:35 -0400 Subject: [PATCH 34/77] More changes to library linking. wheel fails to find all libraries still --- swiftest/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swiftest/CMakeLists.txt b/swiftest/CMakeLists.txt index 37d232d87..45f02ca0d 100644 --- a/swiftest/CMakeLists.txt +++ b/swiftest/CMakeLists.txt @@ -33,10 +33,8 @@ PYTHON_ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE "${CMAKE_CURRENT_BINARY_DIR}/${SW IF (NOT BUILD_SHARED_LIBS) SET_PROPERTY(TARGET ${SWIFTEST_BINDINGS} PROPERTY POSITION_INDEPENDENT_CODE) - TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff) -ELSE () - TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY}) ENDIF () +TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} PUBLIC ${SWIFTEST_LIBRARY} netCDF::netcdff HDF5::HDF5) TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_BINDINGS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # Define the install locations From 9dc0a88ed92e48bb712e1fd7a98d282e1dfe5eb7 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:02:02 -0400 Subject: [PATCH 35/77] Fixed issue where the library was being named incorrectly --- cmake/Modules/FindNETCDF_Fortran.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindNETCDF_Fortran.cmake b/cmake/Modules/FindNETCDF_Fortran.cmake index 5a74b488a..2b996a27f 100644 --- a/cmake/Modules/FindNETCDF_Fortran.cmake +++ b/cmake/Modules/FindNETCDF_Fortran.cmake @@ -138,7 +138,7 @@ ELSE () ENDIF() ENDIF() - FIND_LIBRARY(netCDF::netcdff + FIND_LIBRARY(NFLIB NAMES ${NETCDFF} PATHS ${NFPREFIX_DIR} From c510683364256d8e75139d14eb1971d893dd2f63 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Sat, 23 Sep 2023 07:38:41 -0400 Subject: [PATCH 36/77] Ensured libraries get put in a consistent place for all builds --- buildscripts/build_hdf5.sh | 2 +- buildscripts/build_libaec.sh | 2 +- buildscripts/build_netcdf-c.sh | 1 + buildscripts/build_netcdf-fortran.sh | 3 ++- buildscripts/build_zlib.sh | 5 ++++- pyproject.toml | 22 ++++++++++++++++------ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 9653f7cd0..36484b473 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -73,7 +73,7 @@ ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER} LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" LIBAEC_TGZ_ORIGPATH="https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/" -HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" +HDF5_ROOT=${PREFIX} ZLIB_ROOT=${PREFIX} SZIP_ROOT=${PREFIX} if [ $OS = "MacOSX" ]; then diff --git a/buildscripts/build_libaec.sh b/buildscripts/build_libaec.sh index 8e2f4d0d2..50266c12e 100755 --- a/buildscripts/build_libaec.sh +++ b/buildscripts/build_libaec.sh @@ -55,7 +55,7 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/libaec-* mkdir build cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PREFIX} +cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_LIBDIR="lib" cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then make install diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 3eafa0d7e..2973e25e1 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -66,6 +66,7 @@ cmake -B build -S . -G Ninja \ -DENABLE_NCZARR_FILTER_TESTING:BOOL=OFF \ -DENABLE_NCZARR_FILTERS_TESTING:BOOL=OFF \ -DENABLE_LIBXML2:BOOL=OFF \ + -DCMAKE_INSTALL_LIBDIR="lib" cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 0f920a8e1..81afcc8ea 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -61,7 +61,8 @@ fi cmake -B build -S . -G Ninja \ -DnetCDF_INCLUDE_DIR:PATH="${NCDIR}/include" \ -DnetCDF_LIBRARIES:FILEPATH="${netCDF_LIBRARIES}" \ - -DCMAKE_INSTALL_PREFIX:PATH=${NFDIR} + -DCMAKE_INSTALL_PREFIX:PATH=${NFDIR} \ + -DCMAKE_INSTALL_LIBDIR="lib" cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then cmake --install build diff --git a/buildscripts/build_zlib.sh b/buildscripts/build_zlib.sh index 93275a8e8..9c6b414fd 100755 --- a/buildscripts/build_zlib.sh +++ b/buildscripts/build_zlib.sh @@ -51,7 +51,10 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/zlib-* -cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} +cmake -B build -S . -G Ninja \ + -DCMAKE_INSTALL_PREFIX=${PREFIX} \ + -DCMAKE_INSTALL_LIBDIR="lib" + cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then cmake --install build diff --git a/pyproject.toml b/pyproject.toml index 5412396b6..d8142f637 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,7 @@ FCFLAGS="-mmacos-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" FFFLAGS="${FCFLAGS}" CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype -arch ${ARCH}" CXXFLAGS="${CFLAGS}" -HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" +HDF5_ROOT="${PREFIX}" HDF5_LIBDIR="${HDF5_ROOT}/lib" HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" @@ -107,11 +107,21 @@ before-all = [ "buildscripts/build_dependencies.sh -p /usr/local" ] [tool.cibuildwheel.linux.environment] -NETCDF_FORTRAN_HOME="/usr/local" -NETCDF_INCLUDE="/usr/local/include" -LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/project/lib" -CPATH="/usr/local/include:/project/include" -netCDF-Fortran_DIR="/usr/local/lib64/cmake/netCDF" +PREFIX="/usr/local" +NCDIR="${PREFIX}" +NFDIR="${PREFIX}" +NETCDF_FORTRAN_HOME="${NFDIR}" +NETCDF_FORTRAN_INCLUDE="${NFDIR}/include" +HDF5_ROOT="${PREFIX}" +HDF5_LIBDIR="${HDF5_ROOT}/lib" +HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" +LD_LIBRARY_PATH="${PREFIX}/lib:/project/lib:${HDF5_LIBDIR}" +CPATH="${PREFIX}/include:/project/include:${HDF5_INCLUDE_DIR}" +netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" +HDF5_DIR="${HDF5_ROOT}/cmake" +PATH="${HDF5_ROOT}/bin:${PATH}" +CMAKE_INSTALL_LIBDIR="lib" [[tool.scikit-build.generate]] path = "version.txt" From b938f213f43d122336d72552092eb4cb1b6ada08 Mon Sep 17 00:00:00 2001 From: David Minton Date: Sat, 23 Sep 2023 08:44:23 -0400 Subject: [PATCH 37/77] Adjustments to build scripts --- buildscripts/build_hdf5.sh | 1 + buildscripts/build_netcdf-c.sh | 1 + buildscripts/set_environment.sh | 2 +- buildscripts/set_environment_linux.sh | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 buildscripts/set_environment_linux.sh diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 36484b473..35773e427 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -85,6 +85,7 @@ else fi ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ + -DCMAKE_BUILD_TYPE:STRING="Release" \ -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ \ -DBUILD_ZLIB_WITH_FETCHCONTENT:BOOL=ON \ -DZLIB_USE_LOCALCONTENT:BOOL=OFF \ diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 2973e25e1..76a7ce794 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -58,6 +58,7 @@ ZLIB_ROOT=${PREFIX} cmake -B build -S . -G Ninja \ -DCMAKE_BUILD_TYPE:STRING="Release" \ -DHDF5_DIR:PATH=${HDF5_ROOT}/cmake \ + -DHDF5_ROOT:PATH=${HDF5_ROOT} \ -DCMAKE_INSTALL_PREFIX:STRING="${NCDIR}" \ -DENABLE_DAP:BOOL=OFF \ -DENABLE_BYTERANGE:BOOL=OFF \ diff --git a/buildscripts/set_environment.sh b/buildscripts/set_environment.sh index bf1775978..cd51f1865 100755 --- a/buildscripts/set_environment.sh +++ b/buildscripts/set_environment.sh @@ -16,7 +16,7 @@ FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" FFFLAGS="${FCFLAGS}" CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype" CXXFLAGS="${CFLAGS}" -HDF5_ROOT="${PREFIX}/HDF_Group/HDF5/1.14.2" +HDF5_ROOT="${PREFIX}" HDF5_LIBDIR="${HDF5_ROOT}/lib" HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" diff --git a/buildscripts/set_environment_linux.sh b/buildscripts/set_environment_linux.sh new file mode 100755 index 000000000..a7c566d59 --- /dev/null +++ b/buildscripts/set_environment_linux.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Sets environment flags on Linux +set -a +PREFIX="/usr/local" +NCDIR="${PREFIX}" +NFDIR="${PREFIX}" +NETCDF_FORTRAN_HOME="${NFDIR}" +NETCDF_FORTRAN_INCLUDE="${NFDIR}/include" +HDF5_ROOT="${PREFIX}" +HDF5_LIBDIR="${HDF5_ROOT}/lib" +HDF5_INCLUDE_DIR="${HDF5_ROOT}/include" +HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin" +LD_LIBRARY_PATH="${PREFIX}/lib" +CPATH="${PREFIX}/include:" +HDF5_DIR="${HDF5_ROOT}/cmake" +PATH="${HDF5_ROOT}/bin:${PATH}" +CMAKE_INSTALL_LIBDIR="lib" \ No newline at end of file From 9d6fc7a89c5af4c1c240d2bfdfd1b2c3ebf489ef Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 25 Sep 2023 08:53:09 -0400 Subject: [PATCH 38/77] Additions made while troubleshooting the build_dependencies script on Linux --- buildscripts/build_dependencies.sh | 2 -- buildscripts/build_hdf5.sh | 37 +++++++++++++++++++--------- buildscripts/build_libaec.sh | 2 ++ buildscripts/build_netcdf-c.sh | 8 ++++-- buildscripts/build_netcdf-fortran.sh | 2 ++ buildscripts/build_zlib.sh | 6 ++--- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 11e3bdbdc..23c923a89 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -41,8 +41,6 @@ if ! command -v ninja &> /dev/null; then fi fi -NPROC=$(nproc) - ${SCRIPT_DIR}/build_libaec.sh ${ARGS} ${SCRIPT_DIR}/build_zlib.sh ${ARGS} ${SCRIPT_DIR}/build_hdf5.sh ${ARGS} diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 35773e427..e7e63a20c 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -26,6 +26,8 @@ if [ $OS = "MacOSX" ]; then ${SCRIPT_DIR}/get_lomp.sh ${ARGS} fi +NPROC=$(nproc) + printf "*********************************************************\n" printf "* STARTING DEPENDENCY BUILD *\n" printf "*********************************************************\n" @@ -54,7 +56,6 @@ if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} fi - printf "\n" printf "*********************************************************\n" printf "* BUILDING HDF5 LIBRARY *\n" @@ -72,6 +73,7 @@ ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" LIBAEC_TGZ_ORIGPATH="https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/" +curl -L "https://github.com/HDFGroup/hdf5_plugins/archive/refs/tags/${PLUGIN_VER}.tar.gz" -o hdf5_plugins.tar.gz HDF5_ROOT=${PREFIX} ZLIB_ROOT=${PREFIX} @@ -85,20 +87,19 @@ else fi ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ + -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="NO" \ -DCMAKE_BUILD_TYPE:STRING="Release" \ - -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ \ - -DBUILD_ZLIB_WITH_FETCHCONTENT:BOOL=ON \ - -DZLIB_USE_LOCALCONTENT:BOOL=OFF \ - -DZLIB_TGZ_ORIGNAME:STRING=${ZLIB_TGZ_NAME} \ - -DZLIB_TGZ_ORIGPATH:STRING=${ZLIB_TGZ_ORIGPATH} \ - -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \ - -DBUILD_SZIP_WITH_FETCHCONTENT:BOOL=ON \ - -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \ - -DLIBAEC_TGZ_ORIGNAME:STRING=${LIBAEC_TGZ_NAME} \ - -DLIBAEC_TGZ_ORIGPATH:STRING=${LIBAEC_TGZ_ORIGPATH} \ + -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} \ + -DZLIB_INCLUDE_DIR:PATH=${ZLIB_ROOT}/include \ + -DZLIB_USE_EXTERNAL:BOOL=OFF \ + -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \ + -DSZIP_LIBRARY:FILEPATH=${SZIP_LIBRARY} \ + -DSZIP_INCLUDE_DIR:PATH=${SZIP_ROOT}/include \ -DHDF5_ENABLE_PLUGIN_SUPPORT:BOOL=OFF \ -DHDF5_BUILD_CPP_LIB:BOOL=OFF \ -DHDF5_BUILD_FORTRAN:BOOL=OFF \ + -DHDF5_BUILD_EXAMPLES:BOOL=ON \ + -DBUILD_TESTING:BOOL=ON \ -DHDF5_BUILD_JAVA:BOOL=OFF" @@ -108,13 +109,25 @@ fi cmake -B build -C ./config/cmake/cacheinit.cmake -G Ninja ${ARGLIST} . -cmake --build build -j${NPROC} +cmake --build build -j${NPROC} --config Release if [ -w ${PREFIX} ]; then cmake --install build else sudo cmake --install build fi +# tar xvzf hdf5_plugins.tar.gz +# PLUGIN_SOURCE=hdf5_plugins-${PLUGIN_VER} + +# BUILD_OPTIONS="-DTGZPATH:PATH=${PLUGIN_SOURCE}/libs -DH5PL_ALLOW_EXTERNAL_SUPPORT:STRING=\"TGZ\"" +# cmake -B ${PLUGIN_SOURCE}/build -C ${PLUGIN_SOURCE}/config/cmake/cacheinit.cmake -DCMAKE_BUILD_TYPE:STRING=Release ${BUILD_OPTIONS} -G Ninja ${PLUGIN_SOURCE} +# cmake --build ${PLUGIN_SOURCE}/build -j${NPROC} --config Release +# if [ -w ${PREFIX} ]; then +# cmake --install ${PLUGIN_SOURCE}/build +# else +# sudo cmake --install ${PLUGIN_SOURCE}/build +# fi + if [ $? -ne 0 ]; then printf "hdf5 could not be compiled.\n" exit 1 diff --git a/buildscripts/build_libaec.sh b/buildscripts/build_libaec.sh index 50266c12e..f8028448a 100755 --- a/buildscripts/build_libaec.sh +++ b/buildscripts/build_libaec.sh @@ -20,6 +20,8 @@ if [ $OS = "MacOSX" ]; then ${SCRIPT_DIR}/get_lomp.sh ${ARGS} fi +NPROC=$(nproc) + printf "*********************************************************\n" printf "* STARTING DEPENDENCY BUILD *\n" printf "*********************************************************\n" diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 76a7ce794..0d4686005 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -20,6 +20,8 @@ if [ $OS = "MacOSX" ]; then ${SCRIPT_DIR}/get_lomp.sh ${ARGS} fi +NPROC=$(nproc) + printf "*********************************************************\n" printf "* STARTING DEPENDENCY BUILD *\n" printf "*********************************************************\n" @@ -55,10 +57,11 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-c-* NCDIR="${PREFIX}" ZLIB_ROOT=${PREFIX} -cmake -B build -S . -G Ninja \ +cmake -B build -S . -G Ninja --debug-find \ -DCMAKE_BUILD_TYPE:STRING="Release" \ -DHDF5_DIR:PATH=${HDF5_ROOT}/cmake \ -DHDF5_ROOT:PATH=${HDF5_ROOT} \ + -DCMAKE_FIND_ROOT_PATH:PATH="${PREFIX}" \ -DCMAKE_INSTALL_PREFIX:STRING="${NCDIR}" \ -DENABLE_DAP:BOOL=OFF \ -DENABLE_BYTERANGE:BOOL=OFF \ @@ -67,7 +70,8 @@ cmake -B build -S . -G Ninja \ -DENABLE_NCZARR_FILTER_TESTING:BOOL=OFF \ -DENABLE_NCZARR_FILTERS_TESTING:BOOL=OFF \ -DENABLE_LIBXML2:BOOL=OFF \ - -DCMAKE_INSTALL_LIBDIR="lib" + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DENABLE_REMOTE_FORTRAN_BOOTSTRAP:BOOL=ON cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 81afcc8ea..0457e74c7 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -20,6 +20,8 @@ if [ $OS = "MacOSX" ]; then ${SCRIPT_DIR}/get_lomp.sh ${ARGS} fi +NPROC=$(nproc) + printf "*********************************************************\n" printf "* STARTING DEPENDENCY BUILD *\n" printf "*********************************************************\n" diff --git a/buildscripts/build_zlib.sh b/buildscripts/build_zlib.sh index 9c6b414fd..c3ef95318 100755 --- a/buildscripts/build_zlib.sh +++ b/buildscripts/build_zlib.sh @@ -20,6 +20,8 @@ if [ $OS = "MacOSX" ]; then ${SCRIPT_DIR}/get_lomp.sh ${ARGS} fi +NPROC=$(nproc) + printf "*********************************************************\n" printf "* STARTING DEPENDENCY BUILD *\n" printf "*********************************************************\n" @@ -51,9 +53,7 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/zlib-* -cmake -B build -S . -G Ninja \ - -DCMAKE_INSTALL_PREFIX=${PREFIX} \ - -DCMAKE_INSTALL_LIBDIR="lib" +cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=${PREFIX} cmake --build build -j${NPROC} if [ -w ${PREFIX} ]; then From 3a5cddb5b16dab9b4d70ca847ff7fe4ea45b5104 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:57:38 -0400 Subject: [PATCH 39/77] Removed debug flag from the netcdf-c build script --- buildscripts/build_netcdf-c.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 0d4686005..6295eeda7 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -57,7 +57,7 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/netcdf-c-* NCDIR="${PREFIX}" ZLIB_ROOT=${PREFIX} -cmake -B build -S . -G Ninja --debug-find \ +cmake -B build -S . -G Ninja \ -DCMAKE_BUILD_TYPE:STRING="Release" \ -DHDF5_DIR:PATH=${HDF5_ROOT}/cmake \ -DHDF5_ROOT:PATH=${HDF5_ROOT} \ @@ -67,8 +67,6 @@ cmake -B build -S . -G Ninja --debug-find \ -DENABLE_BYTERANGE:BOOL=OFF \ -DENABLE_NCZARR:BOOL=OFF \ -DENABLE_NCZARR_FILTERS:BOOL=OFF \ - -DENABLE_NCZARR_FILTER_TESTING:BOOL=OFF \ - -DENABLE_NCZARR_FILTERS_TESTING:BOOL=OFF \ -DENABLE_LIBXML2:BOOL=OFF \ -DCMAKE_INSTALL_LIBDIR="lib" \ -DENABLE_REMOTE_FORTRAN_BOOTSTRAP:BOOL=ON From 1b1186c9d9553d5d3579d63fe6a07e32c67904d9 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:07:23 -0400 Subject: [PATCH 40/77] Added the setting of environment variables to the set_compiler script --- buildscripts/set_compilers.sh | 5 ++++- .../{set_environment.sh => set_environment_macos.sh} | 0 2 files changed, 4 insertions(+), 1 deletion(-) rename buildscripts/{set_environment.sh => set_environment_macos.sh} (100%) diff --git a/buildscripts/set_compilers.sh b/buildscripts/set_compilers.sh index 85495b40d..70dd9f71e 100755 --- a/buildscripts/set_compilers.sh +++ b/buildscripts/set_compilers.sh @@ -13,6 +13,8 @@ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with Swiftest. # If not, see: https://www.gnu.org/licenses. +SCRIPT_DIR=$(realpath $(dirname $0)) +ROOT_DIR=$(realpath ${SCRIPT_DIR}/..) case "$OS" in Linux|MacOSX|Intel) ;; @@ -25,15 +27,16 @@ case "$OS" in esac set -a -# Only replace compiler definitions if they are not already set case $OS in Linux) + . ${SCRIPT_DIR}/set_environment_linux.sh FC=$(command -v gfortran) CC=$(command -v gcc) CXX=$(command -v g++) CPP=$(command -v cpp) ;; MacOSX) + . ${SCRIPT_DIR}/set_environment_macos.sh FC=${HOMEBREW_PREFIX}/bin/gfortran-12 CFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -Wno-deprecated-non-prototype -arch ${ARCH}" FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -arch ${ARCH}" diff --git a/buildscripts/set_environment.sh b/buildscripts/set_environment_macos.sh similarity index 100% rename from buildscripts/set_environment.sh rename to buildscripts/set_environment_macos.sh From e13383f5d1a7abc568761323a5fa20c1422249e4 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 25 Sep 2023 13:00:20 -0400 Subject: [PATCH 41/77] Removed libaec from build dependencies as it caused issues in mac builds --- buildscripts/build_dependencies.sh | 1 - buildscripts/build_hdf5.sh | 10 +---- buildscripts/build_libaec.sh | 71 ------------------------------ 3 files changed, 1 insertion(+), 81 deletions(-) delete mode 100755 buildscripts/build_libaec.sh diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 23c923a89..719f1e8e2 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -41,7 +41,6 @@ if ! command -v ninja &> /dev/null; then fi fi -${SCRIPT_DIR}/build_libaec.sh ${ARGS} ${SCRIPT_DIR}/build_zlib.sh ${ARGS} ${SCRIPT_DIR}/build_hdf5.sh ${ARGS} ${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS} diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index e7e63a20c..9863f33ed 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -14,7 +14,6 @@ HDF5_VER="1_14_2" PLUGIN_VER="1.14.0" ZLIB_VER="1.3" -AEC_VER="1.0.6" SCRIPT_DIR=$(realpath $(dirname $0)) set -a @@ -71,8 +70,6 @@ printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/hdfsrc ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" -LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" -LIBAEC_TGZ_ORIGPATH="https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/" curl -L "https://github.com/HDFGroup/hdf5_plugins/archive/refs/tags/${PLUGIN_VER}.tar.gz" -o hdf5_plugins.tar.gz HDF5_ROOT=${PREFIX} @@ -80,10 +77,8 @@ ZLIB_ROOT=${PREFIX} SZIP_ROOT=${PREFIX} if [ $OS = "MacOSX" ]; then ZLIB_LIBRARY="${ZLIB_ROOT}/lib/libz.dylib" - SZIP_LIBRARY="${SZIP_ROOT}/lib/libsz.dylib" else ZLIB_LIBRARY="${ZLIB_ROOT}/lib/libz.so" - SZIP_LIBRARY="${SZIP_ROOT}/lib/libsz.so" fi ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ @@ -92,9 +87,7 @@ ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} \ -DZLIB_INCLUDE_DIR:PATH=${ZLIB_ROOT}/include \ -DZLIB_USE_EXTERNAL:BOOL=OFF \ - -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON \ - -DSZIP_LIBRARY:FILEPATH=${SZIP_LIBRARY} \ - -DSZIP_INCLUDE_DIR:PATH=${SZIP_ROOT}/include \ + -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF \ -DHDF5_ENABLE_PLUGIN_SUPPORT:BOOL=OFF \ -DHDF5_BUILD_CPP_LIB:BOOL=OFF \ -DHDF5_BUILD_FORTRAN:BOOL=OFF \ @@ -102,7 +95,6 @@ ARGLIST="-DCMAKE_INSTALL_PREFIX:PATH=${HDF5_ROOT} \ -DBUILD_TESTING:BOOL=ON \ -DHDF5_BUILD_JAVA:BOOL=OFF" - if [ $OS = "MacOSX" ]; then ARGLIST="${ARGLIST} -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF" fi diff --git a/buildscripts/build_libaec.sh b/buildscripts/build_libaec.sh deleted file mode 100755 index f8028448a..000000000 --- a/buildscripts/build_libaec.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -# This script will build all of the dependency libraries needed by Swiftest. Builds the following from source: -# Zlib, hdf5, netcdf-c, netcdf-fortran -# -# Copyright 2023 - David Minton -# This file is part of Swiftest. -# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# You should have received a copy of the GNU General Public License along with Swiftest. -# If not, see: https://www.gnu.org/licenses. -SCRIPT_DIR=$(realpath $(dirname $0)) -set -a -ARGS=$@ -. ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} -. ${SCRIPT_DIR}/set_compilers.sh -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi - -NPROC=$(nproc) - -printf "*********************************************************\n" -printf "* STARTING DEPENDENCY BUILD *\n" -printf "*********************************************************\n" -printf "Using ${OS} compilers:\nFC: ${FC}\nCC: ${CC}\nCXX: ${CXX}\n" -printf "Installing to ${PREFIX}\n" -printf "\n" - -AEC_VER="1.0.6" -LIBAEC_TGZ_NAME="libaec-${AEC_VER}.tar.gz" - -printf "*********************************************************\n" -printf "* FETCHING AEC SOURCE *\n" -printf "*********************************************************\n" -printf "Copying files to ${DEPENDENCY_DIR}\n" -mkdir -p ${DEPENDENCY_DIR} -if [ ! -d ${DEPENDENCY_DIR}/aec-${ZLIB_VER} ]; then - [ -d ${DEPENDENCY_DIR}/aec-* ] && rm -rf ${DEPENDENCY_DIR}/aec-* - - curl -L https://github.com/MathisRosenhauer/libaec/releases/download/v${AEC_VER}/${LIBAEC_TGZ_NAME}| tar xvz -C ${DEPENDENCY_DIR} -fi - -printf "*********************************************************\n" -printf "* BUILDING AEC LIBRARY *\n" -printf "*********************************************************\n" -printf "LIBS: ${LIBS}\n" -printf "CFLAGS: ${CFLAGS}\n" -printf "CPPFLAGS: ${CPPFLAGS}\n" -printf "CPATH: ${CPATH}\n" -printf "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}\n" -printf "LDFLAGS: ${LDFLAGS}\n" -printf "*********************************************************\n" - -cd ${DEPENDENCY_DIR}/libaec-* -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_LIBDIR="lib" -cmake --build build -j${NPROC} -if [ -w ${PREFIX} ]; then - make install -else - sudo make install -fi - -if [ $? -ne 0 ]; then - printf "libaec could not be compiled.\n" - exit 1 -fi \ No newline at end of file From c3e3f395fea50f4f8c45f18fba76e7dc6b17d655 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:26:47 -0400 Subject: [PATCH 42/77] Set default dependency build location and prefix to ~/Downloads and /usr/local for simplicity --- buildscripts/_build_getopts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildscripts/_build_getopts.sh b/buildscripts/_build_getopts.sh index 329d39ea4..113f9e526 100755 --- a/buildscripts/_build_getopts.sh +++ b/buildscripts/_build_getopts.sh @@ -49,8 +49,8 @@ while getopts ":d:p:m:h" ARG; do esac done -BUILD_DIR=${BUILD_DIR:-$(mktemp -ut swiftest_build.XXXXXXXX)} -PREFIX=${PREFIX:-${ROOT_DIR}} +BUILD_DIR=${BUILD_DIR:-"${HOME}/Downloads"} +PREFIX=${PREFIX:-"/usr/local"} DEPENDENCY_DIR=${DEPENDENCY_DIR:-${BUILD_DIR}} mkdir -p ${DEPENDENCY_DIR} From 830235a1dbca133b3596d3e9176393e669cb8c13 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:51:59 -0400 Subject: [PATCH 43/77] added back the cp312 build to the wheels --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d8142f637..a4de1c257 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ cmake.verbose = true [tool.cibuildwheel] test-command = "pytest {package}/tests" test-requires = ['pytest'] -skip = "cp312-* pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" +skip = "pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" build-verbosity = 1 [tool.cibuildwheel.macos.environment] From f96817c954c03af181fab148c9ff7f1e04ff59b3 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:20:54 -0400 Subject: [PATCH 44/77] Skip the cp312 Linux version because h5py can't be built --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a4de1c257..b0518b03f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ cmake.verbose = true [tool.cibuildwheel] test-command = "pytest {package}/tests" test-requires = ['pytest'] -skip = "pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" +skip = "cp312-cp312-manylinux* pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" build-verbosity = 1 [tool.cibuildwheel.macos.environment] From 1735a5a2ff6723c7a900e45d63296071d2f63e9a Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 25 Sep 2023 17:07:45 -0400 Subject: [PATCH 45/77] added a cacheinit configuration file for the netcdf-fortran build on Windows (rough draft) --- buildscripts/netcdf-fortran-cacheinit.cmake | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 buildscripts/netcdf-fortran-cacheinit.cmake diff --git a/buildscripts/netcdf-fortran-cacheinit.cmake b/buildscripts/netcdf-fortran-cacheinit.cmake new file mode 100644 index 000000000..9c3fca435 --- /dev/null +++ b/buildscripts/netcdf-fortran-cacheinit.cmake @@ -0,0 +1,5 @@ +SET(netCDF_INCLUDE_DIR "C:/Program Files/netCDF 4.9.2/include" CACHE PATH "Path to NetCDF-C include directory" FORCE) +SET(netCDF_LIBRARIES "C:/Program Files/netCDF 4.9.2/lib/netcdf.lib" CACHE FILEPATH "Location of NetCDF-C library file" FORCE) +SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Use shared libraries" FORCE) +SET(CMAKE_INSTALL_PREFIX "C:/Program Files/NC4F" CACHE PATH "Installation location" FORCE) +SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile build type" FORCE) \ No newline at end of file From fa952e13e8c2f312dec9e4fe3c575683a5c4a481 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 26 Sep 2023 14:18:24 -0400 Subject: [PATCH 46/77] Allow all but the linux build to make the python 3.12 version --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b0518b03f..99f59a292 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ cmake.verbose = true [tool.cibuildwheel] test-command = "pytest {package}/tests" test-requires = ['pytest'] -skip = "cp312-cp312-manylinux* pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" +skip = "pp* *i686 *-manylinux_i686 *_ppc64le *_s390x *-musllinux* *-win32" build-verbosity = 1 [tool.cibuildwheel.macos.environment] @@ -102,6 +102,7 @@ before-all = [ ] [tool.cibuildwheel.linux] +skip = "cp312-*" before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" From 54a9f954f44f7bb4d43c3a188cf4701731a72cbe Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 27 Sep 2023 08:12:37 -0400 Subject: [PATCH 47/77] Added new windows cmake config files --- buildscripts/.gitignore | 3 +- .../windows/hdf5-cacheinit-windows.cmake | 43 +++++++++++++++++++ .../netcdf-fortran-cacheinit-windows.cmake} | 0 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 buildscripts/windows/hdf5-cacheinit-windows.cmake rename buildscripts/{netcdf-fortran-cacheinit.cmake => windows/netcdf-fortran-cacheinit-windows.cmake} (100%) diff --git a/buildscripts/.gitignore b/buildscripts/.gitignore index e2ee4346f..9cfaceeed 100644 --- a/buildscripts/.gitignore +++ b/buildscripts/.gitignore @@ -1 +1,2 @@ -!*.sh \ No newline at end of file +!*.sh +!windows/*.cmake \ No newline at end of file diff --git a/buildscripts/windows/hdf5-cacheinit-windows.cmake b/buildscripts/windows/hdf5-cacheinit-windows.cmake new file mode 100644 index 000000000..433ae0795 --- /dev/null +++ b/buildscripts/windows/hdf5-cacheinit-windows.cmake @@ -0,0 +1,43 @@ +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the COPYING file, which can be found at the root of the source code +# distribution tree, or in https://www.hdfgroup.org/licenses. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +# This is the CMakeCache file. + +######################### +# cache entries for building as part of the Swiftest project +######################### + +set (HDF_PACKAGE_NAMESPACE "hdf5::" CACHE STRING "Name for HDF package namespace (can be empty)" FORCE) +set (HDF5_BUILD_CPP_LIB OFF CACHE BOOL "Build C++ support" FORCE) +set (HDF5_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE) +set (HDF5_BUILD_JAVA OFF CACHE BOOL "Build JAVA support" FORCE) +set (HDF5_BUILD_GENERATORS OFF CACHE BOOL "Build Test Generators" FORCE) +set (BUILD_TESTING OFF CACHE BOOL "Build testing" FORCE) +set (HDF5_BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE) +set (HDF5_ENABLE_ALL_WARNINGS OFF CACHE BOOL "Enable all warnings" FORCE) +set (HDF5_ALLOW_EXTERNAL_SUPPORT "NO" CACHE STRING "Allow External Library Building (NO GIT TGZ)" FORCE) +set_property (CACHE HDF5_ALLOW_EXTERNAL_SUPPORT PROPERTY STRINGS NO GIT TGZ) +set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build with shared libraries" FORCE) + +######################## +# compression options +######################## +SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/lib/zlibstatic.lib" CACHE FILEPATH "ZLIB library file" FORCE) +SET(ZLIB_INCLUDE_DIR "C:/Program Files (x86)/zlib/include" CACHE PATH "ZLIB include directory" FORCE) +set (ZLIB_PACKAGE_NAME "zlib" CACHE STRING "Name of ZLIB package" FORCE) +set (ZLIB_USE_LOCALCONTENT OFF CACHE BOOL "Use local file for ZLIB FetchContent" FORCE) +set (LIBAEC_USE_LOCALCONTENT OFF CACHE BOOL "Use local file for LIBAEC FetchContent" FORCE) +set (ENABLE_SZIP OFF CACHE BOOL "Enable SZIP" FORCE) + +######################## +# filter plugin options +######################## +set (HDF5_ENABLE_PLUGIN_SUPPORT OFF CACHE BOOL "Enable plugins" FORCE) diff --git a/buildscripts/netcdf-fortran-cacheinit.cmake b/buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake similarity index 100% rename from buildscripts/netcdf-fortran-cacheinit.cmake rename to buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake From a9470073bcb18c2a781ce0d0162a9308569847d4 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 27 Sep 2023 09:38:06 -0400 Subject: [PATCH 48/77] Updated windows build cmake settings files --- .../windows/hdf5-cacheinit-windows.cmake | 4 +- .../windows/netcdf-c-cacheinit-windows.cmake | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 buildscripts/windows/netcdf-c-cacheinit-windows.cmake diff --git a/buildscripts/windows/hdf5-cacheinit-windows.cmake b/buildscripts/windows/hdf5-cacheinit-windows.cmake index 433ae0795..d622c5430 100644 --- a/buildscripts/windows/hdf5-cacheinit-windows.cmake +++ b/buildscripts/windows/hdf5-cacheinit-windows.cmake @@ -25,12 +25,12 @@ set (HDF5_BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE) set (HDF5_ENABLE_ALL_WARNINGS OFF CACHE BOOL "Enable all warnings" FORCE) set (HDF5_ALLOW_EXTERNAL_SUPPORT "NO" CACHE STRING "Allow External Library Building (NO GIT TGZ)" FORCE) set_property (CACHE HDF5_ALLOW_EXTERNAL_SUPPORT PROPERTY STRINGS NO GIT TGZ) -set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build with shared libraries" FORCE) +set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE) ######################## # compression options ######################## -SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/lib/zlibstatic.lib" CACHE FILEPATH "ZLIB library file" FORCE) +SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/lib/zlib.lib" CACHE FILEPATH "ZLIB library file" FORCE) SET(ZLIB_INCLUDE_DIR "C:/Program Files (x86)/zlib/include" CACHE PATH "ZLIB include directory" FORCE) set (ZLIB_PACKAGE_NAME "zlib" CACHE STRING "Name of ZLIB package" FORCE) set (ZLIB_USE_LOCALCONTENT OFF CACHE BOOL "Use local file for ZLIB FetchContent" FORCE) diff --git a/buildscripts/windows/netcdf-c-cacheinit-windows.cmake b/buildscripts/windows/netcdf-c-cacheinit-windows.cmake new file mode 100644 index 000000000..679c40b3c --- /dev/null +++ b/buildscripts/windows/netcdf-c-cacheinit-windows.cmake @@ -0,0 +1,55 @@ +# $Id: ConfigUser.cmake 9785 2012-02-29 09:56:54Z fwobbe $ +# +# Copyright (c) 2012, Florian Wobbe +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +# +# Use this file to override variables +# + +# Where netcdf will be installed: +set (CMAKE_INSTALL_PREFIX "C:/Program Files/netCDF" CACHE PATH "Where netcdf will be installed" FORCE) +set (CMAKE_FIND_ROOT_PATH "C:/Program Files" CACHE PATH "Location of find directories" FORCE) +set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build with shared libraries" FORCE) + +# Location of HFD4, HDF5 and zlib +set (HDF5_DIR "C:/Program Files/HDF_Group/HDF5/1.14.2/cmake" CACHE PATH "Location of HDF5 cmake files" FORCE) +set (HDF5_ROOT "C:/Program Files/HDF_Group/HDF5/1.14.2" CACHE PATH "Location of HDF5" FORCE) + +SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/zlib.lib" CACHE FILEPATH "ZLIB library file" FORCE) +SET(ZLIB_INCLUDE_DIR "C:/Program Files (x86)/zlib/include" CACHE PATH "ZLIB include directory" FORCE) + +# Set build type can be: empty, Debug, Release, RelWithDebInfo or MinSizeRel +set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) + +if(MSVC) + # Automatically adds compiler definitions to all subdirectories too. + add_definitions(/D_CRT_SECURE_NO_DEPRECATE /DWIN32_LEAN_AND_MEAN) + # Disable all warnings + string (REPLACE "/W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w") +endif(MSVC) + +set(ENABLE_DAP OFF CACHE BOOL "Enable DAP" FORCE) +set(ENABLE_BYTERANGE OFF CACHE BOOL "Enable BYTERANGE" FORCE) +set(ENABLE_NCZARR OFF CACHE BOOL "Enable NCZARR" FORCE) +set(ENABLE_LIBXML2 OFF CACHE BOOL "Enable LIBXML2" FORCE) +SET(ENABLE_FILTER_TESTING OFF CACHE BOOL "Enable Filter Testing" FORCE) +SET(ENABLE_PLUGINS OFF CACHE BOOL "Enable Plugins" FORCE) From f790687fa82b5555a76c491544eea75781b0339d Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:31:27 -0400 Subject: [PATCH 49/77] Removed file extension from the license file. --- .gitignore | 2 +- LICENSE.txt => LICENSE | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename LICENSE.txt => LICENSE (100%) diff --git a/.gitignore b/.gitignore index ea3fe2120..bee8e6915 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ dump* *ipynb_checkpoints **/.DS_Store !version.txt -!LICENSE.txt +!LICENSE !requirements.txt !pyproject.toml **/_skbuild diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE From 5204862e32fe1e63c17db8d6afb3f879913f7239 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:55:41 -0400 Subject: [PATCH 50/77] More maintenence on license and copying file extensions --- .gitignore | 4 ++-- COPYING.txt => COPYING | 0 pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename COPYING.txt => COPYING (100%) diff --git a/.gitignore b/.gitignore index bee8e6915..19b8038d1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ swiftest_driver.sh !CMakeLists.txt !*.cmake -!COPYING.txt +!COPYING +!LICENSE !CHANGELOG !README.md !README_figs/** @@ -26,7 +27,6 @@ dump* *ipynb_checkpoints **/.DS_Store !version.txt -!LICENSE !requirements.txt !pyproject.toml **/_skbuild diff --git a/COPYING.txt b/COPYING similarity index 100% rename from COPYING.txt rename to COPYING diff --git a/pyproject.toml b/pyproject.toml index 99f59a292..7ef3358cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ maintainers = [ ] readme = "README.md" requires-python=">=3.8" -license={file = "LICENSE.txt"} +license={file = "LICENSE"} classifiers=[ 'Development Status :: 3 - Alpha', 'Intended Audience :: Science/Research', From f379bef27816585e6f52604885b57d3b1f593295 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 27 Sep 2023 14:52:53 -0400 Subject: [PATCH 51/77] Added a link to the compiled library needed for the editable install --- buildscripts/install_editable_debug.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/buildscripts/install_editable_debug.sh b/buildscripts/install_editable_debug.sh index 62abedf5d..d3d1fe721 100755 --- a/buildscripts/install_editable_debug.sh +++ b/buildscripts/install_editable_debug.sh @@ -15,4 +15,7 @@ pip install --config-settings=editable.rebuild=true \ --config-settings=cmake.args="-DUSE_SIMD=ON" \ --config-settings=cmake.args="-DUSE_OPENMP=ON" \ --no-build-isolation \ - -ve . \ No newline at end of file + -ve . +mkdir -p $HOME/.local/lib +LIBFILE=$(realpath ${ROOT_DIR}/build/*/bin/*swiftest.*) +ln -s $LIBFILE $HOME/.local/lib \ No newline at end of file From 0f27a0e78a5d899d0a85b7f79489e6aca97a62e3 Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 27 Sep 2023 15:29:45 -0400 Subject: [PATCH 52/77] Trying to get the dependencies loaded in the windows build --- CMakeLists.txt | 12 ++++++++++-- .../windows/netcdf-c-cacheinit-windows.cmake | 2 +- .../windows/netcdf-fortran-cacheinit-windows.cmake | 5 +++-- .../windows/swiftest-cacheinint-windows.cmake | 7 +++++++ cmake/Modules/FindNETCDF_Fortran.cmake | 5 +++-- 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 buildscripts/windows/swiftest-cacheinint-windows.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ee14a5b37..4ce195ac5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,12 +67,20 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) ENDIF() FIND_PACKAGE(NETCDF_Fortran REQUIRED) -FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED) +IF (MSVC) + FIND_PACKAGE(HDF5 NAMES hdf5 COMPONENTS C HL REQUIRED CONFIG) + MESSAGE(STATUS "HDF5_FOUND: ${HDF5_FOUND}") + MESSAGE(STATUS "HDF5_VERSION: ${HDF5_VERSION}") + MESSAGE(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + MESSAGE(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") +ELSE () + FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED) +ENDIF () # Ensure scikit-build modules FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED) -# Define some directories that are important to the build + SET(SRC "${CMAKE_SOURCE_DIR}/src") SET(PY "${CMAKE_SOURCE_DIR}/swiftest") diff --git a/buildscripts/windows/netcdf-c-cacheinit-windows.cmake b/buildscripts/windows/netcdf-c-cacheinit-windows.cmake index 679c40b3c..34f405d91 100644 --- a/buildscripts/windows/netcdf-c-cacheinit-windows.cmake +++ b/buildscripts/windows/netcdf-c-cacheinit-windows.cmake @@ -33,7 +33,7 @@ set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build with shared libraries" FORCE) set (HDF5_DIR "C:/Program Files/HDF_Group/HDF5/1.14.2/cmake" CACHE PATH "Location of HDF5 cmake files" FORCE) set (HDF5_ROOT "C:/Program Files/HDF_Group/HDF5/1.14.2" CACHE PATH "Location of HDF5" FORCE) -SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/zlib.lib" CACHE FILEPATH "ZLIB library file" FORCE) +SET(ZLIB_LIBRARY "C:/Program Files (x86)/zlib/lib/zlib.lib" CACHE FILEPATH "ZLIB library file" FORCE) SET(ZLIB_INCLUDE_DIR "C:/Program Files (x86)/zlib/include" CACHE PATH "ZLIB include directory" FORCE) # Set build type can be: empty, Debug, Release, RelWithDebInfo or MinSizeRel diff --git a/buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake b/buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake index 9c3fca435..1d1f807b6 100644 --- a/buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake +++ b/buildscripts/windows/netcdf-fortran-cacheinit-windows.cmake @@ -1,5 +1,6 @@ -SET(netCDF_INCLUDE_DIR "C:/Program Files/netCDF 4.9.2/include" CACHE PATH "Path to NetCDF-C include directory" FORCE) -SET(netCDF_LIBRARIES "C:/Program Files/netCDF 4.9.2/lib/netcdf.lib" CACHE FILEPATH "Location of NetCDF-C library file" FORCE) +SET(netCDF_DIR "C:/Program Files/netCDF/lib/cmake/netCDF" CACHE PATH "Location of NetCDF-C cmake config files" FORCE) +SET(HDF5_DIR "C:/Program Files/HDF5_Group/HDF5/1.14.2/cmake" CACHE PATH "Location of HDF5 cmake config files" FORCE) +SET(HDF5_ROOT "C:/Program Files/HDF5_Group/HDF5/1.14.2" CACHE PATH "Location of HDF5" FORCE) SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Use shared libraries" FORCE) SET(CMAKE_INSTALL_PREFIX "C:/Program Files/NC4F" CACHE PATH "Installation location" FORCE) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile build type" FORCE) \ No newline at end of file diff --git a/buildscripts/windows/swiftest-cacheinint-windows.cmake b/buildscripts/windows/swiftest-cacheinint-windows.cmake new file mode 100644 index 000000000..c5c42aa64 --- /dev/null +++ b/buildscripts/windows/swiftest-cacheinint-windows.cmake @@ -0,0 +1,7 @@ +SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) +SET(USE_OPENMP ON CACHE BOOL "Use OpenMP" FORCE) +SET(USE_SIMD OFF CACHE BOOL "Use SIMD instructions" FORCE) +SET(netCDF-Fortran_DIR "C:/Program Files/NC4F/lib/cmake/netCDF" CACHE PATH "Location of NetCDF-Fortran cmake config files" FORCE) +SET(HDF5_DIR "C:/Program Files/HDF5_Group/HDF5/1.14.2/cmake" CACHE PATH "Location of HDF5 cmake config files" FORCE) +SET(HDF5_ROOT "C:/Program Files/HDF5_Group/HDF5/1.14.2" CACHE PATH "Location of HDF5" FORCE) +SET(HDF5_USE_STATIC_LIBRARIES ON CACHE BOOL "Use static HDF5 libraries" FORCE) \ No newline at end of file diff --git a/cmake/Modules/FindNETCDF_Fortran.cmake b/cmake/Modules/FindNETCDF_Fortran.cmake index 2b996a27f..ee56789a5 100644 --- a/cmake/Modules/FindNETCDF_Fortran.cmake +++ b/cmake/Modules/FindNETCDF_Fortran.cmake @@ -128,7 +128,7 @@ ELSE () SET(NETCDF "netcdf.lib") SET(HDF5 "libhdf5.lib") SET(HDF5_HL "libhdf5_hl.lib") - SET(ZLIB "zlibstatic.lib") + SET(ZLIB "zlib.lib") ELSE () SET(NETCDFF "libnetcdff.a") SET(NETCDF "libnetcdf.a") @@ -151,7 +151,7 @@ ELSE () REQUIRED ) ADD_LIBRARY(netCDF::netcdff UNKNOWN IMPORTED PUBLIC) - IF (CMAKE_SYSTEM_NAME STREQUAL "Windows") + IF (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND BUILD_SHARED_LIBS) # Get the DLL added in FIND_FILE(NFDLL NAMES "netcdff.dll" @@ -179,5 +179,6 @@ ELSE () MESSAGE(STATUS "NetCDF-Fortran include directory: ${NETCDF_FORTRAN_INCLUDE_DIR}") ENDIF () + SET(NETCDF_FORTRAN_FOUND TRUE) MARK_AS_ADVANCED(NETCDF_FORTRAN_LIBRARY NETCDF_FORTRAN_INCLUDE_DIR) \ No newline at end of file From 21e00134de64e8e64c95c41011ebfe7c36389d71 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Sat, 30 Sep 2023 19:44:20 -0400 Subject: [PATCH 53/77] Fixed test code --- swiftest/simulation_class.py | 2 +- tests/test_swiftest.py | 121 +---------------------------------- 2 files changed, 2 insertions(+), 121 deletions(-) diff --git a/swiftest/simulation_class.py b/swiftest/simulation_class.py index d6627c325..a4a2b12b8 100644 --- a/swiftest/simulation_class.py +++ b/swiftest/simulation_class.py @@ -413,7 +413,7 @@ def run(self,dask: bool = False, **kwargs): self.set_parameter(**kwargs) # Write out the current parameter set before executing run - self.write_param() + self.save(verbose=False) if self.codename != "Swiftest": warnings.warn(f"Running an integration is not yet supported for {self.codename}",stacklevel=2) diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index e6d1cf4c9..28f4e4a83 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -259,123 +259,4 @@ def test05_gr(self): if __name__ == '__main__': - unittest.main() - if os.path.exists("simdir"): - shutil.rmtree("simdir") - - # Add the modern planets and the Sun using the JPL Horizons Database. - # Add the modern planets and the Sun using the JPL Horizons Database. - sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) - sim.save() - - for f in file_list: - self.assertTrue(os.path.exists(f)) - - print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") - sim = swiftest.Simulation(read_param=True) - # Check if all names in Dataset read in from file match the expected list of names - self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") - - # Check to see if all parameter values read in from file match the expected parameters saved when generating the file - self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) - - def test02_integrators(self): - """ - Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators - """ - print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") - sim = swiftest.Simulation() - sim.clean() - - # Add the modern planets and the Sun using the JPL Horizons Database. - # Add the modern planets and the Sun using the JPL Horizons Database. - sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) - sim.save() - - # Add 10 user-defined test particles. - ntp = 10 - - name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] - a_tp = rng.uniform(0.3, 1.5, ntp) - e_tp = rng.uniform(0.0, 0.2, ntp) - inc_tp = rng.uniform(0.0, 10, ntp) - capom_tp = rng.uniform(0.0, 360.0, ntp) - omega_tp = rng.uniform(0.0, 360.0, ntp) - capm_tp = rng.uniform(0.0, 360.0, ntp) - - integrators= ["helio","whm","rmvs","symba"] - sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) - sim.set_parameter(tstart=0.0, tstop=0.10, dt=0.01, istep_out=1, dump_cadence=0) - for i in integrators: - sim.run(integrator=i) - - - def test03_conservation(self): - """ - Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. - """ - print("\ntest_conservation: Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances.") - - # Error limits - L_slope_limit = 1e-10 - E_slope_limit = 1e-8 - GM_limit = 1e-14 - - sim = swiftest.Simulation() - sim.clean() - - sim.add_solar_system_body(major_bodies) - - dt = 0.01 - nout = 1000 - tstop = 1e4 - tstep_out = tstop / nout - - sim.run(tstart=0.0, tstop=tstop, dt=dt, tstep_out=tstep_out, dump_cadence=0, compute_conservation_values=True, integrator="symba") - - def fit_func(x,slope,b): - """ - Linear function for curve fitting - """ - return slope * x + b - - # Calculate the angular momentum error - sim.data['L_tot'] = sim.data['L_orbit'] + sim.data['L_spin'] + sim.data['L_escape'] - sim.data['DL'] = sim.data['L_tot'] - sim.data['L_tot'].isel(time=0) - L_error = swiftest.tool.magnitude(sim.data,'DL') / swiftest.tool.magnitude(sim.data.isel(time=0), 'L_tot') - - # Calculate the energy error - E_error = (sim.data['TE'] - sim.data['TE'].isel(time=0)) / sim.data['TE'].isel(time=0) - - # Calculate the mass error - sim.data['GMtot'] = sim.data['Gmass'].sum(dim='name',skipna=True) + sim.data['GMescape'] - GM_error = (sim.data['GMtot'] - sim.data['GMtot'].isel(time=0)) / sim.data['GMtot'].isel(time=0) - GM_final = GM_error.isel(time=-1).values - - # Compute the slope of the error vs time fit - E_fit_result = E_error.curvefit("time",fit_func) - L_fit_result = L_error.curvefit("time",fit_func) - - E_slope = E_fit_result['curvefit_coefficients'].sel(param='slope').values - L_slope = L_fit_result['curvefit_coefficients'].sel(param='slope').values - - # Print the final errors - print("\n") - print(f"Angular momentum error slope: {L_slope:.2e}/{sim.TU_name}") - print(f"Energy error slope: {E_slope:.2e}/{sim.TU_name}") - print(f"Final Mass Error: {GM_final:.2e}") - - self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") - self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") - -if __name__ == '__main__': - unittest.main() - if os.path.exists("simdir"): - shutil.rmtree("simdir") + unittest.main() \ No newline at end of file From da736f1d2ddc4e1953291c3d440bb37e92e30d57 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:40:00 -0500 Subject: [PATCH 54/77] Fixed bad merge of test script --- tests/test_swiftest.py | 68 +++++------------------------------------- 1 file changed, 8 insertions(+), 60 deletions(-) diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index 28f4e4a83..117b50788 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - """ Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh This file is part of Swiftest. @@ -25,69 +24,16 @@ import swiftest import unittest import os -import shutil import numpy as np from numpy.random import default_rng from astroquery.jplhorizons import Horizons import datetime - rng = default_rng(seed=123) major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] param = {} - -class TestSwiftest(unittest.TestCase): - - def test01_gen_ic(self): - """ - Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised - """ - print("\ntest_gen_ic: Test whether we can generate simulation initial conditions test") - # Files that are expected to be generated: - simdir = "simdata" - file_list = [simdir, os.path.join(simdir,"param.in"), os.path.join(simdir,"init_cond.nc")] - - sim = swiftest.Simulation() - sim.clean() -#!/usr/bin/env python3 - -""" - Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh - This file is part of Swiftest. - Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with Swiftest. - If not, see: https://www.gnu.org/licenses. -""" - -""" -Tests that energy and momentum errors are within tolerances in a Swiftest simulation - -Input ------- - -Output ------- -None -""" - -import swiftest -import unittest -import os -import shutil -import numpy as np -from numpy.random import default_rng - -rng = default_rng(seed=123) - -major_bodies = ["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"] -param = {} - - class TestSwiftest(unittest.TestCase): def test01_gen_ic(self): @@ -102,7 +48,6 @@ def test01_gen_ic(self): sim = swiftest.Simulation() sim.clean() - # Add the modern planets and the Sun using the JPL Horizons Database. # Add the modern planets and the Sun using the JPL Horizons Database. sim.add_solar_system_body(major_bodies) @@ -112,7 +57,8 @@ def test01_gen_ic(self): for f in file_list: self.assertTrue(os.path.exists(f)) - + return + def test02_read_ic(self): """ @@ -125,7 +71,8 @@ def test02_read_ic(self): # Check to see if all parameter values read in from file match the expected parameters saved when generating the file self.assertTrue(all([v == param[k] for k,v in sim.param.items() if k in param])) - + return + def test03_integrators(self): """ @@ -154,7 +101,7 @@ def test03_integrators(self): sim.run(integrator=i) except: self.fail(f"Failed with integrator {i}") - + return def test04_conservation(self): """ @@ -214,7 +161,7 @@ def fit_func(x,slope,b): self.assertLess(np.abs(L_slope),L_slope_limit, msg=f"Angular Momentum Error of {L_slope:.2e}/{sim.TU_name} higher than threshold value of {L_slope_limit:.2e}/{sim.TU_name}") self.assertLess(np.abs(E_slope),E_slope_limit, msg=f"Energy Error of {E_slope:.2e}/{sim.TU_name} higher than threshold value of {E_slope_limit:.2e}/{sim.TU_name}") self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") - + return def test05_gr(self): """ @@ -253,7 +200,8 @@ def test05_gr(self): varpi_sim = sim.data['varpi'].sel(name="Mercury") dvarpi_gr = np.diff(varpi_sim) / tstep_out dvarpi_err = np.mean(dvarpi_obs - dvarpi_gr) / dvarpi_obs_mean - self.assertLess(np.abs(dvarpi_err),dvarpi_limit,msg=f'Mercury precession rate error of of {dvarpi_err:.2e} "/{sim.TU_name} higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') + print(f'{i}: Mercury precession rate error {dvarpi_err:.2e} "/{sim.TU_name}') + self.assertLess(np.abs(dvarpi_err),dvarpi_limit,msg=f'{dvarpi_err:.2e} /{sim.TU_name} is higher than threshold value of {dvarpi_limit:.2e} "/{sim.TU_name}') return From 6371a5a7814d444ef8ea5fa8be8177ef2332aaad Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:40:11 -0500 Subject: [PATCH 55/77] Updated version --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 6895b410d..3bae60812 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2023.9.4 \ No newline at end of file +2023.10.0 \ No newline at end of file From 5a1157408c2f95ef96d785b8e68329d036af3adc Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:40:37 -0500 Subject: [PATCH 56/77] Streamlined dependency build on MacOS --- buildscripts/build_dependencies.sh | 5 +++++ buildscripts/build_hdf5.sh | 11 ++++------- buildscripts/build_netcdf-c.sh | 4 ---- buildscripts/build_netcdf-fortran.sh | 4 ---- buildscripts/build_zlib.sh | 4 ---- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/buildscripts/build_dependencies.sh b/buildscripts/build_dependencies.sh index 719f1e8e2..32ac73ea9 100755 --- a/buildscripts/build_dependencies.sh +++ b/buildscripts/build_dependencies.sh @@ -41,6 +41,11 @@ if ! command -v ninja &> /dev/null; then fi fi +# Get the OpenMP Libraries +if [ $OS = "MacOSX" ]; then + ${SCRIPT_DIR}/get_lomp.sh ${ARGS} +fi + ${SCRIPT_DIR}/build_zlib.sh ${ARGS} ${SCRIPT_DIR}/build_hdf5.sh ${ARGS} ${SCRIPT_DIR}/build_netcdf-c.sh ${ARGS} diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 9863f33ed..5fa0148a4 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -20,10 +20,7 @@ set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} . ${SCRIPT_DIR}/set_compilers.sh -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi + NPROC=$(nproc) @@ -53,6 +50,9 @@ fi if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} + ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" + ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" + curl -L "https://github.com/HDFGroup/hdf5_plugins/archive/refs/tags/${PLUGIN_VER}.tar.gz" -o hdfsrc/hdf5_plugins.tar.gz fi printf "\n" @@ -68,9 +68,6 @@ printf "LDFLAGS: ${LDFLAGS}\n" printf "*********************************************************\n" cd ${DEPENDENCY_DIR}/hdfsrc -ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" -ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" -curl -L "https://github.com/HDFGroup/hdf5_plugins/archive/refs/tags/${PLUGIN_VER}.tar.gz" -o hdf5_plugins.tar.gz HDF5_ROOT=${PREFIX} ZLIB_ROOT=${PREFIX} diff --git a/buildscripts/build_netcdf-c.sh b/buildscripts/build_netcdf-c.sh index 6295eeda7..ee7415cbf 100755 --- a/buildscripts/build_netcdf-c.sh +++ b/buildscripts/build_netcdf-c.sh @@ -15,10 +15,6 @@ set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} . ${SCRIPT_DIR}/set_compilers.sh -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi NPROC=$(nproc) diff --git a/buildscripts/build_netcdf-fortran.sh b/buildscripts/build_netcdf-fortran.sh index 0457e74c7..c82f24573 100755 --- a/buildscripts/build_netcdf-fortran.sh +++ b/buildscripts/build_netcdf-fortran.sh @@ -15,10 +15,6 @@ set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} . ${SCRIPT_DIR}/set_compilers.sh -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi NPROC=$(nproc) diff --git a/buildscripts/build_zlib.sh b/buildscripts/build_zlib.sh index c3ef95318..337e6a839 100755 --- a/buildscripts/build_zlib.sh +++ b/buildscripts/build_zlib.sh @@ -15,10 +15,6 @@ set -a ARGS=$@ . ${SCRIPT_DIR}/_build_getopts.sh ${ARGS} . ${SCRIPT_DIR}/set_compilers.sh -# Get the OpenMP Libraries -if [ $OS = "MacOSX" ]; then - ${SCRIPT_DIR}/get_lomp.sh ${ARGS} -fi NPROC=$(nproc) From 13da5c70c68abbcea303dc91fdd1cb8fc61b90d4 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:10:45 -0500 Subject: [PATCH 57/77] Updated version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7ef3358cb..5e63045aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "swiftest" -version = "2023.9.4" +version = "2023.9.10" authors=[ {name = 'David A. Minton', email='daminton@purdue.edu'}, {name = 'Carlisle Wishard'}, From cbb8f5a4c7815b4f1da23b8dd3d5f020a357916b Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:24:29 -0500 Subject: [PATCH 58/77] Updated version properly --- pyproject.toml | 2 +- src/globals/globals_module.f90 | 2 +- tests/test_swiftest.py | 40 +++++++++++++++++++--------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5e63045aa..b23dee210 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "swiftest" -version = "2023.9.10" +version = "2023.10.0" authors=[ {name = 'David A. Minton', email='daminton@purdue.edu'}, {name = 'Carlisle Wishard'}, diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index 93ed3ac1e..96ad34e2a 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -48,7 +48,7 @@ module globals integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper !! conversion - offset between upper and lower - character(*), parameter :: VERSION = "2023.9.4" !! Swiftest version + character(*), parameter :: VERSION = "2023.9.10" !! Swiftest version !> Symbolic name for integrator types character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR" diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index 117b50788..717142012 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -36,7 +36,7 @@ class TestSwiftest(unittest.TestCase): - def test01_gen_ic(self): + def test_gen_ic(self): """ Tests that Swiftest is able to successfully generate a set of initial conditions in a file without any exceptions being raised """ @@ -50,9 +50,6 @@ def test01_gen_ic(self): # Add the modern planets and the Sun using the JPL Horizons Database. sim.add_solar_system_body(major_bodies) - - # Display the run configuration parameters. - param = sim.get_parameter(verbose=False) sim.save() for f in file_list: @@ -60,12 +57,17 @@ def test01_gen_ic(self): return - def test02_read_ic(self): + def test_read_ic(self): """ Tests that Swiftest is able to read a set of pre-existing initial conditions files and that they contain the correct data """ print("\ntest_read_ic: Test whether we can read back initial conditions files created by test_gen_ic") - sim = swiftest.Simulation(read_param=True) + sim = swiftest.Simulation() + sim.clean() + + # Add the modern planets and the Sun using the JPL Horizons Database. + sim.add_solar_system_body(major_bodies) + sim.save() # Check if all names in Dataset read in from file match the expected list of names self.assertTrue((major_bodies == sim.init_cond['name']).all(), msg="Name mismatch in Dataset") @@ -74,23 +76,26 @@ def test02_read_ic(self): return - def test03_integrators(self): + def test_integrators(self): """ Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators """ print("\ntest_integrators: Tests that Swiftest is able to integrate a collection of massive bodies and test particles with all available integrators") - sim = swiftest.Simulation(read_param=True) + sim = swiftest.Simulation() + + # Add the modern planets and the Sun using the JPL Horizons Database. + sim.add_solar_system_body(major_bodies) # Add 10 user-defined test particles. ntp = 10 - name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] - a_tp = rng.uniform(0.3, 1.5, ntp) - e_tp = rng.uniform(0.0, 0.2, ntp) - inc_tp = rng.uniform(0.0, 10, ntp) - capom_tp = rng.uniform(0.0, 360.0, ntp) - omega_tp = rng.uniform(0.0, 360.0, ntp) - capm_tp = rng.uniform(0.0, 360.0, ntp) + name_tp = [f"TestParticle_{i:02}" for i in range(1,ntp+1)] + a_tp = rng.uniform(0.3, 1.5, ntp) + e_tp = rng.uniform(0.0, 0.2, ntp) + inc_tp = rng.uniform(0.0, 10, ntp) + capom_tp = rng.uniform(0.0, 360.0, ntp) + omega_tp = rng.uniform(0.0, 360.0, ntp) + capm_tp = rng.uniform(0.0, 360.0, ntp) integrators= ["whm","helio","rmvs","symba"] sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) @@ -98,12 +103,13 @@ def test03_integrators(self): integrators= ["whm","helio","rmvs","symba"] for i in integrators: try: + sim.clean() sim.run(integrator=i) except: self.fail(f"Failed with integrator {i}") return - def test04_conservation(self): + def test_conservation(self): """ Tests that Swiftest conserves mass, energy, and momentum to within acceptable tolerances. """ @@ -163,7 +169,7 @@ def fit_func(x,slope,b): self.assertLess(np.abs(GM_final),GM_limit, msg=f"Mass Error of {GM_final:.2e} higher than threshold value of {GM_limit:.2e}") return - def test05_gr(self): + def test_gr(self): """ Tests that GR is working correctly by computing the precession of Mercury's longitude of periapsis and comparing it to values obtained from the JPL/Horizons ephemeris service From 44b4b9135a139979b022b198f08eeae884f6d959 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:26:58 -0500 Subject: [PATCH 59/77] Fixed bad version --- src/globals/globals_module.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index 96ad34e2a..d1a078329 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -48,7 +48,7 @@ module globals integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper !! conversion - offset between upper and lower - character(*), parameter :: VERSION = "2023.9.10" !! Swiftest version + character(*), parameter :: VERSION = "2023.10.0" !! Swiftest version !> Symbolic name for integrator types character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR" From f539e2677634a1e929143fadc0cb8aa746237382 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:00:05 -0500 Subject: [PATCH 60/77] Fixed issue that was causing initial conditions from being messed up when calling .run() multiple times in the same session, which screwed up the tests. Tests work again --- swiftest/simulation_class.py | 7 ++++--- tests/test_swiftest.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/swiftest/simulation_class.py b/swiftest/simulation_class.py index a4a2b12b8..0f8bea50c 100644 --- a/swiftest/simulation_class.py +++ b/swiftest/simulation_class.py @@ -412,15 +412,16 @@ def run(self,dask: bool = False, **kwargs): if len(kwargs) > 0: self.set_parameter(**kwargs) - # Write out the current parameter set before executing run - self.save(verbose=False) - if self.codename != "Swiftest": warnings.warn(f"Running an integration is not yet supported for {self.codename}",stacklevel=2) return + # Save initial conditions if not self.restart: self.clean() + + # Write out the current parameter set before executing run + self.write_param(verbose=False,**kwargs) print(f"Running a {self.codename} {self.integrator} run from tstart={self.param['TSTART']} {self.TU_name} to tstop={self.param['TSTOP']} {self.TU_name}") diff --git a/tests/test_swiftest.py b/tests/test_swiftest.py index 717142012..63f07829c 100755 --- a/tests/test_swiftest.py +++ b/tests/test_swiftest.py @@ -85,6 +85,7 @@ def test_integrators(self): # Add the modern planets and the Sun using the JPL Horizons Database. sim.add_solar_system_body(major_bodies) + sim.clean() # Add 10 user-defined test particles. ntp = 10 @@ -103,7 +104,6 @@ def test_integrators(self): integrators= ["whm","helio","rmvs","symba"] for i in integrators: try: - sim.clean() sim.run(integrator=i) except: self.fail(f"Failed with integrator {i}") @@ -213,4 +213,5 @@ def test_gr(self): if __name__ == '__main__': + os.environ["HDF5_USE_FILE_LOCKING"]="FALSE" unittest.main() \ No newline at end of file From f40d02f862c22fbdb261d79a4d550b5b0d0da90a Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:59:38 -0500 Subject: [PATCH 61/77] Added the Python 3.12 build to the linux wheels --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b23dee210..bb22467c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,6 @@ before-all = [ ] [tool.cibuildwheel.linux] -skip = "cp312-*" before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" From f55fa15f73a21025ca998944366b3eca54f76944 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:05:26 -0500 Subject: [PATCH 62/77] Updated versioning of dependency python packages and got rid of some cruft in the hdf5 build script --- buildscripts/build_hdf5.sh | 20 -------------------- pyproject.toml | 5 +++-- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 5fa0148a4..97106c03e 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -12,7 +12,6 @@ # If not, see: https://www.gnu.org/licenses. HDF5_VER="1_14_2" -PLUGIN_VER="1.14.0" ZLIB_VER="1.3" SCRIPT_DIR=$(realpath $(dirname $0)) @@ -48,13 +47,6 @@ if [[ (-d ${DEPENDENCY_DIR}/hdfsrc) && (-f ${DEPENDENCY_DIR}/hdfsrc/README.md) ] fi fi -if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then - curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} - ZLIB_TGZ_NAME="zlib-${ZLIB_VER}.tar.gz" - ZLIB_TGZ_ORIGPATH="https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/" - curl -L "https://github.com/HDFGroup/hdf5_plugins/archive/refs/tags/${PLUGIN_VER}.tar.gz" -o hdfsrc/hdf5_plugins.tar.gz -fi - printf "\n" printf "*********************************************************\n" printf "* BUILDING HDF5 LIBRARY *\n" @@ -105,18 +97,6 @@ else sudo cmake --install build fi -# tar xvzf hdf5_plugins.tar.gz -# PLUGIN_SOURCE=hdf5_plugins-${PLUGIN_VER} - -# BUILD_OPTIONS="-DTGZPATH:PATH=${PLUGIN_SOURCE}/libs -DH5PL_ALLOW_EXTERNAL_SUPPORT:STRING=\"TGZ\"" -# cmake -B ${PLUGIN_SOURCE}/build -C ${PLUGIN_SOURCE}/config/cmake/cacheinit.cmake -DCMAKE_BUILD_TYPE:STRING=Release ${BUILD_OPTIONS} -G Ninja ${PLUGIN_SOURCE} -# cmake --build ${PLUGIN_SOURCE}/build -j${NPROC} --config Release -# if [ -w ${PREFIX} ]; then -# cmake --install ${PLUGIN_SOURCE}/build -# else -# sudo cmake --install ${PLUGIN_SOURCE}/build -# fi - if [ $? -ne 0 ]; then printf "hdf5 could not be compiled.\n" exit 1 diff --git a/pyproject.toml b/pyproject.toml index bb22467c7..dd6d5a0c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,9 @@ dependencies = [ 'dask>=2022.1', 'distributed>=2022.1', 'bottleneck>=1.3.5', - 'h5netcdf>=1.0.2', - 'netcdf4>=1.6.2', + 'h5netcdf>=1.2.0', + 'h5py>=3.9.0', + 'netcdf4>=1.6.4', 'matplotlib>=3.7.1', 'astropy>=5.1', 'astroquery>=0.4.6', From 96429ee9b3ca45d9156ce0f4e59ec00ba5259ae1 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:15:28 -0500 Subject: [PATCH 63/77] Relaxing some packaging version requirements --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dd6d5a0c1..b895b752f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,9 +30,9 @@ dependencies = [ 'dask>=2022.1', 'distributed>=2022.1', 'bottleneck>=1.3.5', - 'h5netcdf>=1.2.0', - 'h5py>=3.9.0', - 'netcdf4>=1.6.4', + 'h5netcdf', + 'h5py', + 'netcdf4', 'matplotlib>=3.7.1', 'astropy>=5.1', 'astroquery>=0.4.6', From 0e86eafd9cea6da36cefcdedfc2c0a5dabdfe264 Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 2 Oct 2023 22:12:58 -0500 Subject: [PATCH 64/77] Put back the missing download of hdf5 --- buildscripts/build_hdf5.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildscripts/build_hdf5.sh b/buildscripts/build_hdf5.sh index 97106c03e..3f93d036b 100755 --- a/buildscripts/build_hdf5.sh +++ b/buildscripts/build_hdf5.sh @@ -47,6 +47,9 @@ if [[ (-d ${DEPENDENCY_DIR}/hdfsrc) && (-f ${DEPENDENCY_DIR}/hdfsrc/README.md) ] fi fi +if [ ! -d ${DEPENDENCY_DIR}/hdfsrc ]; then + curl -s -L https://github.com/HDFGroup/hdf5/releases/download/hdf5-${HDF5_VER}/hdf5-${HDF5_VER}.tar.gz | tar xvz -C ${DEPENDENCY_DIR} +fi printf "\n" printf "*********************************************************\n" printf "* BUILDING HDF5 LIBRARY *\n" From d1fd2c9e1e5c9b7663336568202a261db165249a Mon Sep 17 00:00:00 2001 From: David Minton Date: Mon, 2 Oct 2023 22:53:56 -0500 Subject: [PATCH 65/77] Skip the Linux Python 3.12 wheel because it fails --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index b895b752f..7e24d42a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ before-all = [ ] [tool.cibuildwheel.linux] +skip = "cp312-*" before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" From 40b0d0c104dd4045b2d312d05b88221d1fa6b9d0 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 3 Oct 2023 07:43:01 -0500 Subject: [PATCH 66/77] added additional skips to the linux build because it is an override not an append --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7e24d42a4..488fbaf6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,7 @@ before-all = [ ] [tool.cibuildwheel.linux] -skip = "cp312-*" +skip = "cp312-* pp* -manylinux_i686* *-musllinux*" before-all = [ "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" From 47e3c88905c4fb3812850e097dd5a3c28b8ea953 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:12:32 -0500 Subject: [PATCH 67/77] Fixed bug that was preventing initial conditions file from being saved when new bodys are added in multiple add_solar_system_body calls --- swiftest/simulation_class.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swiftest/simulation_class.py b/swiftest/simulation_class.py index 0f8bea50c..eee68f963 100644 --- a/swiftest/simulation_class.py +++ b/swiftest/simulation_class.py @@ -2177,10 +2177,8 @@ def add_solar_system_body(self, dsnew = init_cond.vec2xr(self.param,**kwargs) dsnew = self._combine_and_fix_dsnew(dsnew) - if dsnew['npl'] > 0 or dsnew['ntp'] > 0: + if dsnew['id'].max(dim='name') > 0 and dsnew['name'].size > 0: self.save(verbose=False) - - self.init_cond = self.data.copy(deep=True) From 67814bcf1f999aa834fe08806c92743ce737daab Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:49:42 -0500 Subject: [PATCH 68/77] Cleaned up the Chambers2013 example and added a new run_simulation script that can generate a short test case. --- examples/Chambers2013/init_cond.py | 171 ----------------------------- 1 file changed, 171 deletions(-) delete mode 100755 examples/Chambers2013/init_cond.py diff --git a/examples/Chambers2013/init_cond.py b/examples/Chambers2013/init_cond.py deleted file mode 100755 index d5c9f9f19..000000000 --- a/examples/Chambers2013/init_cond.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env python3 - -""" - Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh - This file is part of Swiftest. - Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with Swiftest. - If not, see: https://www.gnu.org/licenses. -""" - -""" -Generates a set of Swiftest input files from initial conditions with the SyMBA integrator. All simulation -outputs are stored in the /simdata subdirectory. - -Input ------- -None. - -Output ------- -inital_conditions.png : A .png file depicting the simulation initial configuration. -init_cond.nc : A NetCDF file containing the initial conditions for the simulation. -param.in : An ASCII file containing the parameters for the simulation. -""" - -import swiftest -import numpy as np -from numpy.random import default_rng -import matplotlib.pyplot as plt - -# Initialize simulation object -sim = swiftest.Simulation(compute_conservation_values=True, rotation=True, init_cond_format="EL",collision_model="fraggle",encounter_save="none") - -# Add bodies described in Chambers (2013) Sec. 2.1, with the uniform spatial distribution and two bodies sizes (big and small) -Nb = 14 -Ns = 140 -Mb = 2.8e-7 * 14 / Nb -Ms = 2.8e-8 * 140 / Ns -dens = 3000.0 * sim.KG2MU / sim.M2DU**3 - -mtiny = 1e-2 * Ms -minimum_fragment_mass = 1e-5 * Ms -nfrag_reduction = 30.0 -rng = default_rng(seed=3031179) - -runname = "Chambers (2013)" -def a_profile(n_bodies): - """ - Generates the profile described in Sec. 2.1 of Chambers: - - *In all cases, the surface density R = 8 g/cm2 at 1 AU, varying as a**(-3/2), where a is the orbital semi-major axis. - The region with a < 0.7 AU deviates from this law, declining linearly with decreasing distance until R = 0 at 0.3 AU. - The outer edge of the disk is 2 AU in all cases. - """ - def sample(r_inner, r_break, r_outer, slope1, slope2): - """ - Define the functions to pull random semi-major axes from a distribution using a rejection sampling method - This defines a 2-slope model with a break at r_break - Based on (https://stackoverflow.com/questions/66874819/random-numbers-with-user-defined-continuous-probability-distribution) - """ - while True: - x = rng.uniform(r_inner, r_outer, size=1) - - # The proportionality factor A ensures that the PDF approaches the same value on either side of the break point - # Assumes the break point is the max of the PDF - if x < r_break: - slope = slope1 + 1 - A = 1.0 - else: - slope = slope2 + 1 - A = r_break**(slope1-slope2) - y = rng.uniform(0, A*r_break**slope, size=1) - pdf = A*x**(slope) - if (y < pdf): - return x - - a_inner = 0.3 - a_break = 0.7 - a_outer = 2.0 - slope1 = 1.0 - slope2 = -1.5 - - a_vals = np.zeros(n_bodies) - for k in range(n_bodies): - a_vals[k] = sample(a_inner, a_break, a_outer, slope1, slope2) - return a_vals - -# Define the initial orbital elements of the big and small bodies -avalb = a_profile(Nb) -avals = a_profile(Ns) - -esigma = 0.01 -isigma = np.rad2deg(0.5 * esigma) -evalb = rng.rayleigh(scale=esigma, size=Nb) -evals = rng.rayleigh(scale=esigma, size=Ns) -incvalb = rng.rayleigh(scale=isigma, size=Nb) -incvals = rng.rayleigh(scale=isigma, size=Ns) - -capomvalb = rng.uniform(0.0, 360.0, Nb) -capomvals = rng.uniform(0.0, 360.0, Ns) -omegavalb = rng.uniform(0.0, 360.0, Nb) -omegavals = rng.uniform(0.0, 360.0, Ns) -capmvalb = rng.uniform(0.0, 360.0, Nb) -capmvals = rng.uniform(0.0, 360.0, Ns) -Ipvalb = np.full((Nb,3), 0.4) -Ipvals = np.full((Ns,3), 0.4) -rotvalb = np.zeros_like(Ipvalb) -rotvals = np.zeros_like(Ipvals) - -noise_digits = 4 # Approximately the number of digits of precision to vary the mass values to avoid duplicate masses -epsilon = np.finfo(float).eps -Mnoiseb = 1.0 + 10**noise_digits * rng.uniform(-epsilon,epsilon, Nb) -Mnoises = 1.0 + 10**noise_digits * rng.uniform(-epsilon,epsilon, Ns) - -Mvalb = Mb * Mnoiseb -Mvals = Ms * Mnoises - -Rvalb = (3 * Mvalb / (4 * np.pi * dens) )**(1.0 / 3.0) -Rvals = (3 * Mvals / (4 * np.pi * dens) )**(1.0 / 3.0) - -# Give the bodies unique names -nameb = [f"Big{i:03}" for i in range(Nb)] -names = [f"Small{i:03}" for i in range(Ns)] - -# Add the modern planets and the Sun using the JPL Horizons Database. -sim.add_solar_system_body(["Sun","Jupiter","Saturn","Uranus","Neptune"]) -sim.add_body(name=nameb, a=avalb, e=evalb, inc=incvalb, capom=capomvalb, omega=omegavalb, capm=capmvalb, mass=Mvalb, radius=Rvalb, rot=rotvalb, Ip=Ipvalb) -sim.add_body(name=names, a=avals, e=evals, inc=incvals, capom=capomvals, omega=omegavals, capm=capmvals, mass=Mvals, radius=Rvals, rot=rotvals, Ip=Ipvals) -sim.set_parameter(mtiny=mtiny, minimum_fragment_mass=minimum_fragment_mass, nfrag_reduction=nfrag_reduction) - -sim.set_parameter(tstop=3e8, dt=6.0875/365.25, istep_out=60000, dump_cadence=10) -sim.clean() -sim.write_param() - -# Plot the initial conditions -fig = plt.figure(figsize=(8.5, 11)) -ax1 = plt.subplot(2, 1, 1) -ax2 = plt.subplot(2, 1, 2) -fig.suptitle(runname) - -ic = sim.init_cond.isel(time=0) -radius = ic['radius'].values -markersize = radius * 4e5 -markercolor = np.where(radius < 2.0e-5, np.full_like(markersize, "black",dtype=object), np.full_like(markersize,"red",dtype=object)) -a = ic['a'].values -e = ic['e'].values -inc = ic['inc'].values - -ax1.scatter(a, e, s=markersize, color=markercolor, label=None) -ax1.set_xlabel("Semimajor Axis (AU)") -ax1.set_ylabel("Eccentricity") -ax1.set_xlim([0.0, 2.5]) -ax1.set_ylim([0.0,4*esigma]) - -ax2.scatter(a, inc, s=markersize, color=markercolor, label=None) -ax2.set_xlabel("Semimajor Axis (AU)") -ax2.set_ylabel("Inclination (deg)") -ax2.set_xlim([0.0, 2.5]) -ax2.set_ylim([0.0,8*isigma]) - -ax1.scatter(-1, -1, label='planetesimal', color='black') -ax1.scatter(-1, -1, label='embryo', color='red') -ax1.legend(loc='upper right', frameon=False) - -plt.tight_layout() -plt.show() -fig.savefig('initial_conditions.png',dpi=300) - From a057705e84fcc85902dc0cde62ce6251b703fc8f Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:50:05 -0500 Subject: [PATCH 69/77] Cleaned up the Chambers2013 example and added a new run_simulation script that can generate a short test case. --- examples/Chambers2013/.gitignore | 3 +- examples/Chambers2013/initial_conditions.py | 168 ++++++++++++++++++++ examples/Chambers2013/run_simulation.py | 33 ++++ examples/Chambers2013/scattermovie.py | 15 +- pyproject.toml | 27 ++-- 5 files changed, 230 insertions(+), 16 deletions(-) create mode 100755 examples/Chambers2013/initial_conditions.py create mode 100755 examples/Chambers2013/run_simulation.py diff --git a/examples/Chambers2013/.gitignore b/examples/Chambers2013/.gitignore index 64af50e94..0ea510e82 100644 --- a/examples/Chambers2013/.gitignore +++ b/examples/Chambers2013/.gitignore @@ -1,5 +1,6 @@ * !.gitignore -!init_cond.py +!initial_conditions.py !scattermovie.py +!run_simulation.py !README.txt diff --git a/examples/Chambers2013/initial_conditions.py b/examples/Chambers2013/initial_conditions.py new file mode 100755 index 000000000..596d6829c --- /dev/null +++ b/examples/Chambers2013/initial_conditions.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 + +""" + Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +""" +Generates a set of Swiftest input files from initial conditions with the SyMBA integrator. All simulation +outputs are stored in the /simdata subdirectory. + +Input +------ +None. + +Output +------ +inital_conditions.png : A .png file depicting the simulation initial configuration. +init_cond.nc : A NetCDF file containing the initial conditions for the simulation. +param.in : An ASCII file containing the parameters for the simulation. +""" + +import swiftest +import numpy as np +from numpy.random import default_rng +import matplotlib.pyplot as plt + +# Initialize simulation object +sim = swiftest.Simulation(compute_conservation_values=True, rotation=True, init_cond_format="EL",collision_model="fraggle",encounter_save="none") +sim.clean() + +# Add bodies described in Chambers (2013) Sec. 2.1, with the uniform spatial distribution and two bodies sizes (big and small) +Nb = 14 +Ns = 140 +Mb = 2.8e-7 * 14 / Nb +Ms = 2.8e-8 * 140 / Ns +dens = 3000.0 * sim.KG2MU / sim.M2DU**3 +rot = 1e-6 / sim.TU2S # Use a small but non-zero value for the initial rotation state to prevent divide-by-zero errors in analysis + +mtiny = 1e-2 * Ms +minimum_fragment_mass = 1e-5 * Ms +nfrag_reduction = 30.0 +rng = default_rng(seed=3031179) + +runname = "Chambers (2013)" +def a_profile(n_bodies): + """ + Generates the profile described in Sec. 2.1 of Chambers: + + *In all cases, the surface density R = 8 g/cm2 at 1 AU, varying as a**(-3/2), where a is the orbital semi-major axis. + The region with a < 0.7 AU deviates from this law, declining linearly with decreasing distance until R = 0 at 0.3 AU. + The outer edge of the disk is 2 AU in all cases. + """ + def sample(r_inner, r_break, r_outer, slope1, slope2, size): + """ + Define the functions to pull random semi-major axes from a distribution using a rejection sampling method + This defines a 2-slope model with a break at r_break + Based on (https://stackoverflow.com/questions/66874819/random-numbers-with-user-defined-continuous-probability-distribution) + """ + y=np.ones([size]) + pdf=np.zeros([size]) + x=np.empty_like(y) + while np.any(y>pdf): + x = np.where(y>pdf,rng.uniform(r_inner, r_outer, size=size),x) + + # The proportionality factor A ensures that the PDF approaches the same value on either side of the break point + # Assumes the break point is the max of the PDF + A=np.where(x < r_break,1.0,r_break**(slope1-slope2)) + slope=np.where(x < r_break,slope1+1,slope2+1) + y = np.where(y>pdf,rng.uniform(0, A*r_break**slope, size=size),y) + pdf = np.where(y>pdf,A*x**(slope),pdf) + return x + + a_inner = 0.3 + a_break = 0.7 + a_outer = 2.0 + slope1 = 1.0 + slope2 = -1.5 + + a_vals = sample(a_inner, a_break, a_outer, slope1, slope2, n_bodies) + return a_vals + +# Define the initial orbital elements of the big and small bodies +avalb = a_profile(Nb) +avals = a_profile(Ns) + +esigma = 0.01 +isigma = np.rad2deg(0.5 * esigma) +evalb = rng.rayleigh(scale=esigma, size=Nb) +evals = rng.rayleigh(scale=esigma, size=Ns) +incvalb = rng.rayleigh(scale=isigma, size=Nb) +incvals = rng.rayleigh(scale=isigma, size=Ns) + +capomvalb = rng.uniform(0.0, 360.0, Nb) +capomvals = rng.uniform(0.0, 360.0, Ns) +omegavalb = rng.uniform(0.0, 360.0, Nb) +omegavals = rng.uniform(0.0, 360.0, Ns) +capmvalb = rng.uniform(0.0, 360.0, Nb) +capmvals = rng.uniform(0.0, 360.0, Ns) +Ipvalb = np.full((Nb,3), 0.4) +Ipvals = np.full((Ns,3), 0.4) +rotvalb = np.full_like(Ipvalb,rot) +rotvals = np.full_like(Ipvals,rot) + +noise_digits = 4 # Approximately the number of digits of precision to vary the mass values to avoid duplicate masses +epsilon = np.finfo(float).eps +Mnoiseb = 1.0 + 10**noise_digits * rng.uniform(-epsilon,epsilon, Nb) +Mnoises = 1.0 + 10**noise_digits * rng.uniform(-epsilon,epsilon, Ns) + +Mvalb = Mb * Mnoiseb +Mvals = Ms * Mnoises + +Rvalb = (3 * Mvalb / (4 * np.pi * dens) )**(1.0 / 3.0) +Rvals = (3 * Mvals / (4 * np.pi * dens) )**(1.0 / 3.0) + +# Give the bodies unique names +nameb = [f"Big{i:03}" for i in range(Nb)] +names = [f"Small{i:03}" for i in range(Ns)] + +# Add the modern planets and the Sun using the JPL Horizons Database. +sim.add_solar_system_body(["Sun","Jupiter","Saturn","Uranus","Neptune"]) +sim.add_body(name=nameb, a=avalb, e=evalb, inc=incvalb, capom=capomvalb, omega=omegavalb, capm=capmvalb, mass=Mvalb, radius=Rvalb, rot=rotvalb, Ip=Ipvalb) +sim.add_body(name=names, a=avals, e=evals, inc=incvals, capom=capomvals, omega=omegavals, capm=capmvals, mass=Mvals, radius=Rvals, rot=rotvals, Ip=Ipvals) +sim.set_parameter(mtiny=mtiny, minimum_fragment_mass=minimum_fragment_mass, nfrag_reduction=nfrag_reduction) + +sim.set_parameter(tstop=3e8, dt=6.0875/365.25, istep_out=60000, dump_cadence=10) +sim.save() + +# Plot the initial conditions +fig = plt.figure(figsize=(8.5, 11)) +ax1 = plt.subplot(2, 1, 1) +ax2 = plt.subplot(2, 1, 2) +fig.suptitle(runname) + +ic = sim.init_cond.isel(time=0) +radius = ic['radius'].values +markersize = radius * 4e5 +markercolor = np.where(radius < 2.0e-5, np.full_like(markersize, "black",dtype=object), np.full_like(markersize,"red",dtype=object)) +a = ic['a'].values +e = ic['e'].values +inc = ic['inc'].values + +ax1.scatter(a, e, s=markersize, color=markercolor, label=None) +ax1.set_xlabel("Semimajor Axis (AU)") +ax1.set_ylabel("Eccentricity") +ax1.set_xlim([0.0, 2.5]) +ax1.set_ylim([0.0,4*esigma]) + +ax2.scatter(a, inc, s=markersize, color=markercolor, label=None) +ax2.set_xlabel("Semimajor Axis (AU)") +ax2.set_ylabel("Inclination (deg)") +ax2.set_xlim([0.0, 2.5]) +ax2.set_ylim([0.0,8*isigma]) + +ax1.scatter(-1, -1, label='planetesimal', color='black') +ax1.scatter(-1, -1, label='embryo', color='red') +ax1.legend(loc='upper right', frameon=False) + +plt.tight_layout() +plt.show() +fig.savefig('initial_conditions.png',dpi=300) + diff --git a/examples/Chambers2013/run_simulation.py b/examples/Chambers2013/run_simulation.py new file mode 100755 index 000000000..5ae2fb2a3 --- /dev/null +++ b/examples/Chambers2013/run_simulation.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +""" + Copyright 2023 - David Minton + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +""" +This will run the simulation from a set of initial conditions. The simulation parameters in this file are set to generate +a very short simulation for testing purposes. Edit the values passed to the run() function as necessary. + +Input +------ +simdata/param.in : ASCII Swiftest parameter input file. + +Output +------ +Outputs are stored in the /simdata subdirectory. + +""" +import swiftest +sim = swiftest.Simulation(read_param=True) + +# Original run parameters +# sim.run(tstop=3e8, dt=6.0875/365.25, istep_out=60000, dump_cadence=10,integreator="symba") +# +sim.run(tstop=10000.0, dt=6.0875/365.25, istep_out=10000, dump_cadence=0, integrator="symba") diff --git a/examples/Chambers2013/scattermovie.py b/examples/Chambers2013/scattermovie.py index 98b0645ef..e1eda643a 100755 --- a/examples/Chambers2013/scattermovie.py +++ b/examples/Chambers2013/scattermovie.py @@ -15,6 +15,15 @@ Creates a movie from a set of Swiftest output files. All simulation outputs are stored in the /simdata subdirectory. +**NOTE: You must have ffmpeg installed on your system before running this script. For instance, on MacOS: + +```brew install ffmpeg``` + +on Ubuntu: + +```sudo apt-get install ffmpeg``` + + Input ------ param.in : ASCII Swiftest parameter input file. @@ -33,6 +42,8 @@ from matplotlib import animation import matplotlib.colors as mcolors from collections import namedtuple + + plt.switch_backend('agg') titletext = "Chambers (2013)" @@ -108,8 +119,8 @@ def init_plot(self): self.ax.set_ylabel(ylabel[plot_style], fontsize='16', labelpad=1) leg = plt.legend(loc="upper left", scatterpoints=1, fontsize=10) - for i,l in enumerate(leg.legendHandles): - leg.legendHandles[i]._sizes = [20] + for i,l in enumerate(leg.legend_handles): + leg.legend_handles[i]._sizes = [20] if plot_style == "arotscatter": self.ax.set_yscale('log') diff --git a/pyproject.toml b/pyproject.toml index 488fbaf6b..5e76778a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,18 +26,19 @@ keywords=['astronomy','astrophysics', 'planetary', 'nbody integrator', 'symplect dependencies = [ 'numpy>=1.24.3', 'scipy>=1.10.1', - 'xarray>=2022.11.0', - 'dask>=2022.1', - 'distributed>=2022.1', - 'bottleneck>=1.3.5', - 'h5netcdf', - 'h5py', - 'netcdf4', - 'matplotlib>=3.7.1', - 'astropy>=5.1', + 'xarray>=2023.1', + 'dask>=2023.5', + 'distributed>=2023.5', + 'bottleneck>=1.3', + 'h5netcdf>=1.1', + 'h5py>=3.9', + 'netcdf4>=1.6.4', + 'matplotlib>=3.7', + 'astropy>=5.2', 'astroquery>=0.4.6', - 'tqdm>=4.65.0', + 'tqdm>=4.66', 'cython>=3.0.0', + 'pyshtools>=4.10' ] [project.urls] @@ -98,14 +99,14 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ - "brew install coreutils", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" + "brew install coreutils shtools", + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] skip = "cp312-* pp* -manylinux_i686* *-musllinux*" before-all = [ - "yum install doxygen libxml2-devel libcurl-devel -y", + "yum install doxygen libxml2-devel libcurl-devel fftw-devel blas-devel lapack-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" ] [tool.cibuildwheel.linux.environment] From ba9f0883f10f96f2d9b73e2f112b18e1369d6c29 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:02:34 -0500 Subject: [PATCH 70/77] Decrased the number of fragments made in the example movie script to make it run faster, and rearranged script to make the variable that controls fragment number more obvious. --- examples/Fragmentation/Fragmentation_Movie.py | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/examples/Fragmentation/Fragmentation_Movie.py b/examples/Fragmentation/Fragmentation_Movie.py index 4905e05f6..c58ad53c9 100755 --- a/examples/Fragmentation/Fragmentation_Movie.py +++ b/examples/Fragmentation/Fragmentation_Movie.py @@ -14,22 +14,24 @@ Generates and runs a set of Swiftest input files from initial conditions with the SyMBA integrator. All simulation outputs are stored in the subdirectory named after their collisional regime. +**NOTE: You must have ffmpeg installed on your system before running this script. For instance, on MacOS: + +```brew install ffmpeg``` + +on Ubuntu: + +```sudo apt-get install ffmpeg``` + + Inputs _______ -None. +User selects which collisional movie to generate Output ------ -collisions.log : An ASCII file containing the information of any collisional events that occured. -collisions.nc : A NetCDF file containing the collision output. -data.nc : A NetCDF file containing the simulation output. -encounters.nc : A NetCDF file containing the encounter output. -init_cond.nc : A NetCDF file containing the initial conditions for the simulation. -param.00...0.in : A series of parameter input files containing the parameters for the simulation at every output stage. -param.in : An ASCII file containing the inital parameters for the simulation. -param.restart.in : An ASCII file containing the parameters for the simulation at the last output. -swiftest.log : An ASCII file containing the information on the status of the simulation as it runs. -collision.mp4 : A movie file named after the collisional regime depicting the collision. + +Files are stored in directories for each collision type name requested +[COLLISION_TYPE].mp4 : A movie file named after the collisional regime depicting the collision. """ @@ -48,6 +50,22 @@ movie_titles = dict(zip(available_movie_styles, movie_title_list)) num_movie_frames = 1000 + +# ---------------------------------------------------------------------------------------------------------------------- +# To increase the number of bodies generated in each collision type, decrease the value of the corresponding nfrag_reduction number +# ---------------------------------------------------------------------------------------------------------------------- +nfrag_reduction = {"disruption_headon" : 10.0, + "disruption_off_axis" : 10.0, + "supercatastrophic_headon" : 10.0, + "supercatastrophic_off_axis" : 10.0, + "hitandrun_disrupt" : 10.0, + "hitandrun_pure" : 1.0, + "merge" : 1.0, + "merge_spinner" : 1.0, + } + + + # These initial conditions were generated by trial and error names = ["Target","Projectile"] pos_vectors = {"disruption_headon" : [np.array([1.0, -5.0e-05, 0.0]), @@ -124,16 +142,6 @@ "merge_spinner" : 5.0e-3, } -nfrag_reduction = {"disruption_headon" : 1.0, - "disruption_off_axis" : 1.0, - "supercatastrophic_headon" : 1.0, - "supercatastrophic_off_axis" : 10.0, - "hitandrun_disrupt" : 1.0, - "hitandrun_pure" : 1.0, - "merge" : 1.0, - "merge_spinner" : 1.0, - } - density = 3000 * swiftest.AU2M**3 / swiftest.MSun GU = swiftest.GMSun * swiftest.YR2S**2 / swiftest.AU2M**3 body_radius = body_Gmass.copy() From 5e87b551070c6a1d2ab313a5aa1e09911af48bc1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 4 Oct 2023 16:53:26 -0400 Subject: [PATCH 71/77] Fixed mistake in format string that was printing an extra quotation mark --- src/swiftest/swiftest_io.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 46551788a..40a9d286b 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -128,8 +128,8 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal) real(DP), dimension(NDIM) :: L_total_now, L_orbit_now, L_spin_now real(DP) :: ke_orbit_now, ke_spin_now, pe_now, E_orbit_now, be_now, be_cb_now, be_cb_orig, te_now real(DP) :: GMtot_now - character(len=*), parameter :: EGYTERMFMT = '(" DL/L0 = ", ES12.5, "; DE_orbit/|E0| = ", ES12.5, ";"' & - //'" DE_total/|E0| = ", ES12.5, "; DM/M0 = ", ES12.5)' + character(len=*), parameter :: EGYTERMFMT = '(" DL/L0 = ", ES12.5, "; DE_orbit/|E0| = ", ES12.5,' & + //'"; DE_total/|E0| = ", ES12.5, "; DM/M0 = ", ES12.5)' associate(nbody_system => self, pl => self%pl, cb => self%cb, npl => self%pl%nbody, display_unit => param%display_unit) From 618ee628e7df945f5b9d68e2d4ed4ebdb1804a2a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 4 Oct 2023 16:57:45 -0400 Subject: [PATCH 72/77] Fixed typo in omp reduction statement. --- src/swiftest/swiftest_kick.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swiftest/swiftest_kick.f90 b/src/swiftest/swiftest_kick.f90 index d0700d321..cfd9ef54c 100644 --- a/src/swiftest/swiftest_kick.f90 +++ b/src/swiftest/swiftest_kick.f90 @@ -191,7 +191,7 @@ module subroutine swiftest_kick_getacch_int_all_tri_rad_pl(npl, nplm, r, Gmass, ahj(:,:) = 0.0_DP !$omp parallel do default(private) schedule(static)& !$omp shared(npl, nplm, r, Gmass, radius) & - !$omp reduction(+:ahi,j) + !$omp reduction(+:ahi,ahj) do i = 1, nplm #ifdef DOCONLOC do concurrent(j = i+1:npl) shared(i,r,radius,ahi,ahj,Gmass) local(rx,ry,rz,rji2,rlim2) From bf3d684803b8c3d1e0c6ad6cfca292f6df0ad21f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 4 Oct 2023 16:58:16 -0400 Subject: [PATCH 73/77] Fixed issue that caused momentum convergence to be unstable due to floating point precision. --- src/fraggle/fraggle_generate.f90 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index aeeae27d9..d3f059e76 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -635,7 +635,7 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu real(DP), dimension(NDIM) :: vimp_unit, rimp, vrot, vdisp, L_residual, L_residual_unit, L_residual_best, dL, drot, rot_new real(DP), dimension(NDIM) :: dL_metric real(DP) :: vimp, vmag, vesc, dE, E_residual, E_residual_best, E_residual_last, ke_avail, ke_remove, dE_best, fscale - real(DP) :: dE_metric, mfrag, rn, dL1_mag, dE_conv, vumag + real(DP) :: dE_metric, mfrag, rn, dL1_mag, dE_conv, vumag, L_mag_factor integer(I4B), dimension(:), allocatable :: vsign real(DP), dimension(:), allocatable :: vscale real(DP), dimension(:), allocatable :: dLi_mag @@ -754,9 +754,10 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu ! Try to put residual angular momentum into the spin, but if this would go past the spin barrier, then put it into ! velocity shear instead call collider_local%get_energy_and_momentum(nbody_system, param, phase="after") - L_residual(:) = (collider_local%L_total(:,2) - collider_local%L_total(:,1)) + L_mag_factor = .mag.(collider_local%L_total(:,1) + collider_local%L_total(:,2)) + L_residual(:) = (collider_local%L_total(:,2) / L_mag_factor - collider_local%L_total(:,1) / L_mag_factor) L_residual_unit(:) = .unit. L_residual(:) - if (nsteps == 1) L_residual_best(:) = L_residual(:) + if (nsteps == 1) L_residual_best(:) = L_residual(:) * L_mag_factor ! Use equipartition of spin kinetic energy to distribution spin angular momentum #ifdef DOCONLOC @@ -768,7 +769,7 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu (fragments%radius(i) / fragments%radius(istart))**2 * & (fragments%Ip(3,i) / fragments%Ip(3,istart)))**(1.5_DP) end do - dL1_mag = .mag.L_residual(:) / sum(dLi_mag(istart:fragments%nbody)) + dL1_mag = .mag.L_residual(:) * L_mag_factor / sum(dLi_mag(istart:fragments%nbody)) do i = istart,fragments%nbody dL(:) = -dL1_mag * dLi_mag(i) * L_residual_unit(:) @@ -789,20 +790,22 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu fragments%rot(:,i) = fragments%rotmag(i) * .unit. fragments%rot(:,i) end if end if - L_residual(:) = L_residual(:) + drot(:) * fragments%Ip(3,i) * fragments%mass(i) * fragments%radius(i)**2 + L_residual(:) = L_residual(:) + drot(:) * fragments%Ip(3,i) * fragments%mass(i) * fragments%radius(i)**2 & + / L_mag_factor end do ! Put any remaining residual into velocity shear angmtm: do j = 1, MAXANGMTM if (j == MAXANGMTM) exit inner call collider_local%get_energy_and_momentum(nbody_system, param, phase="after") - L_residual(:) = (collider_local%L_total(:,2) - collider_local%L_total(:,1)) - dL_metric(:) = abs(L_residual(:)) / .mag.(collider_local%L_total(:,1)) / MOMENTUM_SUCCESS_METRIC + L_mag_factor = .mag.(collider_local%L_total(:,1) + collider_local%L_total(:,2)) + L_residual(:) = (collider_local%L_total(:,2) / L_mag_factor - collider_local%L_total(:,1)/L_mag_factor) + dL_metric(:) = abs(L_residual(:)) / MOMENTUM_SUCCESS_METRIC if (all(dL_metric(:) <= 1.0_DP)) exit angmtm do i = istart, fragments%nbody - dL(:) = -L_residual(:) * fragments%mass(i) / sum(fragments%mass(istart:fragments%nbody)) + dL(:) = -L_residual(:) * L_mag_factor * fragments%mass(i) / sum(fragments%mass(istart:fragments%nbody)) call collision_util_velocity_torque(dL, fragments%mass(i), fragments%rc(:,i), fragments%vc(:,i)) end do call collision_util_shift_vector_to_origin(fragments%mass, fragments%vc) @@ -817,8 +820,9 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu E_residual_last = E_residual E_residual = dE + impactors%Qloss - L_residual(:) = (collider_local%L_total(:,2) - collider_local%L_total(:,1)) - dL_metric(:) = abs(L_residual(:)) / .mag.collider_local%L_total(:,1) / MOMENTUM_SUCCESS_METRIC + L_mag_factor = .mag.(collider_local%L_total(:,1) + collider_local%L_total(:,2)) + L_residual(:) = (collider_local%L_total(:,2) / L_mag_factor - collider_local%L_total(:,1) / L_mag_factor) + dL_metric(:) = abs(L_residual(:)) / MOMENTUM_SUCCESS_METRIC dE_conv = abs(E_residual - E_residual_last) / abs(E_residual_last) ! Check if we've converged on our constraints @@ -826,7 +830,7 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu if ((abs(E_residual) < abs(E_residual_best)) .or. ((dE < 0.0_DP) .and. (dE_best >= 0.0_DP))) then ! This is our best case so far. Save it for posterity E_residual_best = E_residual - L_residual_best(:) = L_residual(:) + L_residual_best(:) = L_residual(:) * L_mag_factor dE_best = dE nsteps_best = nsteps @@ -877,8 +881,9 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu // trim(adjustl(message)) // " steps.") call collider%get_energy_and_momentum(nbody_system, param, phase="after") - L_residual(:) = (collider%L_total(:,2) - collider%L_total(:,1)) - call collision_util_velocity_torque(-L_residual(:), collider%fragments%mtot, impactors%rbcom, impactors%vbcom) + L_mag_factor = .mag.(collider%L_total(:,1) + collider%L_total(:,2)) + L_residual(:) = (collider%L_total(:,2) / L_mag_factor - collider%L_total(:,1)) / L_mag_factor + call collision_util_velocity_torque(-L_residual(:) * L_mag_factor, collider%fragments%mtot, impactors%rbcom, impactors%vbcom) #ifdef DOCONLOC do concurrent(i = 1:nfrag) shared(collider, impactors) From 05101f98009e23151aca1558ee4b05460d94a420 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:14:48 -0500 Subject: [PATCH 74/77] Improved the fragmentation movie scripts --- examples/Fragmentation/Fragmentation_Movie.py | 6 ++++- .../Multibody_Movie.py | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/Fragmentation/Fragmentation_Movie.py b/examples/Fragmentation/Fragmentation_Movie.py index c58ad53c9..b7154f4bb 100755 --- a/examples/Fragmentation/Fragmentation_Movie.py +++ b/examples/Fragmentation/Fragmentation_Movie.py @@ -366,7 +366,11 @@ def vec_props(self, c): # Set fragmentation parameters minimum_fragment_gmass = 0.01 * body_Gmass[style][1] gmtiny = 0.50 * body_Gmass[style][1] - sim.set_parameter(collision_model="fraggle", encounter_save="both", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, nfrag_reduction=nfrag_reduction[style]) + sim.set_parameter(collision_model="fraggle", + encounter_save="both", + gmtiny=gmtiny, + minimum_fragment_gmass=minimum_fragment_gmass, + nfrag_reduction=nfrag_reduction[style]) sim.run(dt=5e-4, tstop=tstop[style], istep_out=1, dump_cadence=0) print("Generating animation") diff --git a/examples/Multibody_Fragmentation/Multibody_Movie.py b/examples/Multibody_Fragmentation/Multibody_Movie.py index 7c3d28359..dde262355 100755 --- a/examples/Multibody_Fragmentation/Multibody_Movie.py +++ b/examples/Multibody_Fragmentation/Multibody_Movie.py @@ -14,6 +14,15 @@ Generates, runs, and processes a set of initial conditions for a multi-body super-catastrophic distruption collisional event. All Swiftest output files are stored in the /supercatastrophic_multi subdirectory. +**NOTE: You must have ffmpeg installed on your system before running this script. For instance, on MacOS: + +```brew install ffmpeg``` + +on Ubuntu: + +```sudo apt-get install ffmpeg``` + + Inputs _______ None. @@ -47,6 +56,16 @@ movie_titles = dict(zip(available_movie_styles, movie_title_list)) num_movie_frames = 1000 + +# ---------------------------------------------------------------------------------------------------------------------- +# To increase the number of bodies generated in each collision type, decrease the value of the corresponding nfrag_reduction number +# ---------------------------------------------------------------------------------------------------------------------- +nfrag_reduction = { + "supercatastrophic_multi" : 5.0, + } + + + # These initial conditions were generated by trial and error names = ["Body1","Body2","Body3","Body4"] @@ -287,7 +306,12 @@ def vec_props(self, c): # Set fragmentation parameters minimum_fragment_gmass = 0.05 * body_Gmass[style][1] gmtiny = 0.10 * body_Gmass[style][1] - sim.set_parameter(collision_model="fraggle", encounter_save="both", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False) + sim.set_parameter(collision_model="fraggle", + encounter_save="both", + gmtiny=gmtiny, + minimum_fragment_gmass=minimum_fragment_gmass, + nfrag_reduction=nfrag_reduction[style], + verbose=False) sim.run(dt=5e-4, tstop=tstop[style], istep_out=1, dump_cadence=0) print("Generating animation") From d5647ad27d2854603e6fe292f104e27cca879515 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:19:19 -0500 Subject: [PATCH 75/77] Fixed some issues that arose due to the bad merge from the oblate branch --- pyproject.toml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5e76778a6..2789589fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "swiftest" -version = "2023.10.0" +version = "2023.10.1" authors=[ {name = 'David A. Minton', email='daminton@purdue.edu'}, {name = 'Carlisle Wishard'}, @@ -32,13 +32,12 @@ dependencies = [ 'bottleneck>=1.3', 'h5netcdf>=1.1', 'h5py>=3.9', - 'netcdf4>=1.6.4', + 'netcdf4>=1.6', 'matplotlib>=3.7', 'astropy>=5.2', 'astroquery>=0.4.6', 'tqdm>=4.66', 'cython>=3.0.0', - 'pyshtools>=4.10' ] [project.urls] @@ -99,14 +98,14 @@ netCDF-Fortran_DIR="${PREFIX}/lib/cmake/netCDF" [tool.cibuildwheel.macos] before-all = [ - "brew install coreutils shtools", - "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${PREFIX}/build -m ${MACOSX_DEPLOYMENT_TARGET}" + "brew install coreutils", + "LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}" ] [tool.cibuildwheel.linux] skip = "cp312-* pp* -manylinux_i686* *-musllinux*" before-all = [ - "yum install doxygen libxml2-devel libcurl-devel fftw-devel blas-devel lapack-devel -y", + "yum install doxygen libxml2-devel libcurl-devel -y", "buildscripts/build_dependencies.sh -p /usr/local" ] [tool.cibuildwheel.linux.environment] From 6b3a6b918843bd72f82f33b15db95a0e2c2be63d Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:19:27 -0500 Subject: [PATCH 76/77] Updated version --- src/globals/globals_module.f90 | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index d1a078329..def76b400 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -48,7 +48,7 @@ module globals integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper !! conversion - offset between upper and lower - character(*), parameter :: VERSION = "2023.10.0" !! Swiftest version + character(*), parameter :: VERSION = "2023.10.1" !! Swiftest version !> Symbolic name for integrator types character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR" diff --git a/version.txt b/version.txt index 3bae60812..ea516b56c 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2023.10.0 \ No newline at end of file +2023.10.1 \ No newline at end of file From d2e73157f0f4d0f2a5ca1249ab4f8c53744052cf Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:46:42 -0500 Subject: [PATCH 77/77] Tweaks to the fraggle convergence loop limits to get a higher success rate in fitting angular momentum and energy constraints. --- src/fraggle/fraggle_generate.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index d3f059e76..746e768d2 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -644,8 +644,8 @@ module subroutine fraggle_generate_vel_vec(collider, nbody_system, param, lfailu real(DP), parameter :: hitandrun_vscale = 0.25_DP real(DP) :: vmin_guess real(DP) :: vmax_guess - integer(I4B), parameter :: MAXLOOP = 25 - integer(I4B), parameter :: MAXTRY = 10 + integer(I4B), parameter :: MAXLOOP = 50 + integer(I4B), parameter :: MAXTRY = 50 integer(I4B), parameter :: MAXANGMTM = 1000 class(collision_fraggle), allocatable :: collider_local character(len=STRMAX) :: message