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.
- Host: GitHub
- URL: https://github.com/adversing/levicivita.cpp
- Owner: Adversing
- License: mit
- Created: 2024-11-01T21:21:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T21:51:13.000Z (over 1 year ago)
- Last Synced: 2025-06-08T04:24:22.004Z (10 months ago)
- Topics: cpp, differential-geometry, levi-civita, linear-algebra, mathematical-programming, scientific-computing, tensor-analysis
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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;
}
```