Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ doc/*
!readme
!figures/*

.DS_Store
122 changes: 30 additions & 92 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,102 +1,40 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(m3dc1 LANGUAGES Fortran C CXX)

# macro(checkSetParam varName isRequired)
# if("${${varName}}" STREQUAL "") # if varName is empty
# set(${varName} $ENV{${varName}})
# if(("${${varName}}" STREQUAL "") AND ${isRequired}) # if ENV{varName} is empty also
# message(FATAL_ERROR
# "${varName} is not defined or in the environment, please specify ${varName}")
# endif()
# endif()
# endmacro(checkSetParam varName)

option(ENABLE_OPENMP "Enable OpenMP support" OFF)
option(ENABLE_COMPLEX "Build complex version" OFF)
option(ENABLE_3D "Build 3D version" OFF)
option(ENABLE_ST "Build stellarator version " OFF)
option(ENABLE_PARTICLE "Enable kinetic particle module" OFF)
option(M3DC1_ENABLE_OPENMP "Enable OpenMP support" OFF)
if(M3DC1_ENABLE_OPENMP)
find_package(OpenMP REQUIRED COMPONENTS Fortran)
endif()
option(M3DC1_ENABLE_COMPLEX "Build complex version" OFF)
option(M3DC1_ENABLE_3D "Build 3D version" OFF)
option(M3DC1_ENABLE_ST "Build stellarator version " OFF)
option(M3DC1_ENABLE_PARTICLE "Enable kinetic particle module" OFF)
option(M3DC1_ENABLE_GPU "Use GPU/OpenACC Fortran kernels" OFF)
option(M3DC1_ENABLE_ADAS "Enable ADAS radiation data support" OFF)
option(M3DC1_ENABLE_TRILINOS "Enable Trilinos support" OFF)
option(M3DC1_ENABLE_PSPLINE "Enable PSPLINE support for readgato/read_jsolver" OFF)
option(M3DC1_DOWNLOAD_ADAS_DATA "Download OpenADAS ADF11 data as part of the default build" OFF)
set(M3DC1_ADAS_DATA_DIR "${CMAKE_BINARY_DIR}/adas/adf11"
CACHE PATH "Path to OpenADAS ADF11 data directory")

cmake_host_system_information(RESULT HOST QUERY HOSTNAME)
message(STATUS "Configuring to build on: ${HOST}")

# # rhel/centos place x86-64 libs in lib64 instead of lib
# # this *shouldn't* effect searching the lib directory
# # first on other distros where the default install location
# # is lib instead of lib64 (like debian derivatives)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)

# prefer static libraries unless we explicitly specify no to
# set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")
# if(BUILD_SHARED_LIBS)
# set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
# endif()

# set the build type logically
# default is Debug if .git directory exists
# otherwise default is Release
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# include(BuildType)

# # add C++ compiler flags
# if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Cray")
# # todo : set cray-specific cxx flags
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL")
# # todo : check for regular xl vs bg/q xl compiler
# # currently assuming bg/q
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qflag=w -glanglvl=extended0x")
# elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# # todo : set intel-specific cxx flags
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# # todo : version checks to see which c++ standards are available
# # and warn/error if the version is incompatible
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra")
# elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# # todo : version checks to see which c++ standards are available
# # and warn/error if the version is incompatible
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -Wall -Wextra")
# endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake"
"${CMAKE_CURRENT_LIST_DIR}/m3dc1_scorec/cmake")
find_package(PETSc REQUIRED)

# # add C compiler flags
# if("${CMAKE_C_COMPILER_ID}" STREQUAL "Cray")
# # todo : set cray-specific c flags
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "XL")
# # todo : set xl-specific c flags
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
# # todo : set intel-specific c flags
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
# # todo : version checks to see which c standards are available
# # and warn/error if the version is incompatible
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
# elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# # todo : version checks to see which c++ standards are available
# # and warn/error if the version is incompatible
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
# endif()
# Automatically set exe linker flags from PETSc pkg-config data.
# Construct -L<dir> flags from PETSC_LIBRARY_DIRS.
string(REPLACE ";" " -L" _m3dc1_petsc_libdirs_flags "${PETSC_LIBRARY_DIRS}")
if(_m3dc1_petsc_libdirs_flags)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${_m3dc1_petsc_libdirs_flags}")
endif()
# Append PETSc's extra LDFLAGS (which include rpath from pkg-config).
if(PETSC_LDFLAGS_OTHER)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PETSC_LDFLAGS_OTHER}")
endif()

# # add Fortran compiler flags
# if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Cray")
# # todo : set cray-specific fortran flags
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
# elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "XL")
# # todo : set xl-specific fortran flags
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
# elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel")
# # todo : set intel-specific fortran flags
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g noarg_temp_created")
# elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8 -Wall -cpp")
# elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Clang")
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8 -Wall -cpp")
# endif()

message(STATUS "Configuring m3dc1_scorec")
add_subdirectory(m3dc1_scorec EXCLUDE_FROM_ALL)
message(STATUS "Configuring unstructured")
add_subdirectory(m3dc1_scorec)
add_subdirectory(unstructured)

82 changes: 82 additions & 0 deletions cmake/DownloadOpenADAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Download OpenADAS ADF11 data and reader sources
# Called from unstructured/CMakeLists.txt with:
# -DOUT_DIR=<path> : output directory (CMAKE_BINARY_DIR/adas)
# -DADF11_DIR=<path> : where ADF11 data files are placed

set(OA_DATA_URL "https://open.adas.ac.uk/download/adf11")
set(OA_SOURCE_DIR "${OUT_DIR}/source")

# ---- Download and extract reader source code ----
message(STATUS "Downloading OpenADAS reader sources...")
file(DOWNLOAD
"https://open.adas.ac.uk/code/xxdata_11.tar.gz"
"${OUT_DIR}/xxdata_11.tar.gz"
STATUS _dl_status
SHOW_PROGRESS
)
list(GET _dl_status 0 _dl_code)
if(NOT _dl_code EQUAL 0)
message(FATAL_ERROR "Failed to download xxdata_11.tar.gz")
endif()

# Extract into a temporary directory, then move .for → .f to source/
set(_extract_dir "${OUT_DIR}/_extract_tmp")
file(REMOVE_RECURSE "${_extract_dir}")
file(MAKE_DIRECTORY "${_extract_dir}")
file(MAKE_DIRECTORY "${OA_SOURCE_DIR}")

execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${OUT_DIR}/xxdata_11.tar.gz"
WORKING_DIRECTORY "${_extract_dir}"
RESULT_VARIABLE _tar_res
)
if(NOT _tar_res EQUAL 0)
message(FATAL_ERROR "Failed to extract xxdata_11.tar.gz")
endif()

# Find all .for files (recursively, handles possible subdirectories)
# and copy/rename them to OA_SOURCE_DIR as .f
file(GLOB_RECURSE _for_files "${_extract_dir}/*.for")
foreach(_f IN LISTS _for_files)
get_filename_component(_name "${_f}" NAME_WE)
file(COPY "${_f}" DESTINATION "${OA_SOURCE_DIR}")
file(RENAME "${OA_SOURCE_DIR}/${_name}.for" "${OA_SOURCE_DIR}/${_name}.f")
endforeach()

# Cleanup
file(REMOVE_RECURSE "${_extract_dir}")
file(REMOVE "${OUT_DIR}/xxdata_11.tar.gz")
message(STATUS "OpenADAS reader sources extracted to ${OA_SOURCE_DIR}")

# ---- Download ADF11 data files ----
set(_adf11_files
"scd85/scd85_ar.dat"
"scd89/scd89_b.dat"
"plt89/plt89_b.dat"
"plt89/plt89_ar.dat"
"scd96/scd96_he.dat"
"scd96/scd96_be.dat"
"scd96/scd96_c.dat"
"scd96/scd96_ne.dat"
"plt96/plt96_he.dat"
"plt96/plt96_be.dat"
"plt96/plt96_c.dat"
"plt96/plt96_ne.dat"
)

foreach(_f IN LISTS _adf11_files)
get_filename_component(_subdir "${_f}" DIRECTORY)
file(MAKE_DIRECTORY "${ADF11_DIR}/${_subdir}")
message(STATUS "Downloading ${_f}...")
file(DOWNLOAD
"${OA_DATA_URL}/${_f}"
"${ADF11_DIR}/${_f}"
STATUS _dl_status
)
list(GET _dl_status 0 _dl_code)
if(NOT _dl_code EQUAL 0)
message(FATAL_ERROR "Failed to download ${_f}")
endif()
endforeach()

message(STATUS "OpenADAS download complete")
Loading