An open API service indexing awesome lists of open source software.

https://github.com/adversing/levicivita.cpp

A simple approach to the Levi-Civita tensor.
https://github.com/adversing/levicivita.cpp

cpp differential-geometry levi-civita linear-algebra mathematical-programming scientific-computing tensor-analysis

Last synced: 8 months ago
JSON representation

A simple approach to the Levi-Civita tensor.

Awesome Lists containing this project

README

          

# LeviCivita.cpp
A simple approach to the [Levi-Civita tensor](https://en.wikipedia.org/wiki/Levi-Civita_symbol).

## 📚 Example Usage:

```cpp
#include "levi_civita.hpp"
#include
#include

void printTensorValue(const tensor::LeviCivita& tensor, const std::vector& indices) {
std::cout << "ε_";
for (size_t idx : indices) {
std::cout << (idx + 1);
}
std::cout << " = " << (int)tensor.get(indices) << std::endl;
}

int main() {
try {
// Test 2D tensor
tensor::LeviCivita tensor2d(2);
std::cout << "2D Levi-Civita tensor:\n";
printTensorValue(tensor2d, {0, 1});
printTensorValue(tensor2d, {1, 0});
printTensorValue(tensor2d, {0, 0});

std::cout << "\n3D Levi-Civita tensor:\n";
// Test 3D tensor
tensor::LeviCivita tensor3d(3);
printTensorValue(tensor3d, {0, 1, 2});
printTensorValue(tensor3d, {1, 2, 0});
printTensorValue(tensor3d, {2, 0, 1});
printTensorValue(tensor3d, {1, 0, 2});
printTensorValue(tensor3d, {0, 2, 1});
printTensorValue(tensor3d, {2, 1, 0});
printTensorValue(tensor3d, {0, 0, 1});

std::cout << "\n4D Levi-Civita tensor:\n";
// Test 4D tensor
tensor::LeviCivita tensor4d(4);
printTensorValue(tensor4d, {0, 1, 2, 3});
printTensorValue(tensor4d, {3, 2, 1, 0});
printTensorValue(tensor4d, {0, 1, 1, 2});

} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}

return 0;
}
```