artist.core.heliostat_ray_tracer ================================ .. py:module:: artist.core.heliostat_ray_tracer Attributes ---------- .. autoapisummary:: artist.core.heliostat_ray_tracer.log Classes ------- .. autoapisummary:: artist.core.heliostat_ray_tracer.DistortionsDataset artist.core.heliostat_ray_tracer.RestrictedDistributedSampler artist.core.heliostat_ray_tracer.HeliostatRayTracer Module Contents --------------- .. py:data:: log A logger for the heliostat ray tracer. .. py:class:: DistortionsDataset(light_source: artist.scene.LightSource, number_of_points_per_heliostat: int, number_of_heliostats: int, random_seed: int = 7) Bases: :py:obj:`torch.utils.data.Dataset` Initialize the dataset. This class implements a custom dataset according to the ``torch`` interface. The content of this dataset are the distortions. The distortions are used in our version of "heliostat"-tracing to indicate how each incoming ray must be multiplied and scattered on the heliostat. According to ``torch``, this dataset must implement a function to return the length of the dataset and one function to retrieve an element through an index. Parameters ---------- light_source : LightSource The light source used to model the distortions. number_of_points_per_heliostat : int The number of points on the heliostats for which distortions are created. number_of_heliostats : int The number of heliostats in the scenario. random_seed : int The random seed used for generating the distortions (default is 7). .. py:method:: __len__() -> int Calculate the length of the dataset, i.e., the number of items contained. Returns ------- int The length of the dataset. .. py:method:: __getitem__(idx: int) -> tuple[torch.Tensor, torch.Tensor] Select an item from the dataset. Parameters ---------- idx : int The index of the item to select. Returns ------- torch.Tensor The distortions in the up direction for the given index. torch.Tensor The distortions in the east direction for the given index. .. py:class:: RestrictedDistributedSampler(number_of_samples: int, world_size: int = 1, rank: int = 0) Bases: :py:obj:`torch.utils.data.Sampler` Set up a custom distributed sampler to assign data to each rank or leave them idle. Parameters ---------- number_of_samples : int The length of the dataset or total number of samples. world_size : int The world size or total number of processes (default is 1). rank : int The rank of the current process (default is 0). .. py:attribute:: number_of_samples .. py:attribute:: world_size :value: 1 .. py:attribute:: rank :value: 0 .. py:attribute:: number_of_active_ranks .. py:attribute:: number_of_samples_per_rank .. py:method:: __iter__() -> Iterator[int] Generate a sequence of indices for the current rank's portion of the dataset. Returns ------- Iterator[int] An iterator over indices for the current rank. .. py:class:: HeliostatRayTracer(scenario: artist.scenario.scenario.Scenario, heliostat_group: artist.field.heliostat_group.HeliostatGroup, world_size: int = 1, rank: int = 0, batch_size: int = 100, random_seed: int = 7, bitmap_resolution: torch.Tensor = torch.tensor([artist.util.index_mapping.bitmap_resolution, artist.util.index_mapping.bitmap_resolution])) Initialize the heliostat ray tracer. "Heliostat"-tracing is one kind of ray tracing applied in ``ARTIST``. For this kind of ray tracing, the rays are initialized on the heliostats. The rays originate in the discrete surface points. There they are multiplied, distorted, and scattered, and then they are sent to the aim points. Letting the rays originate on the heliostats, drastically reduces the number of rays that need to be traced. Parameters ---------- scenario : Scenario The scenario used to perform ray tracing. heliostat_group : HeliostatGroup The selected heliostat group containing active heliostats. world_size : int The world size i.e., the overall number of processes (default is 1). rank : int The rank, i.e., individual process ID (default is 0). batch_size : int The amount of samples (heliostats) processed in parallel within a single rank (default is 100). random_seed : int The random seed used for generating the distortions (default is 7). bitmap_resolution : torch.Tensor The resolution of the bitmap in both directions. (default is torch.tensor([256,256])). Tensor of shape [2]. .. py:attribute:: scenario .. py:attribute:: heliostat_group .. py:attribute:: world_size :value: 1 .. py:attribute:: rank :value: 0 .. py:attribute:: batch_size :value: 100 .. py:attribute:: light_source .. py:attribute:: distortions_dataset .. py:attribute:: distortions_sampler .. py:attribute:: distortions_loader .. py:attribute:: bitmap_resolution .. py:method:: trace_rays(incident_ray_directions: torch.Tensor, active_heliostats_mask: torch.Tensor, target_area_mask: torch.Tensor, device: torch.device | None = None) -> torch.Tensor Perform heliostat ray tracing. Scatter the rays according to the distortions, calculate the intersections with the target planes, and sample the resulting bitmaps on the target areas. The bitmaps are generated separately for each active heliostat and can be accessed individually or they can be combined to get the total flux density distribution for all heliostats on all target areas. Parameters ---------- incident_ray_directions : torch.Tensor The direction of the incident rays as seen from the heliostats. Tensor of shape [number_of_active_heliostats, 4]. active_heliostats_mask : torch.Tensor A mask where 0 indicates a deactivated heliostat and 1 an activated one. An integer greater than 1 indicates that this heliostat is regarded multiple times. Tensor of shape [number_of_heliostats]. target_area_mask : torch.Tensor The indices of the target areas for each active heliostat. Tensor of shape [number_of_active_heliostats]. device : torch.device | None The device on which to perform computations or load tensors and models (default is None). If None, ``ARTIST`` will automatically select the most appropriate device (CUDA or CPU) based on availability and OS. Raises ------ ValueError If not all heliostats used for ray tracing have been aligned. Returns ------- torch.Tensor The resulting bitmaps per heliostat. Tensor of shape [number_of_active_heliostats, bitmap_resolution_e, bitmap_resolution_u]. .. py:method:: scatter_rays(distortion_u: torch.Tensor, distortion_e: torch.Tensor, original_ray_direction: torch.Tensor, device: torch.device | None = None) -> artist.scene.rays.Rays Scatter the reflected rays around the preferred ray directions for each heliostat. Parameters ---------- distortion_u : torch.Tensor The distortions in up direction (angles for scattering). Tensor of shape [number_of_active_heliostats, number_of_rays, number_of_combined_surface_normals_all_facets]. distortion_e : torch.Tensor The distortions in east direction (angles for scattering). Tensor of shape [number_of_active_heliostats, number_of_rays, number_of_combined_surface_normals_all_facets]. original_ray_direction : torch.Tensor The ray direction around which to scatter. Tensor of shape [number_of_active_heliostats, number_of_combined_surface_normals_all_facets, 4]. device : torch.device | None The device on which to perform computations or load tensors and models (default is None). If None, ``ARTIST`` will automatically select the most appropriate device (CUDA or CPU) based on availability and OS. Returns ------- Rays Scattered rays around the preferred reflection directions. .. py:method:: sample_bitmaps(intersections: torch.Tensor, absolute_intensities: torch.Tensor, active_heliostats_mask: torch.Tensor, target_area_mask: torch.Tensor, device: torch.device | None = None) -> torch.Tensor Sample bitmaps (flux density distributions) of the reflected rays on the target areas. The bitmaps are saved for each active heliostat separately. Parameters ---------- intersections : torch.Tensor The intersections of rays on the target area planes for each heliostat. Tensor of shape [number_of_active_heliostats, number_of_rays, number_of_combined_surface_points_all_facets, 4]. absolute_intensities : torch.Tensor The absolute intensities of the rays hitting the target planes for each heliostat. Tensor of shape [number_of_active_heliostats, number_of_rays, number_of_combined_surface_points_all_facets]. active_heliostats_mask : torch.Tensor Used to map bitmaps per heliostat to correct index. Tensor of shape [number_of_heliostats]. target_area_mask : torch.Tensor The indices of target areas on which each heliostat is raytraced. Tensor of shape [number_of_active_heliostats]. device : torch.device | None The device on which to perform computations or load tensors and models (default is None). If None, ``ARTIST`` will automatically select the most appropriate device (CUDA or CPU) based on availability and OS. Returns ------- torch.Tensor The flux density distributions of the reflected rays on the target areas for each active heliostat. Tensor of shape [number_of_active_heliostats, bitmap_resolution_e, bitmap_resolution_u]. .. py:method:: get_bitmaps_per_target(bitmaps_per_heliostat: torch.Tensor, target_area_mask: torch.Tensor, device: torch.device | None = None) -> torch.Tensor Transform bitmaps per heliostat to bitmaps per target area. Parameters ---------- bitmaps_per_heliostat : torch.Tensor Bitmaps per heliostat. Tensor of shape [number_of_active_heliostats, bitmap_resolution_e, bitmap_resolution_u]. target_area_mask : torch.Tensor The mapping from heliostat to target area. Tensor of shape [number_of_active_heliostats]. device : torch.device | None The device on which to perform computations or load tensors and models (default is None). If None, ``ARTIST`` will automatically select the most appropriate device (CUDA or CPU) based on availability and OS. Returns ------- torch.Tensor Bitmaps per target area. Tensor of shape [number_of_target_areas, bitmap_resolution_e, bitmap_resolution_u].