from mayavi import mlab from raysect.core import World, Point3D, Vector3D from cherab.core.math import ConstantVector3D from vita.modules.cherab import FieldlineTracer, Euler # the world scene-graph world = World() b_field = ConstantVector3D(Vector3D(0, 1.5, 0)) field_tracer = FieldlineTracer(b_field, method=Euler(step_size=0.001)) start_point = Point3D(0, 0, 0) end_point, trajectory = field_tracer.trace(world, start_point, save_trajectory=True, max_steps=1000) num_segments = len(trajectory) x = np.zeros(num_segments) y = np.zeros(num_segments) z = np.zeros(num_segments) for ith_position, position in enumerate(trajectory): x[ith_position] = position.x y[ith_position] = position.y z[ith_position] = position.z mlab.plot3d(x, y, z, tube_radius=0.0005, color=(1, 0, 0)) # mlab.plot3d([0, 0.005, 0.001], [0, 0, 0], [0, 0, 0], tube_radius=0.0005, color=(1, 0, 0)) # mlab.plot3d([0, 0, 0], [0, 0.005, 0.001], [0, 0, 0], tube_radius=0.0005, color=(0, 1, 0))
mesh_powers = {} null_intersections = 0 lost_power = 0 power_per_fieldline = TOTAL_POWER / NUM_OF_FIELDLINES t_start = time.time() for i in range(NUM_OF_FIELDLINES): seed_radius = q_to_s_func(random()) + lcfs_radius seed_angle = random() * 45 seed_point = Point3D(seed_radius * np.cos(np.deg2rad(seed_angle)), seed_radius * np.sin(np.deg2rad(seed_angle)), 0) end_point, intersection, _ = field_tracer.trace(world, seed_point, max_length=15) if intersection is not None: try: powers = mesh_powers[intersection.primitive.name] except KeyError: mesh = intersection.primitive powers = np.zeros((mesh.data.triangles.shape[0])) mesh_powers[intersection.primitive.name] = powers tri_id = intersection.primitive_coords[0] powers[tri_id] += power_per_fieldline else: null_intersections += 1
eq002 = get_resource("ST40", "equilibrium", "eq002") fiesta = Fiesta(eq002) b_field = fiesta.b_field seed_points = [ Point3D(0.507, 0, 0), Point3D(0.6, 0, 0), Point3D(0.7, 0, 0), Point3D(0.733, 0, -0.01) ] field_tracer = FieldlineTracer(b_field, method=RK4(step_size=0.0001)) end_point, _, trajectory1 = field_tracer.trace(world, seed_points[0], save_trajectory=True, max_length=3) end_point, _, trajectory2 = field_tracer.trace(world, seed_points[1], save_trajectory=True, max_length=5) end_point, _, trajectory3 = field_tracer.trace(world, seed_points[2], save_trajectory=True, max_length=15) end_point, _, trajectory4 = field_tracer.trace(world, seed_points[3], save_trajectory=True, max_length=15) # mlab.plot3d([0, 0.005, 0.001], [0, 0, 0], [0, 0, 0], tube_radius=0.0005, color=(1, 0, 0))
centre_column_tiles_upper_45.instance(parent=world, transform=rotate_z(i * 45), name="centre_column_tiles_upper_45") eq002 = get_resource("ST40", "equilibrium", "eq002") fiesta = Fiesta(eq002) b_field = fiesta.b_field 1.08333333 seed_point = Point3D(0.733, 0, -0.01) field_tracer_rk2 = FieldlineTracer(b_field, method=RK2(step_size=0.0001)) field_tracer_rk4 = FieldlineTracer(b_field, method=RK4(step_size=0.0001)) _, _, trajectory_rk2 = field_tracer_rk2.trace(world, seed_point, save_trajectory=True, max_length=15) _, _, trajectory_rk4 = field_tracer_rk4.trace(world, seed_point, save_trajectory=True, max_length=15) rk2_radial_trajectory = np.zeros((trajectory_rk2.shape[0], 2)) for i in range(trajectory_rk2.shape[0]): r = np.sqrt(trajectory_rk2[i, 0]**2 + trajectory_rk2[i, 1]**2) rk2_radial_trajectory[i, 0] = r rk2_radial_trajectory[i, 1] = trajectory_rk2[i, 2] rk4_radial_trajectory = np.zeros((trajectory_rk4.shape[0], 2)) for i in range(trajectory_rk4.shape[0]): r = np.sqrt(trajectory_rk4[i, 0]**2 + trajectory_rk4[i, 1]**2)
field_tracer1 = FieldlineTracer(b_field, method=RK2(step_size=0.0001)) field_tracer2 = FieldlineTracer(b_field, method=RK4(step_size=0.0001)) mlab.plot3d([0, 0.5, 1], [0, 0, 0], [0, 0, 0], tube_radius=0.001, color=(1, 0, 0)) mlab.plot3d([0, 0, 0], [0, 0.5, 1], [0, 0, 0], tube_radius=0.001, color=(0, 1, 0)) mlab.plot3d([0, 0, 0], [0, 0, 0], [0, 0.5, 1], tube_radius=0.001, color=(0, 0, 1)) seed_point = Point3D(1, 0, 0) end_point, _, trajectory1 = field_tracer1.trace(world, seed_point, save_trajectory=True, max_length=50) end_point, _, trajectory2 = field_tracer2.trace(world, seed_point, save_trajectory=True, max_length=50) mlab.plot3d(trajectory1[:, 0], trajectory1[:, 1], trajectory1[:, 2], tube_radius=0.0005, color=(1, 0, 0)) mlab.plot3d(trajectory2[:, 0], trajectory2[:, 1], trajectory2[:, 2], tube_radius=0.0005,
n = 20 for i in range(n): lcfs = 0.72677891 seed_points.append(Point3D(lcfs + i * 0.001, 0.0, 0.0 + 0.02)) #Point3D(0.7270, 0, 0), #Point3D(0.7275, 0, 0), #Point3D(0.7280, 0, 0)] field_tracer = FieldlineTracer(b_field, method=RK2(step_size=0.00005)) end_points = [] trajectories = [] for i in range(n): end_point, _, trajectory = field_tracer.trace(world, seed_points[i], save_trajectory=True, max_length=10) trajectories.append(trajectory) end_points.append(end_point) # mlab.plot3d([0, 0.005, 0.001], [0, 0, 0], [0, 0, 0], tube_radius=0.0005, color=(1, 0, 0)) # mlab.plot3d([0, 0, 0], [0, 0.005, 0.001], [0, 0, 0], tube_radius=0.0005, color=(0, 1, 0)) # mlab.plot3d([0, 0, 0], [0, 0, 0], [0, 0.005, 0.001], tube_radius=0.0005, color=(0, 0, 1)) from raysect_mayavi import visualise_scenegraph visualise_scenegraph(world) for i in range(n): mlab.plot3d(trajectories[i][:, 0], trajectories[i][:, 1], trajectories[i][:, 2],