* @brief Transform the velocity vectors from cartesian to spherical coordinates * * @param vel * @param pos * @return af::array */
| 209 | * @return af::array |
| 210 | */ |
| 211 | af::array cart_to_sph_velocity(const af::array& vel, const af::array& pos) { |
| 212 | if (vel.dims() != pos.dims()) |
| 213 | throw make_error("Arrays must have the same dimensions"); |
| 214 | else if (pos.dims()[0] != 3) |
| 215 | throw make_error("Arrays must have 3 principal coordintes"); |
| 216 | |
| 217 | af::array x = pos(0, af::span); |
| 218 | af::array y = pos(1, af::span); |
| 219 | af::array z = pos(2, af::span); |
| 220 | |
| 221 | af::array r = af::sqrt(x * x + y * y + z * z); |
| 222 | af::array o = af::acos(z / r); |
| 223 | af::array p = af::atan2(y, x); |
| 224 | |
| 225 | af::array ux = vel(0, af::span); |
| 226 | af::array uy = vel(1, af::span); |
| 227 | af::array uz = vel(2, af::span); |
| 228 | |
| 229 | af::array ur = (ux * x + uy * y + uz * z) / r; |
| 230 | af::array up = (uy * af::cos(p) - ux * af::sin(p)) / (r * af::sin(o)); |
| 231 | af::array uo = |
| 232 | (af::cos(o) * (ux * af::cos(p) + uy * af::sin(p)) - uz * af::sin(o)) / |
| 233 | r; |
| 234 | af::array transformed_vel = af::join(0, ur, uo, up); |
| 235 | |
| 236 | return transformed_vel; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @brief Transform the velocity vectors from cartesian to spherical coordinates |
no test coverage detected