def spherical(x, y, z, V): rho, phi, theta = to_spherical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, theta=theta, V=V)) r = safe_eval_compiled(compiled, variables) if not isinstance(r, np.ndarray): r = np.full_like(x, r) return r
def to_radius(r, v, c): x,y,z = v x0,y0,z0 = c v = x-x0, y-y0, z-z0 rho, phi, theta = to_spherical(v, "radians") x,y,z = from_spherical(r, phi, theta, "radians") return x+x0, y+y0, z+z0
def spherical_in(x, y, z, V): rho, phi, theta = to_spherical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, theta=theta, V=V)) v1 = safe_eval_compiled(compiled1, variables) v2 = safe_eval_compiled(compiled2, variables) v3 = safe_eval_compiled(compiled3, variables) return out_coordinates(v1, v2, v3)
def evaluate(self, x, y, z): result = self.vfield.evaluate(x, y, z) if self.coords == 'XYZ': return result[self.axis] elif self.coords == 'CYL': rho, phi, z = to_cylindrical(tuple(result), mode='radians') return [rho, phi, z][self.axis] else: # SPH rho, phi, theta = to_spherical(tuple(result), mode='radians') return [rho, phi, theta][self.axis]
def evaluate_grid(self, xs, ys, zs): results = self.vfield.evaluate_grid(xs, ys, zs) if self.coords == 'XYZ': return results[self.axis] elif self.coords == 'CYL': vectors = np.stack(results).T vectors = np.apply_along_axis(lambda v: np.array(to_cylindrical(tuple(v), mode='radians')), 1, vectors) return vectors[:, self.axis] else: # SPH vectors = np.stack(results).T vectors = np.apply_along_axis(lambda v: np.array(to_spherical(tuple(v), mode='radians')), 1, vectors) return vectors[:, self.axis]
def spherical_in(x, y, z, V): rho, phi, theta = to_spherical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, theta=theta, V=V)) v1 = safe_eval_compiled(compiled1, variables, allowed_names=safe_names_np) v2 = safe_eval_compiled(compiled2, variables, allowed_names=safe_names_np) v3 = safe_eval_compiled(compiled3, variables, allowed_names=safe_names_np) if not isinstance(v1, np.ndarray): v1 = np.full_like(x, v1) if not isinstance(v2, np.ndarray): v2 = np.full_like(x, v2) if not isinstance(v3, np.ndarray): v3 = np.full_like(x, v3) return out_coordinates(v1, v2, v3)
def spherical(x, y, z, V): rho, phi, theta = to_spherical((x, y, z), mode='radians') variables.update(dict(rho=rho, phi=phi, theta=theta, V=V)) return safe_eval_compiled(compiled, variables)
def spherical(v, mode): return to_spherical(v, mode)