diff --git a/.gitignore b/.gitignore index d9bee1a0a..fff9d130a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ dump* !python/swiftest/tests/test_suite.py !version.txt + #Documentation !docs/* !docs/*/* diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index a7c46e10d..c4c18cced 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -123,9 +123,9 @@ IF (NOT BUILD_SHARED_LIBS) IF (USE_OPENMP) SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-qopenmp-link=static" # Intel - ) + ) ENDIF (USE_OPENMP) - ELSEIF (COMPIELR_OPTIONS STREQUAL "GNU") + ELSEIF (COMPILER_OPTIONS STREQUAL "GNU") # Set GNU static libraries SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS}" Fortran "-static-libgfortran" diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 000000000..e8e3a7829 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +!setup.py.in diff --git a/python/setup.py b/python/setup.py index 5abe8d762..cc21e2f32 100644 --- a/python/setup.py +++ b/python/setup.py @@ -19,14 +19,13 @@ include_dirs = "/Users/daminton/git/swiftest/apple_install/usr/local/include;/Users/daminton/git/swiftest/apple_install/usr/local/include" include_dirs = include_dirs.split() include_dirs.append(root_dir) -link_flags = "-lswiftest /Users/daminton/git/swiftest/apple_install/usr/local/lib/libnetcdff.a /Users/daminton/git/swiftest/apple_install/usr/local/lib/libnetcdf.a -L/Users/daminton/git/swiftest/apple_install/usr/local/lib -lhdf5_hl -lhdf5 -lm -lz -lbz2 -lxml2 -lcurl" +link_flags = " -static-libgfortran -static-libgcc -static-libstdc++" link_flags = link_flags.split() pybindings_extension = [Extension('swiftest.bindings', [os.path.join(root_dir,'pybindings.pyx')], - extra_compile_args=['-fPIC', '-O3','-fopenmp'], + extra_compile_args=['-fPIC', '-O3'], extra_link_args=link_flags, - libraries=['gfortran','omp'], include_dirs=include_dirs, )] diff --git a/python/setup.py.in b/python/setup.py.in new file mode 100644 index 000000000..8a111a7d5 --- /dev/null +++ b/python/setup.py.in @@ -0,0 +1,38 @@ +""" + 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. +""" + +from setuptools import setup, find_packages, Extension +from Cython.Build import cythonize +import os + +# Build the pybindings extension that allows us to run the Fortran driver as a Python module. +root_dir = 'pybindings' +include_dirs = "${SWIFTEST_INCLUDE_DIR}" +include_dirs = include_dirs.split() +include_dirs.append(root_dir) +link_flags = "${CMAKE_Fortran_LINK_FLAGS}" +link_flags = link_flags.split() + +pybindings_extension = [Extension('swiftest.bindings', + [os.path.join(root_dir,'pybindings.pyx')], + extra_compile_args=['-fPIC', '-O3'], + extra_link_args=link_flags, + include_dirs=include_dirs, + )] + +setup(name='swiftest', + version='${CMAKE_PROJECT_VERSION}', + author='David A. Minton', + author_email='daminton@purdue.edu', + url='https://github.itap.purdue.edu/MintonGroup/swiftest', + ext_modules = cythonize(pybindings_extension), + packages=find_packages()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9307b7ed..686a0627c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,7 +131,7 @@ IF(USE_COARRAY) SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ") ENDIF(USE_COARRAY) -STRING(REPLACE ";" " " SWIFTEST_LINK_FLAGS "${CMAKE_LINK_LIBRARY_FLAG}${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}") +STRING(REPLACE ";" " " SWIFTEST_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${CMAKE_LINK_LIBRARY_FLAG}${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}") SET(SWIFTEST_LINK_FLAGS "${SWIFTEST_LINK_FLAGS}" CACHE STRING "Link flags to pass to setup.py") GET_TARGET_PROPERTY(SWIFTEST_INCLUDE_DIR ${SWIFTEST_DRIVER} INCLUDE_DIRECTORIES) diff --git a/src/globals/.gitignore b/src/globals/.gitignore new file mode 100644 index 000000000..e5fc85513 --- /dev/null +++ b/src/globals/.gitignore @@ -0,0 +1 @@ +!globals_module.f90.in diff --git a/src/globals/globals_module.f90.in b/src/globals/globals_module.f90.in new file mode 100644 index 000000000..8d107af1e --- /dev/null +++ b/src/globals/globals_module.f90.in @@ -0,0 +1,133 @@ +!! 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. + +module globals + !! author: David A. Minton + !! graph: false + !! + !! Basic parameters, definitions, and global type definitions used throughout the Swiftest project + !! Adapted from David E. Kaufmann's Swifter routine: globals.f90 and module_swifter.f90 + use, intrinsic :: iso_fortran_env ! Use the intrinsic kind definitions + implicit none + public + + integer, parameter :: I8B = int64 !! Symbolic name for kind types of 8-byte integers + integer, parameter :: I4B = int32 !! Symbolic name for kind types of 4-byte integers + integer, parameter :: I2B = int16 !! Symbolic name for kind types of 2-byte integers + integer, parameter :: I1B = int8 !! Symbolic name for kind types of 1-byte integers + + integer, parameter :: SP = real32 !! Symbolic name for kind types of single-precision reals + integer, parameter :: DP = real64 !! Symbolic name for kind types of double-precision reals + integer, parameter :: QP = real128 !! Symbolic name for kind types of quad-precision reals + + real(DP), parameter :: PIBY2 = 1.570796326794896619231321691639751442099_DP !! Definition of /(\pi / 2\) + real(DP), parameter :: PI = 3.141592653589793238462643383279502884197_DP !! Definition of /(\pi\) + real(DP), parameter :: PI3BY2 = 4.712388980384689857693965074919254326296_DP !! Definition of /(3 \pi / 2\) + real(DP), parameter :: TWOPI = 6.283185307179586476925286766559005768394_DP !! Definition of 2 \pi + real(DP), parameter :: THIRD = 0.333333333333333333333333333333333333333_DP !! Definition of 1 / 3 + real(DP), parameter :: SIXTH = 0.166666666666666666666666666666666666667_DP !! Definition of 1 / 3 + real(DP), parameter :: DEG2RAD = PI / 180.0_DP !! Definition of conversion factor from degrees to radians + real(DP), parameter :: RAD2DEG = 180.0_DP / PI !! Definition of conversion factor from degrees to radians + real(DP), parameter :: GC = 6.6743E-11_DP !! Universal gravitational constant in SI units + real(DP), parameter :: einsteinC = 299792458.0_DP !! Speed of light in SI units + + integer(I4B), parameter :: LOWERCASE_BEGIN = iachar('a') !! ASCII character set parameter for lower to upper conversion - start + !! of lowercase + integer(I4B), parameter :: LOWERCASE_END = iachar('z') !! ASCII character set parameter for lower to upper conversion - end of + !! lowercase + 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 = "${CMAKE_PROJECT_VERSION}" !! Swiftest version + + !> Symbolic name for integrator types + character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR" + character(*), parameter :: INT_BS = "Bulirsch-Stoer" + character(*), parameter :: INT_HELIO = "Democratic Heliocentric" + character(*), parameter :: INT_RA15 = "Radau 15th order" + character(*), parameter :: INT_TU4 = "T+U 4th order" + character(*), parameter :: INT_WHM = "Wisdom-Holman Method" + character(*), parameter :: INT_RMVS = "Regularized Mixed Variable Symplectic" + character(*), parameter :: INT_SYMBA = "SyMBA" + character(*), parameter :: INT_RINGMOONS = "SyMBA-RINGMOONS" + + integer(I4B), parameter :: STRMAX = 512 !! Maximum size of character strings + integer(I4B), parameter :: NAMELEN = 32 !! Maximum size of name strings + + character(*), parameter :: CB_TYPE_NAME = "Central Body" + character(*), parameter :: PL_TYPE_NAME = "Massive Body" + character(*), parameter :: TP_TYPE_NAME = "Test Particle" + character(*), parameter :: PL_TINY_TYPE_NAME = "Semi-Interacting Massive Body" + + ! OpenMP Parameters + integer(I4B) :: nthreads = 1 !! Number of OpenMP threads + integer(I4B), parameter :: NTHERSHOLD = 1000 !! Threshold value for OpenMP loop parallelization + + integer(I4B), parameter :: SUCCESS = 0 !! Symbolic name for function return/flag code for success + integer(I4B), parameter :: FAILURE = -1 !! Symbolic name for function return/flag code for failure + integer(I4B), parameter :: USAGE = -2 !! Symbolic name for function return/flag code for printing the usage message + integer(I4B), parameter :: HELP = -3 !! Symbolic name for function return/flag code for printing the usage message + + integer(I4B), parameter :: ELLIPSE = -1 !! Symbolic names for orbit types - ellipse + integer(I4B), parameter :: PARABOLA = 0 !! Symbolic names for orbit types - parabola + integer(I4B), parameter :: HYPERBOLA = 1 !! Symbolic names for orbit types - hyperbola + + !> Symbolic names for body/particle status codes: + integer(I4B), parameter :: ACTIVE = 0 + integer(I4B), parameter :: INACTIVE = 1 + integer(I4B), parameter :: DISCARDED_RMAX = -1 + integer(I4B), parameter :: DISCARDED_RMIN = -2 + integer(I4B), parameter :: DISCARDED_RMAXU = -3 + integer(I4B), parameter :: DISCARDED_PERI = -4 + integer(I4B), parameter :: DISCARDED_PLR = -5 + integer(I4B), parameter :: DISCARDED_PLQ = -6 + integer(I4B), parameter :: DISCARDED_DRIFTERR = -7 + integer(I4B), parameter :: MERGED = -8 + integer(I4B), parameter :: DISRUPTED = -9 + integer(I4B), parameter :: SUPERCATASTROPHIC = -10 + integer(I4B), parameter :: GRAZE_AND_MERGE = -11 + integer(I4B), parameter :: HIT_AND_RUN_DISRUPT = -12 + integer(I4B), parameter :: HIT_AND_RUN_PURE = -13 + integer(I4B), parameter :: COLLIDED = -14 + integer(I4B), parameter :: NEW_PARTICLE = -15 + integer(I4B), parameter :: OLD_PARTICLE = -16 + + !> String labels for body/particle addition/subtraction in discard file + character(*), parameter :: ADD = '+1' + character(*), parameter :: SUB = '-1' + + !> Standard file names + integer(I4B), parameter :: NDUMPFILES = 2 + character(*), parameter :: PARAM_RESTART_FILE = "param.restart.in" +#ifdef COARRAY + character(STRMAX) :: SWIFTEST_LOG_FILE !! Name of file to use to log output when using "COMPACT" or + !! "PROGRESS" display style (each co-image gets its own log file) +#else + character(*), parameter :: SWIFTEST_LOG_FILE = "swiftest.log" !! Name of file to use to log output when using "COMPACT" or + !! "PROGRESS" display style +#endif + integer(I4B), parameter :: SWIFTEST_LOG_OUT = 33 !! File unit for log file when using "COMPACT" display style + + !> Default file names that can be changed by the user in the parameters file + character(*), parameter :: CB_INFILE = 'cb.in' + character(*), parameter :: PL_INFILE = 'pl.in' + character(*), parameter :: TP_INFILE = 'tp.in' + character(*), parameter :: NC_INFILE = 'init_cond.nc' + character(*), parameter :: BIN_OUTFILE = 'data.nc' + integer(I4B), parameter :: BINUNIT = 20 !! File unit number for the binary output file + integer(I4B), parameter :: PARTICLEUNIT = 44 !! File unit number for the binary particle info output file + integer(I4B), parameter :: LUN = 42 !! File unit number for files that are opened and closed within a single + !! subroutine call, and therefore should not collide + + !> Miscellaneous constants: + integer(I4B), parameter :: NDIM = 3 !! Number of dimensions in our reality + integer(I4B), parameter :: NDIM2 = 2 * NDIM !! 2x the number of dimensions + real(DP), parameter :: VSMALL = sqrt(TINY(1._DP)) !! Very small number used to prevent floating underflow + +end module globals