* @brief Transform the velocity vectors from cartesian to spherical coordinates * * @param vel * @param pos * @return af::array */
| 244 | * @return af::array |
| 245 | */ |
| 246 | af::array sph_to_cart_velocity(const af::array& vel, const af::array& pos) { |
| 247 | if (vel.dims() != pos.dims()) |
| 248 | throw make_error("Arrays must have the same dimensions"); |
| 249 | else if (pos.dims()[0] != 3) |
| 250 | throw make_error("Arrays must have 3 principal coordintes"); |
| 251 | |
| 252 | af::array r = pos(0, af::span); |
| 253 | af::array o = pos(1, af::span); |
| 254 | af::array p = pos(2, af::span); |
| 255 | |
| 256 | af::array ur = vel(0, af::span); |
| 257 | af::array uo = vel(1, af::span); |
| 258 | af::array up = vel(2, af::span); |
| 259 | |
| 260 | af::array ux = (ur * af::sin(o) + uo * r * af::cos(o)) * af::cos(p) - |
| 261 | up * r * af::sin(o) * af::sin(p); |
| 262 | af::array uy = (ur * af::sin(o) + uo * r * af::cos(o)) * af::sin(p) + |
| 263 | up * r * af::sin(o) * af::cos(p); |
| 264 | af::array uz = ur * af::cos(o) - uo * r * af::sin(o); |
| 265 | af::array transformed_vel = af::join(0, ux, uy, uz); |
| 266 | |
| 267 | return transformed_vel; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @brief Transform the position vectors from cartesian to oblate coordinates |
no test coverage detected