Skip to content

Commit

Permalink
Merge branch 'quasimc'
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jun 14, 2024
2 parents 12d15c3 + e846d0b commit 471b490
Show file tree
Hide file tree
Showing 47 changed files with 564 additions and 1,489 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
!distclean.cmake
!README.md
!version.txt
!ctem/
!ctem/**.py
!cmake/Modules/*.cmake
!*.bash

!pyproject.toml
!LICENSE
44 changes: 27 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
##################################################
# Define the project and the depencies that it has
##################################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.0...3.27.1)
CMAKE_MINIMUM_REQUIRED(VERSION 3.24.0...3.27.1)
SET(SKBUILD_PROJECT_NAME "ctem" CACHE STRING "Name of project set by scikit-build")

# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(CTEM LANGUAGES C Fortran VERSION ${VERSION})
PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran VERSION ${VERSION})

IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
Expand All @@ -26,7 +27,6 @@ ELSE ()
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)
Expand All @@ -39,30 +39,40 @@ ENDIF()
# Ensure scikit-build modules
FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Add our local modules to the module path
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

# Define some directories that are important to the build
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(PY "${CMAKE_SOURCE_DIR}/ctem")

# Make sure paths are correct for Unix or Windows style
FILE(TO_CMAKE_PATH ${SRC} SRC)
FILE(TO_CMAKE_PATH ${LIB} LIB)
FILE(TO_CMAKE_PATH ${BIN} BIN)
FILE(TO_CMAKE_PATH ${MOD} MOD)
FILE(TO_CMAKE_PATH ${PY} PY)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN})
INCLUDE(GNUInstallDirs)
IF (SKBUILD)
SET(INSTALL_BINDIR ${SKBUILD_SCRIPTS_DIR})
SET(INSTALL_LIBDIR ${SKBUILD_DATA_DIR}/lib)
SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
SET(INSTALL_PYPROJ ${SKBUILD_PLATLIB_DIR}/${SKBUILD_PROJECT_NAME})
IF (APPLE)
SET(CMAKE_INSTALL_RPATH "@loader_path;${CMAKE_BINARY_DIR}/bin")
ELSEIF (LINUX)
SET(CMAKE_INSTALL_RPATH "@ORIGIN;${CMAKE_BINARY_DIR}/bin")
ENDIF ()
ELSE ()
SET(INSTALL_PYPROJ ${PY})
SET(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
SET(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
SET(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
ENDIF ()

SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})
SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)

# Add our local modules to the module path
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

# Set the name of the ctem library
SET(CTEM_LIBRARY ctem)
Expand Down
20 changes: 10 additions & 10 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,10 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
)

# 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
)
# 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}"
Expand Down Expand Up @@ -574,10 +574,10 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
)

# 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
)
# 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}"
Expand Down Expand Up @@ -671,11 +671,11 @@ IF (CMAKE_BUILD_TYPE STREQUAL "PROFILE")
# Enables the optimization reports to be generated
IF (WINOPT)
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/O2 /Qopt-report:5 /traceback /Z7" # Intel Windows
Fortran "/O2 /Qopt-report:3 /traceback /Z7" # Intel Windows
)
ELSE ()
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-O2 -pg -qopt-report=5 -traceback -p -g3" # Intel
Fortran "-O2 -pg -qopt-report=3 -traceback -p -g3" # Intel
)
ENDIF ()
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
Expand Down
15 changes: 3 additions & 12 deletions cmake/Modules/SetParallelizationLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ IF (USE_OPENMP)
ENDIF (NOT OpenMP_Fortran_FLAGS)
ENDIF (USE_OPENMP)

IF (USE_COARRAY)
IF (NOT Coarray_Fortran_FLAGS)
FIND_PACKAGE (Coarray_Fortran)
IF (NOT Coarray_Fortran_FLAGS)
MESSAGE (FATAL_ERROR "Fortran compiler does not support Coarrays")
ENDIF (NOT Coarray_Fortran_FLAGS)
ENDIF (NOT Coarray_Fortran_FLAGS)
ENDIF (USE_COARRAY)

IF (NOT USE_OPENMP AND NOT USE_COARRAY)
# Turn off both OpenMP and CAF
IF (NOT USE_OPENMP)
# Turn off OpenMP
SET (OMP_NUM_PROCS 0 CACHE
STRING "Number of processors OpenMP may use" FORCE)
UNSET (OpenMP_Fortran_FLAGS CACHE)
UNSET (Coarray_Fortran_FLAGS CACHE)
UNSET (GOMP_Fortran_LINK_FLAGS CACHE)
ENDIF (NOT USE_OPENMP AND NOT USE_COARRAY)
ENDIF ()
File renamed without changes.
2 changes: 2 additions & 0 deletions ctem/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ctem.driver import *
from ctem import util
File renamed without changes.
1 change: 0 additions & 1 deletion ctem/ctem/__init__.py

This file was deleted.

17 changes: 8 additions & 9 deletions ctem/ctem/driver.py → ctem/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ def __init__(self, param_file="ctem.in", isnew=True):
}

# Get the location of the CTEM executable
self.ctem_executable = Path(_pyfile).parent.parent.parent / "bin" / "CTEM"
if not self.ctem_executable.exists():
print(f"CTEM driver not found at {self.ctem_executable}. Trying current directory.")
self.ctem_executable = Path(currentdir) / "CTEM"
if not self.ctem_executable.exists():
warnings.warn(f"Cannot find the CTEM driver {str(self.ctem_executable)}", stacklevel=2)
self.ctem_executable = None

self.ctem_executable = shutil.which("CTEM")
if not self.ctem_executable:
warnings.warn(f"Cannot find the CTEM driver {str(self.ctem_executable)}", stacklevel=2)
self.ctem_executable = None

self.user = util.read_user_input(self.user)

Expand Down Expand Up @@ -169,7 +165,10 @@ def __init__(self, param_file="ctem.in", isnew=True):
rclist[:,0] = np.exp(interp(np.log(rclist[:,0])))

#Convert age in Ga to "interval time"
rclist[:,5] = (self.user['interval'] * self.user['numintervals']) - craterproduction.Tscale(rclist[:,5], 'NPF_Moon')
if (self.user['runtype'].upper() == 'STATISTICAL'):
rclist[:,5] = (self.user['interval']) - craterproduction.Tscale(rclist[:,5], 'NPF_Moon')
else:
rclist[:,5] = (self.user['interval'] * self.user['numintervals']) - craterproduction.Tscale(rclist[:,5], 'NPF_Moon')
rclist = rclist[rclist[:,5].argsort()]

#Export to dat file
Expand Down
6 changes: 0 additions & 6 deletions ctem/setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion ctem/ctem/util.py → ctem/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def image_regolith(user, regolith):
height = user['gridsize'] / dpi
width = height
fig = plt.figure(figsize=(width, height), dpi=dpi)
fig.figimage(regolith_scaled, cmap=cm.nipy_spectral, origin='lower')
fig.figimage(regolith_scaled, cmap=cm.magma, origin='lower')
plt.savefig(filename)
plt.close()

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions debug_compile.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake -P distclean.cmake
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build
30 changes: 15 additions & 15 deletions examples/global-lunar-bombardment/ctem.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@


! Testing input. These are used to perform non-Monte Carlo tests.
testflag F ! Set to T to create a single crater with user-defined impactor properties
testimp 100000 ! Diameter of test impactor (m)
testflag T ! Set to T to create a single crater with user-defined impactor properties
testimp 15000.0 ! Diameter of test impactor (m)
testvel 18.3e3 ! Velocity of test crater (m/s)
testang 45.0 ! Impact angle of test crater (deg) - Default 90.0
testxoffset 0 ! x-axis offset of crater center from grid center (m) - Default 0.0
testyoffset 0 ! y-axis offset of crater center from grid center (m) - Default 0.0
testang 90.0 ! Impact angle of test crater (deg) - Default 90.0
testxoffset 0.0 ! x-axis offset of crater center from grid center (m) - Default 0.0
testyoffset 0.0 ! y-axis offset of crater center from grid center (m) - Default 0.0
tallyonly F ! Tally the craters without generating any craters
testtally F
quasimc F ! MC run constrained by non-MC 'real' craters given in a list
realcraterlist qmctest2.in ! list of 'real' craters for Quasi-MC runs
realcraterlist craterlist.in ! list of 'real' craters for Quasi-MC runs



! IDL driver in uts
interval 10.0
interval 1.0
numintervals 1 ! Total number of intervals (total time = interval * numintervals) <--when runtype is 'single'
restart F ! Restart a previous run
impfile NPFextrap.dat ! Impactor SFD rate file (col 1: Dimp (m), col 2: ! impactors > D (m**(-2) y**(-1))
Expand All @@ -33,10 +33,10 @@ runtype single ! Run type: options are normal /
! statistical: surface is reset between intervals

! CTEM required inputs
seed 765 ! Random number generator seed
gridsize 500 ! Size of grid in pixels
seed 1111 ! Random number generator seed
gridsize 1000 ! Size of grid in pixels
numlayers 10 ! Number of perched layers
pix 12.32e3 ! Pixel size (m)
pix 6.16e3 ! Pixel size (m)
mat rock ! Material (rock or ice)
! Bedrock scaling parameters
mu_b 0.55e0 ! Experimentally derived parameter for bedrock crater scaling law
Expand All @@ -60,11 +60,11 @@ doseismic F ! Perform seismic shaking calcul

! Optional inputF These have internally set default values that work reasonable well. Comment them out with
deplimit 9e99 ! Depth limit for craters (m) - Default is to ignore.
maxcrat 0.15 ! Fraction of gridsize that maximum crater can be - Default 1.0 (0.15 for full MC; 3.15e-2 for Quasi-MC)
maxcrat 3.15e-2 ! Fraction of gridsize that maximum crater can be - Default 1.0 <--0.15 for full MC; 3.15e-2 for Quasi-MC
killatmaxcrater F ! Stop the run if a crater larger than the maximum is produced - Default F
basinimp 35.0e3 ! Size of impactor to switch to lunar basin scaling law - Default is to ignore
basinimp 35.0e6 ! Size of impactor to switch to lunar basin scaling law - Default is to ignore
docollapse T ! Do slope collapse - Default T
dosoftening T ! Do ejecta softening - Default T
dosoftening F ! Do ejecta softening - Default T
doangle T ! Vary the impact angle. Set to F to have only vertical impacts - Default T
Kd1 0.0001
psi 2.000
Expand All @@ -74,5 +74,5 @@ doregotrack T
dorays F
superdomain F
dorealistic F
domixing T
dotopodiffusion F
dotopodiffusion F
domixing F
3 changes: 0 additions & 3 deletions examples/global-lunar-bombardment/ctemdriver.py

This file was deleted.

76 changes: 0 additions & 76 deletions examples/global-lunar-bombardment/temp.in

This file was deleted.

1 change: 0 additions & 1 deletion examples/quasimc-global/CTEM

This file was deleted.

Loading

0 comments on commit 471b490

Please sign in to comment.