Skip to content

Commit

Permalink
Fix hopping buffer layout for large multi-orbital models
Browse files Browse the repository at this point in the history
  • Loading branch information
dean0x7d committed Jul 12, 2017
1 parent 634e9fd commit 867b741
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cppcore/include/hamiltonian/HamiltonianModifiers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ struct HoppingBuffer {
hoppings(size * unit_hopping.size()),
pos1(size), pos2(size) {}

/// Replicate each value from the `unit_hopping` matrix `size` times
void reset_hoppings() {
/// Replicate each value from the `unit_hopping` matrix `num` times
void reset_hoppings(idx_t num) {
auto start = idx_t{0};
for (auto const& value : unit_hopping) {
hoppings.segment(start, size).setConstant(value);
start += size;
hoppings.segment(start, num).setConstant(value);
start += num;
}
}

Expand Down Expand Up @@ -269,15 +269,14 @@ void HamiltonianModifiers::apply_to_hoppings_impl(System const& system,

auto buffer = HoppingBuffer<scalar_t>(hopping_family.energy, block.size());
for (auto const coo_slice : sliced(block.coordinates(), buffer.size)) {
buffer.reset_hoppings();

auto size = idx_t{0};
for (auto const& coo : coo_slice) {
buffer.pos1[size] = system.positions[coo.row];
buffer.pos2[size] = detail::shifted(system.positions[coo.col], system_or_boundary);
++size;
}

buffer.reset_hoppings(size);
for (auto const& modifier : hopping) {
modifier.apply(buffer.hoppings_ref(size), buffer.pos1.head(size),
buffer.pos2.head(size), hopping_name);
Expand Down
22 changes: 22 additions & 0 deletions cppcore/tests/test_detail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <complex>

#include "Model.hpp"
#include "detail/algorithm.hpp"
using namespace cpb;

namespace static_test_typelist {
Expand Down Expand Up @@ -34,3 +35,24 @@ TEST_CASE("Symmetry masks") {
}));
}
}

TEST_CASE("sliced") {
auto const v = []{
auto result = std::vector<int>(10);
std::iota(result.begin(), result.end(), 0);
return result;
}();
REQUIRE_THAT(v, Catch::Equals(std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));

auto vectors = std::vector<std::vector<int>>();
for (auto const& slice : sliced(v, 3)) {
auto tmp = std::vector<int>();
std::copy(slice.begin(), slice.end(), std::back_inserter(tmp));
vectors.push_back(tmp);
}
REQUIRE(vectors.size() == 4);
REQUIRE_THAT(vectors[0], Catch::Equals(std::vector<int>{0, 1, 2}));
REQUIRE_THAT(vectors[1], Catch::Equals(std::vector<int>{3, 4, 5}));
REQUIRE_THAT(vectors[2], Catch::Equals(std::vector<int>{6, 7, 8}));
REQUIRE_THAT(vectors[3], Catch::Equals(std::vector<int>{9}));
}

0 comments on commit 867b741

Please # to comment.