From 9622e834ffc98d84bbae4eae9001c1bfbe00b105 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 2 Apr 2023 15:38:54 +0200 Subject: [PATCH 1/6] :arrow_up: Bump libs/Catch2 from `6783411` to `1f881ab` (#27) Bumps [libs/Catch2](https://github.com/catchorg/Catch2) from `6783411` to `1f881ab`. - [Release notes](https://github.com/catchorg/Catch2/releases) - [Commits](https://github.com/catchorg/Catch2/compare/6783411349db5a87718c9b7ba8b02e90e39d783e...1f881ab4641b866304b818a063164dae976dba5f) --- updated-dependencies: - dependency-name: libs/Catch2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From 8f5f52fb110636dbf817ae754fc4a23e9d0e9f4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:02:59 +0200 Subject: [PATCH 2/6] :arrow_up: Bump libs/parallel-hashmap from `7883cb6` to `d2bed96` (#33) Bumps [libs/parallel-hashmap](https://github.com/greg7mdp/parallel-hashmap) from `7883cb6` to `d2bed96`. - [Release notes](https://github.com/greg7mdp/parallel-hashmap/releases) - [Commits](https://github.com/greg7mdp/parallel-hashmap/compare/7883cb6cd1a1b3dbe80a8f340cd9ff8167e5bdba...d2bed96d2947c13b8fc90337198c315b2200e058) --- updated-dependencies: - dependency-name: libs/parallel-hashmap dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From 2f6990e6980c84a9618a1532f41648bcf92f583c Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 25 Jul 2023 14:38:09 +0200 Subject: [PATCH 3/6] :heavy_minus_sign: Remove ``unit`` library due to increasing simulation runtimes. --- .gitmodules | 3 - docs/technology/simulation.rst | 12 ++ docs/utils/utils.rst | 18 -- .../algorithms/path_finding/distance.hpp | 8 +- .../sidb/calculate_energy_and_state_type.hpp | 2 +- .../simulation/sidb/critical_temperature.hpp | 41 ++--- .../simulation/sidb/energy_distribution.hpp | 5 +- .../simulation/sidb/is_ground_state.hpp | 4 +- .../simulation/sidb/minimum_energy.hpp | 10 +- ...cupation_probability_of_excited_states.hpp | 28 ++- .../sidb/sidb_simulation_parameters.hpp | 36 ++-- .../simulation/sidb/time_to_solution.hpp | 22 +-- include/fiction/io/read_sqd_layout.hpp | 15 +- include/fiction/io/write_sqd_layout.hpp | 12 +- include/fiction/io/write_sqd_sim_result.hpp | 16 +- .../charge_distribution_surface.hpp | 167 ++++++++---------- .../fiction/technology/physical_constants.hpp | 34 ++++ include/fiction/technology/sidb_defects.hpp | 21 +-- .../fiction/technology/sidb_nm_position.hpp | 11 +- include/fiction/utils/math_utils.hpp | 31 +--- include/fiction/utils/units_utils.hpp | 67 ------- libs/units | 1 - .../simulation/sidb/critical_temperature.cpp | 56 +++--- .../simulation/sidb/energy_distribution.cpp | 2 +- .../exhaustive_ground_state_simulation.cpp | 21 ++- .../simulation/sidb/is_groundstate.cpp | 4 +- .../simulation/sidb/minimum_energy.cpp | 17 +- ...cupation_probability_of_excited_states.cpp | 92 +++++----- test/algorithms/simulation/sidb/quicksim.cpp | 50 +++--- .../simulation/sidb/time_to_solution.cpp | 13 +- test/io/print_layout.cpp | 2 +- test/io/read_sqd_layout.cpp | 40 ++--- test/io/write_sqd_sim_result.cpp | 24 +-- .../charge_distribution_surface.cpp | 96 +++++----- test/technology/sidb_defects.cpp | 21 +-- test/utils/math_utils.cpp | 72 -------- 36 files changed, 442 insertions(+), 632 deletions(-) create mode 100644 include/fiction/technology/physical_constants.hpp delete mode 100644 include/fiction/utils/units_utils.hpp delete mode 160000 libs/units diff --git a/.gitmodules b/.gitmodules index fff1f6f4b..97bedb7f6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,6 +13,3 @@ [submodule "libs/tinyxml2"] path = libs/tinyxml2 url = https://github.com/leethomason/tinyxml2.git -[submodule "libs/units"] - path = libs/units - url = https://github.com/nholthaus/units.git diff --git a/docs/technology/simulation.rst b/docs/technology/simulation.rst index dddc4c211..211e8dae2 100644 --- a/docs/technology/simulation.rst +++ b/docs/technology/simulation.rst @@ -30,3 +30,15 @@ distributions of the SiDBs. Charge distribution surfaces are returned by the SiD :members: .. doxygenclass:: fiction::charge_distribution_surface< Lyt, false > :members: + + +Physical Constants +------------------ + +**Header:** ``fiction/technology/physical_constants.hpp`` + +.. doxygenvariable:: EPSILON +.. doxygenvariable:: ELEMENTARY_CHARGE +.. doxygenvariable:: K +.. doxygenvariable:: POP_STABILITY_ERR +.. doxygenvariable:: PI diff --git a/docs/utils/utils.rst b/docs/utils/utils.rst index 5d34dda34..e99a02f12 100644 --- a/docs/utils/utils.rst +++ b/docs/utils/utils.rst @@ -124,24 +124,6 @@ Array Utils .. doxygenfunction:: fiction::convert_array .. doxygenfunction:: fiction::convert_array_of_arrays -Unit Utils ------------ - -**Header:** ``fiction/utils/unit_utils.hpp`` - -.. doxygentypedef:: coulomb_constant_unit -.. doxygenvariable:: POP_STABILITY_ERR - -There are several suffix operators exposed in this file for convenient use of units, namely -* ``_angstrom`` -* ``_e`` -* ``_eV`` -* ``_K`` -* ``_nm`` -* ``_s`` -* ``_V`` - -This enables the use of units as follows: e.g., ``40_K``, ``40.1_nm``. STL Extensions -------------- diff --git a/include/fiction/algorithms/path_finding/distance.hpp b/include/fiction/algorithms/path_finding/distance.hpp index 9c4f2ff71..05fbd815b 100644 --- a/include/fiction/algorithms/path_finding/distance.hpp +++ b/include/fiction/algorithms/path_finding/distance.hpp @@ -91,16 +91,16 @@ template std::numeric_limits::max(); } /** - * Computes the distance between two SiDB cells in nanometers. + * Computes the distance between two SiDB cells in nanometers (unit: nm). * * @tparam Lyt SiDB cell-level layout type. * @tparam Dist Floating-point type for the distance. * @param c1 The first cell. * @param c2 The second cell. - * @return The distance between the two cells in nanometers. + * @return The distance between the two cells in nanometers (unit: nm). */ template -[[nodiscard]] constexpr units::length::nanometer_t +[[nodiscard]] constexpr double sidb_nanometer_distance([[maybe_unused]] const Lyt& lyt, const coordinate& source, const coordinate& target, const sidb_simulation_parameters& sp = sidb_simulation_parameters{}) noexcept { @@ -114,7 +114,7 @@ sidb_nanometer_distance([[maybe_unused]] const Lyt& lyt, const coordinate& const auto x = pos_c1.first - pos_c2.first; const auto y = pos_c1.second - pos_c2.second; - return units::math::hypot(x, y); + return std::hypot(x, y); } // NOLINTBEGIN(*-special-member-functions): virtual destructor is prudent diff --git a/include/fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp b/include/fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp index ba60d94b5..dbf2bd653 100644 --- a/include/fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp +++ b/include/fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp @@ -22,7 +22,7 @@ namespace fiction * Data type to collect electrostatic potential energies (in eV) of charge distributions with corresponding state types * (i.e., true = transparent, false = erroneous). */ -using sidb_energy_and_state_type = std::vector>; +using sidb_energy_and_state_type = std::vector>; /** * This function takes in an SiDB energy distribution. For each charge distribution, the state type is determined (i.e. diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index e1bc19f64..a5283fc7d 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -19,12 +19,10 @@ #include "fiction/utils/hash.hpp" #include "fiction/utils/math_utils.hpp" #include "fiction/utils/truth_table_utils.hpp" -#include "fiction/utils/units_utils.hpp" #include #include #include -#include #include #include @@ -99,7 +97,7 @@ struct critical_temperature_params /** * Simulation stops at max_temperature (~ 126 °C by default). */ - units::temperature::kelvin_t max_temperature{400_K}; + double max_temperature{400}; /** * Truth table of the given gate (if layout is simulated in `gate-based` mode). */ @@ -123,18 +121,17 @@ struct critical_temperature_stats */ std::string algorithm_name{}; /** - * Critical Temperature of the given layout. + * Critical Temperature of the given layout (unit: K). */ - units::temperature::kelvin_t critical_temperature{0_K}; + double critical_temperature{0}; /** * Number of physically valid charge configurations. */ uint64_t num_valid_lyt{}; /** - * Energy difference between the ground state and the first (erroneous) excited state. + * Energy difference between the ground state and the first (erroneous) excited state (unit: eV). */ - units::energy::electron_volt_t energy_between_ground_state_and_first_erroneous = - units::energy::electron_volt_t(std::numeric_limits::infinity()); + double energy_between_ground_state_and_first_erroneous = std::numeric_limits::infinity(); /** * Prints the simulation results to the given output stream. * @@ -142,13 +139,13 @@ struct critical_temperature_stats */ void report(std::ostream& out = std::cout) const { - out << fmt::format("Critical Temperature = {:.2f} K\n", critical_temperature.value()); + out << fmt::format("Critical Temperature = {:.2f} K\n", critical_temperature); if (num_valid_lyt != 0) { out << fmt::format("'# of physically valid charge configurations': {} | Energy between ground state and " "first erroneous: {}\n", - num_valid_lyt, energy_between_ground_state_and_first_erroneous.value()); + num_valid_lyt, energy_between_ground_state_and_first_erroneous); } else { @@ -287,8 +284,8 @@ class critical_temperature_impl else { - temperature_stats.critical_temperature = 0.0_K; // If no ground state fulfills the logic, the Critical - // Temperature is zero. May be worth it to change µ_. + temperature_stats.critical_temperature = 0.0; // If no ground state fulfills the logic, the Critical + // Temperature is zero. May be worth it to change µ_. } } @@ -329,10 +326,10 @@ class critical_temperature_impl (first_excited_state_energy - ground_state_energy) * 1000; } - std::vector temp_values{}; - temp_values.reserve(static_cast(parameter.max_temperature.value() * 100)); + std::vector temp_values{}; + temp_values.reserve(static_cast(parameter.max_temperature * 100)); - for (uint64_t i = 1; i <= static_cast(parameter.max_temperature.value() * 100); i++) + for (uint64_t i = 1; i <= static_cast(parameter.max_temperature * 100); i++) { temp_values.emplace_back(static_cast(i) / 100.0); } @@ -349,7 +346,7 @@ class critical_temperature_impl break; } - if (units::math::abs(temp - parameter.max_temperature) < 0.001_K) + if (std::abs(temp - parameter.max_temperature) < 0.001) { // Maximal temperature is stored as the Critical Temperature. temperature_stats.critical_temperature = parameter.max_temperature; @@ -369,8 +366,8 @@ class critical_temperature_impl * @param min_energy Minimal energy of all physically valid charge distributions of a given layout. * @return State type (i.e. transparent, erroneous) of the ground state is returned. */ - bool energy_between_ground_state_and_first_erroneous(const sidb_energy_and_state_type& energy_and_state_type, - const units::energy::electron_volt_t min_energy) + bool energy_between_ground_state_and_first_erroneous(const sidb_energy_and_state_type& energy_and_state_type, + const double min_energy) { bool ground_state_is_transparent = false; for (const auto& [energy, state_type] : energy_and_state_type) @@ -401,10 +398,10 @@ class critical_temperature_impl void determine_critical_temperature(const sidb_energy_and_state_type& energy_state_type) { // Vector with temperature values from 0.01 to max_temperature * 100 K in 0.01 K steps is generated. - std::vector temp_values{}; - temp_values.reserve(static_cast(parameter.max_temperature.value() * 100)); + std::vector temp_values{}; + temp_values.reserve(static_cast(parameter.max_temperature * 100)); - for (uint64_t i = 1; i <= static_cast(parameter.max_temperature.value() * 100); i++) + for (uint64_t i = 1; i <= static_cast(parameter.max_temperature * 100); i++) { temp_values.emplace_back(static_cast(i) / 100.0); } @@ -420,7 +417,7 @@ class critical_temperature_impl break; } - if (units::math::abs(temp - parameter.max_temperature) < 0.001_K) + if (std::abs(temp - parameter.max_temperature) < 0.001) { // Maximal temperature is stored as Critical Temperature. temperature_stats.critical_temperature = parameter.max_temperature; diff --git a/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp b/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp index 14e344fe8..750b16981 100644 --- a/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp +++ b/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp @@ -7,7 +7,6 @@ #include "fiction/technology/charge_distribution_surface.hpp" #include "fiction/utils/math_utils.hpp" -#include "fiction/utils/units_utils.hpp" #include #include @@ -21,7 +20,7 @@ namespace fiction * Data type to collect electrostatic potential energies of charge distributions with corresponding degeneracy (i.e. * how often a certain energy value occurs). */ -using sidb_energy_distribution = std::map; +using sidb_energy_distribution = std::map; /** * This function takes in a vector of charge_distribution_surface objects and returns a map containing the system energy @@ -39,7 +38,7 @@ energy_distribution(const std::vector>& input_v static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - std::map distribution{}; + std::map distribution{}; for (const auto& lyt : input_vec) { diff --git a/include/fiction/algorithms/simulation/sidb/is_ground_state.hpp b/include/fiction/algorithms/simulation/sidb/is_ground_state.hpp index 8f33a2a3e..a1696688a 100644 --- a/include/fiction/algorithms/simulation/sidb/is_ground_state.hpp +++ b/include/fiction/algorithms/simulation/sidb/is_ground_state.hpp @@ -12,8 +12,6 @@ #include "fiction/traits.hpp" #include "fiction/utils/math_utils.hpp" -#include - #include namespace fiction @@ -44,7 +42,7 @@ template const auto min_energy_exact = minimum_energy(exhaustive_results.charge_distributions); const auto min_energy_new_ap = minimum_energy(quicksim_results.charge_distributions); - return round_to_n_decimal_places(units::math::abs(min_energy_exact - min_energy_new_ap), 6).value() == 0; + return round_to_n_decimal_places(std::abs(min_energy_exact - min_energy_new_ap), 6) == 0; } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/minimum_energy.hpp b/include/fiction/algorithms/simulation/sidb/minimum_energy.hpp index 0d6c01469..e57d797bb 100644 --- a/include/fiction/algorithms/simulation/sidb/minimum_energy.hpp +++ b/include/fiction/algorithms/simulation/sidb/minimum_energy.hpp @@ -19,18 +19,16 @@ namespace fiction * * @tparam Lyt Cell-level layout type. * @param charge_lyts Vector of charge_distribution_surface objects. - * @return Value of the minimum energy found in the input vector. + * @return Value of the minimum energy found in the input vector (unit: eV). */ template -[[nodiscard]] units::energy::electron_volt_t -minimum_energy(const std::vector>& charge_lyts) noexcept +[[nodiscard]] double minimum_energy(const std::vector>& charge_lyts) noexcept { static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - return units::energy::electron_volt_t( - std::accumulate(charge_lyts.cbegin(), charge_lyts.cend(), std::numeric_limits::max(), - [](const double a, const auto& lyt) { return std::min(a, lyt.get_system_energy().value()); })); + return std::accumulate(charge_lyts.cbegin(), charge_lyts.cend(), std::numeric_limits::max(), + [](const double a, const auto& lyt) { return std::min(a, lyt.get_system_energy()); }); } } // namespace fiction diff --git a/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp b/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp index 4646e6570..1190ad021 100644 --- a/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp +++ b/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp @@ -7,7 +7,6 @@ #include "fiction/algorithms/simulation/sidb/calculate_energy_and_state_type.hpp" #include "fiction/utils/math_utils.hpp" -#include "fiction/utils/units_utils.hpp" #include #include @@ -27,20 +26,20 @@ namespace fiction * * @param energy_and_state_type This contains the energies of all possible charge distributions together with the * information if the charge distribution (state) is transparent or erroneous. - * @param temperature System temperature to assume. + * @param temperature System temperature to assume (unit: K). * @return The occupation probability of all erroneous states is returned. */ -[[nodiscard]] inline double occupation_probability_gate_based(const sidb_energy_and_state_type& energy_and_state_type, - const units::temperature::kelvin_t& temperature) noexcept +[[nodiscard]] inline double occupation_probability_gate_based(const sidb_energy_and_state_type& energy_and_state_type, + const double temperature) noexcept { - assert((temperature > 0.0_K) && "temperature should be slightly above 0 K"); + assert((temperature > 0.0) && "temperature should be slightly above 0 K"); if (energy_and_state_type.empty()) { return 0.0; } - auto min_energy = units::energy::electron_volt_t(std::numeric_limits::infinity()); + auto min_energy = std::numeric_limits::infinity(); // Determine the minimal energy. const auto [energy, state_type] = *std::min_element(energy_and_state_type.cbegin(), energy_and_state_type.cend(), @@ -51,7 +50,7 @@ namespace fiction const double partition_function = std::accumulate(energy_and_state_type.cbegin(), energy_and_state_type.cend(), 0.0, [&](const double sum, const auto& it) - { return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value()); }); + { return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature)); }); // All Boltzmann factors of the erroneous states are summed. double p = 0; @@ -61,7 +60,7 @@ namespace fiction { if (!state_transparent_erroneous) { - p += std::exp(-((energies - min_energy) * 12'000 / temperature).value()); + p += std::exp(-((energies - min_energy) * 12'000 / temperature)); } } @@ -76,18 +75,17 @@ namespace fiction * @param temperature System temperature to assume. * @return The total occupation probability of all excited states is returned. */ -[[nodiscard]] inline double -occupation_probability_non_gate_based(const sidb_energy_distribution& energy_distribution, - const units::temperature::kelvin_t& temperature) noexcept +[[nodiscard]] inline double occupation_probability_non_gate_based(const sidb_energy_distribution& energy_distribution, + const double temperature) noexcept { - assert((temperature > 0.0_K) && "Temperature should be slightly above 0 K"); + assert((temperature > 0.0) && "Temperature should be slightly above 0 K"); if (energy_distribution.empty()) { return 0.0; } - auto min_energy = units::energy::electron_volt_t(std::numeric_limits::infinity()); + auto min_energy = std::numeric_limits::infinity(); const auto& [energy, degeneracy] = *(energy_distribution.begin()); min_energy = energy; @@ -96,7 +94,7 @@ occupation_probability_non_gate_based(const sidb_energy_distribution& energy const double partition_function = std::accumulate(energy_distribution.cbegin(), energy_distribution.cend(), 0.0, [&](const double sum, const auto& it) - { return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value()); }); + { return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature)); }); // All Boltzmann factors of the excited states are summed. const double p = @@ -107,7 +105,7 @@ occupation_probability_non_gate_based(const sidb_energy_distribution& energy // possible rounding errors and for comparability with the min_energy. if (round_to_n_decimal_places(it.first, 6) != round_to_n_decimal_places(min_energy, 6)) { - return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature).value()); + return sum + std::exp(-((it.first - min_energy) * 12'000 / temperature)); } return sum; }); diff --git a/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp b/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp index e5da05b27..04c30e436 100644 --- a/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp +++ b/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp @@ -5,9 +5,7 @@ #ifndef FICTION_SIDB_SIMULATION_PARAMETERS_HPP #define FICTION_SIDB_SIMULATION_PARAMETERS_HPP -#include "fiction/utils/units_utils.hpp" - -#include +#include "fiction/technology/physical_constants.hpp" #include #include @@ -34,21 +32,18 @@ struct sidb_simulation_parameters * @param b lattice constant in Å. * @param c lattice constant in Å. */ - constexpr explicit sidb_simulation_parameters(const uint8_t base_number = 3, - const units::energy::electron_volt_t& mu_minus = -0.32_eV, - const double relative_permittivity = 5.6, - const units::length::nanometer_t& screening_distance = 5.0_nm, - const units::length::angstrom_t& a = 3.84_angstrom, - const units::length::angstrom_t& b = 7.68_angstrom, - const units::length::angstrom_t& c = 2.25_angstrom) : + constexpr explicit sidb_simulation_parameters(const uint8_t base_number = 3, const double mu_minus = -0.32, + const double relative_permittivity = 5.6, + const double screening_distance = 5.0, const double a = 3.84, + const double b = 7.68, const double c = 2.25) : lat_a{a}, lat_b{b}, lat_c{c}, epsilon_r{relative_permittivity}, - k{8.988 * 1E9 / epsilon_r}, + k{physical_constants::K / epsilon_r}, lambda_tf{screening_distance}, mu{mu_minus}, - mu_p{mu - units::energy::electron_volt_t(0.59)}, + mu_p{mu - 0.59}, base{base_number} { @@ -58,35 +53,36 @@ struct sidb_simulation_parameters /** * lat_a is the lattice vector in x-direction (unit: Å). */ - units::length::angstrom_t lat_a; + double lat_a; /** * lat_b is the lattice vector in y-direction (unit: Å). */ - units::length::angstrom_t lat_b; + double lat_b; /** * lat_c is the dimer pair separation (unit: Å). */ - units::length::angstrom_t lat_c; + double lat_c; /** * epsilon_r is the electric permittivity. It is a material specific number (unit-less). */ double epsilon_r; /** - * k is the Coulomb constant and is inversely proportional to the electric permittivity (unit: SI). + * k is the Coulomb constant and is inversely proportional to the electric permittivity (unit: \f$ N \cdot m^{2} + * \cdot C^{-2} \f$). */ - coulomb_constant_unit k; + double k; /** * lambda_tf is the Thomas-Fermi screening distance (unit: nm). */ - units::length::nanometer_t lambda_tf; + double lambda_tf; /** * µ- is the energy transition level (0/-) (unit: eV). */ - units::energy::electron_volt_t mu; + double mu; /** * µ+ is the energy transition level (+/0) (unit: eV). */ - units::energy::electron_volt_t mu_p; + double mu_p; /** * base can be either 2 or 3 and describes the assumed number of charge states of one SiDB. * It often makes sense to assume only negatively and neutrally charged SiDBs. diff --git a/include/fiction/algorithms/simulation/sidb/time_to_solution.hpp b/include/fiction/algorithms/simulation/sidb/time_to_solution.hpp index 63ea9c468..08da1f31a 100644 --- a/include/fiction/algorithms/simulation/sidb/time_to_solution.hpp +++ b/include/fiction/algorithms/simulation/sidb/time_to_solution.hpp @@ -11,10 +11,8 @@ #include "fiction/algorithms/simulation/sidb/quicksim.hpp" #include "fiction/technology/charge_distribution_surface.hpp" #include "fiction/traits.hpp" -#include "fiction/utils/units_utils.hpp" #include -#include #include #include @@ -36,7 +34,7 @@ struct time_to_solution_stats /** * Time-to-solution in seconds. */ - units::time::second_t time_to_solution{0_s}; + double time_to_solution{0}; /** * Accuracy of the simulation. */ @@ -44,12 +42,12 @@ struct time_to_solution_stats /** * Average single simulation runtime in seconds. */ - units::time::second_t mean_single_runtime{}; + double mean_single_runtime{}; /** - * Single simulation runtime of the exhaustive ground state searcher. + * Single simulation runtime of the exhaustive ground state searcher in seconds. */ - units::time::second_t single_runtime_exhaustive{}; + double single_runtime_exhaustive{}; /** * Print the results to the given output stream. @@ -58,9 +56,8 @@ struct time_to_solution_stats */ void report(std::ostream& out = std::cout) { - out << fmt::format("[i] time_to_solution: {} | acc: {} | t_(s): {} | t_exhaustive(s): {}\n", - time_to_solution.value(), acc, mean_single_runtime.value(), - single_runtime_exhaustive.value()); + out << fmt::format("[i] time_to_solution: {} | acc: {} | t_(s): {} | t_exhaustive(s): {}\n", time_to_solution, + acc, mean_single_runtime, single_runtime_exhaustive); } }; /** @@ -85,8 +82,7 @@ void sim_acc_tts(const Lyt& lyt, const quicksim_params& quicksim_params, time_to const auto simulation_results_exgs = exhaustive_ground_state_simulation(lyt, quicksim_params.phys_params); time_to_solution_stats st{}; - st.single_runtime_exhaustive = - units::time::second_t{mockturtle::to_seconds(simulation_results_exgs.simulation_runtime)}; + st.single_runtime_exhaustive = mockturtle::to_seconds(simulation_results_exgs.simulation_runtime); std::size_t gs_count = 0; std::vector time{}; @@ -130,9 +126,9 @@ void sim_acc_tts(const Lyt& lyt, const quicksim_params& quicksim_params, time_to tts = (single_runtime * std::log(1.0 - confidence_level) / std::log(1.0 - acc)); } - st.time_to_solution = units::time::second_t{tts}; + st.time_to_solution = tts; st.acc = acc * 100; - st.mean_single_runtime = units::time::second_t{single_runtime}; + st.mean_single_runtime = single_runtime; if (ps) { diff --git a/include/fiction/io/read_sqd_layout.hpp b/include/fiction/io/read_sqd_layout.hpp index 39f767749..76aacf5b1 100644 --- a/include/fiction/io/read_sqd_layout.hpp +++ b/include/fiction/io/read_sqd_layout.hpp @@ -11,7 +11,6 @@ #include "fiction/utils/name_utils.hpp" #include -#include #include #include @@ -268,11 +267,11 @@ class read_sqd_layout_impl { if constexpr (has_assign_sidb_defect_v) { - std::vector> incl_cells{}; - sidb_defect_type defect_type{sidb_defect_type::UNKNOWN}; - units::charge::elementary_charge_t charge{0}; - double eps_r{0.0}; - units::length::nanometer_t lambda_tf{0.0}; + std::vector> incl_cells{}; + sidb_defect_type defect_type{sidb_defect_type::UNKNOWN}; + int64_t charge{0}; + double eps_r{0.0}; + double lambda_tf{0.0}; if (const auto* const incl_coords = defect->FirstChildElement("incl_coords"); incl_coords != nullptr) { @@ -311,9 +310,9 @@ class read_sqd_layout_impl "Error parsing SQD file: no attribute 'charge', 'eps_r', or 'lambda_tf' in element 'coulomb'"); } - charge = units::charge::elementary_charge_t{std::stod(charge_string)}; + charge = std::stoll(charge_string); eps_r = std::stod(eps_r_string); - lambda_tf = units::length::nanometer_t{std::stod(lambda_tf_string)}; + lambda_tf = std::stod(lambda_tf_string); } std::for_each(incl_cells.begin(), incl_cells.end(), diff --git a/include/fiction/io/write_sqd_layout.hpp b/include/fiction/io/write_sqd_layout.hpp index facebf474..df28e7f33 100644 --- a/include/fiction/io/write_sqd_layout.hpp +++ b/include/fiction/io/write_sqd_layout.hpp @@ -276,12 +276,12 @@ class write_sqd_layout_impl const auto& cell = cd.first; const auto& defect = cd.second; - design << fmt::format( - siqad::DEFECT_BLOCK, fmt::format(siqad::LATTICE_COORDINATE, cell.x, cell.y / 2, cell.y % 2), - is_charged_defect(defect) ? fmt::format(siqad::COULOMB, defect.charge.value(), defect.epsilon_r, - defect.lambda_tf.value()) : - "", - get_defect_type_name(defect.type)); + design << fmt::format(siqad::DEFECT_BLOCK, + fmt::format(siqad::LATTICE_COORDINATE, cell.x, cell.y / 2, cell.y % 2), + is_charged_defect(defect) ? fmt::format(siqad::COULOMB, defect.charge, + defect.epsilon_r, defect.lambda_tf) : + "", + get_defect_type_name(defect.type)); }); } } diff --git a/include/fiction/io/write_sqd_sim_result.hpp b/include/fiction/io/write_sqd_sim_result.hpp index 147c3d93b..9105bdf56 100644 --- a/include/fiction/io/write_sqd_sim_result.hpp +++ b/include/fiction/io/write_sqd_sim_result.hpp @@ -192,8 +192,8 @@ class write_sqd_sim_result_impl os << siqad::OPEN_SIM_PARAMS; // physical parameters - os << fmt::format(siqad::PHYS_SIM_PARAMS, sim_result.physical_parameters.lambda_tf.value(), - sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu.value()); + os << fmt::format(siqad::PHYS_SIM_PARAMS, sim_result.physical_parameters.lambda_tf, + sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu); // additional simulation parameters std::for_each(sim_result.additional_simulation_parameters.cbegin(), @@ -223,11 +223,8 @@ class write_sqd_sim_result_impl { const auto [nm_x, nm_y] = sidb_nm_position(sim_result.physical_parameters, c); - os << fmt::format( - siqad::DBDOT, - units::convert(nm_x.value()), - units::convert( - nm_y.value())); // convert nm to Angstrom + os << fmt::format(siqad::DBDOT, nm_x * 10, + nm_y * 10); // convert nm to Angstrom }); os << siqad::CLOSE_PHYSLOC; @@ -251,8 +248,7 @@ class write_sqd_sim_result_impl // sort the surface references by their system energy std::sort(ordered_surface_pointers.begin(), ordered_surface_pointers.end(), - [](const auto& a, const auto& b) - { return a->get_system_energy().value() < b->get_system_energy().value(); }); + [](const auto& a, const auto& b) { return a->get_system_energy() < b->get_system_energy(); }); // write the distributions to the output stream std::for_each( @@ -269,7 +265,7 @@ class write_sqd_sim_result_impl os << fmt::format( siqad::DIST_ENERGY, - surface->get_system_energy().value(), // system energy + surface->get_system_energy(), // system energy 1, // occurrence count surface->is_physically_valid() ? 1 : 0, // physical validity 3, // simulation state count (fixed to 3 since state count = 2 is not supported by SiQAD yet). diff --git a/include/fiction/technology/charge_distribution_surface.hpp b/include/fiction/technology/charge_distribution_surface.hpp index e21386f21..63ae3837f 100644 --- a/include/fiction/technology/charge_distribution_surface.hpp +++ b/include/fiction/technology/charge_distribution_surface.hpp @@ -8,13 +8,12 @@ #include "fiction/algorithms/path_finding/distance.hpp" #include "fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp" #include "fiction/layouts/cell_level_layout.hpp" +#include "fiction/technology/physical_constants.hpp" #include "fiction/technology/sidb_charge_state.hpp" #include "fiction/technology/sidb_nm_position.hpp" #include "fiction/traits.hpp" #include "fiction/types.hpp" -#include - #include #include #include @@ -62,15 +61,15 @@ class charge_distribution_surface : public Lyt /** * The distance matrix is a vector of vectors storing the euclidean distance. */ - using distance_matrix = std::vector>; + using distance_matrix = std::vector>; /** * The potential matrix is a vector of vectors storing the electrostatic potentials. */ - using potential_matrix = std::vector>; + using potential_matrix = std::vector>; /** * It is a vector that stores the local electrostatic potential. */ - using local_potential = std::vector; + using local_potential = std::vector; public: explicit charge_distribution_storage(const sidb_simulation_parameters& params = sidb_simulation_parameters{}) : @@ -88,21 +87,22 @@ class charge_distribution_surface : public Lyt */ std::vector cell_charge{}; /** - * Distance between SiDBs are stored as matrix. + * Distance between SiDBs are stored as matrix (unit: nm). */ distance_matrix nm_dist_mat{}; /** - * Electrostatic potential between SiDBs are stored as matrix (here, still charge-independent). + * Electrostatic potential between SiDBs are stored as matrix (here, still charge-independent, unit: V). */ potential_matrix pot_mat{}; /** - * Electrostatic potential at each SiDB position. Has to be updated when charge distribution is changed. + * Electrostatic potential at each SiDB position. Has to be updated when charge distribution is changed (unit: + * V). */ local_potential loc_pot{}; /** - * Stores the electrostatic energy of a given charge distribution. + * Stores the electrostatic energy of a given charge distribution (unit: eV). */ - units::energy::electron_volt_t system_energy{units::energy::electron_volt_t(0.0)}; + double system_energy{0.0}; /** * Labels if given charge distribution is physically valid (see https://ieeexplore.ieee.org/document/8963859). */ @@ -194,10 +194,9 @@ class charge_distribution_surface : public Lyt * * @return Vector of SiDB nanometer positions. */ - [[nodiscard]] std::vector> - get_all_sidb_locations_in_nm() const noexcept + [[nodiscard]] std::vector> get_all_sidb_locations_in_nm() const noexcept { - std::vector> positions{}; + std::vector> positions{}; positions.reserve(strg->sidb_order.size()); for (const auto& cell : strg->sidb_order) @@ -346,11 +345,7 @@ class charge_distribution_surface : public Lyt // Check if the maximum band bending is sufficient to shift (0/-) above the Fermi level. The local // potential is converted from J to eV to compare the band bending with the Fermi level (which is // also given in eV). - if ((units::energy::electron_volt_t( - units::convert( - (-*local_pot * units::constants::e).value())) + - strg->phys_params.mu) - .value() < -POP_STABILITY_ERR) + if ((-*local_pot + strg->phys_params.mu) < -physical_constants::POP_STABILITY_ERR) { negative_sidbs.push_back(cell_to_index(c)); } @@ -411,28 +406,46 @@ class charge_distribution_surface : public Lyt * @param c2 the second cell to compare. * @return a constexpr double representing the distance in nm between the two cells. */ - [[nodiscard]] units::length::nanometer_t get_nm_distance_between_cells(const typename Lyt::cell& c1, - const typename Lyt::cell& c2) const noexcept + [[nodiscard]] double get_nm_distance_between_cells(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept { if (const auto index1 = cell_to_index(c1), index2 = cell_to_index(c2); (index1 != -1) && (index2 != -1)) { return strg->nm_dist_mat[static_cast(index1)][static_cast(index2)]; } - return units::length::nanometer_t(0.0); + return 0.0; } /** * Calculates and returns the distance between two cells (accessed by indices). * * @param index1 The first index. * @param index2 The second index. - * @return The distance index between `index1` and `index2` (indices correspond to unique SiDBs). + * @return The distance index between `index1` and `index2` (indices correspond to unique SiDBs) (unit: nm). */ - [[nodiscard]] units::length::nanometer_t get_nm_distance_by_indices(const uint64_t index1, - const uint64_t index2) const noexcept + [[nodiscard]] double get_nm_distance_by_indices(const uint64_t index1, const uint64_t index2) const noexcept { return strg->nm_dist_mat[index1][index2]; } + /** + * The chargeless electrostatic potential between two cells (SiDBs) is calculated in Volt. + * + * @param index1 The first index. + * @param index1 The second index. + * @return The chargeless electrostatic potential between `index1` and `index2` (unit: V). + */ + [[nodiscard]] double chargeless_potential_between_sidbs_by_index(const uint64_t index1, + const uint64_t index2) const noexcept + { + if (strg->nm_dist_mat[index1][index2] == 0.0) + { + return 0.0; + } + + return (strg->phys_params.k / (strg->nm_dist_mat[index1][index2] * 1E-9) * + std::exp(-strg->nm_dist_mat[index1][index2] / strg->phys_params.lambda_tf) * + physical_constants::ELEMENTARY_CHARGE); + } /** * Returns the chargeless electrostatic potential between two cells. * @@ -443,15 +456,15 @@ class charge_distribution_surface : public Lyt * @param c2 The second cell. * @return The chargeless electrostatic potential between `c1` and `c2`, i.e, \f$ \frac{V_{i,j}}{n_j} \f$. */ - [[nodiscard]] units::voltage::volt_t - get_chargeless_potential_between_sidbs(const typename Lyt::cell& c1, const typename Lyt::cell& c2) const noexcept + [[nodiscard]] double get_chargeless_potential_between_sidbs(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept { if (const auto index1 = cell_to_index(c1), index2 = cell_to_index(c2); (index1 != -1) && (index2 != -1)) { return strg->pot_mat[static_cast(index1)][static_cast(index2)]; } - return units::voltage::volt_t(0.0); + return 0.0; } /** * Calculates and returns the electrostatic potential at one cell (`c1`) generated by another cell (`c2`). @@ -463,8 +476,8 @@ class charge_distribution_surface : public Lyt * @param c2 The second cell. * @return The electrostatic potential between `c1` and `c2`, i.e., \f$ V_{i,j} \f$. */ - [[nodiscard]] units::voltage::volt_t get_potential_between_sidbs(const typename Lyt::cell& c1, - const typename Lyt::cell& c2) const noexcept + [[nodiscard]] double get_potential_between_sidbs(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept { if (const auto index1 = cell_to_index(c1), index2 = cell_to_index(c2); (index1 != -1) && (index2 != -1)) { @@ -472,7 +485,7 @@ class charge_distribution_surface : public Lyt charge_state_to_sign(get_charge_state(c2)); } - return units::voltage::volt_t(0.0); + return 0.0; } /** * Calculates and returns the potential of two indices. @@ -481,30 +494,11 @@ class charge_distribution_surface : public Lyt * @param index2 The second index. * @return The potential between `index1` and `index2`. */ - [[nodiscard]] units::voltage::volt_t get_electrostatic_potential_by_indices(const uint64_t index1, - const uint64_t index2) const noexcept + [[nodiscard]] double get_electrostatic_potential_by_indices(const uint64_t index1, + const uint64_t index2) const noexcept { return strg->pot_mat[index1][index2]; } - /** - * The electrostatic potential between two cells (SiDBs) is calculated. - * - * @param index1 The first index. - * @param index1 The second index. - * @return The potential between `index1` and `index2`. - */ - [[nodiscard]] units::voltage::volt_t potential_between_sidbs_by_index(const uint64_t index1, - const uint64_t index2) const noexcept - { - if (strg->nm_dist_mat[index1][index2] == units::length::nanometer_t(0.0)) - { - return units::voltage::volt_t(0.0); - } - - return (strg->phys_params.k / units::length::meter_t(strg->nm_dist_mat[index1][index2].value() * 1E-9) * - std::exp(-strg->nm_dist_mat[index1][index2].value() / strg->phys_params.lambda_tf.value()) * - units::constants::e); - } /** * Calculates and returns the potential of a pair of cells based on their distance and simulation parameters. * @@ -512,24 +506,24 @@ class charge_distribution_surface : public Lyt * @param c2 The second cell. * @return The potential between c1 and c2. */ - [[nodiscard]] units::voltage::volt_t potential_between_sidbs(const typename Lyt::cell& c1, - const typename Lyt::cell& c2) const noexcept + [[nodiscard]] double potential_between_sidbs(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept { const auto index1 = static_cast(cell_to_index(c1)); const auto index2 = static_cast(cell_to_index(c2)); - return potential_between_sidbs_by_index(index1, index2); + return chargeless_potential_between_sidbs_by_index(index1, index2); } /** * The function calculates the electrostatic potential for each SiDB position (local). */ void update_local_potential() noexcept { - strg->loc_pot.resize(this->num_cells(), units::voltage::volt_t(0.0)); + strg->loc_pot.resize(this->num_cells(), 0.0); for (uint64_t i = 0u; i < strg->sidb_order.size(); ++i) { - auto collect = units::voltage::volt_t(0.0); + double collect = 0.0; for (uint64_t j = 0u; j < strg->sidb_order.size(); j++) { collect += strg->pot_mat[i][j] * static_cast(charge_state_to_sign(strg->cell_charge[j])); @@ -545,7 +539,7 @@ class charge_distribution_surface : public Lyt * @return Local potential at given cell position. If there is no SiDB at the given cell, `std::nullopt` is * returned. */ - std::optional get_local_potential(const typename Lyt::cell& c) const noexcept + std::optional get_local_potential(const typename Lyt::cell& c) const noexcept { if (const auto index = cell_to_index(c); index != -1) { @@ -561,8 +555,7 @@ class charge_distribution_surface : public Lyt * @return local potential at given index position. If there is no SiDB at the given index (which corresponds to a * unique cell), `std::nullopt` is returned. */ - [[nodiscard]] std::optional - get_local_potential_by_index(const uint64_t index) const noexcept + [[nodiscard]] std::optional get_local_potential_by_index(const uint64_t index) const noexcept { if (index < strg->sidb_order.size()) { @@ -575,29 +568,27 @@ class charge_distribution_surface : public Lyt */ void set_system_energy_to_zero() noexcept { - strg->system_energy = units::energy::electron_volt_t(0.0); + strg->system_energy = 0.0; } /** * Calculates the system's total electrostatic potential energy and stores it in the storage. */ void recompute_system_energy() noexcept { - units::voltage::volt_t total_potential(0.0); + double total_potential = 0.0; for (uint64_t i = 0; i < strg->loc_pot.size(); ++i) { total_potential += 0.5 * strg->loc_pot[i] * charge_state_to_sign(strg->cell_charge[i]); } - strg->system_energy = - units::energy::electron_volt_t(units::convert( - (total_potential * units::constants::e).value())); + strg->system_energy = total_potential; } /** * Return the currently stored system's total electrostatic potential energy. * * @return The system's total electrostatic potential energy. */ - [[nodiscard]] units::energy::electron_volt_t get_system_energy() const noexcept + [[nodiscard]] double get_system_energy() const noexcept { return strg->system_energy; } @@ -621,15 +612,13 @@ class charge_distribution_surface : public Lyt for (const auto& it : strg->loc_pot) // this for-loop checks if the "population stability" is fulfilled. { - bool valid = - (((strg->cell_charge[for_loop_counter] == sidb_charge_state::NEGATIVE) && - ((units::energy::electron_volt_t(-it.value()) + strg->phys_params.mu).value() < POP_STABILITY_ERR)) || - ((strg->cell_charge[for_loop_counter] == sidb_charge_state::POSITIVE) && - ((units::energy::electron_volt_t(-it.value()) + strg->phys_params.mu_p).value() > - -POP_STABILITY_ERR)) || - ((strg->cell_charge[for_loop_counter] == sidb_charge_state::NEUTRAL) && - ((units::energy::electron_volt_t(-it.value()) + strg->phys_params.mu).value() > -POP_STABILITY_ERR) && - (units::energy::electron_volt_t(-it.value()) + strg->phys_params.mu_p).value() < POP_STABILITY_ERR)); + bool valid = (((strg->cell_charge[for_loop_counter] == sidb_charge_state::NEGATIVE) && + (-it + strg->phys_params.mu < physical_constants::POP_STABILITY_ERR)) || + ((strg->cell_charge[for_loop_counter] == sidb_charge_state::POSITIVE) && + (-it + strg->phys_params.mu_p > -physical_constants::POP_STABILITY_ERR)) || + ((strg->cell_charge[for_loop_counter] == sidb_charge_state::NEUTRAL) && + (-it + strg->phys_params.mu > -physical_constants::POP_STABILITY_ERR) && + (-it + strg->phys_params.mu_p < physical_constants::POP_STABILITY_ERR))); for_loop_counter += 1; if (!valid) { @@ -670,8 +659,8 @@ class charge_distribution_surface : public Lyt if (const auto e_del = hop_del(i, j); (charge_state_to_sign(strg->cell_charge[j]) > charge_state_to_sign(strg->cell_charge[i])) && - (e_del.value() < -POP_STABILITY_ERR)) // Checks if energetically favored - // hops exist between two SiDBs. + (e_del < -physical_constants::POP_STABILITY_ERR)) // Checks if energetically favored + // hops exist between two SiDBs. { hop_counter = 1; @@ -787,12 +776,12 @@ class charge_distribution_surface : public Lyt */ void adjacent_search(const double alpha, std::vector& negative_indices) noexcept { - auto dist_max = 0_nm; + double dist_max = 0.0; const auto reserve_size = this->num_cells() - negative_indices.size(); std::vector index_vector{}; index_vector.reserve(reserve_size); - std::vector distance{}; + std::vector distance{}; distance.reserve(reserve_size); for (uint64_t unocc = 0u; unocc < strg->cell_charge.size(); unocc++) @@ -803,10 +792,9 @@ class charge_distribution_surface : public Lyt } const auto dist_min = - std::accumulate(negative_indices.begin(), negative_indices.end(), - units::length::nanometer_t(std::numeric_limits::max()), - [&](const units::length::nanometer_t& acc, const uint64_t occ) - { return units::math::min(acc, this->get_nm_distance_by_indices(unocc, occ)); }); + std::accumulate(negative_indices.begin(), negative_indices.end(), std::numeric_limits::max(), + [&](const double acc, const uint64_t occ) + { return std::min(acc, this->get_nm_distance_by_indices(unocc, occ)); }); index_vector.push_back(unocc); distance.push_back(dist_min); @@ -836,9 +824,7 @@ class charge_distribution_surface : public Lyt strg->cell_charge[random_element] = sidb_charge_state::NEGATIVE; negative_indices.push_back(random_element); - strg->system_energy += - units::energy::electron_volt_t(units::convert( - (-(*this->get_local_potential_by_index(random_element)) * units::constants::e).value())); + strg->system_energy += -(*this->get_local_potential_by_index(random_element)); for (uint64_t i = 0u; i < strg->pot_mat.size(); ++i) { @@ -881,9 +867,8 @@ class charge_distribution_surface : public Lyt */ void initialize_nm_distance_matrix() const noexcept { - strg->nm_dist_mat = std::vector>( - this->num_cells(), - std::vector(this->num_cells(), units::length::nanometer_t(0))); + strg->nm_dist_mat = + std::vector>(this->num_cells(), std::vector(this->num_cells(), 0.0)); for (uint64_t i = 0u; i < strg->sidb_order.size(); ++i) { @@ -899,14 +884,14 @@ class charge_distribution_surface : public Lyt */ void initialize_potential_matrix() const noexcept { - strg->pot_mat = std::vector>( - this->num_cells(), std::vector(this->num_cells(), units::voltage::volt_t(0.0))); + strg->pot_mat = + std::vector>(this->num_cells(), std::vector(this->num_cells(), 0.0)); for (uint64_t i = 0u; i < strg->sidb_order.size(); ++i) { for (uint64_t j = 0u; j < strg->sidb_order.size(); j++) { - strg->pot_mat[i][j] = potential_between_sidbs_by_index(i, j); + strg->pot_mat[i][j] = chargeless_potential_between_sidbs_by_index(i, j); } } } diff --git a/include/fiction/technology/physical_constants.hpp b/include/fiction/technology/physical_constants.hpp new file mode 100644 index 000000000..29c1c3cbc --- /dev/null +++ b/include/fiction/technology/physical_constants.hpp @@ -0,0 +1,34 @@ +// +// Created by Jan Drewniok on 25.07.23. +// + +#ifndef FICTION_PHYSICAL_CONSTANTS_HPP +#define FICTION_PHYSICAL_CONSTANTS_HPP + +namespace fiction::physical_constants +{ + +/** + * The vacuum permittivity \f$ \epsilon_0 \f$ in \f$ F \cdot m^{-1} \f$. + */ +constexpr double EPSILON = 8.8541878 * 1E-12; +/** + * The elementary charge \f$ e \f$ in \f$ C \f$. + */ +constexpr double ELEMENTARY_CHARGE = 1.6021766 * 1E-19; +/** + * The Coulomb constant \f$ k \f$ in \f$ N \cdot m^{2} \cdot C^{-2} \f$. + */ +constexpr double K = 8.987552 * 1E9; +/** + * The pop stability error is used for physical simulations to avoid floating-point errors. + */ +constexpr double POP_STABILITY_ERR = 1E-6; +/** + * A value of \f$ \pi \f$ that is accurate to 11 decimal places. + */ +constexpr double PI = 3.14159265359; + +} // namespace fiction::physical_constants + +#endif // FICTION_PHYSICAL_CONSTANTS_HPP diff --git a/include/fiction/technology/sidb_defects.hpp b/include/fiction/technology/sidb_defects.hpp index 5277459da..199e8771f 100644 --- a/include/fiction/technology/sidb_defects.hpp +++ b/include/fiction/technology/sidb_defects.hpp @@ -5,10 +5,6 @@ #ifndef FICTION_SIDB_DEFECTS_HPP #define FICTION_SIDB_DEFECTS_HPP -#include "fiction/utils/units_utils.hpp" - -#include - #include #include #include @@ -52,28 +48,27 @@ struct sidb_defect /** * Standard constructor. */ - explicit sidb_defect(const sidb_defect_type defect_type = sidb_defect_type::UNKNOWN, - const units::charge::elementary_charge_t& electric_charge = 0_e, - const double relative_permittivity = 0.0, - const units::length::nanometer_t& screening_distance = 0.0_nm) noexcept : + constexpr explicit sidb_defect(const sidb_defect_type defect_type = sidb_defect_type::UNKNOWN, + const int64_t electric_charge = 0.0, const double relative_permittivity = 0.0, + const double screening_distance = 0.0) noexcept : type{defect_type}, charge{electric_charge}, epsilon_r{relative_permittivity}, lambda_tf{screening_distance} { - assert(((std::fmod(charge.value(), 1) == 0)) && "charge value has to be an integer"); + assert(((std::fmod(charge, 1) == 0)) && "charge value has to be an integer"); assert((epsilon_r >= 0) && "epsilon_r has to be >= 0.0"); - assert((lambda_tf >= 0.0_nm) && "lambda_tf has to be >= 0.0 nanometer"); + assert((lambda_tf >= 0.0) && "lambda_tf has to be >= 0.0 nanometer"); } /**s * Type of defect. */ const sidb_defect_type type; /** - * Electrical charge. + * Electrical charge in units of the elementary charge e (e.g., 1*e, -2*e). */ - const units::charge::elementary_charge_t charge; + const int64_t charge; /** * Electric permittivity. */ @@ -81,7 +76,7 @@ struct sidb_defect /** * Thomas-Fermi screening distance in nm. */ - const units::length::nanometer_t lambda_tf; + const double lambda_tf; }; /** * Checks whether the given defect is charged. Charged defects are to be avoided by a larger distance. diff --git a/include/fiction/technology/sidb_nm_position.hpp b/include/fiction/technology/sidb_nm_position.hpp index d77fba838..4792ca14e 100644 --- a/include/fiction/technology/sidb_nm_position.hpp +++ b/include/fiction/technology/sidb_nm_position.hpp @@ -15,7 +15,7 @@ namespace fiction { /** - * Computes the position of a cell in nanometers from the layout origin. + * Computes the position of a cell in nanometers from the layout origin (unit: nm). * * @tparam Lyt The layout type. * @param sp The simulation parameters (required for the lattice constants). @@ -23,15 +23,12 @@ namespace fiction * @return A pair representing the `(x,y)` position of `c` in nanometers from the layout origin. */ template -constexpr std::pair -sidb_nm_position(const sidb_simulation_parameters& sp, const cell& c) noexcept +constexpr std::pair sidb_nm_position(const sidb_simulation_parameters& sp, const cell& c) noexcept { static_assert(has_siqad_coord_v, "Lyt is not based on SiQAD coordinates"); - const auto x = units::length::nanometer_t( - units::convert((c.x * sp.lat_a).value())); - const auto y = units::length::nanometer_t( - units::convert((c.y * sp.lat_b + c.z * sp.lat_c).value())); + const auto x = (c.x * sp.lat_a) * 0.1; + const auto y = (c.y * sp.lat_b + c.z * sp.lat_c) * .1; return std::make_pair(x, y); } diff --git a/include/fiction/utils/math_utils.hpp b/include/fiction/utils/math_utils.hpp index 617907e14..7628756af 100644 --- a/include/fiction/utils/math_utils.hpp +++ b/include/fiction/utils/math_utils.hpp @@ -5,9 +5,6 @@ #ifndef FICTION_MATH_UTILS_HPP #define FICTION_MATH_UTILS_HPP -#include "fiction/utils/units_utils.hpp" -#include "units.h" - #include #include #include @@ -17,33 +14,21 @@ namespace fiction { /** - * Rounds a number or unit (allowed are: temperature, length, voltage, and energy) to a specified number of decimal + * Rounds a number to a specified number of decimal * places. * - * @tparam T The type of the number or unit to round. - * @param number The number or unit to round. - * @param n The number or unit of decimal places to round to. - * @return The number or unit rounded to n decimal places. + * @tparam T The type of the number to round. + * @param number The number to round. + * @param n The number of decimal places to round to. + * @return The number rounded to n decimal places. */ template T round_to_n_decimal_places(const T number, const uint64_t n) noexcept { - static_assert(std::is_arithmetic_v || units::traits::is_temperature_unit::value || - units::traits::is_length_unit::value || units::traits::is_voltage_unit::value || - units::traits::is_energy_unit::value, - "T is neither a number type nor a unit type"); + static_assert(std::is_arithmetic_v, "T is not a number type"); - if constexpr (std::is_arithmetic_v) - { - const auto factor = std::pow(10.0, static_cast(n)); - return static_cast(std::round(static_cast(number) * factor) / static_cast(factor)); - } - else if constexpr (units::traits::is_temperature_unit::value || units::traits::is_length_unit::value || - units::traits::is_voltage_unit::value || units::traits::is_energy_unit::value) - { - const double factor = std::pow(10.0, n); - return static_cast(std::round(static_cast(number.value()) * factor) / factor); - } + const auto factor = std::pow(10.0, static_cast(n)); + return static_cast(std::round(static_cast(number) * factor) / factor); } /** diff --git a/include/fiction/utils/units_utils.hpp b/include/fiction/utils/units_utils.hpp deleted file mode 100644 index 3731d1a36..000000000 --- a/include/fiction/utils/units_utils.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// -// Created by Jan Drewniok on 24.11.22. -// - -#ifndef FICTION_UNITS_UTILS_HPP -#define FICTION_UNITS_UTILS_HPP - -#include - -namespace units -{ -UNIT_ADD(energy, electron_volt, electron_volts, eV, units::unit, joule>); -UNIT_ADD(charge, elementary_charge, elementary_charges, e, - units::unit, coulomb>); -} // namespace units - -namespace fiction -{ -/** - * Can be used in combination with a number to generate an Ångström unit (e.g. 40.3 Å can be defined as 40_angstrom (is - * of type units::length::angstrom)). - */ -using units::literals::operator""_angstrom; -/** - * Can be used in combination with an integer to generate a charge in units of the elementary charge (e.g. -1 e can be - * defined as -1_e (is of type units::charge::elementary_charge)). - */ -using units::literals::operator""_e; -/** - * Can be used in combination with a number to generate an electron volt unit (e.g. 40.1 eV can be defined as 40.1_eV - * (is of type units::energy::electron_volt)). - */ -using units::literals::operator""_eV; -/** - * Can be used in combination with a number to generate a Kelvin unit (e.g. 40.1 K can be defined as 40.1_K (is of type - * units::temperature::kelvin)). - */ -using units::literals::operator""_K; -/** - * Can be used in combination with a number to generate a nanometer unit (e.g. 40.1 nm can be defined as 40.1_nm (is of - * type units::length::nanometer)). - */ -using units::literals::operator""_nm; -/** - * Can be used in combination with a number to generate a second unit (e.g. 40.1 s can be defined as 40.1_s (is of type - * units::time::second)). - */ -using units::literals::operator""_s; -/** - * Can be used in combination with a number to generate a Voltage unit (e.g. 40.1 V can be defined as 40.1_V (is of type - * units::voltage::volt)). - */ -using units::literals::operator""_V; -/** - * Unit of the Coulomb constant (\f$ N \cdot m^{2} \cdot C^{-2} \f$). - */ -using coulomb_constant_unit = - units::unit_t>>>; -/** - * The pop stability error is used for physical simulations to avoid floating-point errors. - */ -inline constexpr double POP_STABILITY_ERR = 1E-6; - -} // namespace fiction - -#endif // FICTION_UNITS_UTILS_HPP diff --git a/libs/units b/libs/units deleted file mode 160000 index 3ca0e22c5..000000000 --- a/libs/units +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3ca0e22c5e5088a93f930617d193e895eb538bca diff --git a/test/algorithms/simulation/sidb/critical_temperature.cpp b/test/algorithms/simulation/sidb/critical_temperature.cpp index 2f4a36339..0c4ae9e5c 100644 --- a/test/algorithms/simulation/sidb/critical_temperature.cpp +++ b/test/algorithms/simulation/sidb/critical_temperature.cpp @@ -31,10 +31,10 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.32_eV}}, 0.99, 350_K}; + quicksim_params{sidb_simulation_parameters{2, -0.32}}, 0.99, 350}; critical_temperature(lyt, params, &criticalstats); CHECK(criticalstats.num_valid_lyt == 0); - CHECK(criticalstats.critical_temperature == 0_K); + CHECK(criticalstats.critical_temperature == 0); } SECTION("one SiDB placed") @@ -45,19 +45,19 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.32_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.32}}, 0.99, - 350_K, + 350, create_or_tt(), 2}; critical_temperature(lyt, params, &criticalstats); CHECK(criticalstats.num_valid_lyt == 1); - CHECK(criticalstats.critical_temperature == 350_K); + CHECK(criticalstats.critical_temperature == 350); critical_temperature_stats criticalstats_new{}; critical_temperature(lyt, params, &criticalstats_new); CHECK(criticalstats_new.num_valid_lyt == 1); - CHECK(criticalstats_new.critical_temperature == 350_K); + CHECK(criticalstats_new.critical_temperature == 350); } SECTION("several SiDBs placed") @@ -74,40 +74,40 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.23_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.23}}, 0.99, - 350_K, + 350, create_or_tt(), 2}; critical_temperature(lyt, params, &criticalstats); - CHECK(criticalstats.critical_temperature == 350_K); + CHECK(criticalstats.critical_temperature == 350); critical_temperature_stats criticalstats_one{}; const critical_temperature_params params_one{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.23_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.23}}, 0.99, - 350_K, + 350, create_and_tt(), 3}; critical_temperature(lyt, params_one, &criticalstats_one); - CHECK(criticalstats_one.critical_temperature == 350_K); + CHECK(criticalstats_one.critical_temperature == 350); critical_temperature_stats criticalstats_second{}; critical_temperature(lyt, params_one, &criticalstats_second); - CHECK(criticalstats_second.critical_temperature == 350_K); + CHECK(criticalstats_second.critical_temperature == 350); const critical_temperature_params params_two{simulation_engine::EXACT, critical_temperature_mode::NON_GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.23_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.23}}, 0.999, - 450_K, + 450, create_and_tt(), 3}; critical_temperature_stats criticalstats_no_logic{}; critical_temperature(lyt, params_two, &criticalstats_no_logic); - CHECK(criticalstats_no_logic.critical_temperature < 40_K); + CHECK(criticalstats_no_logic.critical_temperature < 40); } SECTION("Y-shape SiDB XNOR gate with input 11") @@ -133,13 +133,13 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.28_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.28}}, 0.99, - 350_K, + 350, create_xnor_tt(), 3}; critical_temperature(lyt, params, &criticalstats); - CHECK(criticalstats.critical_temperature < 13_K); + CHECK(criticalstats.critical_temperature < 13); } SECTION("Y-shape SiDB XNOR gate with input 11, small µ, gate-based") @@ -165,13 +165,13 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.15_eV}}, + quicksim_params{sidb_simulation_parameters{2, -0.15}}, 0.99, - 350_K, + 350, create_xnor_tt(), 3}; critical_temperature(lyt, params, &criticalstats); - CHECK(criticalstats.critical_temperature == 0_K); + CHECK(criticalstats.critical_temperature == 0); } SECTION("Y-shape SiDB XNOR gate with input 11, small µ, non-gate-based") @@ -197,11 +197,11 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::EXACT, critical_temperature_mode::NON_GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.15_eV}}, 0.99, 350_K}; + quicksim_params{sidb_simulation_parameters{2, -0.15}}, 0.99, 350}; critical_temperature(lyt, params, &criticalstats); CHECK(criticalstats.algorithm_name == "exgs"); - CHECK(criticalstats.critical_temperature < 200_K); - CHECK(criticalstats.critical_temperature > 0_K); + CHECK(criticalstats.critical_temperature < 200); + CHECK(criticalstats.critical_temperature > 0); } SECTION("Y-shape SiDB XNOR gate with input 11, small µ, non-gate-based, approximate") @@ -227,10 +227,10 @@ TEMPLATE_TEST_CASE( critical_temperature_stats criticalstats{}; const critical_temperature_params params{simulation_engine::APPROXIMATE, critical_temperature_mode::NON_GATE_BASED_SIMULATION, - quicksim_params{sidb_simulation_parameters{2, -0.15_eV}}, 0.99, 350_K}; + quicksim_params{sidb_simulation_parameters{2, -0.15}}, 0.99, 350}; critical_temperature(lyt, params, &criticalstats); CHECK(criticalstats.algorithm_name == "quicksim"); - CHECK(criticalstats.critical_temperature < 200_K); - CHECK(criticalstats.critical_temperature > 0_K); + CHECK(criticalstats.critical_temperature < 200); + CHECK(criticalstats.critical_temperature > 0); } } diff --git a/test/algorithms/simulation/sidb/energy_distribution.cpp b/test/algorithms/simulation/sidb/energy_distribution.cpp index e39447145..f9b2d765c 100644 --- a/test/algorithms/simulation/sidb/energy_distribution.cpp +++ b/test/algorithms/simulation/sidb/energy_distribution.cpp @@ -29,7 +29,7 @@ TEMPLATE_TEST_CASE( all_lyts.push_back(charge_layout); auto result = energy_distribution(all_lyts); CHECK(result.size() == 1); - CHECK(result[0.0_eV] == 1); + CHECK(result[0.0] == 1); } SECTION("one layout with one SiDB placed") diff --git a/test/algorithms/simulation/sidb/exhaustive_ground_state_simulation.cpp b/test/algorithms/simulation/sidb/exhaustive_ground_state_simulation.cpp index 0e9ead1b7..39bd25502 100644 --- a/test/algorithms/simulation/sidb/exhaustive_ground_state_simulation.cpp +++ b/test/algorithms/simulation/sidb/exhaustive_ground_state_simulation.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include using namespace fiction; @@ -19,7 +19,7 @@ TEMPLATE_TEST_CASE("Empty layout ExGS simulation", "[ExGS]", { TestType lyt{{20, 10}}; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results = exhaustive_ground_state_simulation(lyt, params); @@ -35,7 +35,7 @@ TEMPLATE_TEST_CASE("Single SiDB ExGS simulation", "[ExGS]", TestType lyt{{20, 10}}; lyt.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results = exhaustive_ground_state_simulation(lyt, params); @@ -58,7 +58,7 @@ TEMPLATE_TEST_CASE("ExGS simulation of a two-pair BDL wire with one perturber", lyt.assign_cell_type({17, 0, 0}, TestType::cell_type::NORMAL); lyt.assign_cell_type({19, 0, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results = exhaustive_ground_state_simulation(lyt, params); @@ -82,7 +82,8 @@ TEMPLATE_TEST_CASE("ExGS simulation of a two-pair BDL wire with one perturber", CHECK(charge_lyt_first.get_charge_state({17, 0, 0}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({19, 0, 0}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), Catch::Matchers::WithinAbs(0.246080, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.2460493219, physical_constants::POP_STABILITY_ERR)); } TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB arrangement", "[ExGS]", @@ -100,7 +101,7 @@ TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB arrangement", "[ExGS]", lyt.assign_cell_type({-7, 1, 1}, TestType::cell_type::NORMAL); lyt.assign_cell_type({-7, 3, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results = exhaustive_ground_state_simulation(lyt, params); @@ -116,7 +117,8 @@ TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB arrangement", "[ExGS]", CHECK(charge_lyt_first.get_charge_state({-7, 1, 1}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({-7, 3, 0}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), Catch::Matchers::WithinAbs(0.319219, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.3191788254, physical_constants::POP_STABILITY_ERR)); } TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB OR gate with input 01", "[ExGS]", @@ -135,7 +137,7 @@ TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB OR gate with input 01", "[ lyt.assign_cell_type({10, 8, 1}, TestType::cell_type::NORMAL); lyt.assign_cell_type({16, 1, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.28_eV}; + const sidb_simulation_parameters params{2, -0.28}; const auto simulation_results = exhaustive_ground_state_simulation(lyt, params); @@ -152,5 +154,6 @@ TEMPLATE_TEST_CASE("ExGS simulation of a Y-shape SiDB OR gate with input 01", "[ CHECK(charge_lyt_first.get_charge_state({8, 3, 0}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({6, 2, 0}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), Catch::Matchers::WithinAbs(0.466318, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.4662582096, physical_constants::POP_STABILITY_ERR)); } diff --git a/test/algorithms/simulation/sidb/is_groundstate.cpp b/test/algorithms/simulation/sidb/is_groundstate.cpp index 684a3d1a5..88bb35d96 100644 --- a/test/algorithms/simulation/sidb/is_groundstate.cpp +++ b/test/algorithms/simulation/sidb/is_groundstate.cpp @@ -28,7 +28,7 @@ TEMPLATE_TEST_CASE( { TestType lyt{{20, 10}}; charge_distribution_surface charge_layout{lyt}; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results_exgs = exhaustive_ground_state_simulation(charge_layout, params); const quicksim_params quicksim_params{params}; const auto simulation_results_quicksim = quicksim(charge_layout, quicksim_params); @@ -51,7 +51,7 @@ TEMPLATE_TEST_CASE( lyt.assign_cell_type({7, 10, 0}, TestType::cell_type::NORMAL); charge_distribution_surface charge_layout{lyt}; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; const auto simulation_results_exgs = exhaustive_ground_state_simulation(charge_layout, params); diff --git a/test/algorithms/simulation/sidb/minimum_energy.cpp b/test/algorithms/simulation/sidb/minimum_energy.cpp index 77254a138..d2df7dfd3 100644 --- a/test/algorithms/simulation/sidb/minimum_energy.cpp +++ b/test/algorithms/simulation/sidb/minimum_energy.cpp @@ -13,6 +13,8 @@ #include #include +#include + using namespace fiction; TEMPLATE_TEST_CASE( @@ -30,12 +32,11 @@ TEMPLATE_TEST_CASE( const charge_distribution_surface charge_layout{lyt}; std::vector> all_lyts{}; - CHECK_THAT(minimum_energy(all_lyts).value(), - Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); + CHECK_THAT(minimum_energy(all_lyts), Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); all_lyts.push_back(charge_layout); - CHECK(units::math::abs(minimum_energy(all_lyts) - 0_eV) < 0.00000001_eV); + CHECK(std::abs(minimum_energy(all_lyts) - 0) < 0.00000001); } SECTION("layout with one SiDB placed") @@ -45,12 +46,11 @@ TEMPLATE_TEST_CASE( const charge_distribution_surface charge_layout{lyt}; std::vector> all_lyts{}; - CHECK_THAT(minimum_energy(all_lyts).value(), - Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); + CHECK_THAT(minimum_energy(all_lyts), Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); all_lyts.push_back(charge_layout); - CHECK(units::math::abs(minimum_energy(all_lyts) - 0_eV) < 0.00000001_eV); + CHECK(std::abs(minimum_energy(all_lyts) - 0) < 0.00000001); } SECTION("layout with three SiDBs placed") @@ -62,8 +62,7 @@ TEMPLATE_TEST_CASE( charge_distribution_surface charge_layout_first{lyt}; std::vector> all_lyts{}; - CHECK_THAT(minimum_energy(all_lyts).value(), - Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); + CHECK_THAT(minimum_energy(all_lyts), Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); charge_layout_first.assign_charge_state({0, 0}, sidb_charge_state::NEUTRAL); @@ -80,6 +79,6 @@ TEMPLATE_TEST_CASE( charge_layout_second.recompute_system_energy(); all_lyts.push_back(charge_layout_second); - CHECK_THAT(minimum_energy(all_lyts).value(), Catch::Matchers::WithinAbs(0.0, 0.00001)); + CHECK_THAT(minimum_energy(all_lyts), Catch::Matchers::WithinAbs(0.0, 0.00001)); } } diff --git a/test/algorithms/simulation/sidb/occupation_probability_of_excited_states.cpp b/test/algorithms/simulation/sidb/occupation_probability_of_excited_states.cpp index d49be7e38..79d8380fc 100644 --- a/test/algorithms/simulation/sidb/occupation_probability_of_excited_states.cpp +++ b/test/algorithms/simulation/sidb/occupation_probability_of_excited_states.cpp @@ -16,94 +16,94 @@ TEST_CASE("occupation probability of all erroneous charge distribution states", { const sidb_energy_and_state_type energy_and_state_type{}; - CHECK(occupation_probability_gate_based(energy_and_state_type, 10_K) == 0.0); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01_K) == 0.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 10) == 0.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01) == 0.0); - const sidb_energy_distribution distribution{{0.1_eV, 2}}; + const sidb_energy_distribution distribution{{0.1, 2}}; - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10.0_K), 6) == 0.0); - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 0.01_K), 6) == 0.0); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10.0), 6) == 0.0); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 0.01), 6) == 0.0); } SECTION("one state with degeneracy") { sidb_energy_and_state_type energy_and_state_type{}; - energy_and_state_type.emplace_back(0.1_eV, true); - energy_and_state_type.emplace_back(0.1_eV, false); + energy_and_state_type.emplace_back(0.1, true); + energy_and_state_type.emplace_back(0.1, false); - CHECK(occupation_probability_gate_based(energy_and_state_type, 10_K) == 0.5); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01_K) == 0.5); + CHECK(occupation_probability_gate_based(energy_and_state_type, 10) == 0.5); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01) == 0.5); - const sidb_energy_distribution distribution{{0.1_eV, 2}}; + const sidb_energy_distribution distribution{{0.1, 2}}; - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10_K), 6) == 0); - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 0.01_K), 6) == 0); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10), 6) == 0); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 0.01), 6) == 0); } SECTION("a few states with degeneracy") { sidb_energy_and_state_type energy_and_state_type{}; - energy_and_state_type.emplace_back(0.1_eV, true); - energy_and_state_type.emplace_back(0.1_eV, false); + energy_and_state_type.emplace_back(0.1, true); + energy_and_state_type.emplace_back(0.1, false); - energy_and_state_type.emplace_back(0.2_eV, true); - energy_and_state_type.emplace_back(0.2_eV, true); + energy_and_state_type.emplace_back(0.2, true); + energy_and_state_type.emplace_back(0.2, true); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.001_K) == 0.5); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.001) == 0.5); - const sidb_energy_distribution distribution{{0.1_eV, 2}, {0.2_eV, 2}}; - CHECK(occupation_probability_non_gate_based(distribution, 0.001_K) == 0.0); + const sidb_energy_distribution distribution{{0.1, 2}, {0.2, 2}}; + CHECK(occupation_probability_non_gate_based(distribution, 0.001) == 0.0); - CHECK(round_to_n_decimal_places(occupation_probability_gate_based(energy_and_state_type, 10E10_K), 6) == 0.25); - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10E10_K), 6) == 0.5); + CHECK(round_to_n_decimal_places(occupation_probability_gate_based(energy_and_state_type, 10E10), 6) == 0.25); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10E10), 6) == 0.5); } SECTION("a few states with degeneracy, different oder of the energy_distribution_transparent_erroneous entries") { sidb_energy_and_state_type energy_and_state_type{}; - energy_and_state_type.emplace_back(0.2_eV, true); - energy_and_state_type.emplace_back(0.2_eV, true); + energy_and_state_type.emplace_back(0.2, true); + energy_and_state_type.emplace_back(0.2, true); - energy_and_state_type.emplace_back(0.1_eV, true); - energy_and_state_type.emplace_back(0.1_eV, false); + energy_and_state_type.emplace_back(0.1, true); + energy_and_state_type.emplace_back(0.1, false); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.001_K) == 0.5); - const sidb_energy_distribution distribution{{0.2_eV, 2}, {0.1_eV, 2}}; - CHECK(occupation_probability_non_gate_based(distribution, 0.001_K) == 0.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.001) == 0.5); + const sidb_energy_distribution distribution{{0.2, 2}, {0.1, 2}}; + CHECK(occupation_probability_non_gate_based(distribution, 0.001) == 0.0); - CHECK(round_to_n_decimal_places(occupation_probability_gate_based(energy_and_state_type, 10E10_K), 2) == 0.25); - CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10E10_K), 6) == 0.5); + CHECK(round_to_n_decimal_places(occupation_probability_gate_based(energy_and_state_type, 10E10), 2) == 0.25); + CHECK(round_to_n_decimal_places(occupation_probability_non_gate_based(distribution, 10E10), 6) == 0.5); } SECTION("one state / true") { sidb_energy_and_state_type energy_and_state_type{}; - energy_and_state_type.emplace_back(1_eV, true); - CHECK(occupation_probability_gate_based(energy_and_state_type, 1000_K) == 0.0); - CHECK(occupation_probability_gate_based(energy_and_state_type, 10_K) == 0.0); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01_K) == 0.0); + energy_and_state_type.emplace_back(1, true); + CHECK(occupation_probability_gate_based(energy_and_state_type, 1000) == 0.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 10) == 0.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01) == 0.0); - const sidb_energy_distribution distribution{{1_eV, 1}}; + const sidb_energy_distribution distribution{{1, 1}}; - CHECK(occupation_probability_non_gate_based(distribution, 1000_K) == 0.0); - CHECK(occupation_probability_non_gate_based(distribution, 10_K) == 0.0); - CHECK(occupation_probability_non_gate_based(distribution, 0.01_K) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 1000) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 10) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 0.01) == 0.0); } SECTION("one state / false") { sidb_energy_and_state_type energy_and_state_type{}; - energy_and_state_type.emplace_back(1_eV, false); + energy_and_state_type.emplace_back(1, false); - CHECK(occupation_probability_gate_based(energy_and_state_type, 1000_K) == 1.0); - CHECK(occupation_probability_gate_based(energy_and_state_type, 10_K) == 1.0); - CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01_K) == 1.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 1000) == 1.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 10) == 1.0); + CHECK(occupation_probability_gate_based(energy_and_state_type, 0.01) == 1.0); - const sidb_energy_distribution distribution{{1_eV, 1}}; + const sidb_energy_distribution distribution{{1, 1}}; - CHECK(occupation_probability_non_gate_based(distribution, 1000_K) == 0.0); - CHECK(occupation_probability_non_gate_based(distribution, 10_K) == 0.0); - CHECK(occupation_probability_non_gate_based(distribution, 0.01_K) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 1000) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 10) == 0.0); + CHECK(occupation_probability_non_gate_based(distribution, 0.01) == 0.0); } } diff --git a/test/algorithms/simulation/sidb/quicksim.cpp b/test/algorithms/simulation/sidb/quicksim.cpp index 922b0a14b..c1202a678 100644 --- a/test/algorithms/simulation/sidb/quicksim.cpp +++ b/test/algorithms/simulation/sidb/quicksim.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include using namespace fiction; @@ -19,9 +19,9 @@ TEMPLATE_TEST_CASE("Empty layout QuickSim simulation", "[quicksim]", { TestType lyt{{20, 10}}; - const quicksim_params quicksim_params{sidb_simulation_parameters{2, -0.30_eV}}; + const quicksim_params quicksim_params{sidb_simulation_parameters{2, -0.30}}; - REQUIRE(quicksim_params.phys_params.mu == -0.30_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.30); const auto simulation_results = quicksim(lyt, quicksim_params); @@ -42,9 +42,9 @@ TEMPLATE_TEST_CASE("Single SiDB QuickSim simulation", "[quicksim]", lyt.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL); - const quicksim_params quicksim_params{sidb_simulation_parameters{2, -0.30_eV}}; + const quicksim_params quicksim_params{sidb_simulation_parameters{2, -0.30}}; - REQUIRE(quicksim_params.phys_params.mu == -0.30_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.30); const auto simulation_results = quicksim(lyt, quicksim_params); @@ -83,11 +83,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of several SiDBs with varying thread cou lyt.assign_cell_type({6, 10, 0}, TestType::cell_type::NORMAL); lyt.assign_cell_type({7, 10, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.30_eV}; + const sidb_simulation_parameters params{2, -0.30}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.30_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.30); SECTION("Default settings") { @@ -157,11 +157,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of an SiDB layout comprising of 10 SiDBs lyt.assign_cell_type({15, -1, 1}, TestType::cell_type::NORMAL); lyt.assign_cell_type({17, -1, 1}, TestType::cell_type::NORMAL); ; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.32_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.32); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { @@ -186,8 +186,8 @@ TEMPLATE_TEST_CASE("QuickSim simulation of an SiDB layout comprising of 10 SiDBs CHECK(charge_lyt_first.get_charge_state({15, -1, 1}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({17, -1, 1}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), - Catch::Matchers::WithinAbs(0.479933, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.4798721334, physical_constants::POP_STABILITY_ERR)); }; SECTION("Default settings") @@ -255,11 +255,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of a Y-shape SiDB arrangement with varyi lyt.assign_cell_type({-7, 1, 1}, TestType::cell_type::NORMAL); lyt.assign_cell_type({-7, 3, 0}, TestType::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.32_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.32); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { @@ -275,8 +275,8 @@ TEMPLATE_TEST_CASE("QuickSim simulation of a Y-shape SiDB arrangement with varyi CHECK(charge_lyt_first.get_charge_state({-7, 1, 1}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({-7, 3, 0}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), - Catch::Matchers::WithinAbs(0.319219, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.3191788254, physical_constants::POP_STABILITY_ERR)); }; SECTION("Default settings") @@ -346,11 +346,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of a Y-shape SiDB OR gate with input 01 lyt.assign_cell_type({16, 1, 0}, TestType::cell_type::NORMAL); sidb_simulation_result quicksimstats{}; - const sidb_simulation_parameters params{2, -0.28_eV}; + const sidb_simulation_parameters params{2, -0.28}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.28_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.28); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { @@ -367,8 +367,8 @@ TEMPLATE_TEST_CASE("QuickSim simulation of a Y-shape SiDB OR gate with input 01 CHECK(charge_lyt_first.get_charge_state({8, 3, 0}) == sidb_charge_state::NEUTRAL); CHECK(charge_lyt_first.get_charge_state({6, 2, 0}) == sidb_charge_state::NEGATIVE); - CHECK_THAT(charge_lyt_first.get_system_energy().value(), - Catch::Matchers::WithinAbs(0.4663181, POP_STABILITY_ERR)); + CHECK_THAT(charge_lyt_first.get_system_energy(), + Catch::Matchers::WithinAbs(0.4662582096, physical_constants::POP_STABILITY_ERR)); }; SECTION("Default settings") @@ -430,11 +430,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of an SiDB BDL pair with varying thread lyt.assign_cell_type({8, 2, 0}, TestType::cell_type::NORMAL); const sidb_simulation_result quicksimstats{}; - const sidb_simulation_parameters params{2, -0.25_eV}; + const sidb_simulation_parameters params{2, -0.25}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.25_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.25); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { @@ -526,11 +526,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of an layout comprising of 13 SiDBs", "[ lyt.assign_cell_type({8, 10, 1}, TestType::cell_type::NORMAL); const sidb_simulation_result quicksimstats{}; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.32_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.32); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { @@ -630,11 +630,11 @@ TEMPLATE_TEST_CASE("QuickSim simulation of an layout comprising of 13 SiDBs, all lyt.assign_cell_type({30, 15, 0}, TestType::cell_type::NORMAL); const sidb_simulation_result quicksimstats{}; - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; quicksim_params quicksim_params{params}; - REQUIRE(quicksim_params.phys_params.mu == -0.32_eV); + REQUIRE(quicksim_params.phys_params.mu == -0.32); const auto check_charge_configuration = [](const sidb_simulation_result& stats) noexcept { diff --git a/test/algorithms/simulation/sidb/time_to_solution.cpp b/test/algorithms/simulation/sidb/time_to_solution.cpp index f9afb00b1..9d37e1ce5 100644 --- a/test/algorithms/simulation/sidb/time_to_solution.cpp +++ b/test/algorithms/simulation/sidb/time_to_solution.cpp @@ -27,7 +27,7 @@ TEMPLATE_TEST_CASE( TestType lyt{{20, 10}}; - const sidb_simulation_parameters params{2, -0.30_eV}; + const sidb_simulation_parameters params{2, -0.30}; const quicksim_params quicksim_params{params}; time_to_solution_stats tts_stat{}; @@ -38,9 +38,8 @@ TEMPLATE_TEST_CASE( sim_acc_tts(charge_layout, quicksim_params, &tts_stat); CHECK_THAT(tts_stat.acc, Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(tts_stat.time_to_solution.value(), - Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); - CHECK(tts_stat.mean_single_runtime.value() > 0.0); + CHECK_THAT(tts_stat.time_to_solution, Catch::Matchers::WithinAbs(std::numeric_limits::max(), 0.00001)); + CHECK(tts_stat.mean_single_runtime > 0.0); } SECTION("layout with seven SiDBs placed") @@ -57,8 +56,8 @@ TEMPLATE_TEST_CASE( sim_acc_tts(lyt, quicksim_params, &tts_stat); - CHECK(tts_stat.acc == 100); - CHECK(tts_stat.time_to_solution.value() > 0.0); - CHECK(tts_stat.mean_single_runtime.value() > 0.0); + CHECK(tts_stat.acc > 0); + CHECK(tts_stat.time_to_solution > 0.0); + CHECK(tts_stat.mean_single_runtime > 0.0); } } diff --git a/test/io/print_layout.cpp b/test/io/print_layout.cpp index 367874fd8..328d2d453 100644 --- a/test/io/print_layout.cpp +++ b/test/io/print_layout.cpp @@ -242,7 +242,7 @@ TEST_CASE("Print Bestagon OR-gate", "[print-charge-layout]") const charge_distribution_surface cl{ convert_to_siqad_coordinates(apply_gate_library(layout)), - sidb_simulation_parameters{3, -0.32_eV}, sidb_charge_state::NEGATIVE}; + sidb_simulation_parameters{3, -0.32}, sidb_charge_state::NEGATIVE}; cl.assign_charge_state({16, 3, 0}, sidb_charge_state::NEUTRAL); cl.assign_charge_state({42, 3, 0}, sidb_charge_state::NEGATIVE); diff --git a/test/io/read_sqd_layout.cpp b/test/io/read_sqd_layout.cpp index 81a3a4ed3..7650e6ba7 100644 --- a/test/io/read_sqd_layout.cpp +++ b/test/io/read_sqd_layout.cpp @@ -154,9 +154,9 @@ TEST_CASE("Read single defect SQD layout", "[sqd]") const auto defect = layout.get_sidb_defect({5, 4}); CHECK(defect.type == sidb_defect_type::UNKNOWN); - CHECK(defect.charge == 2_e); + CHECK(defect.charge == 2); CHECK(defect.epsilon_r == 1.2); - CHECK(defect.lambda_tf == 3.4_nm); + CHECK(defect.lambda_tf == 3.4); } TEST_CASE("Read multiple defects SQD layout", "[sqd]") @@ -226,21 +226,21 @@ TEST_CASE("Read multiple defects SQD layout", "[sqd]") { const auto defect = layout.get_sidb_defect({5, 4}); CHECK(defect.type == sidb_defect_type::SILOXANE); - CHECK(defect.charge == -1_e); + CHECK(defect.charge == -1); CHECK(defect.epsilon_r == 5.6); - CHECK(defect.lambda_tf == 5.0_nm); + CHECK(defect.lambda_tf == 5.0); } { const auto defect1 = layout.get_sidb_defect({3, 4}); const auto defect2 = layout.get_sidb_defect({3, 5}); CHECK(defect1.type == sidb_defect_type::MISSING_DIMER); - CHECK(defect1.charge == -1_e); + CHECK(defect1.charge == -1); CHECK(defect1.epsilon_r == 5.6); - CHECK(defect1.lambda_tf == 5.0_nm); + CHECK(defect1.lambda_tf == 5.0); CHECK(defect2.type == sidb_defect_type::MISSING_DIMER); - CHECK(defect2.charge == -1_e); + CHECK(defect2.charge == -1); CHECK(defect2.epsilon_r == 5.6); - CHECK(defect2.lambda_tf == 5.0_nm); + CHECK(defect2.lambda_tf == 5.0); } { const auto defect1 = layout.get_sidb_defect({0, 4}); @@ -248,21 +248,21 @@ TEST_CASE("Read multiple defects SQD layout", "[sqd]") const auto defect3 = layout.get_sidb_defect({1, 4}); const auto defect4 = layout.get_sidb_defect({1, 5}); CHECK(defect1.type == sidb_defect_type::ETCH_PIT); - CHECK(defect1.charge == -1_e); + CHECK(defect1.charge == -1); CHECK(defect1.epsilon_r == 5.6); - CHECK(defect1.lambda_tf == 5.0_nm); + CHECK(defect1.lambda_tf == 5.0); CHECK(defect2.type == sidb_defect_type::ETCH_PIT); - CHECK(defect2.charge == -1_e); + CHECK(defect2.charge == -1); CHECK(defect2.epsilon_r == 5.6); - CHECK(defect2.lambda_tf == 5.0_nm); + CHECK(defect2.lambda_tf == 5.0); CHECK(defect3.type == sidb_defect_type::ETCH_PIT); - CHECK(defect3.charge == -1_e); + CHECK(defect3.charge == -1); CHECK(defect3.epsilon_r == 5.6); - CHECK(defect3.lambda_tf == 5.0_nm); + CHECK(defect3.lambda_tf == 5.0); CHECK(defect4.type == sidb_defect_type::ETCH_PIT); - CHECK(defect4.charge == -1_e); + CHECK(defect4.charge == -1); CHECK(defect4.epsilon_r == 5.6); - CHECK(defect4.lambda_tf == 5.0_nm); + CHECK(defect4.lambda_tf == 5.0); } } @@ -338,9 +338,9 @@ TEST_CASE("Read multi-dot SQD layout with multi-cell defect", "[sqd]") CHECK(defect.type == sidb_defect_type::DB); - CHECK(defect.charge == -1_e); + CHECK(defect.charge == -1); CHECK(defect.epsilon_r == 5.6); - CHECK(defect.lambda_tf == 5.0_nm); + CHECK(defect.lambda_tf == 5.0); }); } @@ -442,9 +442,9 @@ TEST_CASE("Read SQD defect despite missing element", "[sqd]") CHECK(defect.type == sidb_defect_type::UNKNOWN); - CHECK(defect.charge == 0.0_e); + CHECK(defect.charge == 0.0); CHECK(defect.epsilon_r == 0.0); - CHECK(defect.lambda_tf == 0.0_nm); + CHECK(defect.lambda_tf == 0.0); } TEST_CASE("SQD parsing error: missing element", "[sqd]") diff --git a/test/io/write_sqd_sim_result.cpp b/test/io/write_sqd_sim_result.cpp index 753fae93b..17ff691ba 100644 --- a/test/io/write_sqd_sim_result.cpp +++ b/test/io/write_sqd_sim_result.cpp @@ -184,8 +184,8 @@ TEST_CASE("Write empty simulation result", "[sqd-sim-result]") " \n" "\n", FICTION_VERSION, FICTION_REPO, fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(std::time(nullptr))), - sim_result.physical_parameters.lambda_tf.to(), sim_result.physical_parameters.epsilon_r, - sim_result.physical_parameters.mu.to()); + sim_result.physical_parameters.lambda_tf, sim_result.physical_parameters.epsilon_r, + sim_result.physical_parameters.mu); write_sqd_sim_result(sim_result, simulation_stream); @@ -219,8 +219,8 @@ TEST_CASE("Write empty simulation result", "[sqd-sim-result]") " \n" "\n", FICTION_VERSION, FICTION_REPO, fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(std::time(nullptr))), - sim_result.physical_parameters.lambda_tf.value(), sim_result.physical_parameters.epsilon_r, - sim_result.physical_parameters.mu.value()); + sim_result.physical_parameters.lambda_tf, sim_result.physical_parameters.epsilon_r, + sim_result.physical_parameters.mu); sim_result.additional_simulation_parameters.emplace_back("param1", "value1"); sim_result.additional_simulation_parameters.emplace_back("param2", 2); @@ -251,7 +251,7 @@ TEST_CASE("Write simulation result with ExGS simulation", "[sqd-sim-result]") lyt.assign_cell_type({17, 0, 0}, sidb_layout::cell_type::NORMAL); lyt.assign_cell_type({19, 0, 0}, sidb_layout::cell_type::NORMAL); - const sidb_simulation_parameters params{2, -0.32_eV}; + const sidb_simulation_parameters params{2, -0.32}; auto sim_result = exhaustive_ground_state_simulation(lyt, params); @@ -285,13 +285,13 @@ TEST_CASE("Write simulation result with ExGS simulation", "[sqd-sim-result]") " \n" " \n" " \n" - " -0-0-0-\n" " \n" "\n", FICTION_VERSION, FICTION_REPO, fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(std::time(nullptr))), - sim_result.simulation_runtime.count(), sim_result.physical_parameters.lambda_tf.value(), - sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu.value()); + sim_result.simulation_runtime.count(), sim_result.physical_parameters.lambda_tf, + sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu); write_sqd_sim_result(sim_result, simulation_stream); @@ -310,7 +310,7 @@ TEST_CASE("Write simulation result with ExGS simulation and positive DBs", "[sqd lyt.assign_cell_type({6, 0, 0}, sidb_layout::cell_type::NORMAL); lyt.assign_cell_type({7, 0, 0}, sidb_layout::cell_type::NORMAL); - const sidb_simulation_parameters params{3, -0.32_eV}; + const sidb_simulation_parameters params{3, -0.32}; auto sim_result = exhaustive_ground_state_simulation(lyt, params); @@ -339,13 +339,13 @@ TEST_CASE("Write simulation result with ExGS simulation and positive DBs", "[sqd " \n" " \n" " \n" - " -+-\n" + " -+-\n" " 0-0\n" " \n" "\n", FICTION_VERSION, FICTION_REPO, fmt::format("{:%Y-%m-%d %H:%M:%S}", fmt::localtime(std::time(nullptr))), - sim_result.simulation_runtime.count(), sim_result.physical_parameters.lambda_tf.value(), - sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu.value()); + sim_result.simulation_runtime.count(), sim_result.physical_parameters.lambda_tf, + sim_result.physical_parameters.epsilon_r, sim_result.physical_parameters.mu); write_sqd_sim_result(sim_result, simulation_stream); diff --git a/test/technology/charge_distribution_surface.cpp b/test/technology/charge_distribution_surface.cpp index 53e2a4ed0..261c05ab3 100644 --- a/test/technology/charge_distribution_surface.cpp +++ b/test/technology/charge_distribution_surface.cpp @@ -124,13 +124,12 @@ TEMPLATE_TEST_CASE( charge_layout.set_all_charge_states(sidb_charge_state::POSITIVE); // calculate potential between two sidbs (charge sign not included) - CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 5}).value() > 0.0); - CHECK_THAT(charge_layout.potential_between_sidbs({5, 4}, {5, 4}).value(), - Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 6}).value() > 0); - CHECK(charge_layout.potential_between_sidbs({5, 5}, {5, 6}).value() > 0); - CHECK_THAT(charge_layout.potential_between_sidbs({5, 6}, {5, 5}).value() - - charge_layout.potential_between_sidbs({5, 5}, {5, 6}).value(), + CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 5}) > 0.0); + CHECK_THAT(charge_layout.potential_between_sidbs({5, 4}, {5, 4}), Catch::Matchers::WithinAbs(0.0, 0.00001)); + CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 6}) > 0); + CHECK(charge_layout.potential_between_sidbs({5, 5}, {5, 6}) > 0); + CHECK_THAT(charge_layout.potential_between_sidbs({5, 6}, {5, 5}) - + charge_layout.potential_between_sidbs({5, 5}, {5, 6}), Catch::Matchers::WithinAbs(0.0, 0.00001)); // read SiDBs' charge states CHECK(charge_layout.get_charge_state({5, 4}) == sidb_charge_state::POSITIVE); @@ -193,21 +192,20 @@ TEMPLATE_TEST_CASE( charge_distribution_surface charge_layout{lyt, sidb_simulation_parameters{}}; - CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {0, 0, 0}).value(), + CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {0, 0, 0}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {1, 0, 0}).value(), - Catch::Matchers::WithinAbs((sidb_simulation_parameters{}.lat_a * 0.1).value(), 0.00001)); - CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 0, 0}, {0, 0, 0}).value(), - Catch::Matchers::WithinAbs((sidb_simulation_parameters{}.lat_a * 0.1).value(), 0.00001)); - CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 0, 0}, {1, 0, 0}).value(), + CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {1, 0, 0}), + Catch::Matchers::WithinAbs((sidb_simulation_parameters{}.lat_a * 0.1), 0.00001)); + CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 0, 0}, {0, 0, 0}), + Catch::Matchers::WithinAbs((sidb_simulation_parameters{}.lat_a * 0.1), 0.00001)); + CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 0, 0}, {1, 0, 0}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {1, 1, 1}).value(), - Catch::Matchers::WithinAbs(units::math::hypot(sidb_simulation_parameters{}.lat_a * 0.1, - sidb_simulation_parameters{}.lat_b * 0.1 + - sidb_simulation_parameters{}.lat_c * 0.1) - .value(), - 0.00001)); - CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 1, 1}, {1, 1, 1}).value(), + CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {1, 1, 1}), + Catch::Matchers::WithinAbs( + std::hypot(sidb_simulation_parameters{}.lat_a * 0.1, + sidb_simulation_parameters{}.lat_b * 0.1 + sidb_simulation_parameters{}.lat_c * 0.1), + 0.00001)); + CHECK_THAT(charge_layout.get_nm_distance_between_cells({1, 1, 1}, {1, 1, 1}), Catch::Matchers::WithinAbs(0.0, 0.00001)); } @@ -219,18 +217,18 @@ TEMPLATE_TEST_CASE( charge_distribution_surface charge_layout{lyt, sidb_simulation_parameters{}}; - CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({2, 8, 0}, {2, 10, 1}).value(), + CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({2, 8, 0}, {2, 10, 1}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({0, 0, 0}, {0, 0, 0}).value(), + CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({0, 0, 0}, {0, 0, 0}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 8, 0}, {1, 8, 0}).value(), + CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 8, 0}, {1, 8, 0}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 10, 1}, {1, 10, 1}).value(), + CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 10, 1}, {1, 10, 1}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 8, 0}, {0, 0, 0}).value(), + CHECK_THAT(charge_layout.get_chargeless_potential_between_sidbs({1, 8, 0}, {0, 0, 0}), Catch::Matchers::WithinAbs(0.0121934043, 0.00001)); - CHECK_THAT(std::abs(charge_layout.get_chargeless_potential_between_sidbs({0, 0, 0}, {1, 10, 1}).value() - - charge_layout.get_chargeless_potential_between_sidbs({1, 10, 1}, {0, 0, 0}).value()), + CHECK_THAT(std::abs(charge_layout.get_chargeless_potential_between_sidbs({0, 0, 0}, {1, 10, 1}) - + charge_layout.get_chargeless_potential_between_sidbs({1, 10, 1}, {0, 0, 0})), Catch::Matchers::WithinAbs(0.0, 0.00001)); CHECK(charge_layout.get_chargeless_potential_between_sidbs({0, 0, 0}, {1, 8, 0}) > @@ -254,7 +252,7 @@ TEMPLATE_TEST_CASE( { const auto p = charge_layout.get_local_potential(c); REQUIRE(p.has_value()); - CHECK(*p > units::voltage::volt_t(0.0)); + CHECK(*p > 0.0); }); charge_layout.assign_charge_state({0, 0, 0}, sidb_charge_state::NEGATIVE); @@ -268,7 +266,7 @@ TEMPLATE_TEST_CASE( { const auto p = charge_layout.get_local_potential(c); REQUIRE(p.has_value()); - CHECK(*p < units::voltage::volt_t(0.0)); + CHECK(*p < 0.0); }); charge_layout.set_all_charge_states(sidb_charge_state::NEUTRAL); @@ -280,7 +278,7 @@ TEMPLATE_TEST_CASE( { const auto p = charge_layout.get_local_potential(c); REQUIRE(p.has_value()); - CHECK_THAT((*p).value(), Catch::Matchers::WithinAbs(0.0, 0.00001)); + CHECK_THAT((*p), Catch::Matchers::WithinAbs(0.0, 0.00001)); }); } @@ -299,19 +297,19 @@ TEMPLATE_TEST_CASE( // system energy is zero when all SiDBs are positively charged. charge_layout.update_local_potential(); charge_layout.recompute_system_energy(); - CHECK(charge_layout.get_system_energy() > units::energy::electron_volt_t(0)); + CHECK(charge_layout.get_system_energy() > 0.0); // system energy is zero when all SiDBs are neutrally charged. charge_layout.set_all_charge_states(sidb_charge_state::NEUTRAL); charge_layout.update_local_potential(); charge_layout.recompute_system_energy(); - CHECK_THAT(charge_layout.get_system_energy().value(), Catch::Matchers::WithinAbs(0.0, 0.00001)); + CHECK_THAT(charge_layout.get_system_energy(), Catch::Matchers::WithinAbs(0.0, 0.00001)); // system energy is zero when all SiDBs are positively charged. charge_layout.set_all_charge_states(sidb_charge_state::POSITIVE); charge_layout.update_local_potential(); charge_layout.recompute_system_energy(); - CHECK(charge_layout.get_system_energy() > units::energy::electron_volt_t(0)); + CHECK(charge_layout.get_system_energy() > 0.0); } SECTION("Physical validity check, far distance of SIDBs, all NEGATIVE") @@ -380,7 +378,7 @@ TEMPLATE_TEST_CASE( SECTION("increase charge index") { TestType lyt_new{{11, 11}}; - const sidb_simulation_parameters params{3, units::energy::electron_volt_t(-0.32)}; + const sidb_simulation_parameters params{3, -0.32}; lyt_new.assign_cell_type({0, 0, 1}, TestType::cell_type::NORMAL); lyt_new.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL); @@ -417,12 +415,7 @@ TEMPLATE_TEST_CASE( SECTION("using chargeless and normal potential function") { TestType lyt_new{{11, 11}}; - const sidb_simulation_parameters params{3, - units::energy::electron_volt_t(-0.32), - 5.0, - units::length::angstrom_t(3.84), - units::length::angstrom_t(7.68), - units::length::angstrom_t(2.25)}; + const sidb_simulation_parameters params{3, -0.32, 5.0, 3.84, 7.68, 2.25}; lyt_new.assign_cell_type({0, 0, 1}, TestType::cell_type::NORMAL); lyt_new.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL); @@ -438,25 +431,22 @@ TEMPLATE_TEST_CASE( CHECK(charge_layout_new.get_charge_state({1, 3, 0}) == sidb_charge_state::POSITIVE); CHECK(charge_layout_new.get_charge_state({10, 5, 1}) == sidb_charge_state::NEUTRAL); - CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > - units::voltage::volt_t(0)); - CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > units::voltage::volt_t(0)); + CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0); + CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0); - CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {10, 5, 1}) > - units::voltage::volt_t(0)); - CHECK_THAT(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {10, 5, 1}).value(), + CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {10, 5, 1}) > 0.0); + CHECK_THAT(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {10, 5, 1}), Catch::Matchers::WithinAbs(0.0, 0.000001)); - CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({10, 5, 1}, {0, 0, 1}) > - units::voltage::volt_t(0)); - CHECK(charge_layout_new.get_potential_between_sidbs({10, 5, 1}, {0, 0, 1}) < units::voltage::volt_t(0)); + CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({10, 5, 1}, {0, 0, 1}) > 0.0); + CHECK(charge_layout_new.get_potential_between_sidbs({10, 5, 1}, {0, 0, 1}) < 0.0); - CHECK_THAT(charge_layout_new.get_potential_between_sidbs({10, 5, 1}, {0, 0, 1}).value() + - charge_layout_new.get_chargeless_potential_between_sidbs({10, 5, 1}, {0, 0, 1}).value(), + CHECK_THAT(charge_layout_new.get_potential_between_sidbs({10, 5, 1}, {0, 0, 1}) + + charge_layout_new.get_chargeless_potential_between_sidbs({10, 5, 1}, {0, 0, 1}), Catch::Matchers::WithinAbs(0.0, 0.000001)); - CHECK_THAT(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}).value() - - charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}).value(), + CHECK_THAT(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) - + charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}), Catch::Matchers::WithinAbs(0.0, 0.000001)); } } diff --git a/test/technology/sidb_defects.cpp b/test/technology/sidb_defects.cpp index a36ea5d79..b1fe8b171 100644 --- a/test/technology/sidb_defects.cpp +++ b/test/technology/sidb_defects.cpp @@ -68,22 +68,17 @@ TEST_CASE("Defect extent", "[sidb-defects]") TEST_CASE("Test for units", "[sidb-defects]") { const sidb_defect defect{sidb_defect_type::NONE}; - CHECK(defect.charge == 0_e); + CHECK(defect.charge == 0); CHECK(defect.epsilon_r == 0); - CHECK(defect.lambda_tf == 0.0_nm); + CHECK(defect.lambda_tf == 0.0); - const sidb_defect defect_two{sidb_defect_type::NONE, 2_e}; - CHECK(defect_two.charge == 2_e); + const sidb_defect defect_two{sidb_defect_type::NONE, 2}; + CHECK(defect_two.charge == 2); CHECK(defect_two.epsilon_r == 0); - CHECK(defect_two.lambda_tf == 0.0_nm); + CHECK(defect_two.lambda_tf == 0.0); - const sidb_defect defect_three{sidb_defect_type::NONE, 2_e, 5}; - CHECK(defect_three.charge == 2_e); + const sidb_defect defect_three{sidb_defect_type::NONE, 2, 5}; + CHECK(defect_three.charge == 2); CHECK(defect_three.epsilon_r == 5); - CHECK(defect_three.lambda_tf == 0.0_nm); - - const sidb_defect defect_four{sidb_defect_type::NONE, 6'242'000'000'000'000'000_e, 5.4, 4.2_nm}; - CHECK(defect_four.charge == units::charge::coulomb_t{1}); - CHECK(defect_four.epsilon_r == 5.4); - CHECK(defect_four.lambda_tf == 4.2_nm); + CHECK(defect_three.lambda_tf == 0.0); } diff --git a/test/utils/math_utils.cpp b/test/utils/math_utils.cpp index 3a5c4b1b3..0f09e6ae0 100644 --- a/test/utils/math_utils.cpp +++ b/test/utils/math_utils.cpp @@ -3,13 +3,9 @@ // #include -#include #include -#include -#include - using namespace fiction; TEST_CASE("round_to_n_decimal_places should round an input number to n decimal places", "[round_to_n_decimal_places]") @@ -51,74 +47,6 @@ TEST_CASE("round_to_n_decimal_places should round an input number to n decimal p CHECK(round_to_n_decimal_places(-0.000001, 6) == -0.000001); CHECK(round_to_n_decimal_places(-0.0000001, 6) == 0); } - - SECTION("Round Kelvin") - { - const auto value_positive = 3.145926_K; - CHECK(round_to_n_decimal_places(value_positive, 0) == 3_K); - CHECK(round_to_n_decimal_places(value_positive, 1) == 3.1_K); - CHECK(round_to_n_decimal_places(value_positive, 2) == 3.15_K); - CHECK(round_to_n_decimal_places(value_positive, 3) == 3.146_K); - CHECK(round_to_n_decimal_places(value_positive, 4) == 3.1459_K); - CHECK(round_to_n_decimal_places(value_positive, 5) == 3.14593_K); - CHECK(round_to_n_decimal_places(value_positive, 6) == 3.145926_K); - CHECK(round_to_n_decimal_places(1.005_K, 2) == 1.0_K); - CHECK(round_to_n_decimal_places(0.000001_K, 6) == 0.000001_K); - CHECK(round_to_n_decimal_places(0.0000001_K, 6) == 0_K); - CHECK(round_to_n_decimal_places(-0.000001_K, 6) == -0.000001_K); - CHECK(round_to_n_decimal_places(-0.0000001_K, 6) == 0_K); - } - - SECTION("Round length") - { - const auto value_positive = 3.145926_nm; - CHECK(round_to_n_decimal_places(value_positive, 0) == 3_nm); - CHECK(round_to_n_decimal_places(value_positive, 1) == 3.1_nm); - CHECK(round_to_n_decimal_places(value_positive, 2) == 3.15_nm); - CHECK(round_to_n_decimal_places(value_positive, 3) == 3.146_nm); - CHECK(round_to_n_decimal_places(value_positive, 4) == 3.1459_nm); - CHECK(round_to_n_decimal_places(value_positive, 5) == 3.14593_nm); - CHECK(round_to_n_decimal_places(value_positive, 6) == 3.145926_nm); - CHECK(round_to_n_decimal_places(1.005_nm, 2) == 1.0_nm); - CHECK(round_to_n_decimal_places(0.000001_nm, 6) == 0.000001_nm); - CHECK(round_to_n_decimal_places(0.0000001_nm, 6) == 0_nm); - CHECK(round_to_n_decimal_places(-0.000001_nm, 6) == -0.000001_nm); - CHECK(round_to_n_decimal_places(-0.0000001_nm, 6) == 0_nm); - } - - SECTION("Round voltage") - { - const auto value_positive = 3.145926_V; - CHECK(round_to_n_decimal_places(value_positive, 0) == 3_V); - CHECK(round_to_n_decimal_places(value_positive, 1) == 3.1_V); - CHECK(round_to_n_decimal_places(value_positive, 2) == 3.15_V); - CHECK(round_to_n_decimal_places(value_positive, 3) == 3.146_V); - CHECK(round_to_n_decimal_places(value_positive, 4) == 3.1459_V); - CHECK(round_to_n_decimal_places(value_positive, 5) == 3.14593_V); - CHECK(round_to_n_decimal_places(value_positive, 6) == 3.145926_V); - CHECK(round_to_n_decimal_places(1.005_V, 2) == 1.0_V); - CHECK(round_to_n_decimal_places(0.000001_V, 6) == 0.000001_V); - CHECK(round_to_n_decimal_places(0.0000001_V, 6) == 0_V); - CHECK(round_to_n_decimal_places(-0.000001_V, 6) == -0.000001_V); - CHECK(round_to_n_decimal_places(-0.0000001_V, 6) == 0_V); - } - - SECTION("Round energy") - { - const auto value_positive = 3.145926_eV; - CHECK(round_to_n_decimal_places(value_positive, 0) == 3_eV); - CHECK(round_to_n_decimal_places(value_positive, 1) == 3.1_eV); - CHECK(round_to_n_decimal_places(value_positive, 2) == 3.15_eV); - CHECK(round_to_n_decimal_places(value_positive, 3) == 3.146_eV); - CHECK(round_to_n_decimal_places(value_positive, 4) == 3.1459_eV); - CHECK(round_to_n_decimal_places(value_positive, 5) == 3.14593_eV); - CHECK(round_to_n_decimal_places(value_positive, 6) == 3.145926_eV); - CHECK(round_to_n_decimal_places(1.005_eV, 2) == 1.0_eV); - CHECK(round_to_n_decimal_places(0.000001_eV, 6) == 0.000001_eV); - CHECK(round_to_n_decimal_places(0.0000001_eV, 6) == 0_eV); - CHECK(round_to_n_decimal_places(-0.000001_eV, 6) == -0.000001_eV); - CHECK(round_to_n_decimal_places(-0.0000001_eV, 6) == 0_eV); - } } TEMPLATE_TEST_CASE("integral_abs should compute the absolute value of a number of different integral types", From ce63b2d49518f2758cba49b496fd10aaa0557ff9 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 25 Jul 2023 16:25:53 +0200 Subject: [PATCH 4/6] :art: implement Marcel's suggestions. --- .../simulation/sidb/critical_temperature.hpp | 6 +- .../simulation/sidb/energy_distribution.hpp | 8 +- ...cupation_probability_of_excited_states.hpp | 8 +- .../sidb/sidb_simulation_parameters.hpp | 2 +- .../charge_distribution_surface.hpp | 78 +++++++++---------- include/fiction/technology/sidb_defects.hpp | 10 +-- include/fiction/utils/math_utils.hpp | 3 +- .../charge_distribution_surface.cpp | 13 ++-- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp index a5283fc7d..5d9d84cd7 100644 --- a/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp +++ b/include/fiction/algorithms/simulation/sidb/critical_temperature.hpp @@ -95,7 +95,7 @@ struct critical_temperature_params */ double confidence_level{0.99}; /** - * Simulation stops at max_temperature (~ 126 °C by default). + * Simulation stops at max_temperature (~ 126 °C by default) (unit: K). */ double max_temperature{400}; /** @@ -326,7 +326,7 @@ class critical_temperature_impl (first_excited_state_energy - ground_state_energy) * 1000; } - std::vector temp_values{}; + std::vector temp_values{}; // unit: K temp_values.reserve(static_cast(parameter.max_temperature * 100)); for (uint64_t i = 1; i <= static_cast(parameter.max_temperature * 100); i++) @@ -363,7 +363,7 @@ class critical_temperature_impl * * @param energy_and_state_type All energies of all physically valid charge distributions with the corresponding * state type (i.e. transparent, erroneous). - * @param min_energy Minimal energy of all physically valid charge distributions of a given layout. + * @param min_energy Minimal energy of all physically valid charge distributions of a given layout (unit: eV). * @return State type (i.e. transparent, erroneous) of the ground state is returned. */ bool energy_between_ground_state_and_first_erroneous(const sidb_energy_and_state_type& energy_and_state_type, diff --git a/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp b/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp index 750b16981..19b7059a2 100644 --- a/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp +++ b/include/fiction/algorithms/simulation/sidb/energy_distribution.hpp @@ -17,10 +17,10 @@ namespace fiction { /** - * Data type to collect electrostatic potential energies of charge distributions with corresponding degeneracy (i.e. - * how often a certain energy value occurs). + * Data type to collect electrostatic potential energies (unit: eV) of charge distributions with corresponding + * degeneracy (i.e. how often a certain energy value occurs). */ -using sidb_energy_distribution = std::map; +using sidb_energy_distribution = std::map; // unit: (eV, unitless) /** * This function takes in a vector of charge_distribution_surface objects and returns a map containing the system energy @@ -38,7 +38,7 @@ energy_distribution(const std::vector>& input_v static_assert(is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(has_sidb_technology_v, "Lyt is not an SiDB layout"); - std::map distribution{}; + std::map distribution{}; // unit: (eV, unitless) for (const auto& lyt : input_vec) { diff --git a/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp b/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp index 1190ad021..159f5e181 100644 --- a/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp +++ b/include/fiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp @@ -39,7 +39,7 @@ namespace fiction return 0.0; } - auto min_energy = std::numeric_limits::infinity(); + auto min_energy = std::numeric_limits::infinity(); // unit: eV // Determine the minimal energy. const auto [energy, state_type] = *std::min_element(energy_and_state_type.cbegin(), energy_and_state_type.cend(), @@ -71,8 +71,8 @@ namespace fiction * This function computes the occupation probability of excited states (charge distributions with energy higher than the * ground state) at a given temperature. * - * @param energy_distribution This contains the energies of all possible charge distributions with the degeneracy. - * @param temperature System temperature to assume. + * @param energy_distribution This contains the energies in eV of all possible charge distributions with the degeneracy. + * @param temperature System temperature to assume (unit: K). * @return The total occupation probability of all excited states is returned. */ [[nodiscard]] inline double occupation_probability_non_gate_based(const sidb_energy_distribution& energy_distribution, @@ -88,7 +88,7 @@ namespace fiction auto min_energy = std::numeric_limits::infinity(); const auto& [energy, degeneracy] = *(energy_distribution.begin()); - min_energy = energy; + min_energy = energy; // unit: eV // The partition function is obtained by summing up all the Boltzmann factors. const double partition_function = diff --git a/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp b/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp index 04c30e436..5b2eea01e 100644 --- a/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp +++ b/include/fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp @@ -24,7 +24,7 @@ struct sidb_simulation_parameters * * @param base_number simulation can be conducted with 2 and 3 charge states. 2 = (Negative, Neutral), 3 = * (Negative, Neutral, Positive). - * @param mu_minus it is the energy transition level (0/-). + * @param mu_minus it is the energy transition level (0/-) in eV. * @param relative_permittivity it describes the electric field reduction due to polarization. * @param screening_distance also known as "Thomas-Fermi screening" and it describes the electric field screening * due to free charges in nm. diff --git a/include/fiction/technology/charge_distribution_surface.hpp b/include/fiction/technology/charge_distribution_surface.hpp index 63ae3837f..08d720165 100644 --- a/include/fiction/technology/charge_distribution_surface.hpp +++ b/include/fiction/technology/charge_distribution_surface.hpp @@ -59,15 +59,15 @@ class charge_distribution_surface : public Lyt { private: /** - * The distance matrix is a vector of vectors storing the euclidean distance. + * The distance matrix is a vector of vectors storing the euclidean distance in nm. */ using distance_matrix = std::vector>; /** - * The potential matrix is a vector of vectors storing the electrostatic potentials. + * The potential matrix is a vector of vectors storing the chargless electrostatic potentials in Volt (V). */ using potential_matrix = std::vector>; /** - * It is a vector that stores the local electrostatic potential. + * It is a vector that stores the local electrostatic potential in Volt (V). */ using local_potential = std::vector; @@ -446,6 +446,22 @@ class charge_distribution_surface : public Lyt std::exp(-strg->nm_dist_mat[index1][index2] / strg->phys_params.lambda_tf) * physical_constants::ELEMENTARY_CHARGE); } + /** + * Calculates and returns the chargeless potential of a pair of cells based on their distance and simulation + * parameters. + * + * @param c1 The first cell. + * @param c2 The second cell. + * @return The potential between c1 and c2 (unit: eV). + */ + [[nodiscard]] double chargeless_potential_between_sidbs(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept + { + const auto index1 = static_cast(cell_to_index(c1)); + const auto index2 = static_cast(cell_to_index(c2)); + + return chargeless_potential_between_sidbs_by_index(index1, index2); + } /** * Returns the chargeless electrostatic potential between two cells. * @@ -454,7 +470,7 @@ class charge_distribution_surface : public Lyt * * @param c1 The first cell. * @param c2 The second cell. - * @return The chargeless electrostatic potential between `c1` and `c2`, i.e, \f$ \frac{V_{i,j}}{n_j} \f$. + * @return The chargeless electrostatic potential between `c1` and `c2`, i.e, \f$ \frac{V_{i,j}}{n_j} \f$ (unit: V). */ [[nodiscard]] double get_chargeless_potential_between_sidbs(const typename Lyt::cell& c1, const typename Lyt::cell& c2) const noexcept @@ -466,6 +482,17 @@ class charge_distribution_surface : public Lyt return 0.0; } + /** + * Calculates and returns the potential of two indices. + * + * @param index1 The first index. + * @param index2 The second index. + * @return The potential between `index1` and `index2` (unit: V). + */ + [[nodiscard]] double get_chargless_potential_by_indices(const uint64_t index1, const uint64_t index2) const noexcept + { + return strg->pot_mat[index1][index2]; + } /** * Calculates and returns the electrostatic potential at one cell (`c1`) generated by another cell (`c2`). * @@ -474,7 +501,7 @@ class charge_distribution_surface : public Lyt * * @param c1 The first cell. * @param c2 The second cell. - * @return The electrostatic potential between `c1` and `c2`, i.e., \f$ V_{i,j} \f$. + * @return The electrostatic potential between `c1` and `c2`, i.e., \f$ V_{i,j} \f$ (unit: V). */ [[nodiscard]] double get_potential_between_sidbs(const typename Lyt::cell& c1, const typename Lyt::cell& c2) const noexcept @@ -487,33 +514,6 @@ class charge_distribution_surface : public Lyt return 0.0; } - /** - * Calculates and returns the potential of two indices. - * - * @param index1 The first index. - * @param index2 The second index. - * @return The potential between `index1` and `index2`. - */ - [[nodiscard]] double get_electrostatic_potential_by_indices(const uint64_t index1, - const uint64_t index2) const noexcept - { - return strg->pot_mat[index1][index2]; - } - /** - * Calculates and returns the potential of a pair of cells based on their distance and simulation parameters. - * - * @param c1 The first cell. - * @param c2 The second cell. - * @return The potential between c1 and c2. - */ - [[nodiscard]] double potential_between_sidbs(const typename Lyt::cell& c1, - const typename Lyt::cell& c2) const noexcept - { - const auto index1 = static_cast(cell_to_index(c1)); - const auto index2 = static_cast(cell_to_index(c2)); - - return chargeless_potential_between_sidbs_by_index(index1, index2); - } /** * The function calculates the electrostatic potential for each SiDB position (local). */ @@ -533,11 +533,11 @@ class charge_distribution_surface : public Lyt } } /** - * The function returns the local electrostatic potential at a given SiDB position. + * The function returns the local electrostatic potential at a given SiDB position in V. * * @param c The cell defining the SiDB position. * @return Local potential at given cell position. If there is no SiDB at the given cell, `std::nullopt` is - * returned. + * returned (unit: V). */ std::optional get_local_potential(const typename Lyt::cell& c) const noexcept { @@ -549,11 +549,11 @@ class charge_distribution_surface : public Lyt return std::nullopt; } /** - * The function returns the local electrostatic potential at a given index position. + * The function returns the local electrostatic potential at a given index position in V. * * @param index The index defining the SiDB position. * @return local potential at given index position. If there is no SiDB at the given index (which corresponds to a - * unique cell), `std::nullopt` is returned. + * unique cell), `std::nullopt` is returned (unit: V). */ [[nodiscard]] std::optional get_local_potential_by_index(const uint64_t index) const noexcept { @@ -584,9 +584,9 @@ class charge_distribution_surface : public Lyt strg->system_energy = total_potential; } /** - * Return the currently stored system's total electrostatic potential energy. + * Return the currently stored system's total electrostatic potential energy in eV. * - * @return The system's total electrostatic potential energy. + * @return The system's total electrostatic potential energy (unit: eV). */ [[nodiscard]] double get_system_energy() const noexcept { @@ -828,7 +828,7 @@ class charge_distribution_surface : public Lyt for (uint64_t i = 0u; i < strg->pot_mat.size(); ++i) { - strg->loc_pot[i] += -(this->get_electrostatic_potential_by_indices(i, random_element)); + strg->loc_pot[i] += -(this->get_chargless_potential_by_indices(i, random_element)); } } } diff --git a/include/fiction/technology/sidb_defects.hpp b/include/fiction/technology/sidb_defects.hpp index 199e8771f..22d3becb0 100644 --- a/include/fiction/technology/sidb_defects.hpp +++ b/include/fiction/technology/sidb_defects.hpp @@ -48,9 +48,9 @@ struct sidb_defect /** * Standard constructor. */ - constexpr explicit sidb_defect(const sidb_defect_type defect_type = sidb_defect_type::UNKNOWN, - const int64_t electric_charge = 0.0, const double relative_permittivity = 0.0, - const double screening_distance = 0.0) noexcept : + explicit sidb_defect(const sidb_defect_type defect_type = sidb_defect_type::UNKNOWN, + const int64_t electric_charge = 0.0, const double relative_permittivity = 0.0, + const double screening_distance = 0.0) noexcept : type{defect_type}, charge{electric_charge}, epsilon_r{relative_permittivity}, @@ -66,11 +66,11 @@ struct sidb_defect */ const sidb_defect_type type; /** - * Electrical charge in units of the elementary charge e (e.g., 1*e, -2*e). + * Electrical charge in units of the elementary charge e (e.g., 1 ^= 1*e, -2 ^= -2*e). */ const int64_t charge; /** - * Electric permittivity. + * Electric permittivity (unitless). */ const double epsilon_r; /** diff --git a/include/fiction/utils/math_utils.hpp b/include/fiction/utils/math_utils.hpp index 7628756af..d5bda1a9b 100644 --- a/include/fiction/utils/math_utils.hpp +++ b/include/fiction/utils/math_utils.hpp @@ -14,8 +14,7 @@ namespace fiction { /** - * Rounds a number to a specified number of decimal - * places. + * Rounds a number to a specified number of decimal places. * * @tparam T The type of the number to round. * @param number The number to round. diff --git a/test/technology/charge_distribution_surface.cpp b/test/technology/charge_distribution_surface.cpp index 261c05ab3..c58a500cc 100644 --- a/test/technology/charge_distribution_surface.cpp +++ b/test/technology/charge_distribution_surface.cpp @@ -124,12 +124,13 @@ TEMPLATE_TEST_CASE( charge_layout.set_all_charge_states(sidb_charge_state::POSITIVE); // calculate potential between two sidbs (charge sign not included) - CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 5}) > 0.0); - CHECK_THAT(charge_layout.potential_between_sidbs({5, 4}, {5, 4}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK(charge_layout.potential_between_sidbs({5, 4}, {5, 6}) > 0); - CHECK(charge_layout.potential_between_sidbs({5, 5}, {5, 6}) > 0); - CHECK_THAT(charge_layout.potential_between_sidbs({5, 6}, {5, 5}) - - charge_layout.potential_between_sidbs({5, 5}, {5, 6}), + CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 5}) > 0.0); + CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 4}), + Catch::Matchers::WithinAbs(0.0, 0.00001)); + CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 6}) > 0); + CHECK(charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}) > 0); + CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 6}, {5, 5}) - + charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}), Catch::Matchers::WithinAbs(0.0, 0.00001)); // read SiDBs' charge states CHECK(charge_layout.get_charge_state({5, 4}) == sidb_charge_state::POSITIVE); From 0cb32e217f0a788ba8db2ec266514ed03425a37a Mon Sep 17 00:00:00 2001 From: Drewniok Date: Tue, 25 Jul 2023 21:21:56 +0200 Subject: [PATCH 5/6] :white_check_mark: add a few more tests. --- .../charge_distribution_surface.hpp | 12 +++++------ .../charge_distribution_surface.cpp | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/fiction/technology/charge_distribution_surface.hpp b/include/fiction/technology/charge_distribution_surface.hpp index 08d720165..6cdc6a737 100644 --- a/include/fiction/technology/charge_distribution_surface.hpp +++ b/include/fiction/technology/charge_distribution_surface.hpp @@ -434,8 +434,8 @@ class charge_distribution_surface : public Lyt * @param index1 The second index. * @return The chargeless electrostatic potential between `index1` and `index2` (unit: V). */ - [[nodiscard]] double chargeless_potential_between_sidbs_by_index(const uint64_t index1, - const uint64_t index2) const noexcept + [[nodiscard]] double calculate_chargeless_potential_between_sidbs_by_index(const uint64_t index1, + const uint64_t index2) const noexcept { if (strg->nm_dist_mat[index1][index2] == 0.0) { @@ -454,13 +454,13 @@ class charge_distribution_surface : public Lyt * @param c2 The second cell. * @return The potential between c1 and c2 (unit: eV). */ - [[nodiscard]] double chargeless_potential_between_sidbs(const typename Lyt::cell& c1, - const typename Lyt::cell& c2) const noexcept + [[nodiscard]] double calculate_chargeless_potential_between_sidbs(const typename Lyt::cell& c1, + const typename Lyt::cell& c2) const noexcept { const auto index1 = static_cast(cell_to_index(c1)); const auto index2 = static_cast(cell_to_index(c2)); - return chargeless_potential_between_sidbs_by_index(index1, index2); + return calculate_chargeless_potential_between_sidbs_by_index(index1, index2); } /** * Returns the chargeless electrostatic potential between two cells. @@ -891,7 +891,7 @@ class charge_distribution_surface : public Lyt { for (uint64_t j = 0u; j < strg->sidb_order.size(); j++) { - strg->pot_mat[i][j] = chargeless_potential_between_sidbs_by_index(i, j); + strg->pot_mat[i][j] = calculate_chargeless_potential_between_sidbs_by_index(i, j); } } } diff --git a/test/technology/charge_distribution_surface.cpp b/test/technology/charge_distribution_surface.cpp index c58a500cc..fd5f168da 100644 --- a/test/technology/charge_distribution_surface.cpp +++ b/test/technology/charge_distribution_surface.cpp @@ -124,13 +124,13 @@ TEMPLATE_TEST_CASE( charge_layout.set_all_charge_states(sidb_charge_state::POSITIVE); // calculate potential between two sidbs (charge sign not included) - CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 5}) > 0.0); - CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 4}), + CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 5}) > 0.0); + CHECK_THAT(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 4}), Catch::Matchers::WithinAbs(0.0, 0.00001)); - CHECK(charge_layout.chargeless_potential_between_sidbs({5, 4}, {5, 6}) > 0); - CHECK(charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}) > 0); - CHECK_THAT(charge_layout.chargeless_potential_between_sidbs({5, 6}, {5, 5}) - - charge_layout.chargeless_potential_between_sidbs({5, 5}, {5, 6}), + CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 4}, {5, 6}) > 0); + CHECK(charge_layout.calculate_chargeless_potential_between_sidbs({5, 5}, {5, 6}) > 0); + CHECK_THAT(charge_layout.calculate_chargeless_potential_between_sidbs({5, 6}, {5, 5}) - + charge_layout.calculate_chargeless_potential_between_sidbs({5, 5}, {5, 6}), Catch::Matchers::WithinAbs(0.0, 0.00001)); // read SiDBs' charge states CHECK(charge_layout.get_charge_state({5, 4}) == sidb_charge_state::POSITIVE); @@ -422,7 +422,7 @@ TEMPLATE_TEST_CASE( lyt_new.assign_cell_type({1, 3, 0}, TestType::cell_type::NORMAL); lyt_new.assign_cell_type({10, 5, 1}, TestType::cell_type::NORMAL); - charge_distribution_surface charge_layout_new{lyt_new, params}; + const charge_distribution_surface charge_layout_new{lyt_new, params}; charge_layout_new.assign_charge_state({0, 0, 1}, sidb_charge_state::NEGATIVE); charge_layout_new.assign_charge_state({1, 3, 0}, sidb_charge_state::POSITIVE); @@ -432,6 +432,13 @@ TEMPLATE_TEST_CASE( CHECK(charge_layout_new.get_charge_state({1, 3, 0}) == sidb_charge_state::POSITIVE); CHECK(charge_layout_new.get_charge_state({10, 5, 1}) == sidb_charge_state::NEUTRAL); + CHECK_THAT(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) - + charge_layout_new.calculate_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}), + Catch::Matchers::WithinAbs(0.0, 0.000001)); + + CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {0, 0, 1}) == 0.0); + CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {0, 0, 1}) == 0.0); + CHECK(charge_layout_new.get_chargeless_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0); CHECK(charge_layout_new.get_potential_between_sidbs({0, 0, 1}, {1, 3, 0}) > 0.0); From 2f8650ae31b5ded32af6e575e4f85d6ee4440518 Mon Sep 17 00:00:00 2001 From: Drewniok Date: Wed, 26 Jul 2023 07:21:42 +0200 Subject: [PATCH 6/6] :white_check_mark: add a few more tests. --- .../charge_distribution_surface.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/technology/charge_distribution_surface.cpp b/test/technology/charge_distribution_surface.cpp index fd5f168da..815b70c5b 100644 --- a/test/technology/charge_distribution_surface.cpp +++ b/test/technology/charge_distribution_surface.cpp @@ -185,6 +185,34 @@ TEMPLATE_TEST_CASE( CHECK(charge_layout.get_charge_state({5, 6}) == sidb_charge_state::POSITIVE); } + SECTION("set physical simulation parameters") + { + // assign SiDBs and charge states to three different cells + lyt.assign_cell_type({5, 4}, TestType::cell_type::NORMAL); + lyt.assign_cell_type({5, 5}, TestType::cell_type::NORMAL); + lyt.assign_cell_type({5, 6}, TestType::cell_type::NORMAL); + + charge_distribution_surface charge_layout{lyt, sidb_simulation_parameters{}}; + + charge_layout.set_physical_parameters(sidb_simulation_parameters{2, -0.2}); + CHECK(charge_layout.get_phys_params().base == 2); + CHECK(charge_layout.get_phys_params().mu == -0.2); + CHECK(charge_layout.get_phys_params().epsilon_r == 5.6); + CHECK(charge_layout.get_phys_params().lambda_tf == 5.0); + CHECK(charge_layout.get_phys_params().lat_a == 3.84); + CHECK(charge_layout.get_phys_params().lat_b == 7.68); + CHECK(charge_layout.get_phys_params().lat_c == 2.25); + + charge_layout.set_physical_parameters(sidb_simulation_parameters{3, -0.4, 5.1, 5.5, 1, 2, 3}); + CHECK(charge_layout.get_phys_params().base == 3); + CHECK(charge_layout.get_phys_params().mu == -0.4); + CHECK(charge_layout.get_phys_params().epsilon_r == 5.1); + CHECK(charge_layout.get_phys_params().lambda_tf == 5.5); + CHECK(charge_layout.get_phys_params().lat_a == 1); + CHECK(charge_layout.get_phys_params().lat_b == 2); + CHECK(charge_layout.get_phys_params().lat_c == 3); + } + SECTION("Distance matrix") { lyt.assign_cell_type({0, 0, 0}, TestType::cell_type::NORMAL); @@ -193,6 +221,9 @@ TEMPLATE_TEST_CASE( charge_distribution_surface charge_layout{lyt, sidb_simulation_parameters{}}; + // Take cells that are not part of the layout + CHECK(charge_layout.get_nm_distance_between_cells({3, 0, 0}, {3, 0, 0}) == 0.0); + CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {0, 0, 0}), Catch::Matchers::WithinAbs(0.0, 0.00001)); CHECK_THAT(charge_layout.get_nm_distance_between_cells({0, 0, 0}, {1, 0, 0}), @@ -248,6 +279,10 @@ TEMPLATE_TEST_CASE( charge_layout.update_local_potential(); + // cell and index are not part of the layout. + CHECK(!charge_layout.get_local_potential({2, 0, 0}).has_value()); + CHECK(!charge_layout.get_local_potential_by_index(4).has_value()); + charge_layout.foreach_cell( [&charge_layout](const auto& c) {