def load_vessel_world(mesh_parts, shift_p5=False): """Load the world containing the vessel mesh parts. <mesh_parts> is a list of filenames containing mesh files in either RSM or OBJ format, which are to be loaded into the world. If shift_p5 is True, the mesh files representing the P5 coils will have a downward shift applied to them to account for the UEP sag. This is described in CD/MU/04783. Returns world, the root of the scenegraph. """ world = World() for path, _ in mesh_parts: print("importing {} ...".format(os.path.split(path)[1])) filename = os.path.split(path)[-1] name, ext = filename.split('.') if 'P5_' in path and shift_p5: p5_zshift = -0.00485 # From CD/MU/04783 transform = translate(0, 0, p5_zshift) else: transform = None if ext.lower() == 'rsm': Mesh.from_file(path, parent=world, material=AbsorbingSurface(), transform=transform, name=name) elif ext.lower() == 'obj': import_obj(path, parent=world, material=AbsorbingSurface(), name=name) else: raise ValueError("Only RSM and OBJ meshes are supported.") # Add a solid cylinder at R=0 to prevent rays finding their way through the # gaps in the centre column armour. This is only necessary for the MAST # meshes, but it does no harm to add it to MAST-U meshes too height = 6 radius = 0.1 Cylinder(radius=radius, height=height, parent=world, transform=translate(0, 0, -height / 2), material=AbsorbingSurface(), name='Blocking Cylinder') return world
from raysect.primitive import import_obj from raysect.optical import World from raysect.optical.material import AbsorbingSurface from cherab.jet.machine.cad_files import KB5V, KB5H from cherab.jet.bolometry import load_kb5_camera # Calculate KB5V camera sensitivities world = World() kb5v_collimator_mesh = import_obj(KB5V[0][0], scaling=0.001, name='kb5v_collimator', parent=world, material=AbsorbingSurface()) kb5h_collimator_mesh = import_obj(KB5H[0][0], scaling=0.001, name='kb5h_collimator', parent=world, material=AbsorbingSurface()) kb5v = load_kb5_camera('KB5V', parent=world) for detector in kb5v: etendue, etendue_error = detector.calculate_etendue(ray_count=400000) print("Detector {}: etendue {:.4G} +- {:.3G} m^2 str".format( detector.name, etendue, etendue_error)) kb5h = load_kb5_camera('KB5H', parent=world) for detector in kb5h: etendue, etendue_error = detector.calculate_etendue(ray_count=400000)
cube_size = 2 min_wl = 400 max_wl = 401 # sanity check! if cube_size <= 2 * sphere_radius: raise ValueError("The cube dimensions must be larger that the sphere.") # set-up scenegraph world = World() emitter = Sphere(radius=sphere_radius, parent=world) base_path = os.path.split(os.path.realpath(__file__))[0] mesh = import_obj(os.path.join(base_path, "../resources/box_normals_inwards.obj"), scaling=2.0) power = PowerPipeline1D(accumulate=False) observer = MeshCamera(mesh, pipelines=[power], parent=world, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=samples) # Emitter is a sphere volume emitter located at the origin # Volume of the sphere is 4/3 * Pi * r^3, emission over 4 * pi # UnityVolumeEmitter emits 1W/str/m^3/ x nm, where x is the wavelength interval, integrated over length
sphere_radius = 0.01 min_wl = 400 max_wl = 401 # set-up scenegraph world = World() emitter = Sphere(radius=sphere_radius, parent=world, transform=rotate_x(-90) * translate(-0.05409, -0.01264, 0.10064)) base_path = os.path.split(os.path.realpath(__file__))[0] mesh = import_obj(os.path.join(base_path, "../resources/stanford_bunny.obj"), material=AbsorbingSurface(), parent=world, flip_normals=True) power = PowerPipeline0D(accumulate=False) observer = MeshPixel(mesh, pipelines=[power], parent=world, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=samples, surface_offset=1E-6) print("Starting observations with volume emitter...") calculated_volume_emission = 16 / 3 * pi**2 * sphere_radius**3 * (max_wl - min_wl)
from raysect.primitive import Sphere, Box, import_obj from raysect.optical.observer import PinholeCamera, RGBPipeline2D, RGBAdaptiveSampler2D from raysect.optical.library import RoughTitanium from raysect.optical.material import UniformSurfaceEmitter, UniformVolumeEmitter, Dielectric, Sellmeier # DIAMOND MATERIAL diamond_material = Dielectric(Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0), ConstantSF(1)) diamond_material.importance = 2 world = World() base_path = os.path.split(os.path.realpath(__file__))[0] # the diamond diamond = import_obj(os.path.join(base_path, "../resources/diamond.obj"), scaling=0.01, smoothing=False, parent=world, transform=translate(0.0, 0.713001, 0.0)*rotate(-10, 0, 0), material=diamond_material) # floor Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # front light Sphere(5, world, transform=translate(1, 8, -10), material=UniformVolumeEmitter(d65_white, 1.0)) # fill light Sphere(10, world, transform=translate(7, 20, 20), material=UniformSurfaceEmitter(d65_white, 0.15)) # camera rgb_pipeline = RGBPipeline2D(display_update_time=15, display_unsaturated_fraction=0.998) sampler = RGBAdaptiveSampler2D(rgb_pipeline, min_samples=400, fraction=0.1) camera = PinholeCamera((1024, 1024), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -46, 0), pipelines=[rgb_pipeline], frame_sampler=sampler) camera.spectral_bins = 18
# DIAMOND MATERIAL diamond_material = Dielectric( Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0), ConstantSF(0.998)) diamond_material.importance = 2 world = World() base_path = os.path.split(os.path.realpath(__file__))[0] # the diamond diamond = import_obj(os.path.join(base_path, "../resources/diamond.obj"), scaling=0.01, smoothing=False, parent=world, transform=translate(0.0, 0.713001, 0.0) * rotate(-10, 0, 0), material=diamond_material) # floor Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=RoughTitanium(0.1)) # front light Sphere(5, world, transform=translate(1, 8, -10), material=UniformVolumeEmitter(d65_white, 1.0))
import numpy as np from mayavi import mlab from raysect.core import Point3D, World from raysect.primitive import import_obj from vita.modules.projection.cherab import FieldlineTracer, RK2 from vita.modules.equilibrium.fiesta import Fiesta from vita.utility import get_resource # the world scene-graph world = World() ST40_mesh = get_resource("ST40", "mesh", "ST40_IVC") import_obj(ST40_mesh, scaling=0.001, parent=world) 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 = []
cube_size = 2 min_wl = 400 max_wl = 401 # sanity check! if cube_size <= 2 * sphere_radius: raise ValueError("The cube dimensions must be larger that the sphere.") # set-up scenegraph world = World() emitter = Sphere(radius=sphere_radius, parent=world) base_path = os.path.split(os.path.realpath(__file__))[0] mesh = import_obj(os.path.join(base_path, "../resources/box_normals_inwards.obj"), scaling=2.0) power = PowerPipeline0D(accumulate=False) observer = MeshPixel(mesh, pipelines=[power], parent=world, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=samples) # Emitter is a sphere volume emitter located at the origin # Volume of the sphere is 4/3 * Pi * r^3, emission over 4 * pi # UnityVolumeEmitter emits 1W/str/m^3/ x nm, where x is the wavelength interval, integrated over length print("Starting observations with volume emitter...") calculated_volume_emission = 16 / 3 * pi**2 * sphere_radius**3 * (max_wl - min_wl) emitter.material = UnityVolumeEmitter() observer.observe()
this is necessary, since I assumed that this kind of thing would have been built into the wrapper and happen transparently, but it seems not. :param it: A python iterable. :return: A vtkIdList """ vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil world = World() mesh = import_obj( "/home/matt/pyFusion/raysect/demos/resources/stanford_bunny.obj", parent=world, transform=translate(0, 0, 0) * rotate(165, 0, 0)) # We'll create the building blocks of polydata including data attributes. cube = vtk.vtkPolyData() points = vtk.vtkPoints() polys = vtk.vtkCellArray() # Load the point, cell, and data attributes. for i, xi in enumerate(mesh.data.vertices): points.InsertPoint(i, xi) for pt in mesh.data.triangles: polys.InsertNextCell(mkVtkIdList(pt)) # We now assign the pieces to the vtkPolyData. cube.SetPoints(points)
samples = 1000000 sphere_radius = 0.01 min_wl = 400 max_wl = 401 # set-up scenegraph world = World() emitter = Sphere(radius=sphere_radius, parent=world, transform=rotate_x(-90)*translate(-0.05409, -0.01264, 0.10064)) base_path = os.path.split(os.path.realpath(__file__))[0] mesh = import_obj(os.path.join(base_path, "../resources/stanford_bunny.obj"), material=AbsorbingSurface(), parent=world, flip_normals=True) power = PowerPipeline0D(accumulate=False) observer = MeshPixel(mesh, pipelines=[power], parent=world, min_wavelength=min_wl, max_wavelength=max_wl, spectral_bins=1, pixel_samples=samples, surface_offset=1E-6) print("Starting observations with volume emitter...") calculated_volume_emission = 16 / 3 * pi**2 * sphere_radius**3 * (max_wl - min_wl) emitter.material = UnityVolumeEmitter() observer.observe() measured_volume_emission = power.value.mean measured_volume_error = power.value.error()
import matplotlib.pyplot as plt from raysect.primitive import import_obj from raysect.optical import World from raysect.optical.material import AbsorbingSurface from cherab.jet.machine import import_jet_mesh from cherab.jet.machine.cad_files import KB5V, KB5H from cherab.jet.bolometry import load_kb5_camera, load_kb5_inversion_grid # Calculate KB5V camera sensitivities kb5v_world = World() inversion_grid = load_kb5_inversion_grid(parent=kb5v_world, name="KB5 inversion grid") import_jet_mesh(kb5v_world, override_material=AbsorbingSurface()) kb5v_collimator_mesh = import_obj(KB5V[0][0], scaling=0.001, parent=kb5v_world, material=AbsorbingSurface()) kb5v = load_kb5_camera('KB5V', parent=kb5v_world) kb5v_ch14 = kb5v['KB5V_CH14'] start_time = time.time() sensitivities = kb5v_ch14.calculate_sensitivity(inversion_grid, ray_count=1000) print("run time - {:.2G}mins".format((time.time() - start_time) / 60)) plt.ion() inversion_grid.plot(voxel_values=sensitivities) plt.show() # start_time = time.time() # for detector in kb5v: