MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / cart_to_sph_velocity

Function cart_to_sph_velocity

examples/pde/bhrt.cpp:211–237  ·  view source on GitHub ↗

* @brief Transform the velocity vectors from cartesian to spherical coordinates * * @param vel * @param pos * @return af::array */

Source from the content-addressed store, hash-verified

209 * @return af::array
210 */
211af::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

Callers 1

Calls 8

make_errorFunction · 0.85
sqrtFunction · 0.85
acosFunction · 0.85
atan2Function · 0.85
cosFunction · 0.85
sinFunction · 0.85
joinFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected