Skip to content

Commit 12620d2

Browse files
authored
Setup CMake (#364)
* Add CMakeLists in the various subfolders. * First pass at setting up cmake compilation and targets. * Add the right include folder for the selected mechanism. * A few fixes in CMakeLists.txt. * Update to have CUDA working. Self build of lib functions. * Jon's suggestions. * Fixes related to updated cmake minimum version. * Remove *_api and a few fixes. Tested as a subdir in LMeX with MPI, MPI+CUDA and MPI+HIP.
1 parent 230c2f6 commit 12620d2

File tree

10 files changed

+370
-0
lines changed

10 files changed

+370
-0
lines changed

CMake/PelePhysicsConfig.cmake.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@PACKAGE_INIT@
2+
3+
set(PELEPHYSICS_SPACEDIM @PELEPHYSICS_SPACEDIM@)
4+
set(PELEPHYSICS_CHEMISTRY_MODEL @PELEPHYSICS_CHEMISTRY_MODEL@)
5+
set(PELEPHYSICS_EOS_MODEL @PELEPHYSICS_EOS_MODEL@)
6+
set(PELEPHYSICS_TRANSPORT_MODEL @PELEPHYSICS_TRANSPORT_MODEL@)
7+
8+
set(PELEPHYSICS_MPI @PELEPHYSICS_MPI@)
9+
set(PELEPHYSICS_OMP @PELEPHYSICS_OMP@)
10+
set(PELEPHYSICS_CUDA @PELEPHYSICS_CUDA@)
11+
set(PELEPHYSICS_HIP @PELEPHYSICS_HIP@)
12+
set(PELEPHYSICS_SYCL @PELEPHYSICS_SYCL@)
13+
14+
find_package(AMReX QUIET REQUIRED @AMREX_REQUIRED_COMPONENTS@)
15+
find_package(SUNDIALS QUIET REQUIRED)
16+
17+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
18+
19+
set(@PROJECT_NAME@_INCLUDE_DIRS "${PROJECT_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
20+
set(@PROJECT_NAME@_LIBRARY_DIRS "${PROJECT_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@")
21+
set(@PROJECT_NAME@_LIBRARIES "@PROJECT_NAME@::PelePhysics-@PELEPHYSICS_CHEMISTRY_MODEL@-@PELEPHYSICS_EOS_MODEL@-@PELEPHYSICS_TRANSPORT_MODEL@")
22+
23+
set(@PROJECT_NAME@_FOUND TRUE)
24+
check_required_components(@PROJECT_NAME@)

CMakeLists.txt

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
cmake_minimum_required(VERSION 3.23)
2+
3+
project( PelePhysics
4+
DESCRIPTION "A respository of physics databases and implementation code for use with the Pele suite of of codes"
5+
HOMEPAGE_URL "https://github.com/AMReX-Combustion/PelePhysics"
6+
LANGUAGES CXX
7+
)
8+
9+
message(STATUS "CMake version: ${CMAKE_VERSION}")
10+
11+
#
12+
# Options for model selection
13+
#
14+
set( PELEPHYSICS_SPACEDIM 3 CACHE STRING "Spatial dimension")
15+
set( PELEPHYSICS_PRECISION "DOUBLE" CACHE STRING "Floating point precision")
16+
set( PELEPHYSICS_CHEMISTRY_MODEL drm19 CACHE STRING "Chemical mechanism")
17+
set( PELEPHYSICS_EOS_MODEL Fuego CACHE STRING "Eq. of state model")
18+
set( PELEPHYSICS_TRANSPORT_MODEL Simple CACHE STRING "Transport model")
19+
20+
#
21+
# Options for library content
22+
#
23+
option( PELEPHYSICS_REACTIONS "Enable Reaction" ON)
24+
option( PELEPHYSICS_TRANSPORT "Enable Transport" ON)
25+
option( PELEPHYSICS_EOS "Enable EOS" ON)
26+
option( PELEPHYSICS_UTILS "Enable Utilities" ON)
27+
28+
#
29+
# Options for HPC
30+
#
31+
option( PELEPHYSICS_MPI "Enable MPI" OFF)
32+
option( PELEPHYSICS_OMP "Enable OpenMP" OFF)
33+
option( PELEPHYSICS_CUDA "Enable CUDA" OFF)
34+
option( PELEPHYSICS_HIP "Enable HIP" OFF)
35+
option( PELEPHYSICS_SYCL "Enable SYCL" OFF)
36+
set(PELEPHYSICS_GPU_BACKEND NONE)
37+
38+
if (PELEPHYSICS_CUDA)
39+
enable_language(CUDA)
40+
set(PELEPHYSICS_GPU_BACKEND CUDA)
41+
endif ()
42+
43+
if (PELEPHYSICS_HIP)
44+
enable_language(HIP)
45+
set(PELEPHYSICS_GPU_BACKEND HIP)
46+
endif ()
47+
48+
if (PELEPHYSICS_SYCL)
49+
enable_language(SYCL)
50+
set(PELEPHYSICS_GPU_BACKEND SYCL)
51+
endif ()
52+
53+
set(AMREX_HOME "" CACHE PATH "Path to AMReX top-level source directory")
54+
55+
if (AMREX_HOME) # SUPERBUILD MODE
56+
57+
message(STATUS "AMReX top-level source directory path: ${AMREX_HOME}")
58+
59+
# Add AMReX module path
60+
list(APPEND CMAKE_MODULE_PATH ${AMREX_HOME}/Tools/CMake)
61+
set(AMREX_BINARY_DIR "${CMAKE_BINARY_DIR}/amrex" CACHE INTERNAL "Path to AMReX top-level binary directory")
62+
63+
# Set required settings for AMReX
64+
set(USE_XSDK_DEFAULTS ON CACHE INTERNAL "")
65+
set(XSDK_ENABLE_Fortran OFF CACHE INTERNAL "")
66+
set(XSDK_PRECISION ${PELEPHYSICS_PRECISION} CACHE INTERNAL "")
67+
set(AMReX_SPACEDIM ${PELEPHYSICS_SPACEDIM} CACHE INTERNAL "")
68+
set(AMReX_MPI ${PELEPHYSICS_MPI} CACHE INTERNAL "")
69+
set(AMReX_OMP ${PELEPHYSICS_OMP} CACHE INTERNAL "")
70+
set(AMReX_GPU_BACKEND ${PELEPHYSICS_GPU_BACKEND} CACHE INTERNAL "")
71+
set(AMReX_SUNDIALS ON CACHE INTERNAL "")
72+
set(AMReX_EB OFF CACHE INTERNAL "")
73+
set(AMReX_FORTRAN OFF CACHE INTERNAL "")
74+
set(AMReX_LINEAR_SOLVERS OFF CACHE INTERNAL "")
75+
set(AMReX_AMRLEVEL OFF CACHE INTERNAL "")
76+
set(AMReX_BUILD_TUTORIALS OFF CACHE INTERNAL "")
77+
78+
# Add AMReX as a sub-project: incflo inherits all AMReX options
79+
add_subdirectory(${AMREX_HOME} ${AMREX_BINARY_DIR})
80+
81+
message(STATUS "AMReX binary directory: ${AMREX_BINARY_DIR}")
82+
83+
else ()
84+
85+
#
86+
# if AMReX::amrex is not part of the targets, use find_package
87+
#
88+
if (NOT TARGET AMReX::amrex)
89+
set(AMREX_REQUIRED_COMPONENTS ${PELEPHYSICS_SPACEDIM}D ${PELEPHYSICS_PRECISION})
90+
if (PELEPHYSICS_MPI)
91+
list(APPEND AMREX_REQUIRED_COMPONENTS MPI)
92+
endif ()
93+
if (PELEPHYSICS_OMP)
94+
list(APPEND AMREX_REQUIRED_COMPONENTS OMP)
95+
endif ()
96+
if (NOT PELEPHYSICS_GPU_BACKEND STREQUAL "NONE")
97+
list(APPEND AMREX_REQUIRED_COMPONENTS ${PELEPHYSICS_GPU_BACKEND})
98+
endif ()
99+
find_package(AMReX CONFIG REQUIRED ${AMREX_REQUIRED_COMPONENTS} )
100+
endif ()
101+
102+
endif ()
103+
104+
set(SUNDIALS_HOME "" CACHE PATH "Path to SUNDIALS top-level source directory")
105+
106+
if (SUNDIALS_HOME) # SUPERBUILD MODE
107+
message(STATUS "SUNDIALS top-level source directory path: ${SUNDIALS_HOME}")
108+
109+
# Add SUNDIALS module path
110+
list(APPEND CMAKE_MODULE_PATH ${SUNDIALS_HOME}/cmake)
111+
set(SUNDIALS_BINARY_DIR "${CMAKE_BINARY_DIR}/sundials" CACHE INTERNAL "Path to SUNDIALS top-level binary directory")
112+
113+
# Set required settings for SUNDIALS
114+
set(SUNDIALS_PRECISION ${PELEPHYSICS_PRECISION} CACHE STRING "Floating point precision" FORCE)
115+
set(BUILD_ARKODE ON CACHE INTERNAL "")
116+
set(BUILD_CVODE ON CACHE INTERNAL "")
117+
set(SUNDIALS_INDEX_SIZE 32 CACHE INTERNAL "")
118+
set(BUILD_CVODES OFF CACHE INTERNAL "")
119+
set(BUILD_IDA OFF CACHE INTERNAL "")
120+
set(BUILD_IDAS OFF CACHE INTERNAL "")
121+
set(BUILD_KINSOL OFF CACHE INTERNAL "")
122+
set(BUILD_CPODES OFF CACHE INTERNAL "")
123+
set(BUILD_EXAMPLES OFF CACHE INTERNAL "")
124+
set(_BUILD_EXAMPLES OFF CACHE INTERNAL "")
125+
set(BUILD_TESTING OFF CACHE INTERNAL "")
126+
set(EXAMPLES_ENABLE_C OFF CACHE INTERNAL "")
127+
set(EXAMPLES_ENABLE_CXX OFF CACHE INTERNAL "")
128+
set(EXAMPLES_INSTALL OFF CACHE INTERNAL "")
129+
set(ENABLE_CUDA ${PELEPHYSICS_CUDA} CACHE INTERNAL "")
130+
set(ENABLE_HIP ${PELEPHYSICS_HIP} CACHE INTERNAL "")
131+
set(ENABLE_SYCL ${PELEPHYSICS_SYCL} CACHE INTERNAL "")
132+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
133+
134+
add_subdirectory(${SUNDIALS_HOME} ${SUNDIALS_BINARY_DIR})
135+
136+
message(STATUS "SUNDIALS binary directory: ${SUNDIALS_BINARY_DIR}")
137+
else ()
138+
139+
#
140+
# Find SUNDIALS, check for required components
141+
#
142+
if (NOT TARGET SUNDIALS::cvode)
143+
# Check if we can require components
144+
find_package(SUNDIALS)
145+
endif ()
146+
147+
endif ()
148+
149+
#
150+
# Enable CUDA if requested
151+
#
152+
if (PELEPHYSICS_GPU_BACKEND STREQUAL "CUDA")
153+
include(AMReXTargetHelpers)
154+
endif ()
155+
156+
#
157+
# Define the object library to compile
158+
#
159+
set(pelephysics_lib_name PelePhysics-${PELEPHYSICS_CHEMISTRY_MODEL}-${PELEPHYSICS_EOS_MODEL}-${PELEPHYSICS_TRANSPORT_MODEL})
160+
add_library(${pelephysics_lib_name} OBJECT)
161+
target_link_libraries(${pelephysics_lib_name} PUBLIC AMReX::amrex)
162+
target_link_libraries(${pelephysics_lib_name} PUBLIC SUNDIALS::cvode SUNDIALS::arkode)
163+
164+
add_subdirectory(Source)
165+
166+
set(PELEPHYSICS_MECH_DIR "Support/Mechanism/")
167+
add_subdirectory(${PELEPHYSICS_MECH_DIR})
168+
169+
if (PELEPHYSICS_UTILS)
170+
add_subdirectory(Utility/PMF)
171+
add_subdirectory(Utility/TurbInflow)
172+
add_subdirectory(Utility/PltFileManager)
173+
endif ()
174+
175+
if (PELEPHYSICS_TRANSPORT)
176+
add_subdirectory(Transport)
177+
endif ()
178+
179+
if (PELEPHYSICS_EOS)
180+
add_subdirectory(Eos)
181+
endif ()
182+
183+
if (PELEPHYSICS_REACTIONS)
184+
add_subdirectory(Reactions)
185+
endif ()
186+
187+
if (PELEPHYSICS_GPU_BACKEND STREQUAL "CUDA")
188+
setup_target_for_cuda_compilation(${pelephysics_lib_name})
189+
endif ()
190+
191+
if ( NOT CMAKE_CXX_FLAGS )
192+
target_link_libraries(${pelephysics_lib_name} PUBLIC AMReX::Flags_CXX)
193+
endif ()
194+
195+
# Installation rules
196+
include(CMakePackageConfigHelpers)
197+
include(GNUInstallDirs)
198+
199+
message( STATUS "PelePhysics configuration summary: ")
200+
message( STATUS " Build type = ${CMAKE_BUILD_TYPE}")
201+
message( STATUS " Install directory = ${CMAKE_INSTALL_PREFIX}")
202+
message( STATUS " CMake target = ${pelephysics_lib_name}")
203+
204+
# Collect all headers and make them installable with the target
205+
get_target_property(PELEPHYSICS_INCLUDES ${pelephysics_lib_name} SOURCES)
206+
list(FILTER PELEPHYSICS_INCLUDES INCLUDE REGEX "\\.H")
207+
set_target_properties(
208+
${pelephysics_lib_name} PROPERTIES PUBLIC_HEADER "${PELEPHYSICS_INCLUDES}")
209+
210+
# Install PelePhysics
211+
install(
212+
TARGETS ${pelephysics_lib_name}
213+
EXPORT ${PROJECT_NAME}Targets
214+
RUNTIME DESTINATION bin
215+
ARCHIVE DESTINATION lib
216+
LIBRARY DESTINATION lib
217+
INCLUDES DESTINATION include
218+
PUBLIC_HEADER DESTINATION include
219+
)
220+
221+
# Make PelePhysics discoverable using `find_package`
222+
install(
223+
EXPORT ${PROJECT_NAME}Targets
224+
NAMESPACE ${PROJECT_NAME}::
225+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
226+
)
227+
configure_package_config_file(
228+
CMake/${PROJECT_NAME}Config.cmake.in
229+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
230+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
231+
)
232+
install(FILES
233+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
234+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
235+
)

Eos/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
EOS.H
6+
EOS.cpp
7+
Fuego.H
8+
GammaLaw.H
9+
SRK.H
10+
)
11+
12+
if("${PELEPHYSICS_EOS_MODEL}" STREQUAL "GammaLaw")
13+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_GAMMALAW_EOS)
14+
endif()
15+
if("${PELEPHYSICS_EOS_MODEL}" STREQUAL "Fuego")
16+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_FUEGO_EOS)
17+
endif()
18+
if("${PELEPHYSICS_EOS_MODEL}" STREQUAL "Soave-Redlich-Kwong")
19+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_SRK_EOS)
20+
endif()

Reactions/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
ReactorArkode.cpp
6+
ReactorArkode.H
7+
ReactorBase.H
8+
ReactorBase.cpp
9+
ReactorBDF.H
10+
ReactorBDF.cpp
11+
ReactorBDFsolver.H
12+
ReactorCvode.H
13+
ReactorCvode.cpp
14+
ReactorCvodeCustomLinSolver.H
15+
ReactorCvodeCustomLinSolver.cpp
16+
ReactorCvodeJacobian.H
17+
ReactorCvodeJacobian.cpp
18+
ReactorCvodePreconditioner.H
19+
ReactorCvodePreconditioner.cpp
20+
ReactorCvodeUtils.H
21+
ReactorCvodeUtils.cpp
22+
ReactorNull.H
23+
ReactorNull.cpp
24+
ReactorRK64.H
25+
ReactorRK64.cpp
26+
ReactorTypes.H
27+
ReactorUtils.H
28+
ReactorUtils.cpp
29+
)

Source/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
Factory.H
6+
PelePhysics.H
7+
PelePhysicsConstraints.H
8+
PhysicsConstants.H
9+
)

Support/Mechanism/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/Models/${PELEPHYSICS_CHEMISTRY_MODEL}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
Models/${PELEPHYSICS_CHEMISTRY_MODEL}/mechanism.H
6+
Models/${PELEPHYSICS_CHEMISTRY_MODEL}/mechanism.cpp
7+
)

Transport/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
Constant.H
6+
Simple.H
7+
Sutherland.H
8+
Transport.cpp
9+
Transport.H
10+
TransportParams.H
11+
TransportTypes.H
12+
)
13+
14+
if("${PELEPHYSICS_TRANSPORT_MODEL}" STREQUAL "Constant")
15+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_CONSTANT_TRANSPORT)
16+
endif()
17+
if("${PELEPHYSICS_TRANSPORT_MODEL}" STREQUAL "Simple")
18+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_SIMPLE_TRANSPORT)
19+
endif()
20+
if("${PELEPHYSICS_TRANSPORT_MODEL}" STREQUAL "Sutherland")
21+
target_compile_definitions(${pelephysics_lib_name} PUBLIC USE_SUTHERLAND_TRANSPORT)
22+
endif()
23+

Utility/PMF/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
PMF.H
6+
PMFData.cpp
7+
PMFData.H
8+
)

Utility/PltFileManager/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
PltFileManager.cpp
6+
PltFileManager.H
7+
PltFileManagerBCFill.H
8+
)

Utility/TurbInflow/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
target_include_directories(${pelephysics_lib_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2+
3+
target_sources(${pelephysics_lib_name}
4+
PRIVATE
5+
turbinflow.cpp
6+
turbinflow.H
7+
)

0 commit comments

Comments
 (0)