Skip to content

Commit

Permalink
Merge branch 'springs-assembly' of github.com:Exawind/openturbine int…
Browse files Browse the repository at this point in the history
…o springs-assembly
  • Loading branch information
ddement committed Jan 7, 2025
2 parents 822f366 + d45ff90 commit 12355ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 49 deletions.
15 changes: 8 additions & 7 deletions tests/regression_tests/regression/test_spring_mass_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ inline auto SetUpSpringMassSystem() {

// Add two nodes for the spring element
model.AddNode(
{0, 0, 0, 1, 0, 0, 0}, // First node at origin
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
{0., 0., 0., 1., 0., 0., 0.}, // First node at origin
{0., 0., 0., 1., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}
);
model.AddNode(
{2, 0, 0, 1, 0, 0, 0}, // Second node at (2,0,0)
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
{2., 0., 0., 1., 0., 0., 0.}, // Second node at (2., 0., 0.) initially
{0., 0., 0., 1., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}
);

// No beams
Expand Down Expand Up @@ -73,7 +73,7 @@ inline auto SetUpSpringMassSystem() {
);

// The spring-mass system should move periodically between -2 and 2 (position of the second node)
// with simple harmonic motion where the time period is 2 * pi * sqrt(m / k) = 1.98691765316s
// with simple harmonic motion where the time period is 2 * pi * sqrt(m / k) = 1.98691765316 s
constexpr double T = 1.98691765316;

// Set up step parameters
Expand All @@ -88,12 +88,13 @@ inline auto SetUpSpringMassSystem() {
auto converged = Step(parameters, solver, elements, state, constraints);
EXPECT_TRUE(converged);
}

auto q = Kokkos::create_mirror(state.q);
Kokkos::deep_copy(q, state.q);
EXPECT_EQ(q(0, 0), 0.); // First node is fixed
EXPECT_NEAR(
q(1, 0), -3.9999201563071107, 1.e-12
); // Second node should have displcement close to -4.0 after T/2
); // Second node should have displcement close to -4.0 after T/2 seconds

// Run simulation for a total of ~T seconds
for (auto time_step = 0U; time_step <= 500; ++time_step) {
Expand All @@ -105,7 +106,7 @@ inline auto SetUpSpringMassSystem() {
EXPECT_EQ(q(0, 0), 0.); // First node is fixed
EXPECT_NEAR(
q(1, 0), -0.00015948103228367424, 1.e-12
); // Second node should have displcement close to 0. after T
); // Second node should have displcement close to 0. after T seconds
}

TEST(SpringMassSystemTest, FinalDisplacement) {
Expand Down
61 changes: 19 additions & 42 deletions tests/regression_tests/regression/test_springs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,36 @@ inline auto SetUpSprings() {
auto model = Model();
// Add two nodes for the spring element
model.AddNode(
{0, 0, 0, 1, 0, 0, 0}, // First node at origin
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
{0., 0., 0., 1., 0., 0., 0.}, // First node at origin
{0., 0., 0., 1., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}
);
model.AddNode(
{1, 0, 0, 1, 0, 0, 0}, // Second node at (1,0,0)
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
{1., 0., 0., 1., 0., 0., 0.}, // Second node at (1,0,0)
{0., 0., 0., 1., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0.}
);

const auto springs_input = SpringsInput({SpringElement(
std::array{model.GetNode(0), model.GetNode(1)},
1000., // Spring stiffness
1. // Undeformed length
10., // Spring stiffness coeff.
1. // Undeformed length
)});

return CreateSprings(springs_input);
auto springs = CreateSprings(springs_input);
auto state = model.CreateState();

return std::make_tuple(springs, state);
}

TEST(SpringsTest, NodeStateIndices) {
const auto springs = SetUpSprings();
auto [springs, _] = SetUpSprings();
auto node_state_indices_host = Kokkos::create_mirror(springs.node_state_indices);
Kokkos::deep_copy(node_state_indices_host, springs.node_state_indices);
EXPECT_EQ(node_state_indices_host(0, 0), 0);
EXPECT_EQ(node_state_indices_host(0, 1), 1);
}

TEST(SpringsTest, InitialPositionVector) {
const auto springs = SetUpSprings();
auto [springs, _] = SetUpSprings();
expect_kokkos_view_2D_equal(
springs.x0,
{
Expand All @@ -49,43 +52,17 @@ TEST(SpringsTest, InitialPositionVector) {
}

TEST(SpringsTest, ReferenceLength) {
const auto springs = SetUpSprings();
auto [springs, _] = SetUpSprings();
expect_kokkos_view_1D_equal(springs.l_ref, {1.}); // Undeformed length
}

TEST(SpringsTest, SpringStiffness) {
const auto springs = SetUpSprings();
expect_kokkos_view_1D_equal(springs.k, {1000.}); // Spring stiffness
auto [springs, _] = SetUpSprings();
expect_kokkos_view_1D_equal(springs.k, {10.}); // Spring stiffness
}

inline auto SetUpSpringsForceTest() {
auto model = Model();

// Add two nodes for the spring element
model.AddNode(
{0, 0, 0, 1, 0, 0, 0}, // First node at origin
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
);
model.AddNode(
{1, 0, 0, 1, 0, 0, 0}, // Second node at (1,0,0)
{0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}
);

const auto springs_input = SpringsInput({SpringElement(
std::array{model.GetNode(0), model.GetNode(1)},
10., // Spring stiffness coeff.
1. // Undeformed length
)});

auto springs = CreateSprings(springs_input);
auto state = model.CreateState();

return std::make_tuple(springs, state);
}

TEST(SpringsForceTest, ZeroDisplacement) {
auto [springs, state] = SetUpSpringsForceTest();

TEST(SpringsTest, SpringsForceWithZeroDisplacement) {
auto [springs, state] = SetUpSprings();
UpdateSystemVariablesSprings(springs, state);

auto l_ref_host = Kokkos::create_mirror(springs.l_ref);
Expand All @@ -108,8 +85,8 @@ TEST(SpringsForceTest, ZeroDisplacement) {
);
}

TEST(SpringsForceTest, UnitDisplacement) {
auto [springs, state] = SetUpSpringsForceTest();
TEST(SpringsTest, SpringsForceWithUnitDisplacement) {
auto [springs, state] = SetUpSprings();

auto q = Kokkos::create_mirror(state.q);
q(1, 0) = 1.; // Displace second node in x direction
Expand Down

0 comments on commit 12355ff

Please sign in to comment.