Skip to content

Commit

Permalink
clang-tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deslaughter committed Jan 9, 2025
1 parent 8e28713 commit c29935d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 57 deletions.
41 changes: 6 additions & 35 deletions src/model/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Model {
NodeBuilder AddNode() {
const auto id = this->nodes_.size();
this->nodes_.emplace_back(id);
return NodeBuilder(this->nodes_.back());
return this->nodes_.back();
}

/// Returns a node by ID - const/read-only version
Expand Down Expand Up @@ -128,9 +128,7 @@ class Model {
[[nodiscard]] size_t NumBeamElements() const { return this->beam_elements_.size(); }

/// Returns initialized BeamsInput struct
[[nodiscard]] BeamsInput CreateBeamsInput() {
return BeamsInput(this->beam_elements_, this->gravity_);
}
[[nodiscard]] BeamsInput CreateBeamsInput() { return {this->beam_elements_, this->gravity_}; }

/// Returns Beams struct initialized with beams
[[nodiscard]] Beams CreateBeams() {
Expand Down Expand Up @@ -257,7 +255,7 @@ class Model {
size_t AddFixedBC(const size_t node_id) {
const auto id = this->constraints_.size();
this->constraints_.emplace_back(
Constraint(ConstraintType::kFixedBC, constraints_.size(), InvalidNodeID, node_id)
ConstraintType::kFixedBC, constraints_.size(), InvalidNodeID, node_id
);
return id;
}
Expand Down Expand Up @@ -296,32 +294,9 @@ class Model {
// Solver
//--------------------------------------------------------------------------

[[nodiscard]] Solver CreateSolver(State& state, Elements& elements, Constraints& constraints) {
assemble_node_freedom_allocation_table(state, elements, constraints);
compute_node_freedom_map_table(state);
create_element_freedom_table(elements, state);
create_constraint_freedom_table(constraints, state);
auto solver = Solver(
state.ID, state.node_freedom_allocation_table, state.node_freedom_map_table,
elements.NumberOfNodesPerElement(), elements.NodeStateIndices(), constraints.num_dofs,
constraints.type, constraints.base_node_freedom_table,
constraints.target_node_freedom_table, constraints.row_range
);
return solver;
}

//--------------------------------------------------------------------------
// Solution
//--------------------------------------------------------------------------

/// @brief Creates all data structures needed for solution
/// @return Solution structure initialized with state, elements, constraints, and solver
[[nodiscard]] Solution CreateSolution(
bool is_dynamic_solve, size_t max_iter, double step_size, double rho_inf
[[nodiscard]] Solver static CreateSolver(
State& state, Elements& elements, Constraints& constraints
) {
auto state = this->CreateState();
auto elements = this->CreateElements();
auto constraints = this->CreateConstraints();
assemble_node_freedom_allocation_table(state, elements, constraints);
compute_node_freedom_map_table(state);
create_element_freedom_table(elements, state);
Expand All @@ -332,11 +307,7 @@ class Model {
constraints.type, constraints.base_node_freedom_table,
constraints.target_node_freedom_table, constraints.row_range
);
return Solution{
std::move(state), std::move(elements),
std::move(constraints), StepParameters(is_dynamic_solve, max_iter, step_size, rho_inf),
std::move(solver),
};
return solver;
}

private:
Expand Down
9 changes: 7 additions & 2 deletions src/model/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Node {
Array_6 velocity = Array_6{0., 0., 0., 0., 0., 0.},
Array_6 acceleration = Array_6{0., 0., 0., 0., 0., 0.}
)
: ID(id), x(position), u(displacement), v(velocity), vd(acceleration) {}
: ID(id), x(position), u(displacement), v(velocity), vd(acceleration), s(0.) {}

/// Translate node by a displacement vector
void Translate(const Array_3& displacement) {
Expand Down Expand Up @@ -67,6 +67,11 @@ struct Node {
class NodeBuilder {
public:
NodeBuilder(Node& n) : node(n) {}
~NodeBuilder() = default;
NodeBuilder(const NodeBuilder&) = delete;
NodeBuilder(NodeBuilder&&) = delete;
NodeBuilder& operator=(const NodeBuilder&) = delete;
NodeBuilder& operator=(NodeBuilder&&) = delete;

NodeBuilder& SetPosition(
const double x, const double y, const double z, const double w, const double i,
Expand Down Expand Up @@ -127,7 +132,7 @@ class NodeBuilder {
return *this;
}

size_t Build() const { return this->node.ID; }
[[nodiscard]] size_t Build() const { return this->node.ID; }

private:
Node& node;
Expand Down
11 changes: 7 additions & 4 deletions tests/unit_tests/elements/beams/test_beams_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ class BeamsInputTest : public ::testing::Test {
// Create a mock Model for creating nodes
auto model = Model();
std::vector<double> s{0., 0.5, 1.0, 0., 1., 0., 0.33, 0.67, 1.0};
std::vector<size_t> node_ids;
for (size_t i = 0; i < 9; ++i) {
model.AddNode()
.SetElemLocation(s[i])
.SetPosition(static_cast<double>(i), 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
.Build();
node_ids.emplace_back(
model.AddNode()
.SetElemLocation(s[i])
.SetPosition(static_cast<double>(i), 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
.Build()
);
}

// Create 3 elements with different numbers of nodes and quadrature points
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/elements/masses/test_masses_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class MassesInputTest : public ::testing::Test {
static auto CreateTestElements() {
// Create a mock Model and add 2 nodes
auto model = Model();
for (int i = 0; i < 2; ++i) {
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build();
}
std::vector<size_t> node_ids{
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build(),
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build(),
};

// Create an identity mass matrix
constexpr auto mass_matrix = std::array{
Expand Down
10 changes: 7 additions & 3 deletions tests/unit_tests/elements/springs/test_springs_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class SpringsInputTest : public ::testing::Test {
static auto CreateTestElements() {
auto model = Model();
// Add 4 nodes to the model
for (int i = 0; i < 4; ++i) {
model.AddNode().SetPosition(static_cast<double>(i), 0., 0., 1., 0., 0., 0.).Build();
}
std::vector<size_t> node_ids{
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build(),
model.AddNode().SetPosition(1., 0., 0., 1., 0., 0., 0.).Build(),
model.AddNode().SetPosition(2., 0., 0., 1., 0., 0., 0.).Build(),
model.AddNode().SetPosition(3., 0., 0., 1., 0., 0., 0.).Build(),
};

// Create 2 spring elements based on the nodes
return std::vector<SpringElement>{
SpringElement(0U, {0U, 1U}, 1000., 0.), // element 1
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/model/test_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ TEST(Model, ModelCreateState) {
auto R2 = RotationVectorToQuaternion({0., 1., 0.});

// Create node with initial position and displacement from initial position
model.AddNode()
.SetPosition(1., 2., 3., R1[0], R1[1], R1[2], R1[3])
.SetDisplacement(3., 2., 1., R2[0], R2[1], R2[2], R2[3])
.Build();
static_cast<void>(model.AddNode()
.SetPosition(1., 2., 3., R1[0], R1[1], R1[2], R1[3])
.SetDisplacement(3., 2., 1., R2[0], R2[1], R2[2], R2[3])
.Build());

// Create state object from model
auto state = model.CreateState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace openturbine::tests {

inline auto SetUpSpringResidualTest() {
auto model = Model();
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build();
model.AddNode().SetPosition(1., 0., 0., 1., 0., 0., 0.).Build();
const auto springs_input = SpringsInput({SpringElement(0U, {0U, 1U}, 1., 1.)});
auto node1_id = model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build();
auto node2_id = model.AddNode().SetPosition(1., 0., 0., 1., 0., 0., 0.).Build();
const auto springs_input = SpringsInput({SpringElement(0U, {node1_id, node2_id}, 1., 1.)});
return CreateSprings(springs_input, model.GetNodes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace openturbine::tests {

inline auto SetUpSpringStiffnessTest() {
auto model = Model();
model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build();
model.AddNode().SetPosition(1., 0., 0., 1., 0., 0., 0.).Build();
const auto springs_input = SpringsInput({SpringElement(0U, {0U, 1U}, 1., 1.)});
auto node1_id = model.AddNode().SetPosition(0., 0., 0., 1., 0., 0., 0.).Build();
auto node2_id = model.AddNode().SetPosition(1., 0., 0., 1., 0., 0., 0.).Build();
const auto springs_input = SpringsInput({SpringElement(0U, {node1_id, node2_id}, 1., 1.)});
return CreateSprings(springs_input, model.GetNodes());
}

Expand Down

0 comments on commit c29935d

Please sign in to comment.