Skip to content

Commit

Permalink
Merge pull request #230 from Exawind/fix_clang_tidy_2
Browse files Browse the repository at this point in the history
Fix clang-tidy checks in .cpp files
  • Loading branch information
ddement authored Aug 1, 2024
2 parents 8e88b34 + dc0a61b commit c7cf060
Show file tree
Hide file tree
Showing 86 changed files with 2,700 additions and 2,675 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Checks: "bugprone*,
portability*,
readability*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-non-private-member-variables-in-classes,
-modernize-use-trailing-return-type,
-readability-else-after-return,
-readability-magic-numbers,
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ jobs:
cd build-clangtidy
cmake .. \
-DOpenTurbine_ENABLE_CLANG_TIDY=ON \
-DOpenTurbine_WARNINGS_AS_ERRORS=OFF \
-DCMAKE_BUILD_TYPE=Debug
cmake --build .
2 changes: 1 addition & 1 deletion src/restruct_poc/beams/beam_section.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct BeamSection {
double s, std::array<std::array<double, 6>, 6> mass,
std::array<std::array<double, 6>, 6> stiffness
)
: position(s), M_star(std::move(mass)), C_star(std::move(stiffness)) {}
: position(s), M_star(mass), C_star(stiffness) {}
};

} // namespace openturbine
4 changes: 1 addition & 3 deletions src/restruct_poc/beams/beams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Beams {
Kokkos::pair<size_t, size_t> node_range;
Kokkos::pair<size_t, size_t> qp_range;
Kokkos::pair<size_t, size_t> qp_shape_range;
ElemIndices() {}
ElemIndices() = default;
ElemIndices(size_t n_nodes, size_t n_qps, size_t i_node_start, size_t i_qp_start)
: num_nodes(n_nodes),
num_qps(n_qps),
Expand Down Expand Up @@ -88,8 +88,6 @@ struct Beams {
View_NxN shape_interp; // shape function matrix for interpolation [Nodes x QPs]
View_NxN shape_deriv; // shape function matrix for derivative interp [Nodes x QPs]

Beams() {} // Default constructor which doesn't initialize views

// Constructor which initializes views based on given sizes
Beams(
const size_t n_beams, const size_t n_nodes, const size_t n_qps, const size_t max_e_nodes,
Expand Down
12 changes: 6 additions & 6 deletions src/restruct_poc/beams/beams_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ struct BeamsInput {
std::array<double, 3> gravity;

BeamsInput(std::vector<BeamElement> elems, std::array<double, 3> g)
: elements(std::move(elems)), gravity(std::move(g)) {}
: elements(std::move(elems)), gravity(g) {}

size_t NumElements() const { return elements.size(); };
[[nodiscard]] size_t NumElements() const { return elements.size(); };

size_t NumNodes() const {
[[nodiscard]] size_t NumNodes() const {
size_t num_nodes{0};
for (const auto& e : this->elements) {
num_nodes += e.nodes.size();
}
return num_nodes;
}

size_t NumQuadraturePoints() const {
[[nodiscard]] size_t NumQuadraturePoints() const {
size_t num_qps{0};
for (const auto& e : this->elements) {
num_qps += e.quadrature.size();
}
return num_qps;
}

size_t MaxElemNodes() const {
[[nodiscard]] size_t MaxElemNodes() const {
size_t max_elem_nodes{0};
for (const auto& e : this->elements) {
max_elem_nodes = std::max(max_elem_nodes, e.nodes.size());
}
return max_elem_nodes;
}

size_t MaxElemQuadraturePoints() const {
[[nodiscard]] size_t MaxElemQuadraturePoints() const {
size_t max_elem_qps{0};
for (const auto& e : this->elements) {
max_elem_qps = std::max(max_elem_qps, e.quadrature.size());
Expand Down
15 changes: 8 additions & 7 deletions src/restruct_poc/beams/calculate_jacobian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ struct CalculateJacobian {

KOKKOS_FUNCTION
void operator()(const int i_elem) const {
auto& idx = elem_indices[i_elem];
auto shape_deriv = Kokkos::subview(shape_derivative, idx.node_range, idx.qp_shape_range);
auto qp_pos_deriv = Kokkos::subview(qp_position_derivative, idx.qp_range, Kokkos::ALL);
auto node_pos =
const auto& idx = elem_indices[i_elem];
const auto shape_deriv =
Kokkos::subview(shape_derivative, idx.node_range, idx.qp_shape_range);
const auto qp_pos_deriv = Kokkos::subview(qp_position_derivative, idx.qp_range, Kokkos::ALL);
const auto node_pos =
Kokkos::subview(node_position_rotation, idx.node_range, Kokkos::make_pair(0, 3));
auto qp_jacob = Kokkos::subview(qp_jacobian, idx.qp_range);
const auto qp_jacob = Kokkos::subview(qp_jacobian, idx.qp_range);

InterpVector3(shape_deriv, node_pos, qp_pos_deriv);

for (auto j = 0u; j < idx.num_qps; ++j) {
for (auto j = 0U; j < idx.num_qps; ++j) {
const auto jacobian = Kokkos::sqrt(
Kokkos::pow(qp_pos_deriv(j, 0), 2.) + Kokkos::pow(qp_pos_deriv(j, 1), 2.) +
Kokkos::pow(qp_pos_deriv(j, 2), 2.)
);
qp_jacob(j) = jacobian;
for (int k = 0; k < 3; ++k) {
for (auto k = 0U; k < 3U; ++k) {
qp_pos_deriv(j, k) /= jacobian;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/restruct_poc/beams/create_beams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ inline Beams CreateBeams(const BeamsInput& beams_input) {

for (size_t i = 0; i < beams_input.NumElements(); i++) {
// Get number of nodes and quadrature points in element
size_t num_nodes = beams_input.elements[i].nodes.size();
size_t num_qps = beams_input.elements[i].quadrature.size();
const auto num_nodes = beams_input.elements[i].nodes.size();
const auto num_qps = beams_input.elements[i].quadrature.size();

// Create element indices and set in host mirror
host_elem_indices[i] = Beams::ElemIndices(num_nodes, num_qps, node_counter, qp_counter);
auto& idx = host_elem_indices[i];
const auto& idx = host_elem_indices[i];

// Populate beam node->state indices
for (size_t j = 0; j < num_nodes; ++j) {
Expand Down
17 changes: 9 additions & 8 deletions src/restruct_poc/beams/interpolate_QP_position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ struct InterpolateQPPosition {

KOKKOS_FUNCTION
void operator()(const int i_elem) const {
auto& idx = elem_indices[i_elem];
auto shape_interp = Kokkos::subview(shape_interpolation, idx.node_range, idx.qp_shape_range);
auto node_pos =
const auto& idx = elem_indices[i_elem];
const auto shape_interp =
Kokkos::subview(shape_interpolation, idx.node_range, idx.qp_shape_range);
const auto node_pos =
Kokkos::subview(node_position_rotation, idx.node_range, Kokkos::make_pair(0, 3));
auto qp_pos = Kokkos::subview(qp_position, idx.qp_range, Kokkos::ALL);
const auto qp_pos = Kokkos::subview(qp_position, idx.qp_range, Kokkos::ALL);

for (auto j = 0u; j < idx.num_qps; ++j) {
for (auto j = 0U; j < idx.num_qps; ++j) {
auto local_result = Kokkos::Array<double, 3>{};
for (auto i = 0u; i < idx.num_nodes; ++i) {
for (auto i = 0U; i < idx.num_nodes; ++i) {
const auto phi = shape_interp(i, j);
for (auto k = 0u; k < kVectorComponents; ++k) {
for (auto k = 0U; k < kVectorComponents; ++k) {
local_result[k] += node_pos(i, k) * phi;
}
}
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
qp_pos(j, k) = local_result[k];
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/restruct_poc/beams/interpolate_QP_rotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ struct InterpolateQPRotation {

KOKKOS_FUNCTION
void operator()(const int i_elem) const {
auto& idx = elem_indices[i_elem];
auto shape_interp = Kokkos::subview(shape_interpolation, idx.node_range, idx.qp_shape_range);
auto node_rot =
const auto& idx = elem_indices[i_elem];
const auto shape_interp =
Kokkos::subview(shape_interpolation, idx.node_range, idx.qp_shape_range);
const auto node_rot =
Kokkos::subview(node_position_rotation, idx.node_range, Kokkos::make_pair(3, 7));
auto qp_rot = Kokkos::subview(qp_rotation, idx.qp_range, Kokkos::ALL);
const auto qp_rot = Kokkos::subview(qp_rotation, idx.qp_range, Kokkos::ALL);

InterpQuaternion(shape_interp, node_rot, qp_rot);
}
Expand Down
24 changes: 12 additions & 12 deletions src/restruct_poc/beams/interpolate_QP_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct InterpolateQPState_u {
void operator()(size_t j_index) const {
const auto j = first_qp + j_index;
auto local_total = Kokkos::Array<double, 3>{};
for (auto i_index = 0u; i_index < num_nodes; ++i_index) {
for (auto i_index = 0U; i_index < num_nodes; ++i_index) {
const auto i = first_node + i_index;
const auto phi = shape_interp(i, j_index);
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
local_total[k] += node_u(i, k) * phi;
}
}
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
qp_u(j, k) = local_total[k];
}
}
Expand All @@ -45,14 +45,14 @@ struct InterpolateQPState_uprime {
const auto j = first_qp + j_index;
const auto jacobian = qp_jacobian(j);
auto local_total = Kokkos::Array<double, 3>{};
for (auto i_index = 0u; i_index < num_nodes; ++i_index) {
for (auto i_index = 0U; i_index < num_nodes; ++i_index) {
const auto i = first_node + i_index;
const auto dphi = shape_deriv(i, j_index);
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
local_total[k] += node_u(i, k) * dphi / jacobian;
}
}
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
qp_uprime(j, k) = local_total[k];
}
}
Expand All @@ -70,10 +70,10 @@ struct InterpolateQPState_r {
void operator()(size_t j_index) const {
const auto j = first_qp + j_index;
auto local_total = Kokkos::Array<double, 4>{};
for (auto i_index = 0u; i_index < num_nodes; ++i_index) {
for (auto i_index = 0U; i_index < num_nodes; ++i_index) {
const auto i = first_node + i_index;
const auto phi = shape_interp(i, j_index);
for (auto k = 0u; k < 4u; ++k) {
for (auto k = 0U; k < 4U; ++k) {
local_total[k] += node_u(i, k + 3) * phi;
}
}
Expand All @@ -85,7 +85,7 @@ struct InterpolateQPState_r {
if (length == 0.) {
local_total = length_zero_result;
}
for (auto k = 0u; k < 4u; ++k) {
for (auto k = 0U; k < 4U; ++k) {
qp_r(j, k) = local_total[k];
}
}
Expand All @@ -105,14 +105,14 @@ struct InterpolateQPState_rprime {
const auto j = first_qp + j_index;
const auto jacobian = qp_jacobian(j);
auto local_total = Kokkos::Array<double, 4>{};
for (auto i_index = 0u; i_index < num_nodes; ++i_index) {
for (auto i_index = 0U; i_index < num_nodes; ++i_index) {
const auto i = first_node + i_index;
const auto dphi = shape_deriv(i, j_index);
for (auto k = 0u; k < 4u; ++k) {
for (auto k = 0U; k < 4U; ++k) {
local_total[k] += node_u(i, k + 3) * dphi / jacobian;
}
}
for (auto k = 0u; k < 4u; ++k) {
for (auto k = 0U; k < 4U; ++k) {
qp_rprime(j, k) = local_total[k];
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/restruct_poc/beams/interpolate_QP_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct InterpolateQPVector {
void operator()(size_t j_index) const {
const auto j = first_qp + j_index;
auto local_total = Kokkos::Array<double, 3>{};
for (auto i_index = 0u; i_index < num_nodes; ++i_index) {
for (auto i_index = 0U; i_index < num_nodes; ++i_index) {
const auto i = first_node + i_index;
const auto phi = shape_interp(i, j_index);
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
local_total[k] += node_vector(i, k) * phi;
}
}
for (auto k = 0u; k < 3u; ++k) {
for (auto k = 0U; k < 3U; ++k) {
qp_vector(j, k) = local_total[k];
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/restruct_poc/beams/interpolation_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
namespace openturbine {

KOKKOS_INLINE_FUNCTION
void InterpVector3(View_NxN::const_type shape_matrix, View_Nx3::const_type node_v, View_Nx3 qp_v) {
void InterpVector3(
const View_NxN::const_type& shape_matrix, const View_Nx3::const_type& node_v,
const View_Nx3& qp_v
) {
for (int j = 0; j < qp_v.extent_int(0); ++j) {
auto local_total = Kokkos::Array<double, 3>{};
for (int i = 0; i < node_v.extent_int(0); ++i) {
Expand All @@ -23,7 +26,10 @@ void InterpVector3(View_NxN::const_type shape_matrix, View_Nx3::const_type node_
}

KOKKOS_INLINE_FUNCTION
void InterpVector4(View_NxN::const_type shape_matrix, View_Nx4::const_type node_v, View_Nx4 qp_v) {
void InterpVector4(
const View_NxN::const_type& shape_matrix, const View_Nx4::const_type& node_v,
const View_Nx4& qp_v
) {
for (int j = 0; j < qp_v.extent_int(0); ++j) {
auto local_total = Kokkos::Array<double, 4>{};
for (int i = 0; i < node_v.extent_int(0); ++i) {
Expand All @@ -40,7 +46,8 @@ void InterpVector4(View_NxN::const_type shape_matrix, View_Nx4::const_type node_

KOKKOS_INLINE_FUNCTION
void InterpQuaternion(
View_NxN::const_type shape_matrix, View_Nx4::const_type node_v, View_Nx4 qp_v
const View_NxN::const_type& shape_matrix, const View_Nx4::const_type& node_v,
const View_Nx4& qp_v
) {
InterpVector4(shape_matrix, node_v, qp_v);
static constexpr auto length_zero_result = Kokkos::Array<double, 4>{1., 0., 0., 0.};
Expand All @@ -63,8 +70,8 @@ void InterpQuaternion(

KOKKOS_INLINE_FUNCTION
void InterpVector3Deriv(
View_NxN::const_type shape_matrix_deriv, View_N::const_type jacobian,
View_Nx3::const_type node_v, View_Nx3 qp_v
const View_NxN::const_type& shape_matrix_deriv, const View_N::const_type& jacobian,
const View_Nx3::const_type& node_v, const View_Nx3& qp_v
) {
InterpVector3(shape_matrix_deriv, node_v, qp_v);
for (int j = 0; j < qp_v.extent_int(0); ++j) {
Expand All @@ -77,8 +84,8 @@ void InterpVector3Deriv(

KOKKOS_INLINE_FUNCTION
void InterpVector4Deriv(
View_NxN::const_type shape_matrix_deriv, View_N::const_type jacobian,
View_Nx4::const_type node_v, View_Nx4 qp_v
const View_NxN::const_type& shape_matrix_deriv, const View_N::const_type& jacobian,
const View_Nx4::const_type& node_v, const View_Nx4& qp_v
) {
InterpVector4(shape_matrix_deriv, node_v, qp_v);
for (int j = 0; j < qp_v.extent_int(0); ++j) {
Expand Down
2 changes: 1 addition & 1 deletion src/restruct_poc/math/vector_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ constexpr Array_3 CrossProduct(const Array_3& a, const Array_3& b) {
/// UnitVector returns the unit vector of the given vector
constexpr Array_3 UnitVector(const Array_3& v) {
// Calculate vector norm
double norm = std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
const double norm = std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
if (norm == 0.) {
throw std::invalid_argument("Cannot normalize a zero vector");
}
Expand Down
Loading

0 comments on commit c7cf060

Please sign in to comment.