diff --git a/CMakeLists.txt b/CMakeLists.txt index 27964c5..f1d2611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12.0) +cmake_minimum_required(VERSION 3.14) project(catima) ############ options ############# @@ -32,7 +32,6 @@ MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) ######### compiler flags ########### set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) MESSAGE(STATUS "install prefix: " ${CMAKE_INSTALL_PREFIX}) @@ -49,22 +48,32 @@ if(GSL_INTEGRATION OR GSL_INTERPOLATION) list(APPEND EXTRA_LIBS ${GSL_LIBRARIES} ) endif() -find_package(nurex QUIET) -if(nurex_FOUND) -message(STATUS "nurex library found") -set(NUREX ON) -list(APPEND EXTRA_LIBS nurex::nurex) -endif(nurex_FOUND) +#find_package(nurex QUIET) +#if(nurex_FOUND) +#message(STATUS "nurex library found") +#set(NUREX ON) +#list(APPEND EXTRA_LIBS nurex::nurex) +#endif(nurex_FOUND) +find_package(fmt QUIET) +if(NOT fmt_FOUND) +message("fmt library not found, trying to dowload") + include(FetchContent) + FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 8.1.1 + ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(FMT_INSTALL ON) + FetchContent_MakeAvailable(fmt) +endif(NOT fmt_FOUND) -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/build_config.in" - "${CMAKE_CURRENT_BINARY_DIR}/include/catima/build_config.h" - ) +configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/build_config.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/catima/build_config.h") configure_file("${PROJECT_SOURCE_DIR}/init.sh.in" - "${PROJECT_BINARY_DIR}/init.sh" - ) + "${PROJECT_BINARY_DIR}/init.sh") ############### main build ########################### file(GLOB SOURCES *.cpp) @@ -80,8 +89,8 @@ set_target_properties(catima PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) -target_link_libraries(catima ${EXTRA_LIBS}) - +target_link_libraries(catima PUBLIC ${EXTRA_LIBS}) +target_compile_features(catima PRIVATE cxx_std_17) target_include_directories(catima PUBLIC $ $ @@ -94,7 +103,7 @@ FILE(COPY ${HEADERS} DESTINATION ${PROJECT_BINARY_DIR}/include/catima) # the compiler used for C++ files MESSAGE( STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER} ) -######## for python module +######## for python module ######### find_package(Python COMPONENTS Interpreter Development) if(Python_FOUND) message(STATUS "Python found: ${Python_EXECUTABLE}") @@ -105,7 +114,7 @@ if(PYTHON_MODULE) endif(NOT Python_FOUND) find_package(pybind11 QUIET) if(NOT pybind11_FOUND) - message(INFO "pybind11 not found, trying to dowload") + message("pybind11 not found, trying to dowload") include(FetchContent) FetchContent_Declare( pybind11 @@ -121,10 +130,12 @@ if(PYTHON_MODULE) $ $ $) - target_link_libraries(pycatima PRIVATE catima) + target_link_libraries(pycatima PRIVATE catima fmt::fmt) endif(PYTHON_MODULE ) + +configure_file("${PROJECT_SOURCE_DIR}/pymodule/setup.py.in" "${PROJECT_BINARY_DIR}/setup.py") if(PYTHON_WHEEL) - execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pymodule/setup.py bdist_wheel) + execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_BINARY_DIR}/setup.py bdist_wheel) endif(PYTHON_WHEEL) ########## Sub Directories ########### @@ -157,6 +168,10 @@ endif(APPS) ####### install part ####### FILE(GLOB headers "*.h") include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +write_basic_package_version_file(catimaConfigVersion.cmake VERSION 1.7 COMPATIBILITY AnyNewerVersion) + install (TARGETS catima EXPORT catimaConfig LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/appveyor.yml b/appveyor.yml index 2a6885b..306d005 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,10 +33,10 @@ build_script: # - git submodule add -b stable ../../pybind/pybind11 extern/pybind11 # - git submodule update --init - mkdir build && cd build -# - cmake -DBUILD_SHARED_LIBS=OFF -DAPPS=OFF -G "Visual Studio 16 2019" -A%PLATFORM% -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") ../ - - cmake -DBUILD_SHARED_LIBS=OFF -DAPPS=OFF -G "Visual Studio 16 2019" -A%PLATFORM% ../ + - cmake -DBUILD_SHARED_LIBS=OFF -DAPPS=OFF -DPYTHON_WHEEL=OFF -G "Visual Studio 16 2019" -A%PLATFORM% ../ - cmake --build ./ --config "%CONFIG%" - - python ../pymodule/setup.py bdist_wheel + - cmake -DBUILD_SHARED_LIBS=OFF -DAPPS=OFF -DPYTHON_WHEEL=ON -G "Visual Studio 16 2019" -A%PLATFORM% ../ +# - python ../pymodule/setup.py bdist_wheel artifacts: - path: build\dist\* diff --git a/catima.cpp b/catima.cpp index a2f7ecb..9c4b0da 100644 --- a/catima.cpp +++ b/catima.cpp @@ -137,14 +137,15 @@ double Tfr(const Projectile &p, double X, double Es2){ } double angular_variance(Projectile p, const Material &t, const Config &c, int order){ - const double T = p.T; - + const double T = p.T; const double p1 = p_from_T(T,p.A); const double beta1 = p1/((T+atomic_mass_unit)*p.A); + assert(T>0.0); + assert(t.density()>0.0); + assert(t.thickness()>0.0); auto& data = _storage.Get(p,t,c); - spline_type range_spline = get_range_spline(data); - double range = range_spline(T); - + spline_type range_spline = get_range_spline(data); + double range = range_spline(T); double rrange = std::min(range/t.density(), t.thickness_cm()); // residual range, in case of stopping inside material double X0 = radiation_length(t); double Es2 = 198.81; @@ -181,11 +182,11 @@ double angular_straggling(Projectile p, const Material &t, const Config &c){ return sqrt(angular_variance(p,t,c)); } -double angular_straggling_from_E(const Projectile &p, double T, double Tout, Material t, const Config &c){ +double angular_straggling_from_E(const Projectile &p, double Tout, Material t, const Config &c){ auto& data = _storage.Get(p,t,c); spline_type range_spline = get_range_spline(data); - double th = range_spline(T)-range_spline(Tout); - t.thickness(th); + double th = range_spline(p.T)-range_spline(Tout); + t.thickness(th); return angular_straggling(p,t,c); } @@ -210,7 +211,7 @@ double energy_out(double T, double thickness, const Interpolator &range_spline){ e = T - (thickness*dedx); while(1){ r = range - range_spline(e) - thickness; - if(fabs(r)::epsilon(); -constexpr double Eout_epsilon = 1e-5; // +constexpr double Eout_th_epsilon = 1e-5; // constexpr double thin_target_limit = 1 - 1e-3; diff --git a/convert.h b/convert.h new file mode 100644 index 0000000..874039a --- /dev/null +++ b/convert.h @@ -0,0 +1,77 @@ +/* + * Author: Andrej Prochazka + * Copyright(C) 2017 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program 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 Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef CONVERT_H +#define CONVERT_H +#include "catima/structures.h" +#include "catima/material_database.h" +#include +#include +#include +#include +#include "fmt/format.h" + +using namespace catima; + +bool mocadi_material_match(const Material &a, const Material&b){ + if(std::fabs(a.density() - b.density())> 1e-6)return false; + if(a.ncomponents() != b.ncomponents())return false; + for(int i=0;i extern "C" { + struct CatimaConfig catima_defaults = {1}; - CatimaResult catima_calculate(double pa, int pz, double T, double ta, double tz, double thickness, double density){ - catima::default_config.z_effective = catima_defaults.z_effective; - catima::Material mat; - catima::Projectile p(pa,pz); + catima::Material make_material(double ta, double tz, double thickness, double density){ + catima::Material mat; if(tz>200){ mat = catima::get_material(tz); } - else{ + else{ mat.add_element(ta,tz,1.0); } mat.density(density).thickness(thickness); + if(density<=0.0){ + catima::Material m0 = catima::get_material(tz); + mat.density(m0.density()); + } + return mat; + } + + CatimaResult catima_calculate(double pa, int pz, double T, double ta, double tz, double thickness, double density){ + catima::default_config.z_effective = catima_defaults.z_effective; + catima::Projectile p(pa,pz); + catima::Material mat = make_material(ta,tz, thickness, density); catima::Result r = catima::calculate(p(T),mat); CatimaResult res; - std::memcpy(&res,&r,sizeof(res)); + res.Ein = r.Ein; + res.Eout = r.Eout; + res.Eloss = r.Eloss; + res.range = r.range; + res.dEdxi = r.dEdxi; + res.dEdxo = r.dEdxo; + res.sigma_E = r.sigma_E; + res.sigma_a = r.sigma_a; + res.sigma_r = r.sigma_r; + res.tof = r.tof; + // printf("%d\n",catima::_storage.get_index()); return res; } - double catima_angular_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz){ + double catima_Eout(double pa, int pz, double T, double ta, double tz, double thickness, double density){ + catima::default_config.z_effective = catima_defaults.z_effective; catima::Projectile p(pa,pz); - - catima::Material mat; - if(tz>200){ - mat = catima::get_material(tz); - } - else{ - mat.add_element(ta,tz,1.0); - } + catima::Material mat = make_material(ta,tz, thickness, density); + return energy_out(p(T), mat); + } - return catima::angular_straggling_from_E(p,Tin,Tout,mat); + double catima_range(double pa, int pz, double T, double ta, double tz){ + catima::default_config.z_effective = catima_defaults.z_effective; + catima::Projectile p(pa,pz); + catima::Material mat = make_material(ta,tz, 0, -1); + return range(p, mat); + } + + double catima_range_straggling(double pa, int pz, double T, double ta, double tz){ + catima::default_config.z_effective = catima_defaults.z_effective; + catima::Projectile p(pa,pz); + catima::Material mat = make_material(ta,tz, 0, -1); + return range_straggling(p, T, mat); + } + + double catima_angular_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz){ + catima::Projectile p(pa,pz); + catima::Material mat = make_material(ta,tz, 0, -1); + + return catima::angular_straggling_from_E(p(Tin),Tout,mat); } double catima_energy_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz){ catima::Projectile p(pa,pz); - catima::Material mat; - if(tz>200){ - mat = catima::get_material(tz); - } - else{ - mat.add_element(ta,tz,1.0); - } + catima::Material mat = make_material(ta,tz, 0, -1); return catima::energy_straggling_from_E(p,Tin,Tout,mat); } + double atomic_weight(int i){return catima::element_atomic_weight(i);} + + double catima_nonreaction_rate(double pa, int pz, double T, double ta, double tz, double thickness){ + catima::Projectile p(pa,pz); + p.T = T; + catima::Material mat = make_material(ta,tz, thickness, -1); + return catima::nonreaction_rate(p,mat); + } + } \ No newline at end of file diff --git a/cwrapper.h b/cwrapper.h index 90ae782..ed17974 100644 --- a/cwrapper.h +++ b/cwrapper.h @@ -34,14 +34,18 @@ struct CatimaConfig { char z_effective; }; -struct CatimaConfig catima_defaults = {none}; +extern struct CatimaConfig catima_defaults; typedef struct CatimaResult CatimaResult; CatimaResult catima_calculate(double pa, int pz, double T, double ta, double tz, double thickness, double density); +double catima_Eout(double pa, int pz, double T, double ta, double tz, double thickness, double density); +double catima_range(double pa, int pz, double T, double ta, double tz); +double catima_range_straggling(double pa, int pz, double T, double ta, double tz); double catima_angular_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz); double catima_energy_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz); - +double atomic_weight(int i); +double catima_nonreaction_rate(double pa, int pz, double T, double ta, double tz, double thickness); #ifdef __cplusplus } diff --git a/pymodule/pycatima.cpp b/pymodule/pycatima.cpp index 50024ca..f2bfe7a 100644 --- a/pymodule/pycatima.cpp +++ b/pymodule/pycatima.cpp @@ -6,8 +6,10 @@ #include "catima/catima.h" #include "catima/srim.h" #include "catima/nucdata.h" +#include "catima/convert.h" #include #include + namespace py = pybind11; using namespace catima; @@ -467,6 +469,7 @@ PYBIND11_MODULE(pycatima,m){ l.append(r.second); return l; }); + m.def("save_mocadi", &save_mocadi,py::arg("filename"),py::arg("projectile"),py::arg("layers"),py::arg("psx")=Phasespace(), py::arg("psy")=Phasespace()); m.def("catima_info",&catima_info); m.def("storage_info",&storage_info); m.def("get_energy_table",&get_energy_table);