SpECTRE  v2024.03.19
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.

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);
Iterate over all nonzero index permutations for a Levi-Civita symbol.
Definition: LeviCivitaIterator.hpp:33
#define CHECK_ITERABLE_APPROX(a, b)
A wrapper around Catch's CHECK macro that checks approximate equality of entries in iterable containe...
Definition: TestingFramework.hpp:91
constexpr T & at(std::array< T, N > &arr, Size index)
Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid.
Definition: Gsl.hpp:125

The documentation for this class was generated from the following file: