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

Enable definition of constraints from a 6-DOF (base) node to a 3-DOF (target) node #327

Merged
merged 62 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
fc9eb02
Minor cosmetic fixes
faisal-bhuiyan Dec 30, 2024
f3c2359
Refactor ConstraintType and helper functions to enhance clarity + uni…
faisal-bhuiyan Dec 30, 2024
ef4bde7
Refactor NumDOFsForConstraint to use if block as opposed to switch
faisal-bhuiyan Dec 30, 2024
b13f4cc
Add unit tests for Constraint struct
faisal-bhuiyan Dec 30, 2024
b17edfb
Refactor Constraints struct + get it under unit test coverage
faisal-bhuiyan Dec 31, 2024
1ace07b
Refactor the system kernels of constraints to look similar to element…
faisal-bhuiyan Dec 31, 2024
8fd1d5c
Start adding unit tests for CreateConstraintFreedomTable -- begin wit…
faisal-bhuiyan Jan 6, 2025
ec4e03c
Complete the unit test suite for create_constraint_freedom_table() by…
faisal-bhuiyan Jan 6, 2025
de8c342
Add RigidJoint3DOFs to the type of constaints
faisal-bhuiyan Jan 6, 2025
9b85db4
Minor tweaks to unit tests for create_constraint_freedom_table()
faisal-bhuiyan Jan 6, 2025
9c61c96
Minor fixes to make static analyzers happy
faisal-bhuiyan Jan 7, 2025
5dad936
Merge branch 'main' into 6-to-3-dof-rigid-constraint
faisal-bhuiyan Jan 7, 2025
0bd5bba
Remove the kRigidJoint3DOF type from ConstraintType enum since we sho…
faisal-bhuiyan Jan 8, 2025
bf669fa
Merge branch 'main' into 6-to-3-dof-rigid-constraint
faisal-bhuiyan Jan 11, 2025
361eaeb
Refactor c-tor of Constraints to create modularity + other minor impr…
faisal-bhuiyan Jan 11, 2025
9d5e588
Add annotations to FreedomSignature and related functions to increase…
faisal-bhuiyan Jan 12, 2025
1481a32
Minor fixes
faisal-bhuiyan Jan 12, 2025
ec5fc4c
Add node_num_dofs attribute to Constraint class to keep track of the …
faisal-bhuiyan Jan 13, 2025
4741418
Bring back the unit tests for Constraint and Constraints structs
faisal-bhuiyan Jan 13, 2025
de4575b
Add attribute node_num_dofs to Constraints + use it to modify the log…
faisal-bhuiyan Jan 13, 2025
989d1a1
Minor fixes to Model class to add num_dofs to AddRigidJointConstraint
faisal-bhuiyan Jan 13, 2025
2503490
Add preliminary implementation of the heavy top problem
faisal-bhuiyan Jan 14, 2025
c157bde
Add node_num_dofs to CalculateFixedBCConstraint + other minor fixes
faisal-bhuiyan Jan 14, 2025
1c30aa7
Refactor unit tests for create_constraint_freedom_table()
faisal-bhuiyan Jan 14, 2025
63fc213
clang-tidy fix
faisal-bhuiyan Jan 14, 2025
ffb55b5
Clang-tidy fixes
faisal-bhuiyan Jan 14, 2025
baa5b15
Add active_dofs attribute to Node struct to manage the FreedomSignatu…
faisal-bhuiyan Jan 14, 2025
785ed29
Add a default c-tor to Elements class to create an empty object to fa…
faisal-bhuiyan Jan 14, 2025
bc6692f
Refactor Constraints struct to assign the base and target_node_freedo…
faisal-bhuiyan Jan 14, 2025
2cb3d8f
Take care of the TODO item in heavy top test
faisal-bhuiyan Jan 14, 2025
ce911f8
Minor change in Constraints to make LieAlgComponents -> 6 for clarity
faisal-bhuiyan Jan 15, 2025
84421b9
Add kFixedBC6DOFsTo3DOFs, kPrescribedBC6DOFsTo3DOFs, and kRigidJoint6…
faisal-bhuiyan Jan 15, 2025
dbf8500
Remove FreedomSignature attribute from Node
faisal-bhuiyan Jan 15, 2025
1dfe1e0
Remove node number of dofs attribute from Constrant and Model class
faisal-bhuiyan Jan 15, 2025
a25b176
Merge branch 'main' into 6-to-3-dof-rigid-constraint
faisal-bhuiyan Jan 15, 2025
977c00e
Add Add_X methods to Model class for new constraint types
faisal-bhuiyan Jan 15, 2025
0ef3a70
Add logic to CalculateConstraintResidualGradient, CalculatePrescribed…
faisal-bhuiyan Jan 15, 2025
96937fd
Minor fixes to heavy top test
faisal-bhuiyan Jan 15, 2025
2a4df71
Modify constraints to allow nodes with different numbers of DOFs
deslaughter Jan 15, 2025
f1c86be
Add algo accln initialization in CopyNodesToState
faisal-bhuiyan Jan 16, 2025
cd02faa
Fix sign in UpdateLambdaPrediction
faisal-bhuiyan Jan 16, 2025
bac11b8
Make adjustments to r-tests due to change in UpdateLambdaPrediction
faisal-bhuiyan Jan 16, 2025
e95e9c7
Merge branch 'main' into 6-to-3-dof-rigid-constraint
faisal-bhuiyan Jan 16, 2025
58b8afa
Fix unit tests in constraints to use the updated interfaces
faisal-bhuiyan Jan 16, 2025
925230c
Fix unit tests in solver->ComputeNumberOfNonZeros_Constraints and Pop…
faisal-bhuiyan Jan 16, 2025
6fee585
Add convergence tolerances to StepParameters
faisal-bhuiyan Jan 16, 2025
368065c
Fix clang-tidy error
faisal-bhuiyan Jan 16, 2025
495cab5
Pass convergence params via StepParameters for heavy top test
faisal-bhuiyan Jan 16, 2025
3a9bb7e
Added constraints to convergence error calculation. Currently have a …
deslaughter Jan 16, 2025
335d144
Fix the SpringMassSystemTest r-test due to changes made to the conver…
faisal-bhuiyan Jan 17, 2025
d169adf
Minor fix to Model class for AddConstraintX methods to match the unde…
faisal-bhuiyan Jan 17, 2025
6805f75
Fix segfault in SolverStep1Test.SolutionVector due to updates to conv…
faisal-bhuiyan Jan 17, 2025
86ac339
Fix clang-tidy error
faisal-bhuiyan Jan 17, 2025
1d7a481
Clean up CalculateRigidJointConstraint and removed unnecessary variables
deslaughter Jan 17, 2025
38aae82
Add checks to heavy-top test
deslaughter Jan 17, 2025
fec8e50
Resolve failing SolverStep1Test.SolutionVector test
deslaughter Jan 17, 2025
d035ff2
Use named View types in calculate constraint functions, remove unnece…
deslaughter Jan 17, 2025
35d608c
Better names for CalculateErrorSumSquares
deslaughter Jan 17, 2025
15b0000
Minor fix to CopyNodesToState to make the setting of algo accln -> vd…
faisal-bhuiyan Jan 17, 2025
d0642f4
Minor fix in ConstraintsType struct to remove throwing exceptions
faisal-bhuiyan Jan 17, 2025
214f67f
Remove redundant attribute from ComputeNumberOfNonZeros_Constraints
faisal-bhuiyan Jan 17, 2025
b7f5da5
Expand unit tests coverage in ComputeNumberOfNonZeros_Constraints for…
faisal-bhuiyan Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/constraints/calculate_constraint_force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ namespace openturbine {
struct CalculateConstraintForce {
Kokkos::View<ConstraintType*>::const_type type;
Kokkos::View<size_t*>::const_type target_node_index;
Kokkos::View<double* [3][3]>::const_type axes;
Kokkos::View<double* [7]>::const_type inputs;
Kokkos::View<double* [7]>::const_type node_u;
Kokkos::View<double* [6]> system_residual_terms;
View_Nx3x3::const_type axes;
View_Nx7::const_type inputs;
View_Nx7::const_type node_u;
View_Nx6 system_residual_terms;

KOKKOS_FUNCTION
void operator()(const int i_constraint) const {
switch (type(i_constraint)) {
case ConstraintType::kRevoluteJoint: {
// Applies the torque from a revolute joint constraint to the system residual
CalculateRevoluteJointForce{
target_node_index, axes, inputs, node_u, system_residual_terms
}(i_constraint);
} break;
default: {
// Do nothing
} break;
if (type(i_constraint) == ConstraintType::kRevoluteJoint) {
// Applies the torque from a revolute joint constraint to the system residual
CalculateRevoluteJointForce{i_constraint, target_node_index, axes, inputs,
node_u, system_residual_terms}();
return;
}
}
};
Expand Down
24 changes: 10 additions & 14 deletions src/constraints/calculate_constraint_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ namespace openturbine {
struct CalculateConstraintOutput {
Kokkos::View<ConstraintType*>::const_type type;
Kokkos::View<size_t*>::const_type target_node_index;
Kokkos::View<double* [3][3]>::const_type axes;
Kokkos::View<double* [7]>::const_type node_x0; // Initial position
Kokkos::View<double* [7]>::const_type node_u; // Displacement
Kokkos::View<double* [6]>::const_type node_udot; // Velocity
Kokkos::View<double* [6]>::const_type node_uddot; // Acceleration
Kokkos::View<double* [3]> outputs;
View_Nx3x3::const_type axes;
View_Nx7::const_type node_x0; // Initial position
View_Nx7::const_type node_u; // Displacement
View_Nx6::const_type node_udot; // Velocity
View_Nx6::const_type node_uddot; // Acceleration
View_Nx3 outputs;

KOKKOS_FUNCTION
void operator()(const int i_constraint) const {
switch (type(i_constraint)) {
case ConstraintType::kRevoluteJoint: {
CalculateRevoluteJointOutput{target_node_index, axes, node_x0, node_u,
node_udot, node_uddot, outputs}(i_constraint);
} break;
default: {
// Do nothing
} break;
if (type(i_constraint) == ConstraintType::kRevoluteJoint) {
CalculateRevoluteJointOutput{i_constraint, target_node_index, axes, node_x0,
node_u, node_udot, node_uddot, outputs}();
return;
}
}
};
Expand Down
116 changes: 71 additions & 45 deletions src/constraints/calculate_constraint_residual_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,83 @@ namespace openturbine {

struct CalculateConstraintResidualGradient {
Kokkos::View<ConstraintType*>::const_type type;
Kokkos::View<Kokkos::pair<size_t, size_t>*>::const_type target_node_col_range;
Kokkos::View<size_t*>::const_type base_node_index;
Kokkos::View<size_t*>::const_type target_node_index;
Kokkos::View<double* [3]>::const_type X0_;
Kokkos::View<double* [3][3]>::const_type axes;
Kokkos::View<double* [7]>::const_type constraint_inputs;
Kokkos::View<double* [7]>::const_type node_u;
Kokkos::View<double* [6]> residual_terms;
Kokkos::View<double* [6][6]> base_gradient_terms;
Kokkos::View<double* [6][6]> target_gradient_terms;
View_Nx3::const_type X0_;
View_Nx3x3::const_type axes;
View_Nx7::const_type constraint_inputs;
View_Nx7::const_type node_u;
View_Nx6 residual_terms;
View_Nx6x6 base_gradient_terms;
View_Nx6x6 target_gradient_terms;

KOKKOS_FUNCTION
void operator()(const int i_constraint) const {
if (type(i_constraint) == ConstraintType::kFixedBC) {
CalculateFixedBCConstraint{target_node_index, X0_,
constraint_inputs, node_u,
residual_terms, target_gradient_terms}(i_constraint);
} else if (type(i_constraint) == ConstraintType::kPrescribedBC) {
CalculatePrescribedBCConstraint{target_node_index, X0_,
constraint_inputs, node_u,
residual_terms, target_gradient_terms}(i_constraint);
} else if (type(i_constraint) == ConstraintType::kRigidJoint) {
CalculateRigidJointConstraint{base_node_index,
target_node_index,
X0_,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms}(i_constraint);
} else if (type(i_constraint) == ConstraintType::kRevoluteJoint) {
CalculateRevoluteJointConstraint{base_node_index,
target_node_index,
X0_,
axes,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms}(i_constraint);
} else if (type(i_constraint) == ConstraintType::kRotationControl) {
CalculateRotationControlConstraint{base_node_index,
target_node_index,
X0_,
axes,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms}(i_constraint);
auto constraint_type = type(i_constraint);
if (constraint_type == ConstraintType::kFixedBC ||
constraint_type == ConstraintType::kFixedBC3DOFs) {
CalculateFixedBCConstraint{
i_constraint, target_node_col_range, target_node_index, X0_, constraint_inputs,
node_u, residual_terms, target_gradient_terms,
}();
return;
};
if (constraint_type == ConstraintType::kPrescribedBC ||
constraint_type == ConstraintType::kPrescribedBC3DOFs) {
CalculatePrescribedBCConstraint{
i_constraint, target_node_col_range, target_node_index, X0_, constraint_inputs,
node_u, residual_terms, target_gradient_terms,
}();
return;
};
if (constraint_type == ConstraintType::kRigidJoint ||
constraint_type == ConstraintType::kRigidJoint6DOFsTo3DOFs) {
CalculateRigidJointConstraint{
i_constraint,
target_node_col_range,
base_node_index,
target_node_index,
X0_,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms,
}();
return;
};
if (constraint_type == ConstraintType::kRevoluteJoint) {
CalculateRevoluteJointConstraint{
i_constraint,
base_node_index,
target_node_index,
X0_,
axes,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms,
}();
return;
};
if (constraint_type == ConstraintType::kRotationControl) {
CalculateRotationControlConstraint{
i_constraint,
base_node_index,
target_node_index,
X0_,
axes,
constraint_inputs,
node_u,
residual_terms,
base_gradient_terms,
target_gradient_terms,
}();
return;
}
}
};
};

} // namespace openturbine
53 changes: 27 additions & 26 deletions src/constraints/calculate_fixed_bc_constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
namespace openturbine {

struct CalculateFixedBCConstraint {
int i_constraint;
Kokkos::View<Kokkos::pair<size_t, size_t>*>::const_type target_node_col_range;
Kokkos::View<size_t*>::const_type target_node_index;
Kokkos::View<double* [3]>::const_type X0_;
Kokkos::View<double* [7]>::const_type constraint_inputs;
Kokkos::View<double* [7]>::const_type node_u;
Kokkos::View<double* [6]> residual_terms;
Kokkos::View<double* [6][6]> target_gradient_terms;
View_Nx3::const_type X0_;
View_Nx7::const_type constraint_inputs;
View_Nx7::const_type node_u;
View_Nx6 residual_terms;
View_Nx6x6 target_gradient_terms;

KOKKOS_FUNCTION
void operator()(const int i_constraint) const {
void operator()() const {
const auto i_node2 = target_node_index(i_constraint);

// Initial difference between nodes
Expand All @@ -43,21 +45,14 @@ struct CalculateFixedBCConstraint {
Kokkos::Array<double, 3>{node_u(i_node2, 0), node_u(i_node2, 1), node_u(i_node2, 2)};
const auto u2 = View_3::const_type{u2_data.data()};

// Rotation control
constexpr auto RCt_data = Kokkos::Array<double, 4>{1., 0., 0., 0.};
const auto RCt = Kokkos::View<double[4]>::const_type{RCt_data.data()};

auto R1t_data = Kokkos::Array<double, 4>{};
const auto R1t = Kokkos::View<double[4]>{R1t_data.data()};

auto R1_X0_data = Kokkos::Array<double, 4>{};
const auto R1_X0 = Kokkos::View<double[4]>{R1_X0_data.data()};

auto R2_RCt_data = Kokkos::Array<double, 4>{};
const auto R2_RCt = Kokkos::View<double[4]>{R2_RCt_data.data()};

auto R2_RCt_R1t_data = Kokkos::Array<double, 4>{};
const auto R2_RCt_R1t = Kokkos::View<double[4]>{R2_RCt_R1t_data.data()};
auto R2_R1t_data = Kokkos::Array<double, 4>{};
const auto R2_R1t = Kokkos::View<double[4]>{R2_R1t_data.data()};

auto A_data = Kokkos::Array<double, 9>{};
const auto A = View_3x3{A_data.data()};
Expand All @@ -72,6 +67,9 @@ struct CalculateFixedBCConstraint {
// Residual Vector
//----------------------------------------------------------------------

const auto target_node_cols =
target_node_col_range(i_constraint).second - target_node_col_range(i_constraint).first;

// Phi(0:3) = u2 + X0 - u1 - R1*X0
QuaternionInverse(R1, R1t);
RotateVectorByQuaternion(R1, X0, R1_X0);
Expand All @@ -81,12 +79,13 @@ struct CalculateFixedBCConstraint {

// Angular residual
// Phi(3:6) = axial(R2*inv(RC)*inv(R1))
QuaternionCompose(R2, RCt, R2_RCt);
QuaternionCompose(R2_RCt, R1t, R2_RCt_R1t);
QuaternionToRotationMatrix(R2_RCt_R1t, C);
AxialVectorOfMatrix(C, V3);
for (int i = 0; i < 3; ++i) {
residual_terms(i_constraint, i + 3) = V3(i);
if (target_node_cols == 6) {
QuaternionCompose(R2, R1t, R2_R1t);
QuaternionToRotationMatrix(R2_R1t, C);
AxialVectorOfMatrix(C, V3);
for (int i = 0; i < 3; ++i) {
residual_terms(i_constraint, i + 3) = V3(i);
}
}

//----------------------------------------------------------------------
Expand All @@ -103,13 +102,15 @@ struct CalculateFixedBCConstraint {
}

// B(3:6,3:6) = AX(R1*RC*inv(R2)) = transpose(AX(R2*inv(RC)*inv(R1)))
AX_Matrix(C, A);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
target_gradient_terms(i_constraint, i + 3, j + 3) = A(j, i);
if (target_node_cols == 6) {
AX_Matrix(C, A);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
target_gradient_terms(i_constraint, i + 3, j + 3) = A(j, i);
}
}
}
}
};
};

} // namespace openturbine
58 changes: 34 additions & 24 deletions src/constraints/calculate_prescribed_bc_constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
namespace openturbine {

struct CalculatePrescribedBCConstraint {
int i_constraint;
Kokkos::View<Kokkos::pair<size_t, size_t>*>::const_type target_node_col_range;
Kokkos::View<size_t*>::const_type target_node_index;
Kokkos::View<double* [3]>::const_type X0_;
Kokkos::View<double* [7]>::const_type constraint_inputs;
Kokkos::View<double* [7]>::const_type node_u;
Kokkos::View<double* [6]> residual_terms;
Kokkos::View<double* [6][6]> target_gradient_terms;
View_Nx3::const_type X0_;
View_Nx7::const_type constraint_inputs;
View_Nx7::const_type node_u;
View_Nx6 residual_terms;
View_Nx6x6 target_gradient_terms;

KOKKOS_FUNCTION
void operator()(const int i_constraint) const {
void operator()() const {
const auto i_node2 = target_node_index(i_constraint);

// Initial difference between nodes
Expand Down Expand Up @@ -50,21 +52,14 @@ struct CalculatePrescribedBCConstraint {
Kokkos::Array<double, 3>{node_u(i_node2, 0), node_u(i_node2, 1), node_u(i_node2, 2)};
const auto u2 = View_3::const_type{u2_data.data()};

// Rotation control
constexpr auto RCt_data = Kokkos::Array<double, 4>{1., 0., 0., 0.};
const auto RCt = Kokkos::View<double[4]>::const_type{RCt_data.data()};

auto R1t_data = Kokkos::Array<double, 4>{};
const auto R1t = Kokkos::View<double[4]>{R1t_data.data()};

auto R1_X0_data = Kokkos::Array<double, 4>{};
const auto R1_X0 = Kokkos::View<double[4]>{R1_X0_data.data()};

auto R2_RCt_data = Kokkos::Array<double, 4>{};
const auto R2_RCt = Kokkos::View<double[4]>{R2_RCt_data.data()};

auto R2_RCt_R1t_data = Kokkos::Array<double, 4>{};
const auto R2_RCt_R1t = Kokkos::View<double[4]>{R2_RCt_R1t_data.data()};
auto R2_R1t_data = Kokkos::Array<double, 4>{};
const auto R2_R1t = Kokkos::View<double[4]>{R2_R1t_data.data()};

auto A_data = Kokkos::Array<double, 9>{};
const auto A = View_3x3{A_data.data()};
Expand All @@ -79,6 +74,9 @@ struct CalculatePrescribedBCConstraint {
// Residual Vector
//----------------------------------------------------------------------

const auto n_target_node_cols =
target_node_col_range(i_constraint).second - target_node_col_range(i_constraint).first;

// Phi(0:3) = u2 + X0 - u1 - R1*X0
QuaternionInverse(R1, R1t);
RotateVectorByQuaternion(R1, X0, R1_X0);
Expand All @@ -87,13 +85,17 @@ struct CalculatePrescribedBCConstraint {
}

// Angular residual
// Phi(3:6) = axial(R2*inv(RC)*inv(R1))
QuaternionCompose(R2, RCt, R2_RCt);
QuaternionCompose(R2_RCt, R1t, R2_RCt_R1t);
QuaternionToRotationMatrix(R2_RCt_R1t, C);
AxialVectorOfMatrix(C, V3);
for (int i = 0; i < 3; ++i) {
residual_terms(i_constraint, i + 3) = V3(i);
residual_terms(i_constraint, i + 3) = 0.;
}
// Phi(3:6) = axial(R2*inv(RC)*inv(R1))
if (n_target_node_cols == 6) {
QuaternionCompose(R2, R1t, R2_R1t);
QuaternionToRotationMatrix(R2_R1t, C);
AxialVectorOfMatrix(C, V3);
for (int i = 0; i < 3; ++i) {
residual_terms(i_constraint, i + 3) = V3(i);
}
}

//----------------------------------------------------------------------
Expand All @@ -109,11 +111,19 @@ struct CalculatePrescribedBCConstraint {
target_gradient_terms(i_constraint, i, i) = 1.;
}

// B(3:6,3:6) = AX(R1*RC*inv(R2)) = transpose(AX(R2*inv(RC)*inv(R1)))
AX_Matrix(C, A);
// B(3:6,3:6) -> initialize to 0
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
target_gradient_terms(i_constraint, i + 3, j + 3) = A(j, i);
target_gradient_terms(i_constraint, i + 3, j + 3) = 0.;
}
}
// B(3:6,3:6) = AX(R1*RC*inv(R2)) = transpose(AX(R2*inv(RC)*inv(R1)))
if (n_target_node_cols == 6) {
AX_Matrix(C, A);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
target_gradient_terms(i_constraint, i + 3, j + 3) = A(j, i);
}
}
}
}
Expand Down
Loading
Loading