import numpy as np import matplotlib.pyplot as plt 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))
"centre_column_tiles_upper_45") centre_column_tiles_upper_45 = import_ply(centre_column_tiles_upper_45, scaling=0.001, name="centre_column_tiles_upper_45") meshes["centre_column_tiles_upper_45"] = centre_column_tiles_upper_45 for i in range(8): centre_column_tiles_upper_45.instance(parent=world, transform=rotate_z(i * 45), name="centre_column_tiles_upper_45") ######################## # load the equilibrium # eq002 = get_resource("ST40", "equilibrium", "eq002") fiesta = Fiesta(eq002) b_field = fiesta.b_field field_tracer = FieldlineTracer(b_field, method=RK2(step_size=0.0001)) def get_lcfs_radius(): equilibrium = fiesta.to_cherab_equilibrium() psin2d = equilibrium.psi_normalised def psin(r, offset=0): return psin2d(r, 0) - 1 + offset r_lcfs = brentq(psin, 0.7, 0.9, args=(0, )) return r_lcfs
# the world scene-graph world = World() ########################## # add machine components # config_file = get_resource("ST40-IVC1", "configuration", 'st40_ivc1_config') load_wall_configuration(config_file, world) ######################## # load the equilibrium # eq007 = get_resource("ST40-IVC1", "equilibrium", "eq_006_2T_export") fiesta = Fiesta(eq007) b_field = fiesta.b_field field_tracer = FieldlineTracer(b_field, method=RK2(step_size=0.0001)) equilibrium = fiesta.to_cherab_equilibrium() psin2d = equilibrium.psi_normalised ############################## # setup the heatflux profile # # specify and load heatflux profile footprint = Eich(1, 0.0001) # lambda_q=2.5, S=0.5 x = np.linspace(-1, 10, 100) footprint.set_coordinates(x) footprint.s_disconnected_dn_max = 2.1 footprint.fx_in_out = 5. footprint.calculate_heat_flux_density("lfs")
world = World() ########################## # add machine components # config_file = get_resource("ST40-IVC1", "configuration", 'st40_ivc1_config') load_wall_configuration(config_file, world) ######################## # load the equilibrium # eq007 = get_resource("ST40-IVC1", "equilibrium", "eq_006_3T_export") fiesta = Fiesta(eq007) b_field = fiesta.b_field field_tracer = FieldlineTracer(b_field, method=RK2(step_size=0.0001)) equilibrium = fiesta.to_cherab_equilibrium() psin2d = equilibrium.psi_normalised ############################## # setup the heatflux profile # # specify and load heatflux profile # footprint = Eich(3, 0.0001) # lambda_q=2.5, S=0.5 # # x = np.linspace(-1, 10, 100) # footprint.set_coordinates(x) # footprint.s_disconnected_dn_max = 2.1 # footprint.fx_in_out = 5. # footprint.calculate_heat_flux_density("lfs")
config_file = get_resource("ST40-IVC2", "configuration", 'st40_ivc2_config') load_wall_configuration(config_file, world) 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],
centre_column_tiles_upper_45 = import_ply(centre_column_tiles_upper_45, scaling=0.001, name="centre_column_tiles_upper_45") for i in range(8): 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
r = sqrt(x**2 + y**2) phi = np.arctan2(y, x) b_mag = 1 / r b_vec = Vector3D(r * np.cos(phi), r * np.sin(phi), 0) b_vec = b_vec.transform(rotate_z(90)) b_vec = b_vec.normalise() * b_mag return b_vec world = World() b_field = PythonVectorFunction3D(vectorfunction3d) 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,
eq001 = get_resource("ST40", "equilibrium", "limited_eq001_export") fiesta = Fiesta(eq001) b_field = fiesta.b_field seed_points = [] 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))