-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from Exawind/add_vfc_data_structures
Added initial data structures and algorithms to support different element types
- Loading branch information
Showing
12 changed files
with
464 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/dof_management/assemble_node_freedom_allocation_table.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "freedom_signature.hpp" | ||
|
||
#include "src/beams/beams.hpp" | ||
#include "src/state/state.hpp" | ||
|
||
namespace openturbine { | ||
|
||
inline void assemble_node_freedom_allocation_table(State& state, const Beams& beams) { | ||
Kokkos::parallel_for( | ||
"Assemble Node Freedom Map Table", 1, | ||
KOKKOS_LAMBDA(size_t) { | ||
for (auto i = 0U; i < beams.num_elems; ++i) { | ||
const auto num_nodes = beams.num_nodes_per_element(i); | ||
for (auto j = 0U; j < num_nodes; ++j) { | ||
const auto node_index = beams.node_state_indices(i, j); | ||
const auto current_signature = state.node_freedom_allocation_table(node_index); | ||
const auto contributed_signature = beams.element_freedom_signature(i, j); | ||
state.node_freedom_allocation_table(node_index) = | ||
current_signature | contributed_signature; | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "freedom_signature.hpp" | ||
|
||
#include "src/beams/beams.hpp" | ||
#include "src/state/state.hpp" | ||
|
||
namespace openturbine { | ||
|
||
inline void compute_node_freedom_map_table(State& state) { | ||
Kokkos::parallel_for( | ||
"Compute Node Freedom Map Table", 1, | ||
KOKKOS_LAMBDA(size_t) { | ||
state.node_freedom_map_table(0) = 0U; | ||
for (auto i = 1U; i < state.num_system_nodes; ++i) { | ||
const auto num_dof = count_active_dofs(state.node_freedom_allocation_table(i - 1)); | ||
state.node_freedom_map_table(i) = state.node_freedom_map_table(i - 1) + num_dof; | ||
} | ||
} | ||
); | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "freedom_signature.hpp" | ||
|
||
#include "src/beams/beams.hpp" | ||
#include "src/state/state.hpp" | ||
|
||
namespace openturbine { | ||
|
||
inline void create_element_freedom_table(Beams& beams, const State& state) { | ||
Kokkos::parallel_for( | ||
"Create Element Freedom Table", 1, | ||
KOKKOS_LAMBDA(size_t) { | ||
for (auto i = 0U; i < beams.num_elems; ++i) { | ||
const auto num_nodes = beams.num_nodes_per_element(i); | ||
for (auto j = 0U; j < num_nodes; ++j) { | ||
const auto node_index = beams.node_state_indices(i, j); | ||
for (auto k = 0U; k < 6U; ++k) { | ||
beams.element_freedom_table(i, j, k) = | ||
state.node_freedom_map_table(node_index) + k; | ||
} | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
namespace openturbine { | ||
|
||
enum class FreedomSignature : std::uint8_t { | ||
AllComponents = 0b00111111, | ||
JustPosition = 0b00111000, | ||
JustRotation = 0b00000111, | ||
NoComponents = 0b00000000 | ||
}; | ||
|
||
KOKKOS_INLINE_FUNCTION | ||
FreedomSignature operator|(FreedomSignature x, FreedomSignature y) { | ||
using T = std::underlying_type_t<FreedomSignature>; | ||
return static_cast<FreedomSignature>(static_cast<T>(x) | static_cast<T>(y)); | ||
} | ||
|
||
KOKKOS_INLINE_FUNCTION | ||
size_t count_active_dofs(FreedomSignature x) { | ||
using T = std::underlying_type_t<FreedomSignature>; | ||
auto count = 0UL; | ||
constexpr auto zero = T{0}; | ||
constexpr auto one = T{1}; | ||
for (auto value = static_cast<T>(x); value > zero; value = value >> 1) { | ||
count += value & one; | ||
} | ||
return count; | ||
} | ||
|
||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Specify the source files for the unit test executable | ||
target_sources( | ||
openturbine_unit_tests | ||
PRIVATE | ||
test_assemble_node_freedom_allocation_table.cpp | ||
test_compute_node_freedom_map_table.cpp | ||
test_create_element_freedom_table.cpp | ||
test_freedom_signature.cpp | ||
) |
69 changes: 69 additions & 0 deletions
69
tests/unit_tests/dof_management/test_assemble_node_freedom_allocation_table.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "src/dof_management/assemble_node_freedom_allocation_table.hpp" | ||
|
||
namespace openturbine::tests { | ||
|
||
TEST(TestAssembleNodeFreedomAllocationTable, OneBeamOneNode) { | ||
auto state = State(1U); | ||
|
||
auto beams = Beams(1U, 1U, 1U); | ||
Kokkos::deep_copy(beams.node_state_indices, 0U); | ||
Kokkos::deep_copy(beams.num_nodes_per_element, 1U); | ||
|
||
assemble_node_freedom_allocation_table(state, beams); | ||
|
||
const auto host_node_freedom_allocation_table = | ||
Kokkos::create_mirror(state.node_freedom_allocation_table); | ||
Kokkos::deep_copy(host_node_freedom_allocation_table, state.node_freedom_allocation_table); | ||
|
||
EXPECT_EQ(host_node_freedom_allocation_table(0), FreedomSignature::AllComponents); | ||
} | ||
|
||
TEST(TestAssembleNodeFreedomAllocationTable, OneBeamTwoNodes) { | ||
auto state = State(2U); | ||
|
||
auto beams = Beams(1U, 2U, 1U); | ||
constexpr auto host_node_state_indices_data = std::array{0UL, 1UL}; | ||
const auto host_node_state_indices = | ||
Kokkos::View<size_t[1][2], Kokkos::HostSpace>::const_type(host_node_state_indices_data.data() | ||
); | ||
const auto mirror_node_state_indices = Kokkos::create_mirror(beams.node_state_indices); | ||
Kokkos::deep_copy(mirror_node_state_indices, host_node_state_indices); | ||
Kokkos::deep_copy(beams.node_state_indices, mirror_node_state_indices); | ||
Kokkos::deep_copy(beams.num_nodes_per_element, 2U); | ||
|
||
assemble_node_freedom_allocation_table(state, beams); | ||
|
||
const auto host_node_freedom_allocation_table = | ||
Kokkos::create_mirror(state.node_freedom_allocation_table); | ||
Kokkos::deep_copy(host_node_freedom_allocation_table, state.node_freedom_allocation_table); | ||
|
||
EXPECT_EQ(host_node_freedom_allocation_table(0), FreedomSignature::AllComponents); | ||
EXPECT_EQ(host_node_freedom_allocation_table(1), FreedomSignature::AllComponents); | ||
} | ||
|
||
TEST(TestAssembleNodeFreedomAllocationTable, TwoBeamsOneNode) { | ||
auto state = State(2U); | ||
|
||
auto beams = Beams(2U, 1U, 1U); | ||
constexpr auto host_node_state_indices_data = std::array{0UL, 1UL}; | ||
const auto host_node_state_indices = | ||
Kokkos::View<size_t[2][1], Kokkos::HostSpace>::const_type(host_node_state_indices_data.data() | ||
); | ||
const auto mirror_node_state_indices = Kokkos::create_mirror(beams.node_state_indices); | ||
Kokkos::deep_copy(mirror_node_state_indices, host_node_state_indices); | ||
Kokkos::deep_copy(beams.node_state_indices, mirror_node_state_indices); | ||
Kokkos::deep_copy(beams.num_nodes_per_element, 1U); | ||
|
||
assemble_node_freedom_allocation_table(state, beams); | ||
|
||
const auto host_node_freedom_allocation_table = | ||
Kokkos::create_mirror(state.node_freedom_allocation_table); | ||
Kokkos::deep_copy(host_node_freedom_allocation_table, state.node_freedom_allocation_table); | ||
|
||
EXPECT_EQ(host_node_freedom_allocation_table(0), FreedomSignature::AllComponents); | ||
EXPECT_EQ(host_node_freedom_allocation_table(1), FreedomSignature::AllComponents); | ||
} | ||
|
||
} // namespace openturbine::tests |
45 changes: 45 additions & 0 deletions
45
tests/unit_tests/dof_management/test_compute_node_freedom_map_table.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "src/dof_management/compute_node_freedom_map_table.hpp" | ||
|
||
namespace openturbine::tests { | ||
|
||
TEST(TestComputeNodeFreedomMapTable, OneNode) { | ||
auto state = State(1U); | ||
Kokkos::deep_copy(state.node_freedom_allocation_table, FreedomSignature::AllComponents); | ||
|
||
compute_node_freedom_map_table(state); | ||
|
||
const auto host_node_freedom_map_table = Kokkos::create_mirror(state.node_freedom_map_table); | ||
Kokkos::deep_copy(host_node_freedom_map_table, state.node_freedom_map_table); | ||
|
||
EXPECT_EQ(host_node_freedom_map_table(0), 0); | ||
} | ||
|
||
TEST(TestComputeNodeFreedomMapTable, FourNodes) { | ||
auto state = State(4U); | ||
constexpr auto host_node_freedom_allocation_table_data = std::array{ | ||
FreedomSignature::AllComponents, FreedomSignature::JustPosition, | ||
FreedomSignature::JustRotation, FreedomSignature::NoComponents | ||
}; | ||
const auto host_node_freedom_allocation_table = | ||
Kokkos::View<FreedomSignature[4], Kokkos::HostSpace>::const_type( | ||
host_node_freedom_allocation_table_data.data() | ||
); | ||
const auto mirror_node_freedom_allocation_table = | ||
Kokkos::create_mirror(state.node_freedom_allocation_table); | ||
Kokkos::deep_copy(mirror_node_freedom_allocation_table, host_node_freedom_allocation_table); | ||
Kokkos::deep_copy(state.node_freedom_allocation_table, mirror_node_freedom_allocation_table); | ||
|
||
compute_node_freedom_map_table(state); | ||
|
||
const auto host_node_freedom_map_table = Kokkos::create_mirror(state.node_freedom_map_table); | ||
Kokkos::deep_copy(host_node_freedom_map_table, state.node_freedom_map_table); | ||
|
||
EXPECT_EQ(host_node_freedom_map_table(0), 0); | ||
EXPECT_EQ(host_node_freedom_map_table(1), 6); | ||
EXPECT_EQ(host_node_freedom_map_table(2), 9); | ||
EXPECT_EQ(host_node_freedom_map_table(3), 12); | ||
} | ||
|
||
} // namespace openturbine::tests |
Oops, something went wrong.