Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Aug 8, 2023
2 parents c250c7a + b7fddf4 commit cc164ee
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 188 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1)
# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(Swiftest VERSION ${VERSION} LANGUAGES Fortran)
PROJECT(swiftest VERSION ${VERSION} LANGUAGES Fortran)

INCLUDE(CTest)

Expand Down Expand Up @@ -58,17 +58,21 @@ INCLUDE_DIRECTORIES($ENV{NETCDF_FORTRAN_HOME}/include;$ENV{NETCDF_HOME}/include)
# Define the actual files and folders that make up the build
############################################################

# Define the executable name
SET(SWIFTEST_DRIVER swiftest_driver)


# Define some directories
SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
SET(MOD ${CMAKE_SOURCE_DIR}/include)
SET(TEST ${CMAKE_SOURCE_DIR}/test)
#SET(TEST ${CMAKE_SOURCE_DIR}/test)
SET(PY ${CMAKE_SOURCE_DIR}/python/swiftest)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN})


FUNCTION(REPLACE_VERSION IN_FILE LANGUAGE)
# Make list of strings from file
FILE(STRINGS ${IN_FILE} LINES)
Expand Down Expand Up @@ -106,9 +110,9 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})
# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})

# Set up test directory
ENABLE_TESTING()
ADD_SUBDIRECTORY(${TEST})
# # Set up test directory
# ENABLE_TESTING()
# ADD_SUBDIRECTORY(${TEST})

# Add a distclean target to the Makefile
ADD_CUSTOM_TARGET(distclean
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ ENV LIBS="-lhdf5_hl -lhdf5 -lz"
COPY ./cmake/ /swiftest/cmake/
COPY ./src/ /swiftest/src/
COPY ./CMakeLists.txt /swiftest/
COPY ./python/ /swiftest/python/
COPY ./version.txt /swiftest/
RUN cd swiftest && \
cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} \
Expand All @@ -128,6 +130,15 @@ ENTRYPOINT ["/usr/local/bin/swiftest_driver"]
FROM scratch AS export_driver
COPY --from=build_driver /usr/local/bin/swiftest_driver /

# This build target exports the static library to the host
FROM scratch as export_library
COPY --from=build_driver /usr/local/lib/libswiftest.a /

# This build target exports the module file to the host
FROM scratch as export_module
COPY --from=build_driver /swiftest/include/ /swiftest/


# This build target creates a container with a conda environment with all dependencies needed to run the Python front end and
# analysis tools
FROM continuumio/miniconda3 as python
Expand All @@ -137,6 +148,8 @@ ENV PATH="/opt/conda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/lib"

COPY --from=build_driver /usr/local/bin/swiftest_driver /opt/conda/bin/swiftest_driver
COPY --from=build_driver /usr/local/lib/libswiftest.a /opt/conda/lib/libswiftest.a
COPY --from=build_driver /swiftest/include/ /opt/conda/include/swiftest/
COPY ./python/. /opt/conda/pkgs/
COPY environment.yml .

Expand Down
24 changes: 24 additions & 0 deletions python/swiftest/f2py/pydriver.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
subroutine driver(integrator, param_file_name, display_style)

!! author: David A. Minton
!!
!! Driver program for the Swiftest integrators. Unlike the earlier Swift and Swifter drivers, in Swiftest all integrators
!! are run from this single program.
!!
!! Adapted from Swifter by David E. Kaufmann's Swifter driver programs swifter_[bs,helio,ra15,rmvs,symba,tu4,whm].f90
!! Adapted from Hal Levison and Martin Duncan's Swift driver programs
use swiftest, only : swiftest_driver
implicit none

! Arguments
character(len=:), intent(in), allocatable :: integrator !! Symbolic code of the requested integrator
character(len=:), intent(in), allocatable :: param_file_name !! Name of the input parameters file
character(len=:), intent(in), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD")
!f2py intent(in) integrator
!f2py intent(in) param_file_name
!f2py intent(in) display_style

call swiftest_driver(integrator, param_file_name, display_style)

return
end subroutine driver
63 changes: 38 additions & 25 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ SET(FAST_MATH_FILES
${SRC}/rmvs/rmvs_util.f90
${SRC}/swiftest/swiftest_discard.f90
${SRC}/swiftest/swiftest_util.f90
${SRC}/swiftest/swiftest_driver.f90
${SRC}/symba/symba_discard.f90
${SRC}/symba/symba_encounter_check.f90
${SRC}/symba/symba_util.f90
${SRC}/walltime/walltime_implementations.f90
${SRC}/whm/whm_util.f90
${SRC}/swiftest/swiftest_driver.f90

)

SET(COARRAY_FILES
Expand All @@ -92,47 +93,44 @@ SET(COARRAY_FILES
${SRC}/rmvs/rmvs_coarray.f90
)

IF(USE_COARRAY)
set(SWIFTEST_src ${COARRAY_FILES} ${FAST_MATH_FILES} ${STRICT_MATH_FILES})
ELSE()
set(SWIFTEST_src ${FAST_MATH_FILES} ${STRICT_MATH_FILES})
ENDIF(USE_COARRAY)
SET(DRIVER_src ${SRC}/main/main.f90)

# Define the executable in terms of the source files
ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${SWIFTEST_src})
# Combine all source files (includ)
set(SWIFTEST_src ${FAST_MATH_FILES} ${STRICT_MATH_FILES})
IF(USE_COARRAY)
set(SWIFTEST_src ${SWIFTEST_src} ${COARRAY_FILES} )
ENDIF ()

# Turn preprocessor on for all files
SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} PROPERTIES Fortran_PREPROCESS ON)
SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} ${DRIVER_src} PROPERTIES Fortran_PREPROCESS ON)

# Create a library from the source files, except the driver
SET(SWIFTEST_LIBRARY swiftest)
ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src})

# Define the executable name
SET(SWIFTEST_DRIVER swiftest_driver)
ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src})

#####################################################
# Add the needed libraries and special compiler flags
#####################################################

TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS})
TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PRIVATE swiftest ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS})

IF(USE_OPENMP)
SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ")
SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${OpenMP_Fortran_FLAGS} ")
SET_PROPERTY(TARGET swiftest ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ")
SET_PROPERTY(TARGET swiftest ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${OpenMP_Fortran_FLAGS} ")
ENDIF(USE_OPENMP)

IF(USE_COARRAY)
TARGET_COMPILE_DEFINITIONS(swiftest PRIVATE -DCOARRAY)
TARGET_COMPILE_DEFINITIONS(${SWIFTEST_DRIVER} PRIVATE -DCOARRAY)
SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${Coarray_Fortran_FLAGS} ")
SET_PROPERTY(TARGET ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ")
SET_PROPERTY(TARGET swiftest ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${Coarray_Fortran_FLAGS} ")
SET_PROPERTY(TARGET swiftest ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ")
ENDIF(USE_COARRAY)


#####################################
# Tell how to install this executable
#####################################

IF(WIN32)
SET(CMAKE_INSTALL_PREFIX "C:\\Program Files")
ELSE()
SET(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF(WIN32)
INSTALL(TARGETS ${SWIFTEST_DRIVER} RUNTIME DESTINATION bin)


#Set strict vs fast math flags
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
Expand Down Expand Up @@ -169,3 +167,18 @@ end program TestDoConcurrentLoc
ENDIF (USE_OPENMP)


#####################################
# Tell how to install this executable
#####################################
IF(WIN32)
SET(CMAKE_INSTALL_PREFIX "C:\\Program Files")
ELSE()
SET(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF(WIN32)
INSTALL(TARGETS ${SWIFTEST_DRIVER} ${SWIFTEST_LIBRARY}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
INSTALL(FILES ${MOD}/swiftest.mod DESTINATION include)

28 changes: 28 additions & 0 deletions src/main/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
!! 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.

program main
!! author: David A. Minton
!!
!! This is used as a wrapper for the swiftest_driver subroutine so that the driver can be used as either
!! a function call or a standalone executable program.
use swiftest
implicit none

character(len=:), allocatable :: integrator !! Integrator type code (see globals for symbolic names)
character(len=:), allocatable :: param_file_name !! Name of the file containing user-defined parameters
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD"

! Read in command line arguments
call swiftest_io_get_args(integrator, param_file_name, display_style)

! Execute the driver
call swiftest_driver(integrator, param_file_name, display_style)

end program main
Loading

0 comments on commit cc164ee

Please sign in to comment.