Skip to content

Commit

Permalink
🎨 adapt sidb defects to unit library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewniok committed Jul 21, 2023
1 parent 6bd8335 commit 29a69f2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
13 changes: 8 additions & 5 deletions include/fiction/io/read_sqd_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "fiction/utils/name_utils.hpp"

#include <tinyxml2.h>
#include <units.h>

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -267,9 +268,11 @@ class read_sqd_layout_impl
{
if constexpr (has_assign_sidb_defect_v<Lyt>)
{
std::vector<cell<Lyt>> incl_cells{};
sidb_defect_type defect_type{sidb_defect_type::UNKNOWN};
double charge{0.0}, eps_r{0.0}, lambda_tf{0.0};
std::vector<cell<Lyt>> 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};

if (const auto* const incl_coords = defect->FirstChildElement("incl_coords"); incl_coords != nullptr)
{
Expand Down Expand Up @@ -308,9 +311,9 @@ class read_sqd_layout_impl
"Error parsing SQD file: no attribute 'charge', 'eps_r', or 'lambda_tf' in element 'coulomb'");
}

charge = std::stod(charge_string);
charge = units::charge::elementary_charge_t{std::stod(charge_string)};
eps_r = std::stod(eps_r_string);
lambda_tf = std::stod(lambda_tf_string);
lambda_tf = units::length::nanometer_t{std::stod(lambda_tf_string)};
}

std::for_each(incl_cells.begin(), incl_cells.end(),
Expand Down
12 changes: 6 additions & 6 deletions include/fiction/io/write_sqd_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
defect.epsilon_r, defect.lambda_tf) :
"",
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.value(), defect.epsilon_r,
defect.lambda_tf.value()) :
"",
get_defect_type_name(defect.type));
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions include/fiction/technology/sidb_defects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ struct sidb_defect
/**
* Standard constructor.
*/
constexpr explicit sidb_defect(const sidb_defect_type defect_type = sidb_defect_type::UNKNOWN,
const units::charge::electron_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 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 :
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((epsilon_r >= 0) && "charge value has to be an integer");
assert((screening_distance >= 0.0_nm) && "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");
}
/**s
* Type of defect.
Expand All @@ -73,7 +73,7 @@ struct sidb_defect
/**
* Electrical charge.
*/
const units::charge::electron_charge_t charge;
const units::charge::elementary_charge_t charge;
/**
* Electric permittivity.
*/
Expand Down
44 changes: 22 additions & 22 deletions test/io/read_sqd_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TEST_CASE("Read single defect SQD layout", "[sqd]")
" <incl_coords>\n"
" <latcoord n=\"5\" m=\"2\" l=\"0\" />\n"
" </incl_coords>\n"
" <coulomb charge=\"2\" eps_r=\"-1.2\" lambda_tf=\"3.4\" />\n"
" <coulomb charge=\"2\" eps_r=\"1.2\" lambda_tf=\"3.4\" />\n"
" </defect>"
" </layer>\n"
" </design>\n"
Expand All @@ -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);
CHECK(defect.epsilon_r == -1.2);
CHECK(defect.lambda_tf == 3.4);
CHECK(defect.charge == 2_e);
CHECK(defect.epsilon_r == 1.2);
CHECK(defect.lambda_tf == 3.4_nm);
}

TEST_CASE("Read multiple defects SQD layout", "[sqd]")
Expand Down Expand Up @@ -226,43 +226,43 @@ 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);
CHECK(defect.charge == -1_e);
CHECK(defect.epsilon_r == 5.6);
CHECK(defect.lambda_tf == 5.0);
CHECK(defect.lambda_tf == 5.0_nm);
}
{
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);
CHECK(defect1.charge == -1_e);
CHECK(defect1.epsilon_r == 5.6);
CHECK(defect1.lambda_tf == 5.0);
CHECK(defect1.lambda_tf == 5.0_nm);
CHECK(defect2.type == sidb_defect_type::MISSING_DIMER);
CHECK(defect2.charge == -1);
CHECK(defect2.charge == -1_e);
CHECK(defect2.epsilon_r == 5.6);
CHECK(defect2.lambda_tf == 5.0);
CHECK(defect2.lambda_tf == 5.0_nm);
}
{
const auto defect1 = layout.get_sidb_defect({0, 4});
const auto defect2 = layout.get_sidb_defect({0, 5});
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);
CHECK(defect1.charge == -1_e);
CHECK(defect1.epsilon_r == 5.6);
CHECK(defect1.lambda_tf == 5.0);
CHECK(defect1.lambda_tf == 5.0_nm);
CHECK(defect2.type == sidb_defect_type::ETCH_PIT);
CHECK(defect2.charge == -1);
CHECK(defect2.charge == -1_e);
CHECK(defect2.epsilon_r == 5.6);
CHECK(defect2.lambda_tf == 5.0);
CHECK(defect2.lambda_tf == 5.0_nm);
CHECK(defect3.type == sidb_defect_type::ETCH_PIT);
CHECK(defect3.charge == -1);
CHECK(defect3.charge == -1_e);
CHECK(defect3.epsilon_r == 5.6);
CHECK(defect3.lambda_tf == 5.0);
CHECK(defect3.lambda_tf == 5.0_nm);
CHECK(defect4.type == sidb_defect_type::ETCH_PIT);
CHECK(defect4.charge == -1);
CHECK(defect4.charge == -1_e);
CHECK(defect4.epsilon_r == 5.6);
CHECK(defect4.lambda_tf == 5.0);
CHECK(defect4.lambda_tf == 5.0_nm);
}
}

Expand Down Expand Up @@ -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);
CHECK(defect.charge == -1_e);
CHECK(defect.epsilon_r == 5.6);
CHECK(defect.lambda_tf == 5.0);
CHECK(defect.lambda_tf == 5.0_nm);
});
}

Expand Down Expand Up @@ -442,9 +442,9 @@ TEST_CASE("Read SQD defect despite missing <coulomb> element", "[sqd]")

CHECK(defect.type == sidb_defect_type::UNKNOWN);

CHECK(defect.charge == 0.0);
CHECK(defect.charge == 0.0_e);
CHECK(defect.epsilon_r == 0.0);
CHECK(defect.lambda_tf == 0.0);
CHECK(defect.lambda_tf == 0.0_nm);
}

TEST_CASE("SQD parsing error: missing <siqad> element", "[sqd]")
Expand Down
4 changes: 2 additions & 2 deletions test/technology/sidb_defects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ TEST_CASE("Test for units", "[sidb-defects]")
CHECK(defect_three.epsilon_r == 5);
CHECK(defect_three.lambda_tf == 0.0_nm);

const sidb_defect defect_four{sidb_defect_type::NONE, 2_e, 5.4, 4.2_nm};
CHECK(defect_four.charge == 2_e);
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);
}

0 comments on commit 29a69f2

Please sign in to comment.