diff --git a/elements/src/CMakeLists.txt b/elements/src/CMakeLists.txt index 3c1af024fc49f745bc9d23899f56d383c12196ca..b550dbdb9a92e73618e74d0da6680b06aac5e56f 100644 --- a/elements/src/CMakeLists.txt +++ b/elements/src/CMakeLists.txt @@ -69,6 +69,7 @@ add_library(${PROJECT_NAME}-elements shape/PointTrait.cc shape/Quad4.cc shape/Seg2.cc + shape/Tet4.cc shape/Tri3.cc shape/Tri6.cc shape/ShapeBase.cc diff --git a/elements/src/include/ae108/elements/shape/Tet4.h b/elements/src/include/ae108/elements/shape/Tet4.h new file mode 100644 index 0000000000000000000000000000000000000000..2656266ea2926a114871a735f5c5a952ded7bb84 --- /dev/null +++ b/elements/src/include/ae108/elements/shape/Tet4.h @@ -0,0 +1,54 @@ +// © 2021 ETH Zurich, Mechanics and Materials Lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "ae108/elements/shape/GradientTrait.h" +#include "ae108/elements/shape/PointTrait.h" +#include "ae108/elements/shape/ShapeBase.h" +#include "ae108/elements/shape/ValueTrait.h" +#include <cstddef> + +namespace ae108 { +namespace elements { +namespace shape { + +// see G. Dhatt, G. Touzot, E. Lefrançois, "Finite Element Method" +// ISTE Ltd, London, 2012, p. 139. +struct Tet4 : ShapeBase<std::size_t, double, 3, 4> {}; + +AE108_ELEMENTS_SHAPE_DEFINE_VALUE(Tet4, {{ + 1 - xi[0] - xi[1] - xi[2], + xi[0], + xi[1], + xi[2], + }}); + +AE108_ELEMENTS_SHAPE_DEFINE_GRADIENTS(Tet4, {{ + {{-1., -1., -1.}}, + {{1., 0., 0.}}, + {{0., 1., 0.}}, + {{0., 0., 1.}}, + }}); + +AE108_ELEMENTS_SHAPE_DEFINE_POINTS(Tet4, {{ + {{0., 0., 0.}}, + {{1., 0., 0.}}, + {{0., 1., 0.}}, + {{0., 0., 1.}}, + }}); + +} // namespace shape +} // namespace elements +} // namespace ae108 \ No newline at end of file diff --git a/elements/src/shape/Tet4.cc b/elements/src/shape/Tet4.cc new file mode 100644 index 0000000000000000000000000000000000000000..5257067cd6df06bacd0d9c67bfc857c74df66296 --- /dev/null +++ b/elements/src/shape/Tet4.cc @@ -0,0 +1,15 @@ +// © 2021 ETH Zurich, Mechanics and Materials Lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "ae108/elements/shape/Tet4.h" \ No newline at end of file diff --git a/elements/test/CMakeLists.txt b/elements/test/CMakeLists.txt index 92574cd20de2b0f5b5d60aba1c58cbbeba23b839..767d50161ebeaf8f8f26ac755b7a0286994d378a 100644 --- a/elements/test/CMakeLists.txt +++ b/elements/test/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(${PROJECT_NAME}-ElementsTests shape/Hexa8_Test.cc shape/Quad4_Test.cc shape/Seg2_Test.cc + shape/Tet4_Test.cc shape/Tri3_Test.cc shape/Tri6_Test.cc tensor/Tensor_Test.cc diff --git a/elements/test/shape/Tet4_Test.cc b/elements/test/shape/Tet4_Test.cc new file mode 100644 index 0000000000000000000000000000000000000000..974a88c6058f747f811658034db097cbc0c2c222 --- /dev/null +++ b/elements/test/shape/Tet4_Test.cc @@ -0,0 +1,52 @@ +// © 2021 ETH Zurich, Mechanics and Materials Lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "Shape_Test.h" +#include "ae108/elements/shape/Tet4.h" +#include "ae108/elements/shape/get_points.h" +#include <gmock/gmock.h> + +using testing::DoubleEq; +using testing::ElementsAre; +using testing::Test; +using testing::Types; + +namespace ae108 { +namespace elements { +namespace shape { +namespace { + +using Configurations = Types<Tet4>; + +INSTANTIATE_TYPED_TEST_CASE_P(Tet4_Test, Shape_Test, Configurations); + +struct Tet4_Test : Test { + using Shape = Tet4; +}; + +TEST_F(Tet4_Test, points_are_correct) { + const auto points = get_points<Shape>(); + + EXPECT_THAT( + points, + ElementsAre(ElementsAre(DoubleEq(0.), DoubleEq(0.), DoubleEq(0.)), + ElementsAre(DoubleEq(1.), DoubleEq(0.), DoubleEq(0.)), + ElementsAre(DoubleEq(0.), DoubleEq(1.), DoubleEq(0.)), + ElementsAre(DoubleEq(0.), DoubleEq(0.), DoubleEq(1.)))); +} + +} // namespace +} // namespace shape +} // namespace elements +} // namespace ae108 \ No newline at end of file