-
Notifications
You must be signed in to change notification settings - Fork 8
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 #217 from Exawind/refactor-model-node-classes
Refactor Model class to hold smart pointers as its attributes
- Loading branch information
Showing
12 changed files
with
547 additions
and
195 deletions.
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
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 |
---|---|---|
@@ -1,22 +1,56 @@ | ||
#pragma once | ||
|
||
#include "src/restruct_poc/math/quaternion_operations.hpp" | ||
#include "src/restruct_poc/types.hpp" | ||
|
||
namespace openturbine { | ||
|
||
struct Node { | ||
int ID; // Node identifier | ||
Array_7 x; // Node positions and orientations | ||
Array_7 u; // Node displacement | ||
Array_6 v; // Node velocity | ||
Array_6 vd; // Node acceleration | ||
int ID; //< Node identifier | ||
Array_7 x; //< Node positions and orientations | ||
Array_7 u; //< Node displacement | ||
Array_6 v; //< Node velocity | ||
Array_6 vd; //< Node acceleration | ||
|
||
/// @brief Construct a node with an ID, position, displacement, velocity, and acceleration | ||
/// vectors | ||
Node( | ||
int id, Array_7 position, Array_7 displacement = Array_7{0., 0., 0., 1., 0., 0., 0.}, | ||
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) {} | ||
|
||
/// Translate node by a displacement vector | ||
void Translate(const Array_3& displacement) { | ||
x[0] += displacement[0]; | ||
x[1] += displacement[1]; | ||
x[2] += displacement[2]; | ||
} | ||
|
||
/// Rotate node by a quaternion | ||
void Rotate(const Array_4& q) { | ||
// Rotate position | ||
auto x_rot = RotateVectorByQuaternion(q, {x[0], x[1], x[2]}); | ||
x[0] = x_rot[0]; | ||
x[1] = x_rot[1]; | ||
x[2] = x_rot[2]; | ||
|
||
// Rotate orientation | ||
auto q_rot = QuaternionCompose(q, {x[3], x[4], x[5], x[6]}); | ||
x[3] = q_rot[0]; | ||
x[4] = q_rot[1]; | ||
x[5] = q_rot[2]; | ||
x[6] = q_rot[3]; | ||
} | ||
|
||
/// Rotate node by a rotation axis and angle | ||
void Rotate(const Array_3& axis, double angle) { | ||
auto q = Array_4{ | ||
cos(angle / 2.), sin(angle / 2.) * axis[0], sin(angle / 2.) * axis[1], | ||
sin(angle / 2.) * axis[2]}; | ||
Rotate(q); | ||
} | ||
}; | ||
|
||
} // namespace openturbine |
Oops, something went wrong.