diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..278fb71 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.10) + +project(FENNECS Fortran C) + + +find_package(MPI COMPONENTS Fortran REQUIRED) +find_package(OpenMP COMPONENTS Fortran C REQUIRED) + +# Search and load the FUTILS configuration file +if(NOT TARGET futils) + find_package(futils PATHS ${FUTILS}/lib/cmake REQUIRED) +endif() + +# Search and load the bsplines configuration file +if(NOT TARGET bsplines) + find_package(bsplines PATHS ${BSPLINES}/lib/cmake REQUIRED) +endif() + +#Search and load the bsplines configuration file +if(NOT TARGET SISL) + find_package(SISL PATHS ${SISL}/lib/cmake REQUIRED) +endif() + +add_subdirectory(src) \ No newline at end of file diff --git a/README.md b/README.md index 8d044b1..549f8e9 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,41 @@ # FENNECS ## Dependencies This code needs the following libraries to run: - futils for writing and reading to .h5 files https://c4science.ch/diffusion/FUTILS/ - bsplines for 2D b-splines interpolation, solving and evaluating the Poisson equation https://c4science.ch/source/spclibs/ - SINTEF SISL a C library for NURBS curves interrogation and calculating the distance to a NURBS curve https://github.com/SINTEF-Geometry/SISL - forSISL a library layer to use SINTEF SISL in Fortran https://github.com/rweed/forSISL/blob/main/LICENSE.txt +- xgrafix optional library to display a graphical interface during a run and show simulation variables https://ptsg.egr.msu.edu/ Each of these libraries must be compiled according to their respective instructions. ## Compilation To compile the program, the dependencies must first be compiled according to their respective instructions. A Makefile is found in the src folder and prior to the compilation the environment variable $PLATFORM must be defined to use the correct *.mk file, which includes options specific to gcc or intel compilers and specifies the paths to the different libraries. An example can be found and adapted in intel.mk and gcc.mk. To compile in linux: - modify the intel.mk or gcc.mk to point to the correct libraries path - $> export PLATFORM=intel - $> make release +The code can also be compiled using cmake +- $> mkdir build +- $> cd build +- $> cmake .. -DFUTILS= -DBSPLINES= -DSISL= -DforSISL= +- $> make + + ## Running the code An example of a simulation configuration can be found in wk/T-REX. The code can be run on a cluster using slurm, by calling the run.sh in command line. The code can be stopped using the stop.sh which will create a file called "mystop" containing the remaining number of time-steps to run. ## Post-processing A number of post-processing routines using matlab have been written and can be found in the matlab folder. To open a hdf5 result file, use the class fennecshdf5 with "result=fennecshdf5(filename);". The object result can then be interrogated to access variables stored in the hdf5 file. diff --git a/cmake/CMakeFlagsHandling.cmake b/cmake/CMakeFlagsHandling.cmake new file mode 100644 index 0000000..4ea3c65 --- /dev/null +++ b/cmake/CMakeFlagsHandling.cmake @@ -0,0 +1,75 @@ +if(_CMAKE_FLAGS_HANDLING) + return() +endif() +set(_CMAKE_FLAGS_HANDLING TRUE) + +#=============================================================================== +# Compilation options handling +#=============================================================================== +macro(_get_flags_message lang type desc) + if(${lang} MATCHES "C.." OR ${lang} MATCHES "Fortran") + set(${desc} "Flags used by the compiler") + elseif(${lang} MATCHES ".*_LINKER") + set(${desc} "Flags used by the linker") + endif() + + if(${lang} MATCHES "SHARED_LINKER") + set(${desc} "${desc} during the creation of shared libraries") + elseif(${lang} MATCHES "MODULE_LINKER") + set(${desc} "${desc} during the creation of modules") + elseif(${lang} MATCHES "STATIC_LINKER") + set(${desc} "${desc} linker during the creation of static libraries") + endif() + + if(${type} MATCHES "ALL") + set(${desc} "${desc} during all build types") + else() + set(${desc} "${desc} during ${type} builds") + endif() +endmacro() + +#=============================================================================== + +function(handle_flags) + include(CMakeParseArguments) + cmake_parse_arguments(_flags + "ADD;REMOVE" "LANG;TYPE" "" + ${ARGN} + ) + + if(NOT _flags_LANG) + set(_flags_LANG ${FLAGS_HANDLING_DEFAULT_LANGUAGE}) + endif() + + set(_variable CMAKE_${_flags_LANG}_FLAGS) + + if (_flags_TYPE) + set(_variable ${_variable}_${_flags_TYPE}) + else() + set(_flags_TYPE "ALL") + endif() + + _get_flags_message(${_flags_LANG} ${_flags_TYPE} _desc) + foreach(flag ${_flags_UNPARSED_ARGUMENTS}) + if (_flags_ADD) + string(REPLACE "${flag}" "match" _temp_var "${${_variable}}") + if(NOT _temp_var MATCHES "match") + set(${_variable} "${flag} ${${_variable}}" CACHE STRING ${_desc} FORCE) + endif() + elseif(_flags_REMOVE) + string(REPLACE "${flag} " "" ${_variable} "${${_variable}}") + set(${_variable} "${${_variable}}" CACHE STRING ${_desc} FORCE) + endif() + endforeach() +endfunction() + +#=============================================================================== +function(add_flags) + handle_flags(ADD ${ARGN}) +endfunction() + +#=============================================================================== +function(remove_flags) + handle_flags(REMOVE ${ARGN}) +endfunction() +#=============================================================================== diff --git a/cmake/FindforSISL.cmake b/cmake/FindforSISL.cmake new file mode 100644 index 0000000..da051cc --- /dev/null +++ b/cmake/FindforSISL.cmake @@ -0,0 +1,6 @@ +find_library(forSISL_LIBRARY NAMES forsisl.a PATHS ${forSISL}/lib) +find_path(forSISL_INCLUDE_DIR forsisl.mod ${forSISL}/include) +mark_as_advanced(forSISL_LIBRARY forSISL_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(forSISL DEFAULT_MSG forSISL_LIBRARY) diff --git a/cmake/Findsisl.cmake b/cmake/Findsisl.cmake new file mode 100644 index 0000000..a81903b --- /dev/null +++ b/cmake/Findsisl.cmake @@ -0,0 +1,7 @@ +find_library(sisl_LIBRARY NAMES sisl PATHS ${SISL}/lib) +find_path(sisl_INCLUDES sisl.h sislP.h ${SISL}/include) + +mark_as_advanced(sisl_LIBRARY sisl_INCLUDES) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(sisl DEFAULT_MSG sisl_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..aa4fab4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,71 @@ +project(fennecs_src Fortran C) + +add_executable(fennecs) + +set(SRCS +main.f90 +basic_mod.f90 +newrun.f90 +restart.f90 +auxval.f90 +inital.f90 +resume.f90 +start.f90 +diagnose.f90 +stepon.f90 +tesend.f90 +endrun.f90 +chkrst.f90 +mv2bk.f90 +constants.f90 +fields_mod.f90 +beam_mod.f90 +mpihelper_mod.f90 +sort_mod.f90 +distrib_mod.f90 +maxwsrce_mod.f90 +celldiag_mod.f90 +geometry_mod.f90 +random_mod.f90 +neutcol_mod.f90 +particletypes_mod.f90 +splinebound_mod.f90 +weighttypes_mod.f90 +psupply_mod.f90 +extra.c +random.f +randother.f +) + +target_sources(fennecs PRIVATE ${SRCS}) + +set_property(SOURCE ${SRCS} APPEND PROPERTY COMPILE_OPTIONS -cpp -fpp -qopenmp ) + +include_directories(SYSTEM ${MPI_INCLUDE_PATH} ${forSISL_INCLUDE_DIR}) + +if(MKL_Fortran_FLAGS) + separate_arguments(MKL_Fortran_FLAGS) + target_compile_options(fennecs PUBLIC ${MKL_Fortran_FLAGS}) + target_link_options(fennecs PUBLIC ${MKL_Fortran_FLAGS}) +endif() + +add_custom_command(TARGET fennecs POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/fennecs + ${CMAKE_CURRENT_BINARY_DIR}/../fennecs) + +target_include_directories(fennecs + PRIVATE $ + futils) + +target_link_libraries(fennecs PUBLIC futils bsplines MPI::MPI_Fortran +OpenMP::OpenMP_Fortran +${BLAS_LIBRARIES} +${MUMPS_LIBRARIES} +${LAPACK_LIBRARIES} +${forSISL_LIBRARY} +${sisl_LIBRARY} +) + + +