diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..46affd0e9 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,60 @@ +Checks: ' + -*, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-misplaced-widening-cast, + -bugprone-unchecked-optional-access, + cert-*, + -cert-err58-cpp, + clang-analyzer-*, + -clang-analyzer-optin.performance.Padding, + -clang-analyzer-optin.mpi.MPI-Checker, + -clang-analyzer-osx.*, + -clang-analyzer-optin.osx.*, + clang-diagnostic-*, + cppcoreguidelines-*, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-narrowing-conversions, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-*, + google-build-explicit-make-pair, + google-build-namespaces, + google-global-names-in-headers, + misc-*, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-return-braced-init-list, + -modernize-use-trailing-return-type, + mpi-*, + performance-*, + portability-*, + readability-*, + -readability-convert-member-functions-to-static, + -readability-else-after-return, + -readability-function-cognitive-complexity, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-named-parameter, + -readability-uppercase-literal-suffix + ' + +CheckOptions: +- key: bugprone-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion + value: "false" +- key: misc-definitions-in-headers.HeaderFileExtensions + value: "H," +- key: modernize-pass-by-value.ValuesOnly + value: "true" + + +HeaderFilterRegex: 'multi_physics[a-z_A-Z0-9\/]+\.hp?p?$' diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml new file mode 100644 index 000000000..460ff4297 --- /dev/null +++ b/.github/workflows/clang_tidy.yml @@ -0,0 +1,46 @@ +name: 🧹 clang-tidy + +on: [push, pull_request] + +jobs: + run_clang_tidy: + name: clang-tidy + runs-on: ubuntu-22.04 + env: {CXXFLAGS: "-Werror -Wshadow -Woverloaded-virtual -Wunreachable-code -fsanitize=address -fsanitize=undefined"} + steps: + - uses: actions/checkout@v4 + - name: install dependencies + run: .github/workflows/dependencies/clang15.sh + - name: Build & run clang-tidy + run: | + + export CXX=$(which clang++-15) + export CC=$(which clang-15) + + + # The following wrapper ensures that only source files + # in multi_physics/QED* are actually processed by clang-tidy + #_______________________________ + cat > clang_tidy_wrapper << EOF + #!/bin/bash + REGEX="[a-z_A-Z0-9\/]*multi_physics\/[a-z_A-Z0-9\/]+.cpp" + if [[ \$4 =~ \$REGEX ]];then + clang-tidy-15 \$@ + fi + EOF + chmod +x clang_tidy_wrapper + #_____________________________________ + + rm -rf build_clang_tidy + + cmake -S multi_physics/QED \ + -DCMAKE_CXX_CLANG_TIDY="$PWD/clang_tidy_wrapper;--system-headers=0;--config-file=$PWD/.clang-tidy" \ + -B build_clang_tidy \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DPXRMP_QED_TEST=ON \ + -DPXRMP_KOKKOS_EXAMPLE=ON \ + -DKokkos_ENABLE_OPENMP=ON + + cmake --build build_clang_tidy -j 4 2> build_clang_tidy/clang-tidy.log + cat build_clang_tidy/clang-tidy.log + if [[ $(wc -m -#include #include -#include -#include #include #include +#include +#include #include +#include +#include +#include #ifdef PXRMP_TABLE_GEN_HAS_OPENMP #include @@ -24,7 +25,6 @@ namespace px_bw = picsar::multi_physics::phys::breit_wheeler; namespace px_qs = picsar::multi_physics::phys::quantum_sync; -namespace px_ut = picsar::multi_physics::utils; // These string constants are used to parse command line instructions const std::string CMD_HELP_S = "-h"; @@ -327,7 +327,7 @@ void generate_quantum_sync_photem_table( double stod_wrapper(const std::string& str) { size_t idx = 0; - double val = std::stod(str, &idx); + const double val = std::stod(str, &idx); if (idx != str.length()){ print_error("Failed to parse '" + str + "' as a floating point number!"); exit(EXIT_FAILURE); @@ -345,7 +345,7 @@ double stod_wrapper(const std::string& str) int stoi_wrapper(const std::string& str) { size_t idx = 0; - int val = std::stoi(str, &idx); + const int val = std::stoi(str, &idx); if (idx != str.length()){ print_error("Failed to parse '" + str + "' as an integer number!"); exit(EXIT_FAILURE); @@ -372,20 +372,24 @@ parse_breit_wheeler_params(std::map args) params.frac_size = px_bw::default_frac_how_many; auto s_cmin = args.find(CMD_CHI_MIN); - if(s_cmin != args.end()) + if(s_cmin != args.end()){ params.chi_min = static_cast(stod_wrapper(s_cmin->second)); + } auto s_cmax = args.find(CMD_CHI_MAX); - if( s_cmax != args.end()) + if( s_cmax != args.end()){ params.chi_max = static_cast(stod_wrapper(s_cmax->second)); + } auto s_csize = args.find(CMD_CHI_SIZE); - if( s_csize != args.end()) + if( s_csize != args.end()){ params.chi_size = stoi_wrapper(s_csize->second); + } auto s_fsize = args.find(CMD_FRAC_SIZE); - if(s_fsize != args.end()) + if(s_fsize != args.end()){ params.frac_size = stoi_wrapper(s_fsize->second); + } return params; } @@ -415,7 +419,7 @@ void do_breit_wheeler(BreitWheelerTableParams params, const std::strin std::cout << " Tables will be generated in double precision." << std::endl; } else{ - const auto prec = + const auto *const prec = (Policy == px_bw::generation_policy::force_internal_double) ? "double" : "single"; std::cout << " Tables will be calculated in " << prec << @@ -465,24 +469,29 @@ parse_quantum_sync_params(std::map args) params.frac_size = px_qs::default_frac_how_many; auto s_cmin = args.find(CMD_CHI_MIN); - if(s_cmin != args.end()) + if(s_cmin != args.end()){ params.chi_min = static_cast(stod_wrapper(s_cmin->second)); + } auto s_cmax = args.find(CMD_CHI_MAX); - if(s_cmax != args.end()) + if(s_cmax != args.end()){ params.chi_max = static_cast(stod_wrapper(s_cmax->second)); + } auto s_fmin = args.find(CMD_FRAC_MIN); - if(s_fmin != args.end()) + if(s_fmin != args.end()){ params.frac_min = static_cast(stod_wrapper(s_fmin->second)); + } auto s_csize = args.find(CMD_CHI_SIZE); - if(s_csize != args.end()) + if(s_csize != args.end()){ params.chi_size = stoi_wrapper(s_csize->second); + } auto s_fsize = args.find(CMD_FRAC_SIZE); - if(s_fsize != args.end()) + if(s_fsize != args.end()){ params.frac_size = stoi_wrapper(s_fsize->second); + } return params; } @@ -512,7 +521,7 @@ void do_quantum_sync(QuantumSyncTableParams params, const std::string& std::cout << " Tables will be generated in double precision." << std::endl; } else{ - const auto prec = + const auto *const prec = (Policy == px_qs::generation_policy::force_internal_double) ? "double" : "single"; std::cout << " Tables will be calculated in " << prec << @@ -654,11 +663,12 @@ void check_argc(int argc) */ void handle_help_argument(int argc, char** argv) { - if(argc < 2) + if(argc < 2){ return; + } const auto arg = std::string{argv[1]}; - if(arg.compare(CMD_HELP_S) == 0 || arg.compare(CMD_HELP_L) == 0){ + if(arg == CMD_HELP_S || arg == CMD_HELP_L){ print_help_message(); exit(EXIT_SUCCESS); } @@ -757,56 +767,63 @@ std::string parse_file_name_prefix(std::map& args){ } } - +// This is added because clang-tidy seems to erroneously +// flag this function for this specific test. +// NOLINTNEXTLINE(bugprone-exception-escape) int main(int argc, char** argv) { - handle_help_argument(argc, argv); - auto args = read_arg_pairs(argc, argv); - - const auto precision = parse_precision(args); - const auto table_type = parse_table_type(args); - const auto file_name_prefix = parse_file_name_prefix(args); - - if(table_type == TableType::breit_wheeler_table){ - if(precision == Precision::double_precision){ - auto params = parse_breit_wheeler_params(args); - do_breit_wheeler< - double, px_bw::generation_policy::regular>( + try{ + handle_help_argument(argc, argv); + auto args = read_arg_pairs(argc, argv); + + const auto precision = parse_precision(args); + const auto table_type = parse_table_type(args); + const auto file_name_prefix = parse_file_name_prefix(args); + + if(table_type == TableType::breit_wheeler_table){ + if(precision == Precision::double_precision){ + auto params = parse_breit_wheeler_params(args); + do_breit_wheeler< + double, px_bw::generation_policy::regular>( + params, file_name_prefix); + } + else if(precision == Precision::single_precision){ + auto params = parse_breit_wheeler_params(args); + do_breit_wheeler< + float, px_bw::generation_policy::regular>( params, file_name_prefix); + } + else if(precision == Precision::single_prec_out_double_prec_comp){ + auto params = parse_breit_wheeler_params(args); + do_breit_wheeler< + float, px_bw::generation_policy::force_internal_double>( + params, file_name_prefix); + } } - else if(precision == Precision::single_precision){ - auto params = parse_breit_wheeler_params(args); - do_breit_wheeler< - float, px_bw::generation_policy::regular>( - params, file_name_prefix); - } - else if(precision == Precision::single_prec_out_double_prec_comp){ - auto params = parse_breit_wheeler_params(args); - do_breit_wheeler< - float, px_bw::generation_policy::force_internal_double>( - params, file_name_prefix); + else if(table_type == TableType::quantum_synchrotron_table){ + if(precision == Precision::double_precision){ + auto params = parse_quantum_sync_params(args); + do_quantum_sync< + double, px_qs::generation_policy::regular>( + params, file_name_prefix); + } + else if(precision == Precision::single_precision){ + auto params = parse_quantum_sync_params(args); + do_quantum_sync< + float, px_qs::generation_policy::regular>( + params, file_name_prefix); + } + else if(precision == Precision::single_prec_out_double_prec_comp){ + auto params = parse_quantum_sync_params(args); + do_quantum_sync< + float, px_qs::generation_policy::force_internal_double>( + params, file_name_prefix); + } } } - else if(table_type == TableType::quantum_synchrotron_table){ - if(precision == Precision::double_precision){ - auto params = parse_quantum_sync_params(args); - do_quantum_sync< - double, px_qs::generation_policy::regular>( - params, file_name_prefix); - } - else if(precision == Precision::single_precision){ - auto params = parse_quantum_sync_params(args); - do_quantum_sync< - float, px_qs::generation_policy::regular>( - params, file_name_prefix); - } - else if(precision == Precision::single_prec_out_double_prec_comp){ - auto params = parse_quantum_sync_params(args); - do_quantum_sync< - float, px_qs::generation_policy::force_internal_double>( - params, file_name_prefix); - } + catch(const std::exception& e){ + std::cerr << e.what(); + exit(EXIT_FAILURE); } - exit(EXIT_SUCCESS); } diff --git a/multi_physics/QED/QED_tests/CMakeLists.txt b/multi_physics/QED/QED_tests/CMakeLists.txt index 9b330cf63..3faa680b2 100644 --- a/multi_physics/QED/QED_tests/CMakeLists.txt +++ b/multi_physics/QED/QED_tests/CMakeLists.txt @@ -50,8 +50,8 @@ foreach(name ${TEST_NAMES}) set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - # Require C++14 or newer - target_compile_features(${name} PUBLIC cxx_std_14) + # Require C++17 or newer + target_compile_features(${name} PUBLIC cxx_std_17) set_target_properties(${name} PROPERTIES CXX_EXTENSIONS OFF) # Enable warnings diff --git a/multi_physics/QED/QED_tests/test_picsar_algo.cpp b/multi_physics/QED/QED_tests/test_picsar_algo.cpp index 78ad83117..7fc5c8571 100644 --- a/multi_physics/QED/QED_tests/test_picsar_algo.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_algo.cpp @@ -27,10 +27,12 @@ const float float_tolerance = 1.0e-6; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_array.cpp b/multi_physics/QED/QED_tests/test_picsar_array.cpp index 8be42ca24..4ba496a6e 100644 --- a/multi_physics/QED/QED_tests/test_picsar_array.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_array.cpp @@ -71,10 +71,10 @@ BOOST_AUTO_TEST_CASE( picsar_array_range_based_loops ) { auto arr = picsar_array(); int i = 0; - for(auto& el : arr) el = ++i; + for(auto& el : arr){ el = ++i; }; int sum = 0; - for(const auto& el : arr) sum += el; - for(auto el : arr) sum += el; + for(const auto& el : arr){ sum += el; } + for(auto el : arr){ sum += el; } BOOST_CHECK_EQUAL(sum, 12); } @@ -86,10 +86,11 @@ BOOST_AUTO_TEST_CASE( picsar_array_copy ) { auto arr = picsar_array(); int j = 0; - for(auto& el : arr) el = ++j; + for(auto& el : arr){ el = ++j; } auto c_arr = arr; - for(int i = 0; i < arr.size(); ++i) + for(int i = 0; i < arr.size(); ++i){ BOOST_CHECK_EQUAL(arr[i], c_arr[i]); + } } // ******************************* diff --git a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_core.cpp b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_core.cpp index 84d679a89..3640122cc 100644 --- a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_core.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_core.cpp @@ -30,19 +30,23 @@ using namespace picsar::multi_physics::math; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } template @@ -50,7 +54,7 @@ struct fake_T_table { RealType interp(RealType chi, bool* is_out = nullptr) const { m_chi = chi; - if(is_out != nullptr) *is_out = m_is_out; + if(is_out != nullptr) { *is_out = m_is_out; } return m_res; } @@ -65,7 +69,7 @@ struct fake_P_table RealType interp(RealType chi, RealType random, bool* is_out = nullptr) const { m_chi = chi; m_random = random; - if(is_out != nullptr) *is_out = m_is_out; + if(is_out != nullptr) { *is_out = m_is_out; } return m_res; } @@ -185,8 +189,8 @@ BOOST_AUTO_TEST_CASE( picsar_breit_wheeler_core_get_dndt) check_dndt(reference_length); check_dndt(); check_dndt(); - check_dndt(reference_omega); - check_dndt(reference_length); + check_dndt(static_cast(reference_omega)); + check_dndt(static_cast(reference_length)); check_dndt(); } @@ -282,8 +286,8 @@ BOOST_AUTO_TEST_CASE( picsar_breit_wheeler_core_evolve_opt_depth) check_evolve_opt_depth(reference_length); check_evolve_opt_depth(); check_evolve_opt_depth(); - check_evolve_opt_depth(reference_omega); - check_evolve_opt_depth(reference_length); + check_evolve_opt_depth(static_cast(reference_omega)); + check_evolve_opt_depth(static_cast(reference_length)); check_evolve_opt_depth(); } @@ -339,7 +343,7 @@ void check_pair_production(RealType ref_q = one) fake_table.m_res = chi_ele; fake_table.m_is_out = false; - const RealType pmom = static_cast(mom); + const auto pmom = static_cast(mom); const auto photon_momentum = vec3{ @@ -424,8 +428,8 @@ BOOST_AUTO_TEST_CASE( picsar_breit_wheeler_core_pair_production) check_pair_production(reference_length); check_pair_production(); check_pair_production(); - check_pair_production(reference_omega); - check_pair_production(reference_length); + check_pair_production(static_cast(reference_omega)); + check_pair_production(static_cast(reference_length)); check_pair_production(); } diff --git a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables.cpp b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables.cpp index 3aa43d6cc..a496fcd20 100644 --- a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables.cpp @@ -28,19 +28,23 @@ using namespace picsar::multi_physics::phys::breit_wheeler; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } // ------------- Helper functions -------------- @@ -94,7 +98,7 @@ void check_dndt_table() for (int i = 0 ; i < static_cast(coords.size()); ++i){ auto res = coords[i]; auto expected = static_cast( - exp(log_chi_min + i*(log_chi_max-log_chi_min)/(how_many-1))); + std::exp(log_chi_min + i*(log_chi_max-log_chi_min)/(how_many-1))); BOOST_CHECK_SMALL((res-expected)/expected, tolerance()); } @@ -105,7 +109,7 @@ void check_dndt_table() std::transform(coords.begin(), coords.end(), vals.begin(), [=](RealType x){return alpha*x;}); - bool result = table.set_all_vals(vals); + const bool result = table.set_all_vals(vals); BOOST_CHECK_EQUAL(result,true); BOOST_CHECK_EQUAL(table.is_init(),true); @@ -120,8 +124,8 @@ void check_dndt_table() const RealType x1 = (chi_max+chi_min)*0.5642 + chi_min; const RealType x2 = chi_max; - const RealType ye_app_o0 = dndt_approx_left(xo0); - const RealType ye_app_o1 = dndt_approx_right(xo1); + const auto ye_app_o0 = dndt_approx_left(xo0); + const auto ye_app_o1 = dndt_approx_right(xo1); const RealType ye0 = alpha*x0; const RealType ye1 = alpha*x1; const RealType ye2 = alpha*x2; @@ -144,10 +148,12 @@ void check_dndt_table() const RealType expect = exp_app[i]; - if(i != 0) + if(i != 0){ BOOST_CHECK_SMALL((res-expect)/expect, tolerance()); - else + } + else{ BOOST_CHECK_SMALL((res-expect), tolerance()); + } } const auto table_view = table.get_view(); @@ -248,15 +254,17 @@ void check_pair_production_table() const auto ii = i/how_many_frac; const auto jj = i%how_many_frac; auto expected_1 = static_cast( - exp(log_chi_min +ii*(log_chi_max-log_chi_min)/(how_many-1))); + std::exp(log_chi_min +ii*(log_chi_max-log_chi_min)/(how_many-1))); auto expected_2 = expected_1*static_cast( 0.0 +jj*0.5/(how_many_frac-1)); BOOST_CHECK_SMALL((res_1-expected_1)/expected_1, tolerance()); - if(expected_2 != static_cast(0.0)) + if(expected_2 != static_cast(0.0)){ BOOST_CHECK_SMALL((res_2-expected_2)/expected_2, tolerance()); - else + } + else { BOOST_CHECK_SMALL((res_2-expected_2), tolerance()); + } } auto vals = VectorType(coords.size()); @@ -269,7 +277,7 @@ void check_pair_production_table() std::transform(coords.begin(), coords.end(), vals.begin(),functor); - bool result = table.set_all_vals(vals); + const bool result = table.set_all_vals(vals); BOOST_CHECK_EQUAL(result,true); BOOST_CHECK_EQUAL(table.is_init(),true); @@ -304,16 +312,18 @@ void check_pair_production_table() BOOST_CHECK_EQUAL(res, res2); auto rxx = xx; - if(rxx < chi_min) rxx = chi_min; - if(rxx > chi_max) rxx = chi_max; + if(rxx < chi_min) { rxx = chi_min; } + if(rxx > chi_max) { rxx = chi_max; } auto eff_rr = (rr > 0.5)?(static_cast(1.0) - rr):rr; auto expected = inverse_functor(std::array{rxx, eff_rr})*xx; - if(rr >= 0.5) expected = xx - expected; + if(rr >= 0.5) { expected = xx - expected; } - if(expected != static_cast(0.0)) + if(expected != static_cast(0.0)) { BOOST_CHECK_SMALL((res-expected)/expected, tolerance()); - else + } + else { BOOST_CHECK_SMALL(res, small()); + } } } @@ -322,8 +332,9 @@ void check_pair_production_table() const auto ff = std::array{0.0, 0.1, 0.5, 0.99}; for(int i = 0 ; i < static_cast(xxs.size()) ; ++i){ - for (auto f : ff) + for (auto f : ff){ BOOST_CHECK_EQUAL(table_view.interp(xxs[i],f ), table.interp(xxs[i], f)); + } } } diff --git a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables_generator.cpp b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables_generator.cpp index a33bd8f98..8c23e5963 100644 --- a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables_generator.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tables_generator.cpp @@ -29,19 +29,23 @@ using namespace picsar::multi_physics::phys::breit_wheeler; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } const double chi_min = 0.1; diff --git a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tabulated_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tabulated_functions.cpp index b8c85fe40..94c7e3aea 100644 --- a/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tabulated_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_breit_wheeler_tabulated_functions.cpp @@ -26,19 +26,23 @@ using namespace picsar::multi_physics::phys::breit_wheeler; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_chi_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_chi_functions.cpp index 3a0722ece..0a8100f60 100644 --- a/multi_physics/QED/QED_tests/test_picsar_chi_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_chi_functions.cpp @@ -25,10 +25,12 @@ const float float_tolerance = 1.0e-6; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } @@ -70,10 +72,12 @@ void test_chi_photons( const auto exp_res = static_cast(t_exp_res); - if(exp_res != static_cast(0.0)) + if(exp_res != static_cast(0.0)){ BOOST_CHECK_SMALL((res-exp_res)/exp_res, tolerance()); - else + } + else{ BOOST_CHECK_SMALL(res, tolerance()); + } } BOOST_AUTO_TEST_CASE( chi_photons_1 ) @@ -275,10 +279,12 @@ void test_chi_ele_pos( const auto exp_res = static_cast(t_exp_res); - if(exp_res != static_cast(0.0)) + if(exp_res != static_cast(0.0)){ BOOST_CHECK_SMALL((res-exp_res)/exp_res, tolerance()); - else + } + else{ BOOST_CHECK_SMALL(res, tolerance()); + } } BOOST_AUTO_TEST_CASE( chi_ele_pos_1 ) diff --git a/multi_physics/QED/QED_tests/test_picsar_gamma_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_gamma_functions.cpp index 1c68e6c0c..cff2d8395 100644 --- a/multi_physics/QED/QED_tests/test_picsar_gamma_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_gamma_functions.cpp @@ -25,10 +25,12 @@ const float float_tolerance = 1.0e-6; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } @@ -54,10 +56,12 @@ void test_gamma_photons( const auto exp_res = static_cast(t_exp_res); - if(exp_res != static_cast(0.0)) + if(exp_res != static_cast(0.0)){ BOOST_CHECK_SMALL((res-exp_res)/exp_res, tolerance()); - else + } + else{ BOOST_CHECK_SMALL(res, tolerance()); + } } void test_gamma_photons_all_cases( @@ -170,10 +174,12 @@ void test_gamma_ele_pos( const auto exp_res = static_cast(t_exp_res); - if(exp_res != static_cast(0.0)) + if(exp_res != static_cast(0.0)){ BOOST_CHECK_SMALL((res-exp_res)/exp_res, tolerance()); - else + } + else{ BOOST_CHECK_SMALL(res, tolerance()); + } } void test_gamma_ele_pos_all_cases( diff --git a/multi_physics/QED/QED_tests/test_picsar_phys_constants.cpp b/multi_physics/QED/QED_tests/test_picsar_phys_constants.cpp index d8a199157..a54d7c1d7 100644 --- a/multi_physics/QED/QED_tests/test_picsar_phys_constants.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_phys_constants.cpp @@ -25,10 +25,12 @@ const float float_tolerance = 1.0e-7; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_quadrature.cpp b/multi_physics/QED/QED_tests/test_picsar_quadrature.cpp index 686f19e12..6d24366f2 100644 --- a/multi_physics/QED/QED_tests/test_picsar_quadrature.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_quadrature.cpp @@ -24,10 +24,12 @@ const float float_tolerance = 1.0e-3; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_core.cpp b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_core.cpp index 1757a4506..0c464c672 100644 --- a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_core.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_core.cpp @@ -30,19 +30,23 @@ using namespace picsar::multi_physics::math; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } template @@ -50,7 +54,7 @@ struct fake_G_table { RealType interp(RealType chi, bool* is_out = nullptr) const { m_chi = chi; - if(is_out != nullptr) *is_out = m_is_out; + if(is_out != nullptr) { *is_out = m_is_out; } return m_res; } @@ -65,7 +69,7 @@ struct fake_P_table RealType interp(RealType chi, RealType random, bool* is_out = nullptr) const { m_chi = chi; m_random = random; - if(is_out != nullptr) *is_out = m_is_out; + if(is_out != nullptr) { *is_out = m_is_out; } return m_res; } @@ -192,8 +196,8 @@ BOOST_AUTO_TEST_CASE( picsar_quantum_sync_core_get_dndt) check_dndt(reference_length); check_dndt(); check_dndt(); - check_dndt(reference_omega); - check_dndt(reference_length); + check_dndt(static_cast(reference_omega)); + check_dndt(static_cast(reference_length)); check_dndt(); } @@ -290,8 +294,8 @@ BOOST_AUTO_TEST_CASE( picsar_quantum_sync_core_evolve_opt_depth) check_evolve_opt_depth(reference_length); check_evolve_opt_depth(); check_evolve_opt_depth(); - check_evolve_opt_depth(reference_omega); - check_evolve_opt_depth(reference_length); + check_evolve_opt_depth(static_cast(reference_omega)); + check_evolve_opt_depth(static_cast(reference_length)); check_evolve_opt_depth(); } @@ -359,13 +363,13 @@ void check_photon_emission(RealType ref_q = one) const auto rand_num = static_cast(rand); - vec3 mom_phot; + vec3 photon_momentum; const bool is_in_table = generate_photon_update_momentum< RealType, fake_P_table, UnitSystem>( chi_ele, ele_momentum, rand_num, - fake_table, mom_phot, ref_q); + fake_table, photon_momentum, ref_q); BOOST_CHECK_EQUAL(fake_table.m_random, rand_num); BOOST_CHECK_EQUAL(fake_table.m_chi, chi_ele); @@ -374,19 +378,19 @@ void check_photon_emission(RealType ref_q = one) const auto me_c = electron_mass<>*light_speed<>; const auto gamma_ele = sqrt(1.0 + (mom/me_c)*(mom/me_c)); const auto gamma_phot = (gamma_ele-1.)*(chi_phot/chi_ele); - const auto t_mom_phot = me_c*gamma_phot; + const auto t_photon_momentum = me_c*gamma_phot; - const auto tv_mom_phot = t_mom_phot * dir * + const auto tv_photon_momentum = t_photon_momentum * dir * conv::fact(1.0, ref_q); - const auto exp_mom_phot = vec3{ - static_cast(tv_mom_phot[0]), - static_cast(tv_mom_phot[1]), - static_cast(tv_mom_phot[2])}; + const auto exp_photon_momentum = vec3{ + static_cast(tv_photon_momentum[0]), + static_cast(tv_photon_momentum[1]), + static_cast(tv_photon_momentum[2])}; - aux_check_small_or_zero(mom_phot, exp_mom_phot); + aux_check_small_or_zero(photon_momentum, exp_photon_momentum); fake_table.m_is_out = true; const bool is_in_table_2 = generate_photon_update_momentum< @@ -394,7 +398,7 @@ void check_photon_emission(RealType ref_q = one) fake_P_table, UnitSystem>( chi_ele, ele_momentum, rand_num, - fake_table, mom_phot, ref_q); + fake_table, photon_momentum, ref_q); BOOST_CHECK_EQUAL(!fake_table.m_is_out, is_in_table_2); } } @@ -416,8 +420,8 @@ BOOST_AUTO_TEST_CASE( picsar_quantum_sync_photon_emission) check_photon_emission(reference_length); check_photon_emission(); check_photon_emission(); - check_photon_emission(reference_omega); - check_photon_emission(reference_length); + check_photon_emission(static_cast(reference_omega)); + check_photon_emission(static_cast(reference_length)); check_photon_emission(); } diff --git a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables.cpp b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables.cpp index 6a6c81537..da9a559a5 100644 --- a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables.cpp @@ -28,19 +28,23 @@ using namespace picsar::multi_physics::phys::quantum_sync; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } const double chi_min = 0.001; @@ -108,7 +112,7 @@ void check_dndt_table() for (int i = 0 ; i < static_cast(coords.size()); ++i){ auto res = coords[i]; auto expected = static_cast( - exp(log_chi_min + i*(log_chi_max-log_chi_min)/(how_many-1))); + std::exp(log_chi_min + i*(log_chi_max-log_chi_min)/(how_many-1))); BOOST_CHECK_SMALL((res-expected)/expected, tolerance()); } @@ -119,7 +123,7 @@ void check_dndt_table() std::transform(coords.begin(), coords.end(), vals.begin(), [=](RealType x){return alpha*x;}); - bool result = table.set_all_vals(vals); + const bool result = table.set_all_vals(vals); BOOST_CHECK_EQUAL(result,true); BOOST_CHECK_EQUAL(table.is_init(),true); @@ -158,10 +162,12 @@ void check_dndt_table() const RealType expect = exp_ext[i]; - if(i != 0) + if(i != 0){ BOOST_CHECK_SMALL((res-expect)/expect, tolerance()); - else + } + else{ BOOST_CHECK_SMALL((res-expect), tolerance()); + } } const auto table_view = table.get_view(); @@ -224,15 +230,17 @@ void check_photon_emission_table() const auto ii = i/how_many_frac; const auto jj = i%how_many_frac; auto expected_1 = static_cast( - exp(log_chi_min +ii*(log_chi_max-log_chi_min)/(how_many-1))); + std::exp(log_chi_min +ii*(log_chi_max-log_chi_min)/(how_many-1))); auto expected_2 = static_cast( - expected_1*exp(log_frac_min +jj*(0.0-log_frac_min)/(how_many_frac-1))); + expected_1*std::exp(log_frac_min +jj*(0.0-log_frac_min)/(how_many_frac-1))); BOOST_CHECK_SMALL((res_1-expected_1)/expected_1, tolerance()); - if(expected_2 != static_cast(0.0)) + if(expected_2 != static_cast(0.0)){ BOOST_CHECK_SMALL((res_2-expected_2)/expected_2, tolerance()); - else + } + else { BOOST_CHECK_SMALL((res_2-expected_2), tolerance()); + } } auto vals = VectorType(coords.size()); @@ -245,7 +253,7 @@ void check_photon_emission_table() std::transform(coords.begin(), coords.end(), vals.begin(),functor); - bool result = table.set_all_vals(vals); + const bool result = table.set_all_vals(vals); BOOST_CHECK_EQUAL(result,true); BOOST_CHECK_EQUAL(table.is_init(),true); @@ -271,22 +279,24 @@ void check_photon_emission_table() for (const auto rr : rrs){ auto res = table.interp(xx, rr); auto rxx = xx; - if(rxx < chi_min) rxx = chi_min; - if(rxx > chi_max) rxx = chi_max; + if(rxx < chi_min) { rxx = chi_min; } + if(rxx > chi_max) { rxx = chi_max; } auto expected = inverse_functor(std::array{rxx, rr})*xx; - if(expected < small()) + if(expected < small()){ BOOST_CHECK_SMALL((res-expected)/expected, tolerance()); - else + } + else{ BOOST_CHECK_SMALL((res-expected), tolerance()); - + } } } const auto table_view = table.get_view(); for(auto xx : xxs){ - for (auto r : rrs) + for (auto r : rrs){ BOOST_CHECK_EQUAL(table_view.interp(xx,r ), table.interp(xx, r)); + } } } @@ -358,10 +368,12 @@ void check_tailopt_photon_emission_table() auto expected_2 = std::exp(tailopt_functor(jj))*expected_1; BOOST_CHECK_SMALL((res_1-expected_1)/expected_1, tolerance()); - if(expected_2 != static_cast(0.0)) + if(expected_2 != static_cast(0.0)){ BOOST_CHECK_SMALL((res_2-expected_2)/expected_2, tolerance()); - else + } + else{ BOOST_CHECK_SMALL((res_2-expected_2), tolerance()); + } } auto vals = VectorType(coords.size()); @@ -374,7 +386,7 @@ void check_tailopt_photon_emission_table() std::transform(coords.begin(), coords.end(), vals.begin(),functor); - bool result = table.set_all_vals(vals); + const bool result = table.set_all_vals(vals); BOOST_CHECK_EQUAL(result,true); BOOST_CHECK_EQUAL(table.is_init(),true); @@ -398,13 +410,15 @@ void check_tailopt_photon_emission_table() for (const auto rr : rrs){ auto res = table.interp(xx, rr); auto rxx = xx; - if(rxx < chi_min) rxx = chi_min; - if(rxx > chi_max) rxx = chi_max; + if(rxx < chi_min) { rxx = chi_min; } + if(rxx > chi_max) { rxx = chi_max; } auto expected = inverse_functor(std::array{rxx, rr})*xx; - if(expected < small()) + if(expected < small()){ BOOST_CHECK_SMALL((res-expected)/expected, tolerance()); - else + } + else { BOOST_CHECK_SMALL((res-expected), tolerance()); + } } } @@ -412,8 +426,9 @@ void check_tailopt_photon_emission_table() const auto table_view = table.get_view(); for(auto xx : xxs){ - for (auto r : rrs) + for (auto r : rrs){ BOOST_CHECK_EQUAL(table_view.interp(xx,r ), table.interp(xx, r)); + } } } diff --git a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables_generator.cpp b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables_generator.cpp index e05a5cb5e..db2f646c8 100644 --- a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables_generator.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tables_generator.cpp @@ -29,19 +29,23 @@ using namespace picsar::multi_physics::phys::quantum_sync; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } const double chi_min = 0.01; diff --git a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tabulated_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tabulated_functions.cpp index 810fd08ac..0225ec367 100644 --- a/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tabulated_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_quantum_sync_tabulated_functions.cpp @@ -26,19 +26,23 @@ using namespace picsar::multi_physics::phys::quantum_sync; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_schwinger_engine_core.cpp b/multi_physics/QED/QED_tests/test_picsar_schwinger_engine_core.cpp index adf2e2192..441bfcf28 100644 --- a/multi_physics/QED/QED_tests/test_picsar_schwinger_engine_core.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_schwinger_engine_core.cpp @@ -28,10 +28,12 @@ const float float_tolerance = 1.0e-4; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- @@ -86,10 +88,12 @@ void test_expected_pair_number(RealType ref = zero) E[i][0]*fe, E[i][1]*fe, E[i][2]*fe, B[i][0]*fb, B[i][1]*fb, B[i][2]*fb, volume*fv, dt*ft, ref); - if(res_exp[i] <= tolerance()) + if(res_exp[i] <= tolerance()){ BOOST_CHECK_SMALL(res, tolerance()); - else + } + else{ BOOST_CHECK_SMALL((res-static_cast(res_exp[i]))/static_cast(res_exp[i]), tolerance()); + } } } @@ -104,8 +108,8 @@ BOOST_AUTO_TEST_CASE( picsar_schwinger_core_expected_pair_number ) test_expected_pair_number (reference_length); test_expected_pair_number (); test_expected_pair_number (); - test_expected_pair_number (reference_omega); - test_expected_pair_number (reference_length); + test_expected_pair_number (static_cast(reference_omega)); + test_expected_pair_number (static_cast(reference_length)); test_expected_pair_number (); } diff --git a/multi_physics/QED/QED_tests/test_picsar_serialization.cpp b/multi_physics/QED/QED_tests/test_picsar_serialization.cpp index d292946cd..5a7305ae7 100644 --- a/multi_physics/QED/QED_tests/test_picsar_serialization.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_serialization.cpp @@ -99,8 +99,9 @@ BOOST_AUTO_TEST_CASE( picsar_serialization_get_n_out) auto doublevec = std::vector{ 1.0, 2,0, 3.0, 4.0, 5.0, 6.0}; - for (auto dd : doublevec) + for (auto dd : doublevec){ put_in(dd, raw_data); + } auto it = raw_data.begin(); auto dvec1 = get_n_out(it, 3); diff --git a/multi_physics/QED/QED_tests/test_picsar_span.cpp b/multi_physics/QED/QED_tests/test_picsar_span.cpp index a7d1d1406..a0e2c899f 100644 --- a/multi_physics/QED/QED_tests/test_picsar_span.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_span.cpp @@ -35,8 +35,9 @@ BOOST_AUTO_TEST_CASE( picsar_span_raw_pointers_constructor ) const auto span = picsar_span{arr.size(), arr.data()}; BOOST_CHECK_EQUAL(span.size(), arr.size()); - for(size_t i = 0; i < arr.size(); ++i) + for(size_t i = 0; i < arr.size(); ++i){ BOOST_CHECK_EQUAL(span[i], arr[i]); + } } // ******************************* @@ -47,11 +48,11 @@ BOOST_AUTO_TEST_CASE( picsar_span_range_based_loops ) { auto arr = std::array(); int i = 0; - for(auto& el : arr) el = ++i; + for(auto& el : arr){ el = ++i; } const auto span = picsar_span{arr.size(), arr.data()}; int sum = 0; - for(const auto& el : span) sum += el; - for(auto el : span) sum += el; + for(const auto& el : span){ sum += el; } + for(auto el : span) { sum += el; } BOOST_CHECK_EQUAL(sum, 12); } @@ -67,8 +68,9 @@ BOOST_AUTO_TEST_CASE( picsar_span_copy ) BOOST_CHECK_EQUAL(cspan.size(), arr.size()); BOOST_CHECK_EQUAL(cspan.data(), arr.data()); - for(size_t i = 0; i < arr.size(); ++i) + for(size_t i = 0; i < arr.size(); ++i){ BOOST_CHECK_EQUAL(cspan[i], arr[i]); + } } // ******************************* diff --git a/multi_physics/QED/QED_tests/test_picsar_spec_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_spec_functions.cpp index 287806203..6a2881ac6 100644 --- a/multi_physics/QED/QED_tests/test_picsar_spec_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_spec_functions.cpp @@ -23,10 +23,12 @@ const float float_tolerance = 1.0e-4; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- diff --git a/multi_physics/QED/QED_tests/test_picsar_tables.cpp b/multi_physics/QED/QED_tests/test_picsar_tables.cpp index 654096540..f174a927f 100644 --- a/multi_physics/QED/QED_tests/test_picsar_tables.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_tables.cpp @@ -29,10 +29,12 @@ const float float_tolerance = 1.0e-5; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } double linear_function(double x) @@ -72,16 +74,15 @@ class Functor { public: - Functor(){} + Functor () = default; Functor(const int zsize, const int zfirst, const double zmin, const double zmax, const double zswitch): m_zsize{zsize}, m_zfirst{zfirst}, - m_zmin{zmin}, m_zmax{zmax}, m_zswitch{zswitch} - { - m_logzmin = std::log(m_zmin); - m_logzswitch = std::log(m_zswitch); - } + m_zmin{zmin}, m_logzmin{std::log(m_zmin)}, + m_zmax{zmax}, m_zswitch{zswitch}, + m_logzswitch{std::log(m_zswitch)} + {} double operator() (const int i) const { @@ -105,6 +106,7 @@ class Functor (this->m_logzswitch == rhs.m_logzswitch); } + [[nodiscard]] std::vector serialize() const { std::vector raw; @@ -151,16 +153,15 @@ class IFunctor { public: - IFunctor(){} + IFunctor() = default; IFunctor(const int zsize, const int zfirst, const double zmin, const double zmax, const double zswitch): m_zsize{zsize}, m_zfirst{zfirst}, - m_zmin{zmin}, m_zmax{zmax}, m_zswitch{zswitch} - { - m_logzmin = std::log(m_zmin); - m_logzswitch = std::log(m_zswitch); - } + m_zmin{zmin}, m_logzmin{std::log(m_zmin)}, + m_zmax{zmax}, m_zswitch{zswitch}, + m_logzswitch{std::log(m_zswitch)} + {} int operator() (const double z) const { @@ -187,6 +188,7 @@ class IFunctor (this->m_logzswitch == rhs.m_logzswitch); } + [[nodiscard]] std::vector serialize() const { std::vector raw; @@ -239,7 +241,7 @@ equispaced_1d_table > make_1d_table() std::vector data(xsize); std::generate(data.begin(), data.end(), [&, n = 0]() mutable { - double x = xmin+((xmax-xmin)*(n++))/(xsize-1); + const double x = xmin+((xmax-xmin)*(n++))/(xsize-1); return linear_function(x); }); @@ -251,8 +253,8 @@ equispaced_2d_table > make_2d_table() std::vector data(xsize*ysize); for (int i = 0; i < xsize; ++i){ for (int j = 0; j < ysize; ++j){ - double x = xmin+i*(xmax-xmin)/(xsize-1); - double y = ymin+j*(ymax-ymin)/(ysize-1); + const double x = xmin+i*(xmax-xmin)/(xsize-1); + const double y = ymin+j*(ymax-ymin)/(ysize-1); data[i*ysize+j] = linear_function(x, y); } } @@ -308,7 +310,7 @@ void check_table_1d( const auto x0 = tab.get_x_coord(0); const auto x1 = tab.get_x_coord(xsize/2); const auto x2 = tab.get_x_coord(xsize-1); - const auto x1exp = (xsize/2)*(xmax - xmin)/(xsize-1) + xmin; + const auto x1exp = (xsize/2.0)*(xmax - xmin)/(xsize-1) + xmin; BOOST_CHECK_SMALL((x0-xmin)/xmin, tolerance()); BOOST_CHECK_SMALL((x1 - x1exp)/x1exp, tolerance()); BOOST_CHECK_SMALL((x2 - xmax)/xmax, tolerance()); @@ -368,7 +370,7 @@ void check_table_2d( const auto x0 = tab.get_x_coord(0); const auto x1 = tab.get_x_coord(xsize/2); const auto x2 = tab.get_x_coord(xsize-1); - const auto x1exp = (xsize/2)*(xmax - xmin)/(xsize-1) + xmin; + const auto x1exp = (xsize/2.0)*(xmax - xmin)/(xsize-1) + xmin; BOOST_CHECK_SMALL((x0-xmin)/xmin, tolerance()); BOOST_CHECK_SMALL((x1 - x1exp)/x1exp, tolerance()); BOOST_CHECK_SMALL((x2 - xmax)/xmax, tolerance()); @@ -380,7 +382,7 @@ void check_table_2d( const auto y0 = tab.get_y_coord(0); const auto y1 = tab.get_y_coord(ysize/2); const auto y2 = tab.get_y_coord(ysize-1); - const auto y1exp = (ysize/2)*(ymax - ymin)/(ysize-1) + ymin; + const auto y1exp = (ysize/2.0)*(ymax - ymin)/(ysize-1) + ymin; BOOST_CHECK_SMALL((y0-ymin)/ymin, tolerance()); BOOST_CHECK_SMALL((y1 - y1exp)/y1exp, tolerance()); BOOST_CHECK_SMALL((y2 - ymax)/ymax, tolerance()); @@ -549,7 +551,7 @@ BOOST_AUTO_TEST_CASE( picsar_equispaced_1d_table_constructor_getters) { auto tab_1d = make_1d_table(); const auto const_tab_1d = make_1d_table(); - auto copy_tab_1d = tab_1d; + const auto copy_tab_1d = tab_1d; // NOLINT(performance-unnecessary-copy-initialization) check_table_1d(tab_1d); check_table_1d(const_tab_1d); @@ -627,7 +629,7 @@ BOOST_AUTO_TEST_CASE( picsar_equispaced_2d_table_constructor_getters) { auto tab_2d = make_2d_table(); const auto const_tab_2d = make_2d_table(); - auto copy_tab_2d = tab_2d; + const auto copy_tab_2d = tab_2d; // NOLINT(performance-unnecessary-copy-initialization) check_table_2d(tab_2d); check_table_2d(const_tab_2d); @@ -727,7 +729,7 @@ BOOST_AUTO_TEST_CASE( picsar_generic_2d_table_constructor_getters) { auto gtab_2d = make_generic_2d_table(); const auto const_gtab_2d = make_generic_2d_table(); - auto copy_gtab_2d = gtab_2d; + auto copy_gtab_2d = gtab_2d; // NOLINT(performance-unnecessary-copy-initialization) check_generic_table_2d(gtab_2d); check_generic_table_2d(const_gtab_2d); diff --git a/multi_physics/QED/QED_tests/test_picsar_units.cpp b/multi_physics/QED/QED_tests/test_picsar_units.cpp index a02529e21..6604b28be 100644 --- a/multi_physics/QED/QED_tests/test_picsar_units.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_units.cpp @@ -28,10 +28,12 @@ const float float_tolerance = 1.0e-4; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } //Auxiliary functions for tests @@ -67,8 +69,9 @@ constexpr void test_to_SI(val_pack vals, const auto res_hl2SI = vals.hl*fact_hl; const auto all_res = std::array{ res_SI2SI, res_omega2SI, res_lambda2SI, res_hl2SI}; - for (const auto& res : all_res) + for (const auto& res : all_res){ BOOST_CHECK_SMALL((res-vals.SI)/vals.SI, tolerance()); + } } template diff --git a/multi_physics/QED/QED_tests/test_picsar_vec_functions.cpp b/multi_physics/QED/QED_tests/test_picsar_vec_functions.cpp index be9849567..bf76dbc0d 100644 --- a/multi_physics/QED/QED_tests/test_picsar_vec_functions.cpp +++ b/multi_physics/QED/QED_tests/test_picsar_vec_functions.cpp @@ -21,10 +21,12 @@ const float float_tolerance = 1.0e-4; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } // ------------- Tests -------------- @@ -60,7 +62,7 @@ void test_norm() const auto c0 = static_cast(1.0); const auto c1 = static_cast(2.0); const auto c2 = static_cast(3.0); - const auto expected = static_cast(sqrt(c0*c0 + c1*c1 + c2*c2)); + const auto expected = static_cast(std::sqrt(c0*c0 + c1*c1 + c2*c2)); const auto vec = vec3{c0, c1, c2}; @@ -123,10 +125,12 @@ void test_cross() const auto expected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(expected[i] != 0.0) + if(expected[i] != 0.0){ BOOST_CHECK_SMALL((veca_x_vecb[i]-expected[i])/expected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(veca_x_vecb[i]-expected[i], tolerance()); + } } } @@ -158,10 +162,12 @@ void test_vec_times_scalar() const auto exptected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(exptected[i] != 0.0) + if(exptected[i] != 0.0){ BOOST_CHECK_SMALL((v_times_c[i]-exptected[i])/exptected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(v_times_c[i]-exptected[i], tolerance()); + } } } @@ -189,10 +195,12 @@ void test_scalar_times_vec() const auto exptected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(exptected[i] != 0.0) + if(exptected[i] != 0.0){ BOOST_CHECK_SMALL((c_times_v[i]-exptected[i])/exptected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(c_times_v[i]-exptected[i], tolerance()); + } } } @@ -224,10 +232,12 @@ void test_vec_div_scalar() const auto exptected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(exptected[i] != 0.0) + if(exptected[i] != 0.0){ BOOST_CHECK_SMALL((v_div_c[i]-exptected[i])/exptected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(v_div_c[i]-exptected[i], tolerance()); + } } } @@ -260,10 +270,12 @@ void test_add() const auto expected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(expected[i] != 0.0) + if(expected[i] != 0.0){ BOOST_CHECK_SMALL((veca_p_vecb[i]-expected[i])/expected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(veca_p_vecb[i]-expected[i], tolerance()); + } } } @@ -296,10 +308,12 @@ void test_subtract() const auto expected = std::array{exp0, exp1, exp2}; for(int i = 0; i < 3; i++){ - if(expected[i] != 0.0) + if(expected[i] != 0.0){ BOOST_CHECK_SMALL((veca_m_vecb[i]-expected[i])/expected[i], tolerance()); - else + } + else{ BOOST_CHECK_SMALL(veca_m_vecb[i]-expected[i], tolerance()); + } } } diff --git a/multi_physics/QED/README.md b/multi_physics/QED/README.md index 617c10f47..f851bdcaf 100644 --- a/multi_physics/QED/README.md +++ b/multi_physics/QED/README.md @@ -3,7 +3,7 @@ ### Library The QED library is a header only library. Its only external dependency is Boost (a recent version is needed). Boost is absolutely necessary to generate lookup tables, but it's not needed at runtime if lookup tables have been previously generated. -C++14 standard is followed. The core functions of the library can be included in GPU kernels, provided that the user sets the `PXRMP_GPU` before including any file of the library (e.g. `#define PXRMP_GPU __host__ __device__`). +C++17 standard is followed. The core functions of the library can be included in GPU kernels, provided that the user sets the `PXRMP_GPU` before including any file of the library (e.g. `#define PXRMP_GPU __host__ __device__`). The library implements the following physical processes: Breit-Wheeler pair production, Quantum Synchrotron photon emission and Schwinger pair production. diff --git a/multi_physics/QED/include/picsar_qed/containers/picsar_array.hpp b/multi_physics/QED/include/picsar_qed/containers/picsar_array.hpp index 59ce76210..778c4c2ed 100644 --- a/multi_physics/QED/include/picsar_qed/containers/picsar_array.hpp +++ b/multi_physics/QED/include/picsar_qed/containers/picsar_array.hpp @@ -10,9 +10,8 @@ #include #endif -namespace picsar{ -namespace multi_physics{ -namespace containers{ +namespace picsar::multi_physics::containers +{ #ifdef PXRMP_ENABLE_GPU_FRIENDLY_ARRAY @@ -34,6 +33,7 @@ namespace containers{ * @param[in] i the index of the element * @return a const reference to the i-th element */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE const T& operator [] (int i) const noexcept { @@ -46,6 +46,7 @@ namespace containers{ * @param[in] i the index of the element * @return a reference to the i-th element */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE T& operator [] (int i) noexcept { @@ -57,6 +58,7 @@ namespace containers{ * * @return a const pointer to the underlying raw data array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE const T* data() const noexcept { @@ -68,6 +70,7 @@ namespace containers{ * * @return the size of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr int size() const noexcept { @@ -79,6 +82,7 @@ namespace containers{ * * @return a const pointer to the first element of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr const T* begin() const noexcept { @@ -90,6 +94,7 @@ namespace containers{ * * @return a const pointer to the end of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr const T* end() const noexcept { @@ -101,6 +106,7 @@ namespace containers{ * * @return a pointer to the first element of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr T* begin() noexcept { @@ -112,6 +118,7 @@ namespace containers{ * * @return a pointer to the end of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr T* end() noexcept { @@ -127,8 +134,6 @@ namespace containers{ using picsar_array = std::array; #endif -} -} } #endif //PICSAR_MULTIPHYSICS_ARRAY diff --git a/multi_physics/QED/include/picsar_qed/containers/picsar_span.hpp b/multi_physics/QED/include/picsar_qed/containers/picsar_span.hpp index 120bf0181..2ea5c47a6 100644 --- a/multi_physics/QED/include/picsar_qed/containers/picsar_span.hpp +++ b/multi_physics/QED/include/picsar_qed/containers/picsar_span.hpp @@ -6,10 +6,8 @@ #include -namespace picsar{ -namespace multi_physics{ -namespace containers{ - +namespace picsar::multi_physics::containers +{ /** * This class implements a non-owning array * @@ -24,7 +22,7 @@ namespace containers{ * Empty constructor. */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE - picsar_span(){} + picsar_span() = default; /** * Constructor requiring the size of the array and the pointer to raw data. @@ -43,6 +41,7 @@ namespace containers{ * @param[in] i index of the desired element * @return a reference to the i-th element */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE T& operator [] (int i) noexcept { @@ -55,6 +54,7 @@ namespace containers{ * @param[in] i index of the desired element * @return a const reference to the i-th element */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE const T& operator [] (int i) const noexcept { @@ -66,6 +66,7 @@ namespace containers{ * * @return a const pointer to the underlying raw data array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr const T* data() const noexcept { @@ -77,6 +78,7 @@ namespace containers{ * * @return the size of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr size_t size() const noexcept { @@ -88,6 +90,7 @@ namespace containers{ * * @return a const pointer to the first element of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr const T* begin() const noexcept { @@ -99,6 +102,7 @@ namespace containers{ * * @return a const pointer to the end of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr const T* end() const noexcept { @@ -110,6 +114,7 @@ namespace containers{ * * @return a pointer to the first element of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr T* begin() noexcept { @@ -121,20 +126,19 @@ namespace containers{ * * @return a pointer to the end of the array */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE constexpr T* end() noexcept { return m_ptr_data+m_size; } - typedef T value_type; + using value_type = T; protected: size_t m_size = 0; /* Array size */ T* m_ptr_data = nullptr; /* Raw pointer to the array data */ }; } -} -} #endif //PICSAR_MULTIPHYSICS_SPAN diff --git a/multi_physics/QED/include/picsar_qed/containers/picsar_tables.hpp b/multi_physics/QED/include/picsar_qed/containers/picsar_tables.hpp index eb53b8af2..13c2af598 100644 --- a/multi_physics/QED/include/picsar_qed/containers/picsar_tables.hpp +++ b/multi_physics/QED/include/picsar_qed/containers/picsar_tables.hpp @@ -19,10 +19,10 @@ #include #include #include +#include -namespace picsar{ -namespace multi_physics{ -namespace containers{ +namespace picsar::multi_physics::containers +{ namespace details{ //________________ Auxiliary functions _____________________________________ @@ -109,12 +109,12 @@ namespace details{ */ equispaced_1d_table( RealType x_min, RealType x_max, VectorType values): - m_x_min{x_min}, m_x_max{x_max}, m_values{values} + m_x_min{x_min}, m_x_max{x_max}, m_x_size{x_max - x_min}, + m_how_many_x{static_cast(values.size())}, + m_dx{m_x_size/(m_how_many_x-1)}, + m_values{std::move(values)} { - m_how_many_x = static_cast(values.size()); - m_x_size = x_max - x_min; - m_dx = m_x_size/(m_how_many_x-1); - //VectorType may need a call to a user-defined method for CPU-GPU synchronization + //VectorType may need a call to a user-defined method for CPU-GPU synchronization details::aux_sync_vec(m_values); } @@ -122,7 +122,7 @@ namespace details{ * Empty constructor */ constexpr - equispaced_1d_table(){} + equispaced_1d_table() = default; /** * Constructor from byte array (not usable on GPUs) @@ -138,9 +138,10 @@ namespace details{ sizeof(m_x_min)+sizeof(m_x_max)+ sizeof(m_how_many_x) + sizeof(m_dx); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a 1D table."); + } auto it_raw_data = raw_data.begin(); @@ -153,14 +154,16 @@ namespace details{ m_x_min = serialization::get_out(it_raw_data); m_x_max = serialization::get_out(it_raw_data); m_x_size = m_x_max - m_x_min; - if(m_x_size < 0) + if(m_x_size < 0){ throw std::runtime_error("raw_data contains invalid data."); + } m_how_many_x = serialization::get_out(it_raw_data); m_dx = serialization::get_out(it_raw_data); - if(m_how_many_x <= 0) + if(m_how_many_x <= 0){ throw std::runtime_error("raw_data contains invalid data."); + } m_values = VectorType(m_how_many_x); auto vals = serialization::get_n_out(it_raw_data, m_how_many_x); @@ -176,6 +179,7 @@ namespace details{ * @param[in] rhs a const reference to a 1D table of the same type * @return true if rhs and *this are equal. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const equispaced_1d_table &rhs) const @@ -195,6 +199,7 @@ namespace details{ * @param[in] i the index of the desired coordinate * @return the i-th coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_coord(const int i) const noexcept { @@ -207,6 +212,7 @@ namespace details{ * @param[in] i the index of the desired value * @return the i-th value */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_val(const size_t i) const noexcept { @@ -218,6 +224,7 @@ namespace details{ * * @return the number of points along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int get_how_many_x() const noexcept { @@ -229,6 +236,7 @@ namespace details{ * * @return the minimum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_min() const noexcept { @@ -240,6 +248,7 @@ namespace details{ * * @return the maximum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_max() const noexcept { @@ -251,6 +260,7 @@ namespace details{ * * @return the size along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_size() const noexcept { @@ -262,6 +272,7 @@ namespace details{ * * @return the size of the steps along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_dx() const noexcept { @@ -274,6 +285,7 @@ namespace details{ * * @return all the coordinates */ + [[nodiscard]] std::vector get_all_coordinates() const noexcept { auto all_coords = std::vector(m_how_many_x); @@ -288,6 +300,7 @@ namespace details{ * * @return a const reference to the underlying Vector holding value data */ + [[nodiscard]] const VectorType& get_values_reference() const noexcept { return m_values; @@ -301,6 +314,7 @@ namespace details{ * @param[in] where_x where to perform the interpolation * @return the interpolated value */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp(const RealType where_x) const noexcept { @@ -308,8 +322,9 @@ namespace details{ const auto idx_left = static_cast( m_floor((m_how_many_x-1)*(where_x-m_x_min)/m_x_size)); - if (idx_left == (m_how_many_x-1)) + if (idx_left == (m_how_many_x-1)){ return m_values[m_how_many_x-1]; + } const auto idx_right = idx_left + 1; const auto xleft = get_x_coord(idx_left); @@ -343,9 +358,10 @@ namespace details{ PXRMP_FORCE_INLINE void set_all_vals(const std::vector& new_values) { - if (new_values.size() != m_values.size()) + if (new_values.size() != m_values.size()){ throw std::runtime_error("Mismatch new_values length \ and m_values length"); + } std::copy(new_values.begin(), new_values.end(), m_values.begin()); //VectorType may need a call to a user-defined method for CPU-GPU synchronization details::aux_sync_vec(m_values); @@ -358,6 +374,7 @@ namespace details{ * * @return a byte vector containing table data */ + [[nodiscard]] std::vector serialize() const { auto raw_data = std::vector{}; @@ -368,8 +385,9 @@ namespace details{ utils::serialization::put_in(m_x_max, raw_data); utils::serialization::put_in(m_how_many_x, raw_data); utils::serialization::put_in(m_dx, raw_data); - for (auto val : m_values) + for (auto val : m_values){ utils::serialization::put_in(val, raw_data); + } return raw_data; } @@ -417,13 +435,13 @@ namespace details{ VectorType values): m_x_min{x_min}, m_x_max{x_max}, m_y_min{y_min}, m_y_max{y_max}, + m_x_size{x_max - x_min}, + m_y_size{y_max - y_min}, m_how_many_x{how_many_x}, m_how_many_y{how_many_y}, - m_values{values} + m_dx{m_x_size/(m_how_many_x-1)}, + m_dy{m_y_size/(m_how_many_y-1)}, + m_values{std::move(values)} { - m_x_size = x_max - x_min; - m_y_size = y_max - y_min; - m_dx = m_x_size/(m_how_many_x-1); - m_dy = m_y_size/(m_how_many_y-1); //VectorType may need a call to a user-defined method for CPU-GPU synchronization details::aux_sync_vec(m_values); } @@ -432,7 +450,7 @@ namespace details{ * Empty constructor */ constexpr - equispaced_2d_table(){} + equispaced_2d_table() = default; /** * Constructor from byte array (not usable on GPUs) @@ -451,9 +469,10 @@ namespace details{ sizeof(m_how_many_y)+ sizeof(m_dx) + sizeof(m_dy); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a 2D table."); + } auto it_raw_data = raw_data.begin(); @@ -469,10 +488,12 @@ namespace details{ m_y_max = serialization::get_out(it_raw_data); m_x_size = m_x_max - m_x_min; m_y_size = m_y_max - m_y_min; - if(m_x_size < 0) + if(m_x_size < 0){ throw std::runtime_error("raw_data contains invalid data."); - if(m_y_size < 0) + } + if(m_y_size < 0){ throw std::runtime_error("raw_data contains invalid data."); + } m_how_many_x = serialization::get_out(it_raw_data); @@ -480,10 +501,12 @@ namespace details{ serialization::get_out(it_raw_data); m_dx = serialization::get_out(it_raw_data); m_dy = serialization::get_out(it_raw_data); - if(m_how_many_x <= 0) + if(m_how_many_x <= 0){ throw std::runtime_error("raw_data contains invalid data."); - if(m_how_many_y <= 0) + } + if(m_how_many_y <= 0){ throw std::runtime_error("raw_data contains invalid data."); + } m_values = VectorType(m_how_many_x*m_how_many_y); auto vals = serialization::get_n_out( it_raw_data, @@ -499,6 +522,7 @@ namespace details{ * @param[in] rhs a const reference to a 2D table of the same type * @return true if rhs and *this are equal. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const equispaced_2d_table &rhs) const @@ -523,6 +547,7 @@ namespace details{ * @param[in] i the index of the desired coordinate * @return the i-th coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_coord(int i) const noexcept { @@ -535,6 +560,7 @@ namespace details{ * @param[in] j the index of the desired coordinate * @return the j-th coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_coord(int j) const noexcept { @@ -548,6 +574,7 @@ namespace details{ * @param[in] j the index of the desired value along y * @return the value at (i,j) */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_val(int i, int j) const noexcept { @@ -559,6 +586,7 @@ namespace details{ * * @return the number of points along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int get_how_many_x() const noexcept { @@ -570,6 +598,7 @@ namespace details{ * * @return the minimum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_min() const noexcept { @@ -581,6 +610,7 @@ namespace details{ * * @return the maximum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_max() const noexcept { @@ -592,6 +622,7 @@ namespace details{ * * @return the size along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_size() const noexcept { @@ -603,6 +634,7 @@ namespace details{ * * @return the size of the steps along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_dx() const noexcept { @@ -614,6 +646,7 @@ namespace details{ * * @return the number of points along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int get_how_many_y() const noexcept { @@ -625,6 +658,7 @@ namespace details{ * * @return the minimum y coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_min() const noexcept { @@ -636,6 +670,7 @@ namespace details{ * * @return the maximum y coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_max() const noexcept { @@ -647,6 +682,7 @@ namespace details{ * * @return the size along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_size() const noexcept { @@ -658,6 +694,7 @@ namespace details{ * * @return the size of the steps along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_dy() const noexcept { @@ -670,16 +707,16 @@ namespace details{ * * @return all the coordinates */ + [[nodiscard]] std::vector> get_all_coordinates() const noexcept { auto all_coords = std::vector>( m_how_many_x*m_how_many_y, {0,0}); - int count = 0; for (int i = 0; i < m_how_many_x; ++i){ for (int j = 0; j < m_how_many_y; ++j){ - all_coords[count][0] = get_x_coord(i); - all_coords[count][1] = get_y_coord(j); - count++; + const auto idx = i*m_how_many_y + j; + all_coords[idx][0] = get_x_coord(i); + all_coords[idx][1] = get_y_coord(j); } } return all_coords; @@ -690,6 +727,7 @@ namespace details{ * * @return a const reference to the underlying Vector holding value data */ + [[nodiscard]] const VectorType& get_values_reference() const noexcept { return m_values; @@ -702,6 +740,7 @@ namespace details{ * @param[in] where_y the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp(const RealType where_x, const RealType where_y) const noexcept { @@ -709,13 +748,15 @@ namespace details{ auto idx_x_left = static_cast( m_floor((m_how_many_x-1)*(where_x-m_x_min)/m_x_size)); - if (idx_x_left == (m_how_many_x-1)) + if (idx_x_left == (m_how_many_x-1)){ idx_x_left = m_how_many_x-2; + } const auto idx_x_right = idx_x_left + 1; auto idx_y_left = static_cast( m_floor((m_how_many_y-1)*(where_y-m_y_min)/m_y_size)); - if (idx_y_left == (m_how_many_y-1)) + if (idx_y_left == (m_how_many_y-1)){ idx_y_left = m_how_many_y-2; + } const auto idx_y_right = idx_y_left + 1; const auto xleft = get_x_coord(idx_x_left); @@ -742,6 +783,7 @@ namespace details{ * @param[in] j the index of the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp_first_coord(RealType where_x, int j) const noexcept { @@ -749,8 +791,9 @@ namespace details{ auto idx_left = static_cast( m_floor((m_how_many_x-1)*(where_x-m_x_min)/m_x_size)); - if (idx_left == (m_how_many_x-1)) + if (idx_left == (m_how_many_x-1)){ idx_left = m_how_many_x-2; + } const auto idx_right = idx_left + 1; const auto xleft = idx_left*m_dx + m_x_min; @@ -770,6 +813,7 @@ namespace details{ * @param[in] where_y the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp_second_coord(int i, RealType where_y) const noexcept { @@ -777,8 +821,9 @@ namespace details{ auto idx_left = static_cast( m_floor((m_how_many_y-1)*(where_y-m_y_min)/m_y_size)); - if (idx_left == (m_how_many_y-1)) + if (idx_left == (m_how_many_y-1)){ idx_left = m_how_many_y-2; + } const auto idx_right = idx_left + 1; const auto left_val = m_values[idx(i, idx_left)]; @@ -828,9 +873,10 @@ namespace details{ PXRMP_FORCE_INLINE void set_all_vals(const std::vector& new_values) { - if (new_values.size() != m_values.size()) + if (new_values.size() != m_values.size()){ throw std::runtime_error("Mismatch new_values length \ and m_values length"); + } std::copy(new_values.begin(), new_values.end(), m_values.begin()); //VectorType may need a call to a user-defined method for CPU-GPU synchronization details::aux_sync_vec(m_values); @@ -843,6 +889,7 @@ namespace details{ * * @return a byte vector containing table data */ + [[nodiscard]] std::vector serialize() const { auto raw_data = std::vector{}; @@ -857,8 +904,9 @@ namespace details{ utils::serialization::put_in(m_how_many_y, raw_data); utils::serialization::put_in(m_dx, raw_data); utils::serialization::put_in(m_dy, raw_data); - for (auto val : m_values) + for (auto val : m_values){ utils::serialization::put_in(val, raw_data); + } return raw_data; } @@ -886,6 +934,7 @@ namespace details{ * @param[in] j index along y * @return index along internal 1D vector */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int idx(int i, int j) const noexcept { @@ -938,7 +987,7 @@ namespace details{ IXMapFunctor ix_map_functor, IYMapFunctor iy_map_functor): m_how_many_x{how_many_x}, m_how_many_y{how_many_y}, - m_values{values}, + m_values{std::move(values)}, m_x_map_functor{x_map_functor}, m_y_map_functor{y_map_functor}, m_ix_map_functor{ix_map_functor}, m_iy_map_functor{iy_map_functor} {} @@ -947,7 +996,7 @@ namespace details{ * Empty constructor */ constexpr - generic_2d_table(){} + generic_2d_table() = default; /** * Constructor from byte array (not usable on GPUs) @@ -963,9 +1012,10 @@ namespace details{ sizeof(m_how_many_x)+ sizeof(m_how_many_y); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a 2D table."); + } auto it_raw_data = raw_data.begin(); @@ -979,10 +1029,12 @@ namespace details{ serialization::get_out(it_raw_data); m_how_many_y = serialization::get_out(it_raw_data); - if(m_how_many_x <= 0) + if(m_how_many_x <= 0){ throw std::runtime_error("raw_data contains invalid data."); - if(m_how_many_y <= 0) + } + if(m_how_many_y <= 0){ throw std::runtime_error("raw_data contains invalid data."); + } //static_cast here has the sole purpose of avoiding to trigger //a CodeQL check in CI (Multiplication result converted to larger type) @@ -1011,6 +1063,7 @@ namespace details{ * * @return true if rhs and *this are equal. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const generic_2d_table< @@ -1035,6 +1088,7 @@ namespace details{ * * @return the i-th coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_coord(int i) const noexcept { @@ -1048,6 +1102,7 @@ namespace details{ * * @return the j-th coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_coord(int j) const noexcept { @@ -1062,6 +1117,7 @@ namespace details{ * * @return the value at (i,j) */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_val(int i, int j) const noexcept { @@ -1073,6 +1129,7 @@ namespace details{ * * @return the number of points along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int get_how_many_x() const noexcept { @@ -1084,6 +1141,7 @@ namespace details{ * * @return the minimum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_min() const noexcept { @@ -1095,6 +1153,7 @@ namespace details{ * * @return the maximum x coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_max() const noexcept { @@ -1106,6 +1165,7 @@ namespace details{ * * @return the size along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_x_size() const noexcept { @@ -1117,6 +1177,7 @@ namespace details{ * * @return the size of the steps along x */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_dx(int i) const noexcept { @@ -1128,6 +1189,7 @@ namespace details{ * * @return the number of points along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int get_how_many_y() const noexcept { @@ -1139,6 +1201,7 @@ namespace details{ * * @return the minimum y coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_min() const noexcept { @@ -1150,6 +1213,7 @@ namespace details{ * * @return the maximum y coordinate */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_max() const noexcept { @@ -1161,6 +1225,7 @@ namespace details{ * * @return the size along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_y_size() const noexcept { @@ -1172,6 +1237,7 @@ namespace details{ * * @return the size of the steps along y */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType get_dy(int j) const noexcept { @@ -1184,16 +1250,16 @@ namespace details{ * * @return all the coordinates */ + [[nodiscard]] std::vector> get_all_coordinates() const noexcept { auto all_coords = std::vector>( static_cast(m_how_many_x*m_how_many_y), {0,0}); - int count = 0; for (int i = 0; i < m_how_many_x; ++i){ for (int j = 0; j < m_how_many_y; ++j){ - all_coords[count][0] = get_x_coord(i); - all_coords[count][1] = get_y_coord(j); - count++; + const auto idx = i*m_how_many_x + j; + all_coords[idx][0] = get_x_coord(i); + all_coords[idx][1] = get_y_coord(j); } } return all_coords; @@ -1204,6 +1270,7 @@ namespace details{ * * @return a const reference to the underlying Vector holding value data */ + [[nodiscard]] const VectorType& get_values_reference() const noexcept { return m_values; @@ -1216,18 +1283,21 @@ namespace details{ * @param[in] where_y the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp(const RealType where_x, const RealType where_y) const noexcept { using namespace picsar::multi_physics::math; auto idx_x_left = m_ix_map_functor(where_x); - if (idx_x_left == (m_how_many_x-1)) + if (idx_x_left == (m_how_many_x-1)){ idx_x_left = m_how_many_x-2; + } const auto idx_x_right = idx_x_left + 1; auto idx_y_left = m_iy_map_functor(where_y); - if (idx_y_left == (m_how_many_y-1)) + if (idx_y_left == (m_how_many_y-1)){ idx_y_left = m_how_many_y-2; + } const auto idx_y_right = idx_y_left + 1; const auto xleft = get_x_coord(idx_x_left); @@ -1254,14 +1324,16 @@ namespace details{ * @param[in] j the index of the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp_first_coord(RealType where_x, int j) const noexcept { using namespace picsar::multi_physics::math; auto idx_left = m_ix_map_functor(where_x); - if (idx_left == (m_how_many_x-1)) + if (idx_left == (m_how_many_x-1)){ idx_left = m_how_many_x-2; + } const auto idx_right = idx_left + 1; const auto xleft = get_x_coord(idx_left); @@ -1281,14 +1353,16 @@ namespace details{ * @param[in] where_y the position along y * @return the result of the interpolation */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp_second_coord(int i, RealType where_y) const noexcept { using namespace picsar::multi_physics::math; auto idx_left = m_iy_map_functor(where_y); - if (idx_left == (m_how_many_y-1)) + if (idx_left == (m_how_many_y-1)){ idx_left = m_how_many_y-2; + } const auto idx_right = idx_left + 1; const auto left_val = m_values[idx(i, idx_left)]; @@ -1338,9 +1412,10 @@ namespace details{ PXRMP_FORCE_INLINE void set_all_vals(const std::vector& new_values) { - if (new_values.size() != m_values.size()) + if (new_values.size() != m_values.size()){ throw std::runtime_error("Mismatch new_values length \ and m_values length"); + } std::copy(new_values.begin(), new_values.end(), m_values.begin()); //VectorType may need a call to a user-defined method for CPU-GPU synchronization details::aux_sync_vec(m_values); @@ -1353,6 +1428,7 @@ namespace details{ * * @return a byte vector containing table data */ + [[nodiscard]] std::vector serialize() const { auto raw_data = std::vector{}; @@ -1361,16 +1437,21 @@ namespace details{ static_cast(sizeof(RealType)), raw_data); utils::serialization::put_in(m_how_many_x, raw_data); utils::serialization::put_in(m_how_many_y, raw_data); - for (const auto val : m_values) + for (const auto val : m_values){ utils::serialization::put_in(val, raw_data); - for (const auto dd : m_x_map_functor.serialize()) + } + for (const auto dd : m_x_map_functor.serialize()){ utils::serialization::put_in(dd, raw_data); - for (const auto dd : m_y_map_functor.serialize()) + } + for (const auto dd : m_y_map_functor.serialize()){ utils::serialization::put_in(dd, raw_data); - for (const auto dd : m_ix_map_functor.serialize()) + } + for (const auto dd : m_ix_map_functor.serialize()){ utils::serialization::put_in(dd, raw_data); - for (const auto dd : m_iy_map_functor.serialize()) + } + for (const auto dd : m_iy_map_functor.serialize()){ utils::serialization::put_in(dd, raw_data); + } return raw_data; } @@ -1394,6 +1475,7 @@ namespace details{ * @param[in] j index along y * @return index along internal 1D vector */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE int idx(int i, int j) const noexcept { @@ -1405,8 +1487,6 @@ namespace details{ } -} -} diff --git a/multi_physics/QED/include/picsar_qed/math/cmath_overloads.hpp b/multi_physics/QED/include/picsar_qed/math/cmath_overloads.hpp index 5f7e35063..b58006018 100644 --- a/multi_physics/QED/include/picsar_qed/math/cmath_overloads.hpp +++ b/multi_physics/QED/include/picsar_qed/math/cmath_overloads.hpp @@ -10,9 +10,8 @@ #include #endif -namespace picsar{ -namespace multi_physics{ -namespace math{ +namespace picsar::multi_physics::math +{ #ifdef PXRMP_PREVENT_USE_STD_FOR_MATH @@ -355,8 +354,6 @@ namespace math{ #endif } -} -} #endif //PICSAR_MULTIPHYSICS_CMATH_OVERLOADS diff --git a/multi_physics/QED/include/picsar_qed/math/math_constants.h b/multi_physics/QED/include/picsar_qed/math/math_constants.h index 7f3d8b660..de0d5718a 100644 --- a/multi_physics/QED/include/picsar_qed/math/math_constants.h +++ b/multi_physics/QED/include/picsar_qed/math/math_constants.h @@ -4,9 +4,8 @@ //Should be included by all the src files of the library #include "picsar_qed/qed_commons.h" -namespace picsar{ -namespace multi_physics{ -namespace math{ +namespace picsar::multi_physics::math +{ // Mathemtatical constants template @@ -42,7 +41,5 @@ namespace math{ constexpr RealType five_thirds = RealType(5.0/3.0); //________________________ } -} -} #endif //PICSAR_MULTIPHYSICS_MATH_CONSTANTS diff --git a/multi_physics/QED/include/picsar_qed/math/quadrature.hpp b/multi_physics/QED/include/picsar_qed/math/quadrature.hpp index 5671b6ba7..523cdc5b4 100644 --- a/multi_physics/QED/include/picsar_qed/math/quadrature.hpp +++ b/multi_physics/QED/include/picsar_qed/math/quadrature.hpp @@ -38,9 +38,8 @@ namespace boost //______________________________________________________ -namespace picsar{ -namespace multi_physics{ -namespace math{ +namespace picsar::multi_physics::math +{ /** * This module is a wrapper around the trapezoidal, * gauss_kronrod, tanh_sinh & exp_sinh quadrature methods provided by the Boost library. @@ -75,48 +74,48 @@ namespace math{ inline constexpr RealType generic_quad_a_b( const std::function& f, RealType a, RealType b) { - PXRMP_CONSTEXPR_IF ( + if constexpr ( QuadAlgo == quadrature_algorithm::trapezoidal){ return boost::math::quadrature::trapezoidal(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::tanh_sinh){ boost::math::quadrature::tanh_sinh integrator; return integrator.integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::exp_sinh){ boost::math::quadrature::exp_sinh integrator; return integrator.integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::gauss_kronrod15){ return boost::math::quadrature::gauss_kronrod ::integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::gauss_kronrod31){ return boost::math::quadrature::gauss_kronrod ::integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::gauss_kronrod41){ return boost::math::quadrature::gauss_kronrod ::integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::gauss_kronrod51){ return boost::math::quadrature::gauss_kronrod ::integrate(f, a, b); } - else PXRMP_CONSTEXPR_IF ( + else if constexpr ( QuadAlgo == quadrature_algorithm::gauss_kronrod61){ return boost::math::quadrature::gauss_kronrod ::integrate(f, a, b); } else { - return boost::math::quadrature::trapezoidal(f, a, b); + throw std::invalid_argument("Value of QuadAlgo is unknown."); } } @@ -178,7 +177,5 @@ namespace math{ f, a, std::numeric_limits::infinity()); } } -} -} #endif //PICSAR_MULTIPHYSICS_QUADRATURE diff --git a/multi_physics/QED/include/picsar_qed/math/special_functions.hpp b/multi_physics/QED/include/picsar_qed/math/special_functions.hpp index 075dfa283..5ddd6a5dd 100644 --- a/multi_physics/QED/include/picsar_qed/math/special_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/math/special_functions.hpp @@ -13,10 +13,8 @@ #include #endif -namespace picsar{ -namespace multi_physics{ -namespace math{ - +namespace picsar::multi_physics::math +{ /** * This function is a wrapper around the Bessel function * of the second kind defined either in the STL (if C++17 is available) @@ -38,7 +36,5 @@ namespace math{ } } -} -} #endif //PICSAR_MULTIPHYSICS_SPECIAL_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/math/vec_functions.hpp b/multi_physics/QED/include/picsar_qed/math/vec_functions.hpp index 97a23a127..c1e67424d 100644 --- a/multi_physics/QED/include/picsar_qed/math/vec_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/math/vec_functions.hpp @@ -9,9 +9,8 @@ //Uses sqrt #include "picsar_qed/math/cmath_overloads.hpp" -namespace picsar{ -namespace multi_physics{ -namespace math{ +namespace picsar::multi_physics::math +{ //This .hpp file contains functions to perform operations on 3-vectors // (norm, scalar multiplication, vector and cross product...) @@ -176,7 +175,5 @@ namespace math{ } } -} -} #endif // PICSAR_MULTIPHYSICS_VEC_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_core.hpp b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_core.hpp index 709d10e92..994b679a0 100644 --- a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_core.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_core.hpp @@ -34,10 +34,8 @@ #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace breit_wheeler{ +namespace picsar::multi_physics::phys::breit_wheeler +{ /** * Computes the optical depth of a new photon (simply a number @@ -229,8 +227,5 @@ namespace breit_wheeler{ } } -} -} -} #endif //PICSAR_MULTIPHYSICS_SCHWINGER_PAIR_ENGINE_CORE diff --git a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables.hpp b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables.hpp index 91bae5000..d3dd99baf 100644 --- a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables.hpp @@ -36,10 +36,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace breit_wheeler{ +namespace picsar::multi_physics::phys::breit_wheeler +{ //________________ Default parameters ______________________________________ @@ -120,7 +118,7 @@ namespace breit_wheeler{ PXRMP_FORCE_INLINE RealType dndt_approx_left(RealType chi_phot) { - constexpr RealType coeff = static_cast(8./3.); + constexpr auto coeff = static_cast(8./3.); return erber_dndt_asynt_a*math::m_exp(-coeff/chi_phot); } @@ -184,14 +182,14 @@ namespace breit_wheeler{ * * @tparam RealType the floating point type to be used */ - typedef dndt_lookup_table< - RealType, containers::picsar_span> view_type; + using view_type = + dndt_lookup_table> ; /** * Empty constructor **/ constexpr - dndt_lookup_table(){} + dndt_lookup_table() = default; /** * Constructor (not designed for GPU) @@ -223,10 +221,9 @@ namespace breit_wheeler{ m_table{containers::equispaced_1d_table{ math::m_log(params.chi_phot_min), math::m_log(params.chi_phot_max), - vals}} - { - m_init_flag = true; - } + vals}}, + m_init_flag{true} + {} /* * Generates the content of the lookup table (not usable on GPUs). @@ -239,7 +236,7 @@ namespace breit_wheeler{ * @param[in] show_progress if true a progress bar is shown */ template - void generate(const bool show_progress = true); + void generate(bool show_progress = true); /* * Initializes the lookup table from a byte array. @@ -255,9 +252,10 @@ namespace breit_wheeler{ sizeof(char)+ //single or double precision sizeof(m_params); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small to be a Breit Wheeler \ T-function lookup-table."); + } auto it_raw_data = raw_data.begin(); @@ -283,6 +281,7 @@ namespace breit_wheeler{ * * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const dndt_lookup_table< @@ -305,11 +304,13 @@ namespace breit_wheeler{ * * @return a table view */ + [[nodiscard]] view_type get_view() const { - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Can't generate a view of an \ uninitialized table"); + } const auto span = containers::picsar_span{ static_cast(m_params.chi_phot_how_many), m_table.get_values_reference().data() @@ -330,18 +331,19 @@ namespace breit_wheeler{ * * @return the value of the T function */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp( RealType chi_phot, bool* const is_out = nullptr) const noexcept { if (chi_phot < m_params.chi_phot_min){ - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } return dndt_approx_left(chi_phot); } if(chi_phot > m_params.chi_phot_max){ - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } return dndt_approx_right(chi_phot); } return math::m_exp(m_table.interp(math::m_log(chi_phot))); @@ -353,6 +355,7 @@ namespace breit_wheeler{ * * @return a vector containing all the table coordinates */ + [[nodiscard]] std::vector get_all_coordinates() const noexcept { auto all_coords = m_table.get_all_coordinates(); @@ -375,8 +378,9 @@ namespace breit_wheeler{ const auto vals_length = vals.size(); auto log_vals = std::vector(vals_length); - if(static_cast(vals_length) != m_table.get_how_many_x()) + if(static_cast(vals_length) != m_table.get_how_many_x()){ return false; + } std::transform(vals.begin(), vals.end(), log_vals.begin(), [](auto x){return math::m_log(x);}); @@ -392,6 +396,7 @@ namespace breit_wheeler{ * * @return true if the table has been initialized, false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool is_init() const @@ -404,12 +409,14 @@ namespace breit_wheeler{ * * @return a byte vector */ + [[nodiscard]] std::vector serialize() const { using namespace utils; - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Cannot serialize an uninitialized table"); + } std::vector res; @@ -424,9 +431,9 @@ namespace breit_wheeler{ protected: dndt_lookup_table_params m_params; /* Table parameters*/ - bool m_init_flag = false; /* Initialization flag*/ containers::equispaced_1d_table< RealType, VectorType> m_table; /* Table data */ + bool m_init_flag = false; /* Initialization flag*/ private: /* @@ -522,14 +529,14 @@ namespace breit_wheeler{ * * @tparam RealType the floating point type to be used */ - typedef pair_prod_lookup_table< - RealType, containers::picsar_span> view_type; + using view_type = + pair_prod_lookup_table>; /** * Empty constructor */ constexpr - pair_prod_lookup_table(){} + pair_prod_lookup_table() = default; /** @@ -568,10 +575,9 @@ namespace breit_wheeler{ math::zero, math::half, params.chi_phot_how_many, params.frac_how_many, - vals}} - { - m_init_flag = true; - } + vals}}, + m_init_flag{true} + {} /* * Generates the content of the lookup table (not usable on GPUs). @@ -600,9 +606,10 @@ namespace breit_wheeler{ sizeof(char)+//single or double precision sizeof(m_params); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small to be a \ Breit Wheeler pair production lookup-table."); + } auto it_raw_data = raw_data.begin(); @@ -628,6 +635,7 @@ namespace breit_wheeler{ * * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const pair_prod_lookup_table< @@ -650,11 +658,13 @@ namespace breit_wheeler{ * * @return a table view */ + [[nodiscard]] view_type get_view() const { - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Can't generate a view of an \ uninitialized table"); + } const auto span = containers::picsar_span{ static_cast(m_params.chi_phot_how_many * m_params.frac_how_many), @@ -685,6 +695,7 @@ namespace breit_wheeler{ * * @return chi of one of the generated particles */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp( @@ -697,11 +708,11 @@ namespace breit_wheeler{ auto e_chi_phot = chi_phot; if(chi_phot m_params.chi_phot_max){ e_chi_phot = m_params.chi_phot_max; - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } } const auto log_e_chi_phot = m_log(e_chi_phot); @@ -743,6 +754,7 @@ namespace breit_wheeler{ * * @return a vector containing all the table coordinates */ + [[nodiscard]] std::vector> get_all_coordinates() const noexcept { auto all_coords = m_table.get_all_coordinates(); @@ -764,8 +776,9 @@ namespace breit_wheeler{ bool set_all_vals(const std::vector& vals) { if(static_cast(vals.size()) != m_table.get_how_many_x()* - m_table.get_how_many_y()) + m_table.get_how_many_y()){ return false; + } m_table.set_all_vals(vals); m_init_flag = true; @@ -778,6 +791,7 @@ namespace breit_wheeler{ * * @return true if the table has been initialized, false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool is_init() const @@ -790,12 +804,14 @@ namespace breit_wheeler{ * * @return a byte vector */ + [[nodiscard]] std::vector serialize() const { using namespace utils; - if(!m_init_flag) + if(!m_init_flag){ throw "Cannot serialize an uninitialized table"; + } std::vector res; @@ -810,9 +826,9 @@ namespace breit_wheeler{ protected: pair_prod_lookup_table_params m_params; /* Table parameters*/ - bool m_init_flag = false; /* Initialization flag*/ containers::equispaced_2d_table< RealType, VectorType> m_table; /* Table data*/ + bool m_init_flag = false; /* Initialization flag*/ private: /* @@ -830,8 +846,5 @@ namespace breit_wheeler{ //__________________________________________________________________________ } -} -} -} #endif // PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE_TABLES diff --git a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables_generator.hpp b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables_generator.hpp index 54a94f7bf..ae929fb93 100644 --- a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables_generator.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tables_generator.hpp @@ -35,10 +35,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace breit_wheeler{ +namespace picsar::multi_physics::phys::breit_wheeler +{ //________________ dN/dt table _____________________________________________ @@ -90,7 +88,7 @@ namespace breit_wheeler{ #pragma omp parallel for #endif for (int i = 0; i < static_cast(all_coords.size()); ++i){ - PXRMP_CONSTEXPR_IF (use_internal_double){ + if constexpr (use_internal_double){ all_vals[i] = aux_generate_double(all_coords[i]); } else { @@ -108,8 +106,9 @@ namespace breit_wheeler{ } for (auto& val : all_vals){ - if(std::isnan(val)) + if(std::isnan(val)){ throw std::runtime_error("Error: nan detected in generated table!"); + } } set_all_vals(all_vals); @@ -200,7 +199,7 @@ namespace breit_wheeler{ ); std::vector vals = std::vector(frac_size); - PXRMP_CONSTEXPR_IF (use_internal_double){ + if constexpr (use_internal_double){ vals = aux_generate_double( chi_phot, chi_parts); } else { @@ -222,8 +221,9 @@ namespace breit_wheeler{ } for (auto& val : all_vals){ - if(std::isnan(val)) + if(std::isnan(val)){ throw std::runtime_error("Error: nan detected in generated table!"); + } } set_all_vals(all_vals); @@ -242,8 +242,5 @@ namespace breit_wheeler{ //__________________________________________________________________________ } -} -} -} #endif //PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE_TABLES_GENERATOR diff --git a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tabulated_functions.hpp b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tabulated_functions.hpp index 19dab4093..25ab1bee4 100644 --- a/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tabulated_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/breit_wheeler/breit_wheeler_engine_tabulated_functions.hpp @@ -29,11 +29,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace breit_wheeler{ - +namespace picsar::multi_physics::phys::breit_wheeler +{ /** * It computes the X parameter (see validation script). * This function is not designed to be run on GPUs. @@ -71,11 +68,13 @@ namespace breit_wheeler{ const RealType chi_phot, const RealType chi_ele) { using namespace math; - if( chi_ele >= chi_phot ) + if( chi_ele >= chi_phot ){ return zero; + } - if (chi_phot == zero || chi_ele == zero) + if (chi_phot == zero || chi_ele == zero){ return zero; + } const auto xx = compute_x(chi_phot, chi_ele); const auto sqrt_xx = m_sqrt(xx); @@ -87,15 +86,16 @@ namespace breit_wheeler{ const auto s_3_2 = s*sqrt_s; const auto arg = two_thirds*s_3_2; - if (std::isinf(arg)) + if (std::isinf(arg)){ return zero; + } return sqrt_s*math::k_v(one_third, arg); }, xx); auto prod = (two-chi_phot*xx_3_2) *k_v(two_thirds, two_thirds*xx_3_2); - if(std::isnan(prod)) prod = zero; + if(std::isnan(prod)) { prod = zero; } return (inner_integral-prod); } @@ -114,7 +114,7 @@ namespace breit_wheeler{ inline RealType compute_T_function(const RealType chi_phot) { using namespace math; - if(chi_phot <= math::zero) return math::zero; + if(chi_phot <= math::zero) { return math::zero; } constexpr auto coeff = static_cast(1./math::pi<>); return coeff*math::quad_a_b_s( [=](RealType cc){ @@ -144,11 +144,11 @@ namespace breit_wheeler{ { using namespace math; - if(chi_photon <= zero) return zero; - if(chi_ele_end <= zero) return zero; + if(chi_photon <= zero) { return zero; } + if(chi_ele_end <= zero) { return zero; } - if(chi_ele_end > chi_photon) chi_ele_end = chi_photon; - if(chi_ele_start >= chi_ele_end) return zero; + if(chi_ele_end > chi_photon) { chi_ele_end = chi_photon; } + if(chi_ele_start >= chi_ele_end) { return zero; } constexpr auto coeff = static_cast(1./pi<>); @@ -213,7 +213,7 @@ namespace breit_wheeler{ auto res = VectorType(chis.size()); if(chi_photon <= zero){ - for (auto& el: res ) el = zero; + for (auto& el: res ){ el = zero; } return res; } @@ -221,10 +221,12 @@ namespace breit_wheeler{ if (den <= zero){ std::transform(chis.begin(), chis.end(), res.begin(), [=](auto chi_part){ - if(chi_part < half*chi_photon - std::numeric_limits::epsilon()) + if(chi_part < half*chi_photon - std::numeric_limits::epsilon()) { return zero; - if(chi_part > half*chi_photon + std::numeric_limits::epsilon()) + } + if(chi_part > half*chi_photon + std::numeric_limits::epsilon()) { return one; + } return half; }); return res; @@ -234,7 +236,7 @@ namespace breit_wheeler{ res.begin(), [=](auto chi_part){ const auto val = compute_cumulative_prob_numerator(chi_photon, chi_part)/den; - if(val <= one) return val; + if(val <= one) { return val; } return one;}); return res; } @@ -256,15 +258,16 @@ namespace breit_wheeler{ inline VectorType compute_cumulative_prob_opt( const RealType chi_photon, const VectorType& chis) { - if(!std::is_sorted(chis.begin(), chis.end())) + if(!std::is_sorted(chis.begin(), chis.end())) { throw std::runtime_error("Chi vector is not sorted!"); + } using namespace math; const auto den = compute_T_function(chi_photon); auto res = VectorType(chis.size()); if(chi_photon <= zero){ - for (auto& el: res ) el = zero; + for (auto& el: res ) { el = zero; } return res; } @@ -272,10 +275,12 @@ namespace breit_wheeler{ if (den <= zero){ std::transform(chis.begin(), chis.end(), res.begin(), [=](auto chi_part){ - if(chi_part < half*chi_photon - std::numeric_limits::epsilon()) + if(chi_part < half*chi_photon - std::numeric_limits::epsilon()) { return zero; - if(chi_part > half*chi_photon + std::numeric_limits::epsilon()) + } + if(chi_part > half*chi_photon + std::numeric_limits::epsilon()) { return one; + } return half; }); return res; @@ -292,7 +297,7 @@ namespace breit_wheeler{ c = (t - sum) - y; sum = t; res[i] = sum; - if(res[i] > one) res[i] = one; + if(res[i] > one) { res[i] = one; } old_chi = chis[i]; } @@ -301,8 +306,5 @@ namespace breit_wheeler{ } } -} -} -} #endif //PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE_TABULATED_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/physics/chi_functions.hpp b/multi_physics/QED/include/picsar_qed/physics/chi_functions.hpp index cfcdcb02c..b30a4dc72 100644 --- a/multi_physics/QED/include/picsar_qed/physics/chi_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/chi_functions.hpp @@ -15,9 +15,8 @@ //Uses gamma functions #include "picsar_qed/physics/gamma_functions.hpp" -namespace picsar{ -namespace multi_physics{ -namespace phys{ +namespace picsar::multi_physics::phys +{ /** * This function returns the chi parameter for a photon @@ -55,8 +54,9 @@ namespace phys{ compute_gamma_photon(p); const auto norm_p = norm(p); - if(norm_p == zero) + if(norm_p == zero){ return zero; + } const auto p_unit = p / norm_p; const auto em_eperp = em_e - dot(p_unit,em_e)*p_unit; @@ -136,8 +136,9 @@ namespace phys{ unit_system::heaviside_lorentz, RealType>::fact(reference_quantity); const auto norm_p = norm(p); - if(norm_p == zero) + if(norm_p == zero){ return zero; + } const auto p_unit = p / norm_p; @@ -195,7 +196,5 @@ namespace phys{ p, em_e, em_b, reference_quantity); } } -} -} #endif //PICSAR_MULTIPHYSICS_CHI_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/physics/gamma_functions.hpp b/multi_physics/QED/include/picsar_qed/physics/gamma_functions.hpp index 128ce5427..05bfca40d 100644 --- a/multi_physics/QED/include/picsar_qed/physics/gamma_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/gamma_functions.hpp @@ -13,10 +13,8 @@ //Uses sqrt #include "picsar_qed/math/cmath_overloads.hpp" -namespace picsar{ -namespace multi_physics{ -namespace phys{ - +namespace picsar::multi_physics::phys +{ /** * This function returns the energy of a photon normalized with respect to the rest mass of an electron * @@ -40,8 +38,9 @@ namespace phys{ unit_system::heaviside_lorentz, RealType>::fact(reference_quantity); const auto norm_p = norm(p); - if(norm_p == zero) + if(norm_p == zero){ return zero; + } const auto gamma_phot = norm_p/ heaviside_lorentz_electron_rest_energy; @@ -131,7 +130,5 @@ namespace phys{ } } -} -} #endif //PICSAR_MULTIPHYSICS_GAMMA_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/physics/phys_constants.h b/multi_physics/QED/include/picsar_qed/physics/phys_constants.h index 89d6fb2fd..a7243e2ce 100644 --- a/multi_physics/QED/include/picsar_qed/physics/phys_constants.h +++ b/multi_physics/QED/include/picsar_qed/physics/phys_constants.h @@ -7,9 +7,8 @@ //Uses some mathematical constants #include "picsar_qed/math/math_constants.h" -namespace picsar{ -namespace multi_physics{ -namespace phys{ +namespace picsar::multi_physics::phys +{ // Some useful physical constants in SI units template @@ -68,7 +67,5 @@ namespace phys{ constexpr auto tau_e = RealType(classical_electron_radius<>/light_speed<>); //_______________________________________________________________________ } -} -} #endif //PICSAR_MULTIPHYSICS_MATH_CONSTANTS diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_core.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_core.hpp index 58b0568ec..276237672 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_core.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_core.hpp @@ -31,10 +31,8 @@ //Uses gamma functions #include "picsar_qed/physics/gamma_functions.hpp" -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ +namespace picsar::multi_physics::phys::quantum_sync +{ /** * Computes the optical depth of a new electron or positron (simply a number @@ -233,8 +231,5 @@ namespace quantum_sync{ } } -} -} -} #endif //PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_CORE diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables.hpp index 8a47b75fe..73b03a57a 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables.hpp @@ -40,10 +40,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ +namespace picsar::multi_physics::phys::quantum_sync +{ //________________ Default parameters ______________________________________ @@ -151,14 +149,14 @@ namespace quantum_sync{ * * @tparam RealType the floating point type to be used */ - typedef dndt_lookup_table< - RealType, containers::picsar_span> view_type; + using view_type = + dndt_lookup_table> ; /** * Empty constructor **/ constexpr - dndt_lookup_table(){} + dndt_lookup_table() = default; /** * Constructor (not designed for GPU usage) @@ -189,10 +187,9 @@ namespace quantum_sync{ m_table{containers::equispaced_1d_table{ math::m_log(params.chi_part_min), math::m_log(params.chi_part_max), - vals}} - { - m_init_flag = true; - } + vals}}, + m_init_flag{true} + {} /* * Generates the content of the lookup table (not usable on GPUs). @@ -205,7 +202,7 @@ namespace quantum_sync{ * @param[in] show_progress if true a progress bar is shown */ template - void generate(const bool show_progress = true); + void generate(bool show_progress = true); /* * Initializes the lookup table from a byte array. @@ -221,9 +218,10 @@ namespace quantum_sync{ sizeof(char)+ //single or double precision sizeof(m_params); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a Quantum Synchrotron G-function lookup-table."); + } auto it_raw_data = raw_data.begin(); @@ -249,6 +247,7 @@ namespace quantum_sync{ * * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const dndt_lookup_table &rhs) const @@ -270,11 +269,13 @@ namespace quantum_sync{ * * @return a table view */ + [[nodiscard]] view_type get_view() const { - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Can't generate a view of an \ uninitialized table"); + } const auto span = containers::picsar_span{ static_cast(m_params.chi_part_how_many), m_table.get_values_reference().data() @@ -295,6 +296,7 @@ namespace quantum_sync{ * * @return the value of the G function */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp( @@ -302,11 +304,11 @@ namespace quantum_sync{ { if(chi_part m_params.chi_part_max){ chi_part = m_params.chi_part_max; - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } } return math::m_exp(m_table.interp(math::m_log(chi_part))); } @@ -317,6 +319,7 @@ namespace quantum_sync{ * * @return a vector containing all the table coordinates */ + [[nodiscard]] std::vector get_all_coordinates() const noexcept { auto all_coords = m_table.get_all_coordinates(); @@ -339,8 +342,9 @@ namespace quantum_sync{ const auto vals_length = vals.size(); auto log_vals = std::vector(vals_length); - if(static_cast(vals_length) != m_table.get_how_many_x()) + if(static_cast(vals_length) != m_table.get_how_many_x()){ return false; + } std::transform(vals.begin(), vals.end(), log_vals.begin(), [](auto x){return math::m_log(x);}); @@ -356,6 +360,7 @@ namespace quantum_sync{ * * @return true if the table has been initialized, false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool is_init() const @@ -368,13 +373,15 @@ namespace quantum_sync{ * * @return a byte vector */ + [[nodiscard]] std::vector serialize() const { using namespace utils; - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Cannot serialize \ an uninitialized table"); + } std::vector res; @@ -389,9 +396,9 @@ namespace quantum_sync{ protected: dndt_lookup_table_params m_params; /* Table parameters*/ - bool m_init_flag = false; /* Initialization flag*/ containers::equispaced_1d_table< RealType, VectorType> m_table; /* Table data */ + bool m_init_flag = false; /* Initialization flag*/ }; //__________________________________________________________________________ @@ -419,6 +426,7 @@ namespace quantum_sync{ * @param[in] rhs a structure of the same type * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] bool operator== ( const photon_emission_lookup_table_params &rhs) const { @@ -477,14 +485,14 @@ namespace quantum_sync{ * * @tparam RealType the floating point type to be used */ - typedef photon_emission_lookup_table< - RealType, containers::picsar_span> view_type; + using view_type = + photon_emission_lookup_table>; /** * Empty constructor */ constexpr - photon_emission_lookup_table(){} + photon_emission_lookup_table() = default; /** * Constructor (not designed for GPU usage) @@ -522,10 +530,9 @@ namespace quantum_sync{ math::m_log(params.frac_min), math::m_log(math::one), params.chi_part_how_many, params.frac_how_many, - vals}} - { - m_init_flag = true; - } + vals}}, + m_init_flag{true} + {} /* * Generates the content of the lookup table (not usable on GPUs). @@ -554,9 +561,10 @@ namespace quantum_sync{ sizeof(char)+//single or double precision sizeof(m_params); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a Quantum Synchrotron emisson lookup-table."); + } auto it_raw_data = raw_data.begin(); @@ -582,6 +590,7 @@ namespace quantum_sync{ * * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const photon_emission_lookup_table< @@ -604,11 +613,13 @@ namespace quantum_sync{ * * @return a table view */ + [[nodiscard]] view_type get_view() const { - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Can't generate a view of an \ uninitialized table"); + } const auto span = containers::picsar_span{ static_cast(m_params.chi_part_how_many * m_params.frac_how_many), @@ -637,6 +648,7 @@ namespace quantum_sync{ * * @return chi of one of the generated particles */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp( @@ -649,11 +661,11 @@ namespace quantum_sync{ auto e_chi_part = chi_part; if(chi_part m_params.chi_part_max){ e_chi_part = m_params.chi_part_max; - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } } const auto log_e_chi_part = m_log(e_chi_part); @@ -665,11 +677,13 @@ namespace quantum_sync{ log_e_chi_part, i)); }); - if(upper_frac_index == 0) + if(upper_frac_index == 0){ return zero; + } - if(upper_frac_index == m_params.frac_how_many) + if(upper_frac_index == m_params.frac_how_many){ return chi_part; + } const auto lower_frac_index = upper_frac_index-1; @@ -695,6 +709,7 @@ namespace quantum_sync{ * * @return a vector containing all the table coordinates */ + [[nodiscard]] std::vector> get_all_coordinates() const noexcept { auto all_coords = m_table.get_all_coordinates(); @@ -719,8 +734,9 @@ namespace quantum_sync{ auto log_vals = std::vector(vals_length); if(static_cast(vals_length) != m_table.get_how_many_x()* - m_table.get_how_many_y()) + m_table.get_how_many_y()){ return false; + } std::transform(vals.begin(), vals.end(), log_vals.begin(), [](auto x){ @@ -738,6 +754,7 @@ namespace quantum_sync{ * * @return true if the table has been initialized, false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool is_init() const @@ -750,12 +767,14 @@ namespace quantum_sync{ * * @return a byte vector */ + [[nodiscard]] std::vector serialize() const { using namespace utils; - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Cannot serialize an uninitialized table"); + } std::vector res; @@ -770,9 +789,9 @@ namespace quantum_sync{ protected: photon_emission_lookup_table_params m_params; /* Table parameters*/ - bool m_init_flag = false; /* Initialization flag*/ containers::equispaced_2d_table< RealType, VectorType> m_table; /* Table data*/ + bool m_init_flag = false; /* Initialization flag*/ }; //__________________________________________________________________________ @@ -889,14 +908,14 @@ namespace quantum_sync{ * * @tparam RealType the floating point type to be used */ - typedef tailopt_photon_emission_lookup_table< - RealType, containers::picsar_span> view_type; + using view_type = + tailopt_photon_emission_lookup_table>; /** * Empty constructor */ constexpr - tailopt_photon_emission_lookup_table(){} + tailopt_photon_emission_lookup_table() = default; /** * Constructor (not designed for GPU usage) @@ -943,7 +962,7 @@ namespace quantum_sync{ tailopt_photon_emission_lookup_table_params params, VectorType vals): m_params{params}, - m_table{Generic2DTableType( + m_table{Generic2DTableType( params.chi_part_how_many, params.frac_how_many, vals, detail::LinFunctor( m_params.chi_part_how_many, @@ -962,10 +981,9 @@ namespace quantum_sync{ m_params.frac_how_many, m_params.frac_first, math::m_log(m_params.frac_min), math::m_log(math::one), - math::m_log(m_params.frac_switch)))} - { - m_init_flag = true; - } + math::m_log(m_params.frac_switch)))}, + m_init_flag{true} + {} /** * Generates the content of the lookup table (not usable on GPUs). @@ -994,9 +1012,10 @@ namespace quantum_sync{ sizeof(char)+//single or double precision sizeof(m_params); - if (raw_data.size() < min_size) + if (raw_data.size() < min_size){ throw std::runtime_error("Binary data is too small \ to be a Tail-optimized Quantum Synchrotron emisson lookup-table."); + } auto it_raw_data = raw_data.begin(); @@ -1021,6 +1040,7 @@ namespace quantum_sync{ * * @return true if rhs is equal to *this. false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool operator== ( const tailopt_photon_emission_lookup_table< @@ -1043,11 +1063,13 @@ namespace quantum_sync{ * * @return a table view */ + [[nodiscard]] view_type get_view() const { - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Can't generate a view of an \ uninitialized table"); + } const auto span = containers::picsar_span{ static_cast(m_params.chi_part_how_many * m_params.frac_how_many), @@ -1076,6 +1098,7 @@ namespace quantum_sync{ * * @return chi of the generated photon``` */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE RealType interp( @@ -1088,11 +1111,11 @@ namespace quantum_sync{ auto e_chi_part = chi_part; if(chi_part m_params.chi_part_max){ e_chi_part = m_params.chi_part_max; - if (is_out != nullptr) *is_out = true; + if (is_out != nullptr) { *is_out = true; } } const auto log_e_chi_part = m_log(e_chi_part); @@ -1104,11 +1127,13 @@ namespace quantum_sync{ log_e_chi_part, i)); }); - if(upper_frac_index == 0) + if(upper_frac_index == 0){ return zero; + } - if(upper_frac_index == m_params.frac_how_many) + if(upper_frac_index == m_params.frac_how_many){ return chi_part; + } const auto lower_frac_index = upper_frac_index-1; @@ -1134,6 +1159,7 @@ namespace quantum_sync{ * * @return a vector containing all the table coordinates */ + [[nodiscard]] std::vector> get_all_coordinates() const noexcept { auto all_coords = m_table.get_all_coordinates(); @@ -1155,8 +1181,9 @@ namespace quantum_sync{ bool set_all_vals(const std::vector& vals) { if(static_cast(vals.size()) != m_table.get_how_many_x()* - m_table.get_how_many_y()) + m_table.get_how_many_y()){ return false; + } auto logvals = VectorType{}; logvals.reserve(vals.size()); @@ -1164,10 +1191,12 @@ namespace quantum_sync{ std::begin(vals), std::end(vals), std::back_inserter(logvals), [](auto vv){ const auto lvv = math::m_log(vv); - if(std::isinf(lvv)) + if(std::isinf(lvv)){ return std::numeric_limits::lowest(); - else + } + else{ return lvv; + } }); m_table.set_all_vals(logvals); m_init_flag = true; @@ -1179,6 +1208,7 @@ namespace quantum_sync{ * * @return true if the table has been initialized, false otherwise */ + [[nodiscard]] PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE bool is_init() const @@ -1191,12 +1221,14 @@ namespace quantum_sync{ * * @return a byte vector */ + [[nodiscard]] std::vector serialize() const { using namespace utils; - if(!m_init_flag) + if(!m_init_flag){ throw std::runtime_error("Cannot serialize an uninitialized table"); + } std::vector res; @@ -1211,18 +1243,14 @@ namespace quantum_sync{ protected: tailopt_photon_emission_lookup_table_params m_params; /* Table parameters*/ - bool m_init_flag = false; /* Initialization flag*/ Generic2DTableType m_table; /* Table data*/ - + bool m_init_flag = false; /* Initialization flag*/ }; //______________________________________________________________________ -} -} -} } #endif // PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_TABLES diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_detail.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_detail.hpp index a06211aa0..74e51c5de 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_detail.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_detail.hpp @@ -12,11 +12,8 @@ //Uses log and exp #include "picsar_qed/math/cmath_overloads.hpp" -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ -namespace detail{ +namespace picsar::multi_physics::phys::quantum_sync::detail +{ /** * This class implements a linear functor to be used in tail-optimized lookup tables. @@ -34,7 +31,7 @@ namespace detail{ * Empty constructor */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE - LinFunctor(){} + LinFunctor() = default; /** * Constructor @@ -45,10 +42,9 @@ namespace detail{ */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE LinFunctor(int zsize, RealType zmin, RealType zmax) : - m_zmin{zmin} - { - m_coeff = (zmax - zmin)/(zsize - 1); - } + m_zmin{zmin}, + m_coeff{(zmax - zmin)/(zsize - 1)} + {} /** * Operator() @@ -82,6 +78,7 @@ namespace detail{ * * @return an std::vector containing the binary representation of the functor */ + [[nodiscard]] std::vector serialize() const { using namespace utils; @@ -139,7 +136,7 @@ namespace detail{ * Empty constructor */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE - ILinFunctor(){} + ILinFunctor() = default; /** * Constructor @@ -150,10 +147,9 @@ namespace detail{ */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE ILinFunctor(int zsize, RealType zmin, RealType zmax) : - m_zmin{zmin} - { - m_coeff = (zsize - 1)/(zmax - zmin); - } + m_zmin{zmin}, + m_coeff{(zsize - 1)/(zmax - zmin)} + {} /** * Operator() @@ -190,6 +186,7 @@ namespace detail{ * * @return an std::vector containing the binary representation of the functor */ + [[nodiscard]] std::vector serialize() const { using namespace utils; @@ -248,7 +245,7 @@ namespace detail{ * Empty constructor */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE - TailOptFunctor(){} + TailOptFunctor() = default; /** * Constructor @@ -262,12 +259,11 @@ namespace detail{ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE TailOptFunctor(const int zsize, const int zfirst, const RealType zmin, const RealType zmax, const RealType zswitch) : - m_zsize{zsize}, m_zfirst{zfirst}, m_zmin{zmin} - { - m_exp_zswitch = math::m_exp(zswitch); - m_coeff_first = (zswitch - zmin) / (zfirst - 1); - m_coeff_second = (math::m_exp(zmax) - m_exp_zswitch) / (zsize - zfirst); - } + m_zsize{zsize}, m_zfirst{zfirst}, m_zmin{zmin}, + m_exp_zswitch{math::m_exp(zswitch)}, + m_coeff_first{(zswitch - zmin) / (zfirst - 1)}, + m_coeff_second{(math::m_exp(zmax) - m_exp_zswitch) / (zsize - zfirst)} + {} /** * Operator() @@ -315,6 +311,7 @@ namespace detail{ * * @return an std::vector containing the binary representation of the functor */ + [[nodiscard]] std::vector serialize() const { using namespace utils; @@ -382,7 +379,7 @@ namespace detail{ * Empty constructor */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE - ITailOptFunctor(){} + ITailOptFunctor() = default; /** * Constructor @@ -396,12 +393,14 @@ namespace detail{ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE ITailOptFunctor(const int zsize, const int zfirst, const RealType zmin, const RealType zmax, const RealType zswitch) : - m_zsize{zsize}, m_zfirst{zfirst}, m_zmin{zmin}, m_zswitch{zswitch} - { - m_exp_zswitch = math::m_exp(zswitch); - m_coeff_first = (zfirst - 1) / (zswitch - zmin); - m_coeff_second = (zsize - zfirst) / (math::m_exp(zmax) - m_exp_zswitch); - } + m_zsize{zsize}, + m_zfirst{zfirst}, + m_zmin{zmin}, + m_zswitch{zswitch}, + m_exp_zswitch{math::m_exp(zswitch)}, + m_coeff_first{(zfirst - 1) / (zswitch - zmin)}, + m_coeff_second{(zsize - zfirst) / (math::m_exp(zmax) - m_exp_zswitch)} + {} /** * Operator() @@ -450,6 +449,7 @@ namespace detail{ * * @return an std::vector containing the binary representation of the functor */ + [[nodiscard]] std::vector serialize() const { using namespace utils; @@ -505,9 +505,5 @@ namespace detail{ }; } -} -} -} -} #endif //PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_TABLES_DETAIL diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator.hpp index 1c19d5c59..22a83b072 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator.hpp @@ -27,10 +27,8 @@ #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ +namespace picsar::multi_physics::phys::quantum_sync +{ //________________ dN/dt table _____________________________________________ @@ -141,8 +139,5 @@ namespace quantum_sync{ //__________________________________________________________________________ } -} -} -} #endif // PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_TABLES_GENERATOR diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator_detail.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator_detail.hpp index b623c5e74..71a071033 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator_detail.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tables_generator_detail.hpp @@ -30,11 +30,9 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ -namespace detail{ +namespace picsar::multi_physics::phys::quantum_sync::detail +{ + //________________ dN/dt table _____________________________________________ /** @@ -63,7 +61,7 @@ namespace detail{ #pragma omp parallel for #endif for (int i = 0; i < static_cast(all_coords.size()); ++i){ - PXRMP_CONSTEXPR_IF (ForceInternalDouble && !std::is_same()){ + if constexpr (ForceInternalDouble && !std::is_same()){ all_vals[i] = static_cast( compute_G_function(all_coords[i])); } @@ -71,19 +69,20 @@ namespace detail{ all_vals[i] = compute_G_function(all_coords[i]); } - PXRMP_CONSTEXPR_IF (ShowProgress){ - #pragma omp critical - { - count++; - utils::draw_progress(count, - all_vals.size(), "Quantum sync dN/dt", 1); + #pragma omp critical + { + count++; + if constexpr (ShowProgress){ + utils::draw_progress(count, all_vals.size(), + "Quantum sync dN/dt", 1); } } } for (const auto& val : all_vals){ - if(std::isnan(val)) + if(std::isnan(val)){ throw std::runtime_error("Error: nan detected in generated table!"); + } } auto t_end = std::chrono::system_clock::now(); @@ -137,7 +136,7 @@ namespace detail{ auto vals = std::vector(all_frac_size); - PXRMP_CONSTEXPR_IF (ForceInternalDouble && !std::is_same()){ + if constexpr (ForceInternalDouble && !std::is_same()){ const auto d_chi_part = static_cast(chi_part); auto d_chi_phots = std::vector(all_frac_size); std::transform( @@ -161,20 +160,20 @@ namespace detail{ std::copy(vals.begin(), vals.end(), all_vals.begin() + i*all_frac_size); - PXRMP_CONSTEXPR_IF (ShowProgress){ -#ifdef PXRMP_HAS_OPENMP - #pragma omp critical -#endif - { - count++; - utils::draw_progress(count, all_chi_part_size, "QS photon emission", 1); + #pragma omp critical + { + count++; + if constexpr (ShowProgress){ + utils::draw_progress(count, all_chi_part_size, + "QS photon emission", 1); } } } for (const auto& val : all_vals){ - if(std::isnan(val)) + if(std::isnan(val)){ throw std::runtime_error("Error: nan detected in generated table!"); + } } auto t_end = std::chrono::system_clock::now(); @@ -193,9 +192,5 @@ namespace detail{ //__________________________________________________________________________ } -} -} -} -} #endif // PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_TABLES_GENERATOR_DETAIL diff --git a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tabulated_functions.hpp b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tabulated_functions.hpp index 5292097f8..57e1c846b 100644 --- a/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tabulated_functions.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/quantum_sync/quantum_sync_engine_tabulated_functions.hpp @@ -30,11 +30,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace quantum_sync{ - +namespace picsar::multi_physics::phys::quantum_sync +{ /** * It computes the y parameter (see validation script). * This function is not designed to be run on GPUs. @@ -49,7 +46,7 @@ namespace quantum_sync{ template PXRMP_FORCE_INLINE constexpr RealType compute_y( - const RealType chi_part, const RealType csi) noexcept + const RealType chi_part, const RealType csi) { return math::two_thirds* csi/(chi_part*(math::one - csi)); @@ -70,15 +67,16 @@ namespace quantum_sync{ * @return the integral of kv(5/3, x) from y to infinity */ template - inline RealType inner_integral(const RealType y) + RealType inner_integral(const RealType y) { using namespace math; return quad_a_inf( [=](RealType s){ using namespace math; using namespace std; - if( y == zero) + if( y == zero){ return numeric_limits::infinity(); + } const auto s2 = s*s; const auto s4 = s2*s2; const auto cc = (one + @@ -87,8 +85,9 @@ namespace quantum_sync{ const auto f1 = static_cast(9.0) + static_cast(36.0) * s2 + static_cast(16.0) * s4; - if(isinf(f1) || isinf(cc)) + if(isinf(f1) || isinf(cc)){ return zero; + } return f1*m_exp(-y*cc)/cc/three;}, zero)/m_sqrt(three); } @@ -106,16 +105,18 @@ namespace quantum_sync{ * @return the value of the integrand of the G function */ template - inline RealType compute_G_integrand( - const RealType chi_part, const RealType csi) noexcept + RealType compute_G_integrand( + const RealType chi_part, const RealType csi) { using namespace math; using namespace std; - if( csi >= one || chi_part == zero ) + if( csi >= one || chi_part == zero ){ return zero; + } - if (csi == zero) + if (csi == zero){ return numeric_limits::infinity(); + } const auto yy = compute_y(chi_part, csi); const RealType coeff = m_sqrt(three<>)/(two<>*pi<>); @@ -123,8 +124,9 @@ namespace quantum_sync{ const auto second_part = (csi*csi/(one-csi))* k_v(two_thirds,yy); - if(isinf(second_part)) + if(isinf(second_part)){ return zero; + } return coeff*csi*(inner + second_part); } @@ -140,7 +142,7 @@ namespace quantum_sync{ * @return the value of the G function */ template - inline RealType compute_G_function(const RealType chi_part) + RealType compute_G_function(const RealType chi_part) { using namespace math; return quad_a_b_s( @@ -164,21 +166,21 @@ namespace quantum_sync{ * @return the value of the numerator of the cumulative probability distribution */ template - inline RealType compute_cumulative_prob_numerator_a_b( + RealType compute_cumulative_prob_numerator_a_b( const RealType chi_particle, RealType chi_photon_start, RealType chi_photon_end) { using namespace math; - if(chi_particle <= math::zero) return math::zero; - if(chi_photon_end <= math::zero) return math::zero; + if(chi_particle <= math::zero) { return math::zero; } + if(chi_photon_end <= math::zero) { return math::zero; } - if(chi_photon_end > chi_particle) chi_photon_end = chi_particle; - if(chi_photon_start >= chi_photon_end) return zero; + if(chi_photon_end > chi_particle) { chi_photon_end = chi_particle; } + if(chi_photon_start >= chi_photon_end) { return zero; } auto frac_end = chi_photon_end/chi_particle; - if(frac_end > math::one) frac_end = math::one; + if(frac_end > math::one) { frac_end = math::one; } auto frac_start = chi_photon_start/chi_particle; //The default quadrature method is very fast but in some rare cases @@ -213,7 +215,7 @@ namespace quantum_sync{ * @return the value of the numerator of the cumulative probability distribution */ template - inline RealType compute_cumulative_prob_numerator( + RealType compute_cumulative_prob_numerator( const RealType chi_particle, RealType chi_photon) { using namespace math; @@ -234,14 +236,14 @@ namespace quantum_sync{ * @return the cumulative probability distribution calculated for all the chi parameters */ template - inline VectorType compute_cumulative_prob( + VectorType compute_cumulative_prob( const RealType chi_particle, const VectorType& chi_photons) { const auto den = compute_G_function(chi_particle); auto res = VectorType(chi_photons.size()); if(chi_particle <= math::zero || den <= math::zero){ - for (auto& el: res ) el = math::zero; + for (auto& el: res ) { el = math::zero; } return res; } @@ -249,7 +251,7 @@ namespace quantum_sync{ res.begin(), [=](auto chi_phot){ const auto val = compute_cumulative_prob_numerator(chi_particle, chi_phot)/den; - if(val <= math::one) return val; + if(val <= math::one) { return val; } return math::one;}); return res; @@ -269,18 +271,19 @@ namespace quantum_sync{ * @return the cumulative probability distribution calculated for all the chi parameters */ template - inline VectorType compute_cumulative_prob_opt( + VectorType compute_cumulative_prob_opt( const RealType chi_particle, const VectorType& chi_photons) { - if(!std::is_sorted(chi_photons.begin(), chi_photons.end())) + if(!std::is_sorted(chi_photons.begin(), chi_photons.end())){ throw std::runtime_error("Chi vector is not sorted!"); + } using namespace math; const auto den = compute_G_function(chi_particle); auto res = VectorType(chi_photons.size()); if(chi_particle <= zero || den <= zero){ - for (auto& el: res ) el = zero; + for (auto& el: res ) { el = zero; } return res; } @@ -295,7 +298,7 @@ namespace quantum_sync{ c = (t - sum) - y; sum = t; res[i] = sum; - if(res[i] > one) res[i] = one; + if(res[i] > one) { res[i] = one; } old_chi = chi_photons[i]; } @@ -304,9 +307,6 @@ namespace quantum_sync{ } -} -} -} } #endif //PICSAR_MULTIPHYSICS_QUANTUM_SYNC_ENGINE_TABULATED_FUNCTIONS diff --git a/multi_physics/QED/include/picsar_qed/physics/schwinger/schwinger_pair_engine_core.hpp b/multi_physics/QED/include/picsar_qed/physics/schwinger/schwinger_pair_engine_core.hpp index f903c2af8..578e1efb4 100644 --- a/multi_physics/QED/include/picsar_qed/physics/schwinger/schwinger_pair_engine_core.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/schwinger/schwinger_pair_engine_core.hpp @@ -15,9 +15,7 @@ //Should be included by all the src files of the library #include "picsar_qed/qed_commons.h" -//Uses GPU-friendly arrays -#include "picsar_qed/math/vec_functions.hpp" -//Uses vector functions +//Uses GPU-friendly arrays and vector functions #include "picsar_qed/math/vec_functions.hpp" //Uses physical constants #include "picsar_qed/physics/phys_constants.h" @@ -26,10 +24,7 @@ //Uses sqrt, exp and tanh #include "picsar_qed/math/cmath_overloads.hpp" -namespace picsar{ -namespace multi_physics{ -namespace phys{ -namespace schwinger{ +namespace picsar::multi_physics::phys::schwinger{ /** * This function computes the Schwinger pair production rate @@ -69,8 +64,8 @@ namespace schwinger{ const auto inner = m_sqrt(ff*ff+ gg*gg); - const auto epsi = m_sqrt(fabs(inner + ff))*one_over_schwinger; - const auto eta = m_sqrt(fabs(inner - ff))*one_over_schwinger; + const auto epsi = m_sqrt(m_fabs(inner + ff))*one_over_schwinger; + const auto eta = m_sqrt(m_fabs(inner - ff))*one_over_schwinger; constexpr const auto coeff = static_cast( heaviside_lorentz_elementary_charge* @@ -81,12 +76,15 @@ namespace schwinger{ const auto rate_conv = conv::fact(1.0, ref_quantity); - if(epsi != zero && eta != zero) + if(epsi != zero && eta != zero){ return coeff*rate_conv*epsi*eta*m_exp(-pi/epsi)/m_tanh(pi*eta/epsi); - else if(epsi == zero) + } + else if(epsi == zero){ return zero; - else + } + else{ return coeff*rate_conv*epsi*epsi*m_exp(-pi/epsi)/pi; + } } /** @@ -199,8 +197,5 @@ namespace schwinger{ } } -} -} -} #endif //PICSAR_MULTIPHYSICS_SCHWINGER_PAIR_ENGINE_CORE diff --git a/multi_physics/QED/include/picsar_qed/physics/unit_conversion.hpp b/multi_physics/QED/include/picsar_qed/physics/unit_conversion.hpp index 4c63e2beb..caab5b932 100644 --- a/multi_physics/QED/include/picsar_qed/physics/unit_conversion.hpp +++ b/multi_physics/QED/include/picsar_qed/physics/unit_conversion.hpp @@ -9,9 +9,8 @@ //Uses several mathematical constants #include "picsar_qed/math/math_constants.h" -namespace picsar{ -namespace multi_physics{ -namespace phys{ +namespace picsar::multi_physics::phys +{ /** * The interface of the PICSAR QED library supports 4 unit systems @@ -132,8 +131,8 @@ namespace phys{ */ PXRMP_GPU_QUALIFIER PXRMP_FORCE_INLINE static constexpr RealType fact( - const RealType reference_quantity_from, - const RealType reference_quantity_to) noexcept; + RealType reference_quantity_from, + RealType reference_quantity_to) noexcept; }; //All possible template specializations follow @@ -2307,7 +2306,5 @@ namespace phys{ phys::elementary_charge*conv::fact()); -} -} } #endif //PICSAR_MULTIPHYSICS_PHYS_UNIT_CONVERSION diff --git a/multi_physics/QED/include/picsar_qed/qed_commons.h b/multi_physics/QED/include/picsar_qed/qed_commons.h index 056427e92..9e9997869 100644 --- a/multi_physics/QED/include/picsar_qed/qed_commons.h +++ b/multi_physics/QED/include/picsar_qed/qed_commons.h @@ -108,17 +108,6 @@ #endif -/** - * If possible (i.e. if C++17 or more recent is used) - * picsar makes use of "if constexpr". Otherwise, the - * expression falls back to a regular "if". - */ - #if __cplusplus >= 201703L - #define PXRMP_CONSTEXPR_IF if constexpr - #else - #define PXRMP_CONSTEXPR_IF if - #endif - /** * Unless PXRMP_PREVENT_USE_STD_FOR_MATH is defined by the * user std::sqrt, std::cbrt... mathematical functions diff --git a/multi_physics/QED/include/picsar_qed/utils/picsar_algo.hpp b/multi_physics/QED/include/picsar_qed/utils/picsar_algo.hpp index 29071deb6..fdceaa910 100644 --- a/multi_physics/QED/include/picsar_qed/utils/picsar_algo.hpp +++ b/multi_physics/QED/include/picsar_qed/utils/picsar_algo.hpp @@ -8,9 +8,7 @@ #include #endif -namespace picsar{ -namespace multi_physics{ -namespace utils{ +namespace picsar::multi_physics::utils{ /** * This function returns an iterator pointing @@ -42,7 +40,7 @@ picsar_upper_bound size_t count = last-first; do{ - auto it = first; + const auto * it = first; const auto step = count/2; it += step; if (!(val<*it)){ @@ -91,7 +89,7 @@ picsar_lower_bound size_t count = last-first; do{ - auto it = first; + const auto * it = first; const auto step = count/2; it += step; if (!(val<=*it)){ @@ -243,8 +241,6 @@ RealType bilinear_interp( return linear_interp(y0, y1, fx0, fx1, y); } -} -} } #endif //PICSAR_MULTIPHYSICS_ALGO diff --git a/multi_physics/QED/include/picsar_qed/utils/progress_bar.hpp b/multi_physics/QED/include/picsar_qed/utils/progress_bar.hpp index a9cde5e24..a5c6b8a39 100644 --- a/multi_physics/QED/include/picsar_qed/utils/progress_bar.hpp +++ b/multi_physics/QED/include/picsar_qed/utils/progress_bar.hpp @@ -7,9 +7,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace utils{ +namespace picsar::multi_physics::utils +{ /** * A simple progress bar @@ -24,32 +23,31 @@ namespace utils{ inline void draw_progress( const int i, const int how_many, - const std::string text = "", + const std::string& text = "", const int up_freq = 1, bool last=false, std::ostream& out = std::cout) { - if (i % up_freq != 0 && i != how_many) - return; + if (i % up_freq != 0 && i != how_many){ + return; + } const auto bar_length = 50; const auto progress = (i*1.0/how_many); const auto pos = static_cast(bar_length*progress); out << " ["; for (int j = 0; j < bar_length; ++j) { - if (j < pos) out << "="; - else if (j == pos) out << ">"; - else out << " "; + if (j < pos) { out << "="; } + else if (j == pos) { out << ">"; } + else { out << " "; } } out << "] " << std::to_string(static_cast(progress * 100.0)) << "% " << text ; - if(last) out <<"\n"; - else out <<"\r"; + if(last) { out <<"\n"; } + else { out <<"\r"; } out.flush(); } } -} -} #endif //PICSAR_MULTIPHYSICS_PROGRESS_BAR diff --git a/multi_physics/QED/include/picsar_qed/utils/serialization.hpp b/multi_physics/QED/include/picsar_qed/utils/serialization.hpp index e84bcf820..811bc73b5 100644 --- a/multi_physics/QED/include/picsar_qed/utils/serialization.hpp +++ b/multi_physics/QED/include/picsar_qed/utils/serialization.hpp @@ -10,10 +10,8 @@ #include #include -namespace picsar{ -namespace multi_physics{ -namespace utils{ -namespace serialization{ +namespace picsar::multi_physics::utils::serialization +{ /** * This function transform a variable of type T into a vector of chars holding its @@ -92,8 +90,5 @@ namespace serialization{ } } -} -} -} #endif //PICSAR_MULTIPHYSICS_SERIALIZATION diff --git a/multi_physics/QED/kokkos_example/kokkos_example_breit_wheeler.cpp b/multi_physics/QED/kokkos_example/kokkos_example_breit_wheeler.cpp index baabdd28e..8bcc199df 100644 --- a/multi_physics/QED/kokkos_example/kokkos_example_breit_wheeler.cpp +++ b/multi_physics/QED/kokkos_example/kokkos_example_breit_wheeler.cpp @@ -78,7 +78,7 @@ auto generate_dndt_table(const Real chi_min, const Real chi_max, const int chi_s << ", " << chi_size <<"]...\n"; std::cout.flush(); - pxr_bw::dndt_lookup_table_params bw_params{chi_min, chi_max, chi_size}; + const pxr_bw::dndt_lookup_table_params bw_params{chi_min, chi_max, chi_size}; auto table = pxr_bw::dndt_lookup_table< Real, Vector>{bw_params}; @@ -106,7 +106,7 @@ auto generate_pair_table(const Real chi_min, const Real chi_max, const int chi_s << ", " << chi_size << " x " << frac_size <<"]...\n"; std::cout.flush(); - pxr_bw::pair_prod_lookup_table_params bw_params{ + const pxr_bw::pair_prod_lookup_table_params bw_params{ chi_min, chi_max, chi_size, frac_size}; auto table = pxr_bw::pair_prod_lookup_table< @@ -133,7 +133,7 @@ fill_opt_test( const int repetitions, Kokkos::Random_XorShift64_Pool<>& rand_pool) { - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ const auto num_particles = pdata.num_particles; Kokkos::parallel_for("FillOpt_"+get_type_name(), @@ -170,7 +170,7 @@ evolve_optical_depth( const TableType& ref_table, const Real dt, const int repetitions) { - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ const auto num_particles = pdata.num_particles; Kokkos::parallel_for("EvolveOpt", num_particles, KOKKOS_LAMBDA(int i){ @@ -224,7 +224,7 @@ generate_pairs( auto pos_momentum = init_multi_comp_view_with_random_content( "pos_momentum", 0.0, 0.0, num_particles, rand_pool); - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ Kokkos::parallel_for("PairGen", num_particles, KOKKOS_LAMBDA(int i){ const auto px = pdata.m_momentum(i,0); @@ -327,22 +327,28 @@ void do_test(Kokkos::Random_XorShift64_Pool<>& rand_pool) int main(int argc, char** argv) { - Kokkos::initialize(argc, argv); - { - Kokkos::Random_XorShift64_Pool<> rand_pool{random_seed}; + try{ + Kokkos::initialize(argc, argv); + { + Kokkos::Random_XorShift64_Pool<> rand_pool{random_seed}; - std::cout << "*** Kokkos example: begin ***" << std::endl; + std::cout << "*** Kokkos example: begin ***" << std::endl; - std::cout << " --- Double precision test ---" << std::endl; - do_test(rand_pool); - std::cout << " --- END ---" << std::endl; + std::cout << " --- Double precision test ---" << std::endl; + do_test(rand_pool); + std::cout << " --- END ---" << std::endl; - std::cout << " --- Single precision test ---" << std::endl; - do_test(rand_pool); - std::cout << " --- END ---" << std::endl; + std::cout << " --- Single precision test ---" << std::endl; + do_test(rand_pool); + std::cout << " --- END ---" << std::endl; - std::cout << "___ END ___" << std::endl; + std::cout << "___ END ___" << std::endl; + } + Kokkos::finalize(); + } + catch(const std::exception& e){ + std::cerr << e.what(); + exit(EXIT_FAILURE); } - Kokkos::finalize(); exit(EXIT_SUCCESS); } diff --git a/multi_physics/QED/kokkos_example/kokkos_example_commons.hpp b/multi_physics/QED/kokkos_example/kokkos_example_commons.hpp index 17a6705da..6e19f03a3 100644 --- a/multi_physics/QED/kokkos_example/kokkos_example_commons.hpp +++ b/multi_physics/QED/kokkos_example/kokkos_example_commons.hpp @@ -1,5 +1,5 @@ -#ifndef __KOKKOS_EXAMPLE_COMMONS__ -#define __KOKKOS_EXAMPLE_COMMONS__ +#ifndef KOKKOS_EXAMPLE_COMMONS_ +#define KOKKOS_EXAMPLE_COMMONS_ //This file contains common functions and constants used by the two Kokkos examples @@ -26,9 +26,10 @@ #include //__________________________________________________ +#include +#include #include #include -#include //Some namespace aliases namespace pxr = picsar::multi_physics::phys; @@ -109,6 +110,7 @@ class KokkosVectorWrapper : public Kokkos::vector * * @return a pointer to the raw vector data */ + [[nodiscard]] const Real* data() const { return KV::d_view.data(); @@ -325,16 +327,18 @@ Real get_rand(GenType& gen) Real res = Real{1.0}; if constexpr (std::is_same::value){ - while(res >= 1.0f) + while(res >= 1.0f){ res = gen.frand(); + } } else { - while(res >= Real(1.0)) + while(res >= Real(1.0)){ res = gen.drand(); + } } return res; } -#endif //__KOKKOS_EXAMPLE_COMMONS__ \ No newline at end of file +#endif // KOKKOS_EXAMPLE_COMMONS_ diff --git a/multi_physics/QED/kokkos_example/kokkos_example_quantum_synchrotron.cpp b/multi_physics/QED/kokkos_example/kokkos_example_quantum_synchrotron.cpp index e7085b222..2b22f8c4a 100644 --- a/multi_physics/QED/kokkos_example/kokkos_example_quantum_synchrotron.cpp +++ b/multi_physics/QED/kokkos_example/kokkos_example_quantum_synchrotron.cpp @@ -37,7 +37,8 @@ auto generate_dndt_table(const Real chi_min, const Real chi_max, const int chi_s << ", " << chi_size <<"]...\n"; std::cout.flush(); - pxr_qs::dndt_lookup_table_params qs_params{chi_min, chi_max, chi_size}; + const auto qs_params = + pxr_qs::dndt_lookup_table_params{chi_min, chi_max, chi_size}; auto table = pxr_qs::dndt_lookup_table< Real, Vector>{qs_params}; @@ -67,7 +68,7 @@ auto generate_photon_emission_table( << ", " << chi_size << " x " << frac_size <<"]...\n"; std::cout.flush(); - pxr_qs::photon_emission_lookup_table_params qs_params{ + const pxr_qs::photon_emission_lookup_table_params qs_params{ chi_min, chi_max, frac_min, chi_size, frac_size}; auto table = pxr_qs::photon_emission_lookup_table< @@ -94,7 +95,7 @@ std::pair const int repetitions, Kokkos::Random_XorShift64_Pool<>& rand_pool) { - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ const auto num_particles = pdata.num_particles; Kokkos::parallel_for("FillOpt_"+get_type_name(), @@ -131,7 +132,7 @@ evolve_optical_depth( const TableType& ref_table, Real dt, const int repetitions) { - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ const auto num_particles = pdata.num_particles; Kokkos::parallel_for("EvolveOpt", num_particles, KOKKOS_LAMBDA(int i){ @@ -185,7 +186,7 @@ generate_photons( auto photon_momentum = init_multi_comp_view_with_random_content( "photon_momentum", 0.0, 0.0, num_particles, rand_pool); - Kokkos::Timer timer; + const Kokkos::Timer timer; for(int rr = 0; rr < repetitions; ++rr){ Kokkos::parallel_for("PhotEm", num_particles, KOKKOS_LAMBDA(int i){ const auto px = pdata.m_momentum(i,0); @@ -290,22 +291,28 @@ void do_test(Kokkos::Random_XorShift64_Pool<>& rand_pool) int main(int argc, char** argv) { - Kokkos::initialize(argc, argv); - { - Kokkos::Random_XorShift64_Pool<> rand_pool{random_seed}; + try{ + Kokkos::initialize(argc, argv); + { + Kokkos::Random_XorShift64_Pool<> rand_pool{random_seed}; - std::cout << "*** Kokkos example: begin ***" << std::endl; + std::cout << "*** Kokkos example: begin ***" << std::endl; - std::cout << " --- Double precision test ---" << std::endl; - do_test(rand_pool); - std::cout << " --- END ---" << std::endl; + std::cout << " --- Double precision test ---" << std::endl; + do_test(rand_pool); + std::cout << " --- END ---" << std::endl; - std::cout << " --- Single precision test ---" << std::endl; - do_test(rand_pool); - std::cout << " --- END ---" << std::endl; + std::cout << " --- Single precision test ---" << std::endl; + do_test(rand_pool); + std::cout << " --- END ---" << std::endl; - std::cout << "___ END ___" << std::endl; + std::cout << "___ END ___" << std::endl; + } + Kokkos::finalize(); + } + catch(const std::exception& e){ + std::cerr << e.what(); + exit(EXIT_FAILURE); } - Kokkos::finalize(); exit(EXIT_SUCCESS); } diff --git a/multi_physics/QED/python_bindings/CMakeLists.txt b/multi_physics/QED/python_bindings/CMakeLists.txt index 96cc74b76..e06f8bee7 100644 --- a/multi_physics/QED/python_bindings/CMakeLists.txt +++ b/multi_physics/QED/python_bindings/CMakeLists.txt @@ -59,8 +59,8 @@ set_target_properties(${name} PROPERTIES configure_file(demo_python_bindings.ipynb ${CMAKE_BINARY_DIR}/python_bindings/demo_python_bindings.ipynb COPYONLY) -# Require C++14 or newer -target_compile_features(${name} PUBLIC cxx_std_14) +# Require C++17 or newer +target_compile_features(${name} PUBLIC cxx_std_17) set_target_properties(${name} PROPERTIES CXX_EXTENSIONS OFF) # Enable warnings diff --git a/multi_physics/QED/python_bindings/pxr_qed.cpp b/multi_physics/QED/python_bindings/pxr_qed.cpp index f920ecd8c..287c38c02 100644 --- a/multi_physics/QED/python_bindings/pxr_qed.cpp +++ b/multi_physics/QED/python_bindings/pxr_qed.cpp @@ -76,13 +76,13 @@ namespace pxr_sc = picsar::multi_physics::phys::schwinger; template void PXRQEDPY_FOR(int N, const Func& func){ #pragma omp parallel for - for (int i = 0; i < N; ++i) func(i); + for (int i = 0; i < N; ++i){ func(i) ;} } const auto PXRQEDPY_OPENMP_FLAG = true; #else template void PXRQEDPY_FOR(int N, const Func& func){ - for (int i = 0; i < N; ++i) func(i); + for (int i = 0; i < N; ++i){ func(i); } } const auto PXRQEDPY_OPENMP_FLAG = false; #endif @@ -100,9 +100,11 @@ namespace pxr_sc = picsar::multi_physics::phys::schwinger; * @return num as a string */ template -std::string float_to_string(Real num) +std::string float_to_string(const Real num) { std::stringstream ss; + constexpr auto precision = 8; + ss.precision(precision); ss << num; return ss.str(); } @@ -153,10 +155,11 @@ using rawVec = std::vector; auto aux_check_and_get_pointers(const long int len, const pyArr& last) { const auto last_buf = last.request(); - if (last_buf.ndim != 1 || last_buf.shape[0] != len) + if (last_buf.ndim != 1 || last_buf.shape[0] != len){ throw_error("All arrays must be one-dimensional with equal size"); + } - const auto cptr = static_cast(last_buf.ptr); + auto *const cptr = static_cast(last_buf.ptr); return std::make_tuple(cptr); } @@ -175,10 +178,11 @@ template auto aux_check_and_get_pointers(const long int len, const pyArr& arg, const Args& ...args) { const auto arg_buf = arg.request(); - if (arg_buf.ndim != 1 || arg_buf.shape[0] != len) + if (arg_buf.ndim != 1 || arg_buf.shape[0] != len){ throw_error("All arrays must be one-dimensional with equal size"); + } - const auto cptr = static_cast(arg_buf.ptr); + auto *const cptr = static_cast(arg_buf.ptr); return std::tuple_cat(std::make_tuple(cptr), aux_check_and_get_pointers(len, args...)); } @@ -198,12 +202,13 @@ template auto check_and_get_pointers(const pyArr& first, const Args& ...args) { const auto first_buf = first.request(); - if (first_buf.ndim != 1) + if (first_buf.ndim != 1){ throw_error("All arrays must be one-dimensional with equal size"); + } const auto len = first_buf.shape[0]; - const auto cptr = static_cast(first_buf.ptr); + auto *const cptr = static_cast(first_buf.ptr); return std::tuple_cat(std::make_tuple(len, cptr), aux_check_and_get_pointers(len, args...)); @@ -219,12 +224,13 @@ auto check_and_get_pointers(const pyArr& first, const Args& ...args) auto check_and_get_pointers(const pyArr& arr) { const auto arr_buf = arr.request(); - if (arr_buf.ndim != 1) + if (arr_buf.ndim != 1){ throw_error("Array must be one-dimensional"); + } const auto len = arr_buf.shape[0]; - const auto cptr = static_cast(arr_buf.ptr); + auto *const cptr = static_cast(arr_buf.ptr); return std::make_tuple(len, cptr); } @@ -240,10 +246,11 @@ auto check_and_get_pointers(const pyArr& arr) auto check_and_get_pointer_nonconst(pyArr& arr, const long int len) { const auto arr_buf = arr.request(); - if (arr_buf.ndim != 1 || arr_buf.shape[0] != len) + if (arr_buf.ndim != 1 || arr_buf.shape[0] != len){ throw_error("Array must be one-dimensional with size " + std::to_string(len)); + } - const auto cptr = static_cast(arr_buf.ptr); + auto *const cptr = static_cast(arr_buf.ptr); return cptr; } @@ -271,9 +278,9 @@ compute_gamma_photon_wrapper( check_and_get_pointers(px, py, pz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); - PXRQEDPY_FOR(how_many, [&, p_px=p_px, p_py=p_py, p_pz=p_pz](int i){ + PXRQEDPY_FOR(static_cast(how_many), [&, p_px=p_px, p_py=p_py, p_pz=p_pz](int i){ p_res[i] = pxr_phys::compute_gamma_photon( p_px[i], p_py[i], p_pz[i], @@ -300,7 +307,7 @@ compute_gamma_ele_pos_wrapper( const REAL *p_px = nullptr, *p_py = nullptr, *p_pz = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -309,7 +316,7 @@ compute_gamma_ele_pos_wrapper( px, py, pz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -352,7 +359,7 @@ chi_photon_wrapper( *p_ex = nullptr, *p_ey = nullptr, *p_ez = nullptr, *p_bx = nullptr, *p_by = nullptr, *p_bz = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -365,7 +372,7 @@ chi_photon_wrapper( bx, by, bz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -406,7 +413,7 @@ chi_ele_pos_wrapper( *p_ex = nullptr, *p_ey = nullptr, *p_ez = nullptr, *p_bx = nullptr, *p_by = nullptr, *p_bz = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -419,7 +426,7 @@ chi_ele_pos_wrapper( bx, by, bz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -470,14 +477,14 @@ bw_get_optical_depth_wrapper( const REAL *p_unf_zero_one_minus_epsi = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, p_unf_zero_one_minus_epsi)= check_and_get_pointers(unf_zero_one_minus_epsi); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -506,7 +513,7 @@ bw_get_dn_dt_wrapper( const REAL *p_energy_phot = nullptr, *p_chi_phot = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -515,7 +522,7 @@ bw_get_dn_dt_wrapper( energy_phot, chi_phot); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -547,7 +554,7 @@ bw_evolve_optical_depth_wrapper( const REAL *p_energy_phot = nullptr, *p_chi_phot = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -555,7 +562,7 @@ bw_evolve_optical_depth_wrapper( check_and_get_pointers( energy_phot, chi_phot); - auto p_optical_depth = + auto* p_optical_depth = check_and_get_pointer_nonconst(optical_depth, how_many); PXRQEDPY_FOR(how_many, [&](int i){ @@ -591,7 +598,7 @@ bw_generate_breit_wheeler_pairs_wrapper( *p_phot_px = nullptr, *p_phot_py = nullptr, *p_phot_pz = nullptr, *p_unf_zero_one_minus_epsi; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -600,18 +607,19 @@ bw_generate_breit_wheeler_pairs_wrapper( check_and_get_pointers( chi_phot, phot_px, phot_py, phot_pz, unf_zero_one_minus_epsi); - auto ele_px = pyArr(how_many); - auto ele_py = pyArr(how_many); - auto ele_pz = pyArr(how_many); - auto pos_px = pyArr(how_many); - auto pos_py = pyArr(how_many); - auto pos_pz = pyArr(how_many); - auto p_ele_px = static_cast(ele_px.request().ptr); - auto p_ele_py = static_cast(ele_py.request().ptr); - auto p_ele_pz = static_cast(ele_pz.request().ptr); - auto p_pos_px = static_cast(pos_px.request().ptr); - auto p_pos_py = static_cast(pos_py.request().ptr); - auto p_pos_pz = static_cast(pos_pz.request().ptr); + const auto casted_how_many = static_cast(how_many); + auto ele_px = pyArr(casted_how_many); + auto ele_py = pyArr(casted_how_many); + auto ele_pz = pyArr(casted_how_many); + auto pos_px = pyArr(casted_how_many); + auto pos_py = pyArr(casted_how_many); + auto pos_pz = pyArr(casted_how_many); + auto* p_ele_px = static_cast(ele_px.request().ptr); + auto* p_ele_py = static_cast(ele_py.request().ptr); + auto* p_ele_pz = static_cast(ele_pz.request().ptr); + auto* p_pos_px = static_cast(pos_px.request().ptr); + auto* p_pos_py = static_cast(pos_py.request().ptr); + auto* p_pos_pz = static_cast(pos_pz.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ auto ele_mom = pxr_math::vec3{}; @@ -675,14 +683,14 @@ qs_get_optical_depth_wrapper( const REAL *p_unf_zero_one_minus_epsi = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, p_unf_zero_one_minus_epsi)= check_and_get_pointers(unf_zero_one_minus_epsi); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -711,7 +719,7 @@ qs_get_dn_dt_wrapper( const REAL *p_energy_part = nullptr, *p_chi_part = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -720,7 +728,7 @@ qs_get_dn_dt_wrapper( energy_part, chi_part); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -752,7 +760,7 @@ qs_evolve_optical_depth_wrapper( const REAL *p_energy_part = nullptr, *p_chi_part = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -760,7 +768,7 @@ qs_evolve_optical_depth_wrapper( check_and_get_pointers( energy_part, chi_part); - auto p_optical_depth = + auto* p_optical_depth = check_and_get_pointer_nonconst(optical_depth, how_many); PXRQEDPY_FOR(how_many, [&](int i){ @@ -794,26 +802,26 @@ qs_generate_photon_update_momentum_wrapper( const REAL *p_chi_part = nullptr, *p_unf_zero_one_minus_epsi = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, p_chi_part, p_unf_zero_one_minus_epsi) = check_and_get_pointers(chi_part, unf_zero_one_minus_epsi); - auto p_part_px = + auto* p_part_px = check_and_get_pointer_nonconst(part_px, how_many); - auto p_part_py = + auto* p_part_py = check_and_get_pointer_nonconst(part_py, how_many); - auto p_part_pz = + auto* p_part_pz = check_and_get_pointer_nonconst(part_pz, how_many); auto phot_px = pyArr(how_many); auto phot_py = pyArr(how_many); auto phot_pz = pyArr(how_many); - auto p_phot_px = static_cast(phot_px.request().ptr); - auto p_phot_py = static_cast(phot_py.request().ptr); - auto p_phot_pz = static_cast(phot_pz.request().ptr); + auto* p_phot_px = static_cast(phot_px.request().ptr); + auto* p_phot_py = static_cast(phot_py.request().ptr); + auto* p_phot_pz = static_cast(phot_pz.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ auto part_mom = pxr_math::vec3{p_part_px[i], p_part_py[i], p_part_pz[i]}; @@ -865,7 +873,7 @@ sc_pair_production_rate_wrapper( *p_ex = nullptr, *p_ey = nullptr, *p_ez = nullptr, *p_bx = nullptr, *p_by = nullptr, *p_bz = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -876,7 +884,7 @@ sc_pair_production_rate_wrapper( bx, by, bz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -914,7 +922,7 @@ sc_expected_pair_number_wrapper( *p_ex = nullptr, *p_ey = nullptr, *p_ez = nullptr, *p_bx = nullptr, *p_by = nullptr, *p_bz = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie( how_many, @@ -925,7 +933,7 @@ sc_expected_pair_number_wrapper( bx, by, bz); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = @@ -1046,32 +1054,37 @@ PYBIND11_MODULE(pxr_qed, m) { .def("generate", [&](bw_dndt_lookup_table &self, bool do_regular, bool verbose){ - if(do_regular) + if(do_regular){ self.generate(verbose); - else + } + else{ self.generate(verbose); + } }, py::arg("do_regular") = py::bool_(true), py::arg("verbose") = py::bool_(true)) .def("save_as", - [&](const bw_dndt_lookup_table &self, const std::string file_name){ - if(!self.is_init()) + [&](const bw_dndt_lookup_table &self, const std::string& file_name){ + if(!self.is_init()){ throw_error("Table must be initialized!"); + } const auto raw = self.serialize(); auto of = std::fstream(file_name, std::ios::out | std::ios::binary); - if( !of ) + if( !of ){ throw_error("Opening file failed!"); - of.write(raw.data(), raw.size()); + } + of.write(raw.data(), static_cast(raw.size())); of.close(); }, py::arg("file_name")) .def("load_from", - [&](bw_dndt_lookup_table &self, const std::string file_name){ + [&](bw_dndt_lookup_table &self, const std::string& file_name){ auto input = std::ifstream(file_name, std::ios::ate | std::ios::binary); - if( !input ) + if( !input ){ throw_error("Opening file failed!"); + } const auto pos = input.tellg(); auto raw = rawVec(pos); @@ -1085,12 +1098,12 @@ PYBIND11_MODULE(pxr_qed, m) { .def("interp", [&](bw_dndt_lookup_table &self, const pyArr& chi_phot){ const REAL* p_chi_phot = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie(how_many, p_chi_phot)= check_and_get_pointers(chi_phot); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = self.interp(p_chi_phot[i]); @@ -1114,32 +1127,37 @@ PYBIND11_MODULE(pxr_qed, m) { .def("generate", [&](bw_pair_prod_lookup_table &self, bool do_regular, bool verbose){ - if(do_regular) + if(do_regular){ self.generate(verbose); - else + } + else{ self.generate(verbose); + } }, py::arg("do_regular") = py::bool_(true), py::arg("verbose") = py::bool_(true)) .def("save_as", - [&](const bw_pair_prod_lookup_table &self, const std::string file_name){ - if(!self.is_init()) + [&](const bw_pair_prod_lookup_table &self, const std::string& file_name){ + if(!self.is_init()){ throw_error("Table must be initialized!"); + } const auto raw = self.serialize(); auto of = std::fstream(file_name, std::ios::out | std::ios::binary); - if( !of ) + if( !of ){ throw_error("Opening file failed!"); - of.write(raw.data(), raw.size()); + } + of.write(raw.data(), static_cast(raw.size())); of.close(); }, py::arg("file_name")) .def("load_from", - [&](bw_pair_prod_lookup_table &self, const std::string file_name){ + [&](bw_pair_prod_lookup_table &self, const std::string& file_name){ auto input = std::ifstream(file_name, std::ios::ate | std::ios::binary); - if( !input ) + if( !input ){ throw_error("Opening file failed!"); + } const auto pos = input.tellg(); auto raw = rawVec(pos); @@ -1155,12 +1173,12 @@ PYBIND11_MODULE(pxr_qed, m) { const pyArr& chi_phot, const pyArr& unf_zero_one_minus_epsi){ const REAL *p_chi_phot = nullptr, *p_unf_zero_one_minus_epsi = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie(how_many, p_chi_phot, p_unf_zero_one_minus_epsi)= check_and_get_pointers(chi_phot, unf_zero_one_minus_epsi); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = self.interp(p_chi_phot[i], p_unf_zero_one_minus_epsi[i]); @@ -1264,32 +1282,37 @@ PYBIND11_MODULE(pxr_qed, m) { .def("generate", [&](qs_dndt_lookup_table &self, bool do_regular, bool verbose){ - if(do_regular) + if(do_regular){ self.generate(verbose); - else + } + else{ self.generate(verbose); + } }, py::arg("do_regular") = py::bool_(true), py::arg("verbose") = py::bool_(true)) .def("save_as", - [&](const qs_dndt_lookup_table &self, const std::string file_name){ - if(!self.is_init()) + [&](const qs_dndt_lookup_table &self, const std::string& file_name){ + if(!self.is_init()){ throw_error("Table must be initialized!"); + } const auto raw = self.serialize(); auto of = std::fstream(file_name, std::ios::out | std::ios::binary); - if( !of ) + if( !of ){ throw_error("Opening file failed!"); - of.write(raw.data(), raw.size()); + } + of.write(raw.data(), static_cast(raw.size())); of.close(); }, py::arg("file_name")) .def("load_from", - [&](qs_dndt_lookup_table &self, const std::string file_name){ + [&](qs_dndt_lookup_table &self, const std::string& file_name){ auto input = std::ifstream(file_name, std::ios::ate | std::ios::binary); - if( !input ) + if( !input ){ throw_error("Opening file failed!"); + } const auto pos = input.tellg(); auto raw = rawVec(pos); @@ -1303,12 +1326,12 @@ PYBIND11_MODULE(pxr_qed, m) { .def("interp", [&](qs_dndt_lookup_table &self, const pyArr& chi_part){ const REAL* p_chi_part = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie(how_many, p_chi_part)= check_and_get_pointers(chi_part); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = self.interp(p_chi_part[i]); @@ -1332,32 +1355,37 @@ PYBIND11_MODULE(pxr_qed, m) { .def("generate", [&](qs_photon_emission_lookup_table &self, bool do_regular, bool verbose){ - if(do_regular) + if(do_regular){ self.generate(verbose); - else + } + else{ self.generate(verbose); + } }, py::arg("do_regular") = py::bool_(true), py::arg("verbose") = py::bool_(true)) .def("save_as", - [&](const qs_photon_emission_lookup_table &self, const std::string file_name){ - if(!self.is_init()) + [&](const qs_photon_emission_lookup_table &self, const std::string& file_name){ + if(!self.is_init()){ throw_error("Table must be initialized!"); + } const auto raw = self.serialize(); auto of = std::fstream(file_name, std::ios::out | std::ios::binary); - if( !of ) + if( !of ){ throw_error("Opening file failed!"); - of.write(raw.data(), raw.size()); + } + of.write(raw.data(), static_cast(raw.size())); of.close(); }, py::arg("file_name")) .def("load_from", - [&](qs_photon_emission_lookup_table &self, const std::string file_name){ + [&](qs_photon_emission_lookup_table &self, const std::string& file_name){ auto input = std::ifstream(file_name, std::ios::ate | std::ios::binary); - if( !input ) + if( !input ){ throw_error("Opening file failed!"); + } const auto pos = input.tellg(); auto raw = rawVec(pos); @@ -1373,12 +1401,12 @@ PYBIND11_MODULE(pxr_qed, m) { const pyArr& chi_part, const pyArr& unf_zero_one_minus_epsi){ const REAL *p_chi_part = nullptr, *p_unf_zero_one_minus_epsi = nullptr; - size_t how_many = 0; + int how_many = 0; std::tie(how_many, p_chi_part, p_unf_zero_one_minus_epsi)= check_and_get_pointers(chi_part, unf_zero_one_minus_epsi); auto res = pyArr(how_many); - auto p_res = static_cast(res.request().ptr); + auto* p_res = static_cast(res.request().ptr); PXRQEDPY_FOR(how_many, [&](int i){ p_res[i] = self.interp(p_chi_part[i], p_unf_zero_one_minus_epsi[i]); diff --git a/multi_physics/QED/test_gpu/test_breit_wheeler.cu b/multi_physics/QED/test_gpu/test_breit_wheeler.cu index 70675642e..2c05e5771 100644 --- a/multi_physics/QED/test_gpu/test_breit_wheeler.cu +++ b/multi_physics/QED/test_gpu/test_breit_wheeler.cu @@ -39,12 +39,12 @@ const double Bs = pxr::schwinger_field<>/pxr::light_speed<>; //__________________________________________________ //Parameters of the test case -const int test_size = 100'000'000; +const int test_size = 25'000'000; const double dt_test = 1e-18; const double table_chi_min = 0.01; const double table_chi_max = 1000.0; -const int table_chi_size = 256; -const int table_frac_size = 256; +const int table_chi_size = 512; +const int table_frac_size = 512; const double max_normalized_field = 0.02; const double max_normalized_momentum = 1000.0; const int random_seed = 22051988; @@ -56,10 +56,12 @@ const float float_tolerance = 1.0e-3; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } //Templated small number for double and single precision @@ -68,10 +70,12 @@ const float float_small = 1.0e-4; template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } //__________________________________________________ @@ -462,7 +466,6 @@ void do_pair_prod_test( else std::cout << " [FAIL] "; - cudaEventElapsedTime(&milliseconds, start, stop); std::cout << " elapsed time : " << milliseconds << " ms \n"; //hack diff --git a/multi_physics/QED/test_gpu/test_quantum_sync.cu b/multi_physics/QED/test_gpu/test_quantum_sync.cu index df86e6be4..ae92b7eec 100644 --- a/multi_physics/QED/test_gpu/test_quantum_sync.cu +++ b/multi_physics/QED/test_gpu/test_quantum_sync.cu @@ -57,10 +57,12 @@ const float float_tolerance = 5.0e-3; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } //Templated small number for double and single precision @@ -69,10 +71,12 @@ const float float_small = 1.0e-4; template T constexpr small() { - if(std::is_same::value) + if(std::is_same::value){ return float_small; - else + } + else{ return double_small; + } } //__________________________________________________ diff --git a/multi_physics/QED/test_gpu/test_schwinger.cu b/multi_physics/QED/test_gpu/test_schwinger.cu index f502d27e3..4e82c0070 100644 --- a/multi_physics/QED/test_gpu/test_schwinger.cu +++ b/multi_physics/QED/test_gpu/test_schwinger.cu @@ -38,10 +38,12 @@ const float float_tolerance = 5.0e-2; template T constexpr tolerance() { - if(std::is_same::value) + if(std::is_same::value){ return float_tolerance; - else + } + else{ return double_tolerance; + } } //*********************** SCHWINGER ENGINE: expected_pair_number ******************************