Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Levi-Civita tensor to Aspect #5318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions include/aspect/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,32 @@ namespace aspect
Tensor<1,21>
to_voigt_stiffness_vector(const SymmetricTensor<4,3> &input);


namespace internal
{
constexpr Tensor<3,3> create_levi_civita_tensor_3d()
{
Tensor<3,3> permutation_operator_3d;
permutation_operator_3d[0][1][2] = 1;
permutation_operator_3d[1][2][0] = 1;
permutation_operator_3d[2][0][1] = 1;
permutation_operator_3d[0][2][1] = -1;
permutation_operator_3d[1][0][2] = -1;
permutation_operator_3d[2][1][0] = -1;
Comment on lines +1284 to +1290
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that's nice -- you don't actually need to replace the zeros!

return permutation_operator_3d;
}
}

/**
* The Levi-Civita tensor, also called a permutation or "totally antisymmetric" tensor.
* See https://en.wikipedia.org/wiki/Levi-Civita_symbol for a definition.
* See https://en.wikipedia.org/wiki/Levi-Civita_symbol for more info.
*/
template<int dim>
constexpr Tensor<dim,dim> levi_civita;

template <> constexpr Tensor<3,3> levi_civita<3> = internal::create_levi_civita_tensor_3d();

}

}
Expand Down
36 changes: 36 additions & 0 deletions unit_tests/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,40 @@ TEST_CASE("CPO elastic tensor transform functions")
}
}
}

/**
* test Levi-Cevita tensor function
*/
{

REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][0][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][0][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][0][2] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][1][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][1][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][1][2] == Approx(1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][2][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][2][1] == Approx(-1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[0][2][2] == Approx(0.0));

REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][0][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][0][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][0][2] == Approx(-1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][1][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][1][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][1][2] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][2][0] == Approx(1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][2][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[1][2][2] == Approx(0.0));

REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][0][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][0][1] == Approx(1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][0][2] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][1][0] == Approx(-1.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][1][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][1][2] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][2][0] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][2][1] == Approx(0.0));
REQUIRE(aspect::Utilities::Tensors::levi_civita<3>[2][2][2] == Approx(0.0));
}
}