Skip to content

Commit a6b5d69

Browse files
committed
Merge branch 'main' into compile_step
2 parents 4fb6d8f + 22157a2 commit a6b5d69

File tree

122 files changed

+25105
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+25105
-296
lines changed

Diff for: .github/workflows/formatting.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ on: push
44

55
jobs:
66
clang-format:
7-
runs-on: ubuntu-latest
7+
runs-on: ubuntu-24.04
88

99
steps:
1010
- name: Checkout repository
1111
uses: actions/checkout@v4
1212

1313
- name: Run clang-format
1414
run: |
15-
find . -regex '.*\.\(cpp\|hpp\|c\|h\)' -exec clang-format -i {} \;
15+
clang-format --version
16+
find . -regex '.*\.\(cpp\|hpp\|c\|h\)' -exec clang-format-18 -i {} \;
1617
1718
- name: Check for formatting changes
1819
run: |

Diff for: cmake/Dependencies.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function(openturbine_setup_dependencies)
6666
BUILD_IN_SOURCE OFF # Build in a separate directory for cleaner output
6767
BINARY_DIR ${CMAKE_BINARY_DIR}/ROSCO_build
6868
SOURCE_SUBDIR rosco/controller
69+
CMAKE_ARGS
70+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} # Use the same build type as the main project
6971
BUILD_COMMAND ${CMAKE_COMMAND} --build . -- -j 1
7072
INSTALL_COMMAND
7173
${CMAKE_COMMAND} -E copy

Diff for: src/beams/beams.hpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ namespace openturbine {
2020
*/
2121
struct Beams {
2222
size_t num_elems; // Total number of element
23-
size_t num_nodes; // Total number of nodes
24-
size_t num_qps; // Total number of quadrature points
2523
size_t max_elem_nodes; // Maximum number of nodes per element
2624
size_t max_elem_qps; // Maximum number of quadrature points per element
2725

@@ -89,13 +87,8 @@ struct Beams {
8987
Kokkos::View<double***> shape_deriv; // Shape function derivatives
9088

9189
// Constructor which initializes views based on given sizes
92-
Beams(
93-
const size_t n_beams, const size_t n_nodes, const size_t n_qps, const size_t max_e_nodes,
94-
const size_t max_e_qps
95-
)
90+
Beams(const size_t n_beams, const size_t max_e_nodes, const size_t max_e_qps)
9691
: num_elems(n_beams),
97-
num_nodes(n_nodes),
98-
num_qps(n_qps),
9992
max_elem_nodes(max_e_nodes),
10093
max_elem_qps(max_e_qps),
10194
// Element Data

Diff for: src/beams/create_beams.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace openturbine {
1111

1212
inline Beams CreateBeams(const BeamsInput& beams_input) {
1313
Beams beams(
14-
beams_input.NumElements(), beams_input.NumNodes(), beams_input.NumQuadraturePoints(),
15-
beams_input.MaxElemNodes(), beams_input.MaxElemQuadraturePoints()
14+
beams_input.NumElements(), beams_input.MaxElemNodes(), beams_input.MaxElemQuadraturePoints()
1615
);
1716

1817
auto host_gravity = Kokkos::create_mirror(beams.gravity);

Diff for: src/constraints/calculate_rotation_control_constraint.hpp

+67-50
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,61 @@ struct CalculateRotationControlConstraint {
2222

2323
KOKKOS_FUNCTION
2424
void operator()(const int i_constraint) const {
25-
const auto i_node1 = base_node_index(i_constraint);
26-
const auto i_node2 = target_node_index(i_constraint);
25+
const auto i_base = base_node_index(i_constraint);
26+
const auto i_target = target_node_index(i_constraint);
2727

2828
// Initial difference between nodes
2929
const auto X0_data = Kokkos::Array<double, 3>{
3030
X0_(i_constraint, 0), X0_(i_constraint, 1), X0_(i_constraint, 2)
3131
};
3232
const auto X0 = View_3::const_type{X0_data.data()};
3333

34-
// Base node displacement
35-
const auto u1_data =
36-
Kokkos::Array<double, 3>{node_u(i_node1, 0), node_u(i_node1, 1), node_u(i_node1, 2)};
37-
const auto R1_data = Kokkos::Array<double, 4>{
38-
node_u(i_node1, 3), node_u(i_node1, 4), node_u(i_node1, 5), node_u(i_node1, 6)
34+
// Base node displacement (translation and rotation)
35+
const auto ub_data =
36+
Kokkos::Array<double, 3>{node_u(i_base, 0), node_u(i_base, 1), node_u(i_base, 2)};
37+
const auto Rb_data = Kokkos::Array<double, 4>{
38+
node_u(i_base, 3), node_u(i_base, 4), node_u(i_base, 5), node_u(i_base, 6)
3939
};
40-
const auto u1 = View_3::const_type{u1_data.data()};
41-
const auto R1 = Kokkos::View<double[4]>::const_type{R1_data.data()};
42-
43-
// Target node displacement
44-
const auto R2_data = Kokkos::Array<double, 4>{
45-
node_u(i_node2, 3), node_u(i_node2, 4), node_u(i_node2, 5), node_u(i_node2, 6)
40+
const auto ub = View_3::const_type{ub_data.data()};
41+
const auto Rb = Kokkos::View<double[4]>::const_type{Rb_data.data()};
42+
43+
// Target node displacement (translation and rotation)
44+
const auto ut_data =
45+
Kokkos::Array<double, 3>{node_u(i_target, 0), node_u(i_target, 1), node_u(i_target, 2)};
46+
const auto ut = View_3::const_type{ut_data.data()};
47+
const auto Rt_data = Kokkos::Array<double, 4>{
48+
node_u(i_target, 3), node_u(i_target, 4), node_u(i_target, 5), node_u(i_target, 6)
4649
};
47-
const auto R2 = Kokkos::View<double[4]>::const_type{R2_data.data()};
48-
const auto u2_data =
49-
Kokkos::Array<double, 3>{node_u(i_node2, 0), node_u(i_node2, 1), node_u(i_node2, 2)};
50-
const auto u2 = View_3::const_type{u2_data.data()};
50+
const auto Rt = Kokkos::View<double[4]>::const_type{Rt_data.data()};
51+
52+
auto AX_data = Kokkos::Array<double, 3>{};
53+
const auto AX = Kokkos::View<double[3]>{AX_data.data()};
54+
55+
// Control rotation vector
56+
auto RV_data = Kokkos::Array<double, 3>{};
57+
const auto RV = Kokkos::View<double[3]>{RV_data.data()};
5158

5259
// Rotation control
53-
auto RC_data = Kokkos::Array<double, 4>{};
54-
const auto RC = Kokkos::View<double[4]>{RC_data.data()};
55-
auto RCt_data = Kokkos::Array<double, 4>{};
56-
const auto RCt = Kokkos::View<double[4]>{RCt_data.data()};
57-
auto RV_data = Kokkos::Array<double, 4>{};
58-
const auto RV = Kokkos::View<double[4]>{RV_data.data()};
60+
auto Rc_data = Kokkos::Array<double, 4>{};
61+
const auto Rc = Kokkos::View<double[4]>{Rc_data.data()};
62+
auto RcT_data = Kokkos::Array<double, 4>{};
63+
const auto RcT = Kokkos::View<double[4]>{RcT_data.data()};
5964

60-
auto R1t_data = Kokkos::Array<double, 4>{};
61-
const auto R1t = Kokkos::View<double[4]>{R1t_data.data()};
65+
// Base rotation transpose
66+
auto RbT_data = Kokkos::Array<double, 4>{};
67+
const auto RbT = Kokkos::View<double[4]>{RbT_data.data()};
6268

63-
auto R1_X0_data = Kokkos::Array<double, 4>{};
64-
const auto R1_X0 = Kokkos::View<double[4]>{R1_X0_data.data()};
69+
// Base rotation * X0
70+
auto Rb_X0_data = Kokkos::Array<double, 4>{};
71+
const auto Rb_X0 = Kokkos::View<double[4]>{Rb_X0_data.data()};
6572

66-
auto R2_RCt_data = Kokkos::Array<double, 4>{};
67-
const auto R2_RCt = Kokkos::View<double[4]>{R2_RCt_data.data()};
73+
// Target rotation * Control rotation transpose
74+
auto Rt_RcT_data = Kokkos::Array<double, 4>{};
75+
const auto Rt_RcT = Kokkos::View<double[4]>{Rt_RcT_data.data()};
6876

69-
auto R2_RCt_R1t_data = Kokkos::Array<double, 4>{};
70-
const auto R2_RCt_R1t = Kokkos::View<double[4]>{R2_RCt_R1t_data.data()};
77+
// Target rotation * Control rotation transpose * Base rotation transpose
78+
auto Rt_RcT_RbT_data = Kokkos::Array<double, 4>{};
79+
const auto Rt_RcT_RbT = Kokkos::View<double[4]>{Rt_RcT_RbT_data.data()};
7180

7281
auto A_data = Kokkos::Array<double, 9>{};
7382
const auto A = View_3x3{A_data.data()};
@@ -79,30 +88,38 @@ struct CalculateRotationControlConstraint {
7988
const auto V3 = View_3{V3_data.data()};
8089

8190
//----------------------------------------------------------------------
82-
// Residual Vector
91+
// Position residual
8392
//----------------------------------------------------------------------
8493

85-
// Phi(0:3) = u2 + X0 - u1 - R1*X0
86-
QuaternionInverse(R1, R1t);
87-
RotateVectorByQuaternion(R1, X0, R1_X0);
94+
// Phi(0:3) = ut + X0 - ub - Rb*X0
95+
RotateVectorByQuaternion(Rb, X0, Rb_X0);
8896
for (int i = 0; i < 3; ++i) {
89-
residual_terms(i_constraint, i) = u2(i) + X0(i) - u1(i) - R1_X0(i);
97+
residual_terms(i_constraint, i) = ut(i) + X0(i) - ub(i) - Rb_X0(i);
9098
}
9199

92-
// Angular residual
93-
// If this is a rotation control constraint, calculate RC from control and axis
100+
//----------------------------------------------------------------------
101+
// Rotation residual
102+
//----------------------------------------------------------------------
103+
104+
auto rotation_command = constraint_inputs(i_constraint, 0);
105+
106+
// Copy rotation axis for this constraint
94107
for (auto i = 0U; i < 3U; ++i) {
95-
RV(i) = axes(i_constraint, 0, i) * constraint_inputs(i_constraint, 0);
108+
AX(i) = axes(i_constraint, 0, i);
109+
RV(i) = AX(i) * rotation_command;
96110
}
97-
RotationVectorToQuaternion(RV, RC);
98-
QuaternionInverse(RC, RCt);
99111

100-
// Phi(3:6) = axial(R2*inv(RC)*inv(R1))
101-
QuaternionCompose(R2, RCt, R2_RCt);
102-
QuaternionCompose(R2_RCt, R1t, R2_RCt_R1t);
103-
QuaternionToRotationMatrix(R2_RCt_R1t, C);
112+
// Convert scaled axis to quaternion and calculate inverse
113+
RotationVectorToQuaternion(RV, Rc);
114+
QuaternionInverse(Rc, RcT);
115+
116+
// Phi(3:6) = axial(Rt*inv(Rc)*inv(Rb))
117+
QuaternionInverse(Rb, RbT);
118+
QuaternionCompose(Rt, RcT, Rt_RcT);
119+
QuaternionCompose(Rt_RcT, RbT, Rt_RcT_RbT);
120+
QuaternionToRotationMatrix(Rt_RcT_RbT, C);
104121
AxialVectorOfMatrix(C, V3);
105-
for (int i = 0; i < 3; ++i) {
122+
for (auto i = 0U; i < 3U; ++i) {
106123
residual_terms(i_constraint, i + 3) = V3(i);
107124
}
108125

@@ -119,7 +136,7 @@ struct CalculateRotationControlConstraint {
119136
target_gradient_terms(i_constraint, i, i) = 1.;
120137
}
121138

122-
// B(3:6,3:6) = AX(R1*RC*inv(R2)) = transpose(AX(R2*inv(RC)*inv(R1)))
139+
// B(3:6,3:6) = AX(Rb*Rc*inv(Rt)) = transpose(AX(Rt*inv(Rc)*inv(Rb)))
123140
AX_Matrix(C, A);
124141
for (int i = 0; i < 3; ++i) {
125142
for (int j = 0; j < 3; ++j) {
@@ -136,15 +153,15 @@ struct CalculateRotationControlConstraint {
136153
base_gradient_terms(i_constraint, i, i) = -1.;
137154
}
138155

139-
// B(0:3,3:6) = tilde(R1*X0)
140-
VecTilde(R1_X0, A);
156+
// B(0:3,3:6) = tilde(Rb*X0)
157+
VecTilde(Rb_X0, A);
141158
for (int i = 0; i < 3; ++i) {
142159
for (int j = 0; j < 3; ++j) {
143160
base_gradient_terms(i_constraint, i, j + 3) = A(i, j);
144161
}
145162
}
146163

147-
// B(3:6,3:6) = -AX(R2*inv(RC)*inv(R1))
164+
// B(3:6,3:6) = -AX(Rt*inv(Rc)*inv(Rb))
148165
AX_Matrix(C, A);
149166
for (int i = 0; i < 3; ++i) {
150167
for (int j = 0; j < 3; ++j) {

Diff for: src/constraints/constraint.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ struct Constraint {
8282
y_axis = {R[0][1], R[1][1], R[2][1]};
8383
z_axis = {R[0][2], R[1][2], R[2][2]};
8484
return;
85+
86+
} else if (type == ConstraintType::kRotationControl) {
87+
x_axis = UnitVector(vec);
88+
return;
8589
}
8690

8791
// If not a revolute/hinge joint, set axes to the input vector

Diff for: src/types.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ using View_Nx6x6 = Kokkos::View<double* [6][6]>;
3232

3333
// Define some type aliases for std::arrays to improve readability
3434
// 1D arrays
35-
using BeamQuadrature = std::vector<std::array<double, 2>>;
35+
using Array_2 = std::array<double, 2>;
3636
using Array_3 = std::array<double, 3>;
3737
using Array_4 = std::array<double, 4>;
3838
using Array_6 = std::array<double, 6>;
3939
using Array_7 = std::array<double, 7>;
40+
using BeamQuadrature = std::vector<Array_2>;
4041
// 2D arrays
4142
using Array_3x3 = std::array<Array_3, 3>;
4243
using Array_6x6 = std::array<Array_6, 6>;

0 commit comments

Comments
 (0)