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

Rotation calculated for spherical particles #274

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
5 changes: 5 additions & 0 deletions cmake/modules/ALL.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# cmake module for adding ALL

option(ENABLE_GPROF "Use the GNU profiler (gprof)" OFF)
if(ENABLE_GPROF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
FG-TUM marked this conversation as resolved.
Show resolved Hide resolved

option(ENABLE_ALLLBL "Enable ALL load balancing library" OFF)
if(ENABLE_ALLLBL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_ALLLBL")
Expand Down
72 changes: 38 additions & 34 deletions src/molecules/Quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,48 @@ void Quaternion::multiply_left(const Quaternion& q) {
}

std::array<double, 3> Quaternion::rotate(const std::array<double, 3>& d) const {
std::array<double, 3> drot;
double ww = m_qw*m_qw;
double xx = m_qx*m_qx;
double yy = m_qy*m_qy;
double zz = m_qz*m_qz;
double wx = m_qw*m_qx;
double wy = m_qw*m_qy;
double wz = m_qw*m_qz;
double xy = m_qx*m_qy;
double xz = m_qx*m_qz;
double yz = m_qy*m_qz;
// 1-2*(yy+zz)
drot[0] = (ww+xx-yy-zz)*d[0] + 2.*(xy-wz)*d[1] + 2.*(wy+xz)*d[2];
// 1-2*(xx+zz)
drot[1] = 2.*(wz+xy)*d[0] + (ww-xx+yy-zz)*d[1] + 2.*(yz-wx)*d[2];
// 1-2*(xx+yy)
drot[2] = 2.*(xz-wy)*d[0] + 2.*(wx+yz)*d[1] + (ww-xx-yy+zz)*d[2];
std::array<double, 3> drot{};
if(std::array<double, 3>{} != d) {
double ww = m_qw*m_qw;
double xx = m_qx*m_qx;
double yy = m_qy*m_qy;
double zz = m_qz*m_qz;
double wx = m_qw*m_qx;
double wy = m_qw*m_qy;
double wz = m_qw*m_qz;
double xy = m_qx*m_qy;
double xz = m_qx*m_qz;
double yz = m_qy*m_qz;
// 1-2*(yy+zz)
drot[0] = (ww+xx-yy-zz)*d[0] + 2.*(xy-wz)*d[1] + 2.*(wy+xz)*d[2];
// 1-2*(xx+zz)
drot[1] = 2.*(wz+xy)*d[0] + (ww-xx+yy-zz)*d[1] + 2.*(yz-wx)*d[2];
// 1-2*(xx+yy)
drot[2] = 2.*(xz-wy)*d[0] + 2.*(wx+yz)*d[1] + (ww-xx-yy+zz)*d[2];
}
return drot;
}

std::array<double, 3> Quaternion::rotateinv(const std::array<double, 3>& d) const {
std::array<double, 3> drot;
double ww = m_qw*m_qw;
double xx = m_qx*m_qx;
double yy = m_qy*m_qy;
double zz = m_qz*m_qz;
double wx = m_qw*m_qx;
double wy = m_qw*m_qy;
double wz = m_qw*m_qz;
double xy = m_qx*m_qy;
double xz = m_qx*m_qz;
double yz = m_qy*m_qz;
// 1-2*(yy+zz)
drot[0] = (ww+xx-yy-zz)*d[0] + 2.*(xy+wz)*d[1] + 2.*(xz-wy)*d[2];
// 1-2*(xx+zz)
drot[1] = 2.*(xy-wz)*d[0] + (ww-xx+yy-zz)*d[1] + 2.*(yz+wx)*d[2];
// 1-2*(xx+yy)
drot[2] = 2.*(xz+wy)*d[0] + 2.*(yz-wx)*d[1] + (ww-xx-yy+zz)*d[2];
std::array<double, 3> drot{};
if (std::array<double, 3>{} != d) {
double ww = m_qw*m_qw;
double xx = m_qx*m_qx;
double yy = m_qy*m_qy;
double zz = m_qz*m_qz;
double wx = m_qw*m_qx;
double wy = m_qw*m_qy;
double wz = m_qw*m_qz;
double xy = m_qx*m_qy;
double xz = m_qx*m_qz;
double yz = m_qy*m_qz;
// 1-2*(yy+zz)
drot[0] = (ww+xx-yy-zz)*d[0] + 2.*(xy+wz)*d[1] + 2.*(xz-wy)*d[2];
// 1-2*(xx+zz)
drot[1] = 2.*(xy-wz)*d[0] + (ww-xx+yy-zz)*d[1] + 2.*(yz+wx)*d[2];
// 1-2*(xx+yy)
drot[2] = 2.*(xz+wy)*d[0] + 2.*(yz-wx)*d[1] + (ww-xx-yy+zz)*d[2];
}
return drot;
}

Expand Down
1 change: 0 additions & 1 deletion src/molecules/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Quaternion {

private:
double m_qw, m_qx, m_qy, m_qz; // components

};

#endif /*QUATERNION_H_*/