SpECTRE  v2026.04.01
Loading...
Searching...
No Matches
LeviCivitaIterator< Dim > Class Template Reference

Iterate over all nonzero index permutations for a Levi-Civita symbol. More...

#include <LeviCivitaIterator.hpp>

Public Member Functions

 operator bool () const
LeviCivitaIteratoroperator++ ()
const std::array< size_t, Dim > operator() () const
 Return a std::array containing the current multi-index, an ordered list of indices for the current permutation.
const size_t & operator[] (const size_t i) const
 Return a specific index from the multi-index of the current permutation.
int sign () const
 Return the sign of the Levi-Civita symbol for the current permutation.

Detailed Description

template<size_t Dim>
class LeviCivitaIterator< Dim >

Iterate over all nonzero index permutations for a Levi-Civita symbol.

Details

This class provides an iterator that allows you to loop over only the nonzero index permutations of a Levi-Civita symbol of dimension dimension. Inside the loop, the operator () returns an std::array containing an ordered list of the indices of this permutation, the operator [] returns a specific index from the same std::array, and the function sign() returns the sign of the Levi-Civita symbol for this permutation.

Note that the Levi-Civita symbol in odd dimensions (like 3) is invariant under cyclic permutations of its indices, but in even dimensions (like 4) it changes sign under cyclic permutations.

Example

const std::array<double, 3> vector_a = {{2.0, 3.0, 4.0}};
const std::array<double, 3> vector_b = {{7.0, 6.0, 5.0}};
const std::array<double, 3> a_cross_b_expected = {{-9.0, 18.0, -9.0}};
std::array<double, 3> a_cross_b = {{0.0, 0.0, 0.0}};
for (LeviCivitaIterator<3> it; it; ++it) {
gsl::at(a_cross_b, it[0]) +=
it.sign() * gsl::at(vector_a, it[1]) * gsl::at(vector_b, it[2]);
}
CHECK_ITERABLE_APPROX(a_cross_b, a_cross_b_expected);

The documentation for this class was generated from the following file:
  • src/DataStructures/LeviCivitaIterator.hpp