scimba_torch.integration.monte_carlo¶
Monte Carlo integration methods for volumetric and surfacic domains.
Classes
| 
 | A sampler for volumetric domains with support for subdomains, holes, and BCs. | 
| 
 | A sampler designed for surfaces defined by a parametric domain. | 
| 
 | A sampler that combines multiple samplers for tensorized sampling. | 
| 
 | Samples points uniformly within a volumetric domain. | 
- class VolumetricSampler(domain)[source]¶
- Bases: - object- Samples points uniformly within a volumetric domain. - Parameters:
- domain ( - VolumetricDomain) – The volumetric domain being sampled.
- Raises:
- TypeError – If domain is not an object of class VolumetricDomain. 
- ValueError – If the estimated volume of the domain is too small. 
 
 - domain¶
- The volumetric domain being sampled. 
 - base_sampler¶
- Uniform sampler for the domain bounds. 
 - 
percent_in: float¶
- Estimated percentage of the bounds occupied by the domain. 
 - base_sampler_postmap¶
- Uniform sampler for the mapped domain bounds. 
 - sample(n, apply_map=True)[source]¶
- Samples points within the volumetric domain. - Parameters:
- n ( - int) – Number of points to sample.
- apply_map ( - bool) – Whether to apply the domain mapping if it exists. Defaults to True.
 
- Return type:
- Tensor
- Returns:
- An array of sampled points of shape (n, d). 
- Raises:
- TypeError – If argument is not an integer. 
- ValueError – If argument is negative. 
 
 
 
- class SurfacicSampler(domain)[source]¶
- Bases: - object- A sampler designed for surfaces defined by a parametric domain. - This sampler generates points on a surface using a volumetric sampler on the associated parametric domain and maps them onto the surface. - Parameters:
- domain ( - SurfacicDomain) – The surface domain to be sampled.
- Raises:
- TypeError – If domain is not an object of class SurfacicDomain. 
 - domain¶
- The surface domain to sample from. 
 - base_sampler¶
- A sampler for the parametric domain. 
 - sample(n, compute_normals=False)[source]¶
- Samples points on the surface. - Parameters:
- n ( - int) – The number of points to sample.
- compute_normals ( - bool) – If True, compute and return surface normals. Defaults to False.
 
- Return type:
- Tensor|- tuple[- Tensor,- Tensor]
- Returns:
- Points on the surface of shape (n, d), or a tuple of (points, normals) if compute_normals is True. 
- Raises:
- TypeError – If argument is not an integer. 
- ValueError – If argument is negative. 
 
 
 
- class DomainSampler(domain, **kwargs)[source]¶
- Bases: - object- A sampler for volumetric domains with support for subdomains, holes, and BCs. - This sampler manages a primary volumetric sampler and additional samplers for boundary conditions, holes, and subdomains. - Parameters:
- domain ( - VolumetricDomain) – The volumetric domain to sample.
- **kwargs – - Additional configuration options including: - pre_sampling: Enable pre-sampling for the volumetric domain. 
- bc_pre_sampling: Enable pre-sampling for boundary condition domains. 
- npoint_pre_sampling: Number of pre-sampled points for the volumetric domain. 
 
 
- Raises:
- TypeError – If domain is not an object of class VolumetricDomain, or if npoints_pre_sampling or bc_npoints_pre_sampling are not integers. 
- ValueError – If npoints_pre_sampling or bc_npoints_pre_sampling are not positive. 
 
 - sample(n)[source]¶
- Samples n points from the volumetric domain and labels them by subdomains. - Possibly uses pre-sampled points. - Parameters:
- n ( - int) – Number of points to sample.
- Returns:
- A tensor of sampled points with their subdomain labels. 
- Return type:
- Raises:
- TypeError – If argument is not an integer. 
- ValueError – If argument is negative. 
 
 
 - bc_sample(n)[source]¶
- Samples n points from the boundary domains. - Parameters:
- n ( - int|- list[- int]) – Number of points to sample. If a list, then samples specific number of points for each bc domain.
- Return type:
- tuple[- LabelTensor,- LabelTensor]
- Returns:
- A tuple of tensors of sampled points. 
- Raises:
- TypeError – If argument is not an integer or a list of integers. 
- ValueError – If argument is negative.s 
 
 
 - sample_pre_sampled_points(n)[source]¶
- Samples n points from the pre-sampled volumetric points. - Parameters:
- n ( - int) – Number of points to sample.
- Returns:
- A tensor of sampled points. 
- Return type:
 
 - sample_new_points(n)[source]¶
- Samples new points from the volumetric domain and labels them by subdomains. - Parameters:
- n ( - int) – Number of points to sample.
- Return type:
- Returns:
- A tensor of sampled points with their subdomain labels. 
 
 - bc_sample_pre_sampled_points(n)[source]¶
- Samples points from the pre-sampled boundary condition points. - Parameters:
- n ( - int|- list[- int]) – Number of points to sample.
- Return type:
- tuple[- LabelTensor,- LabelTensor]
- Returns:
- A tensor of sampled points. 
- Raises:
- TypeError – If argument is not an integer. 
- ValueError – If argument is negative. 
 
 
 - bc_sample_new_points(n)[source]¶
- Samples new points from the boundary domains. - The boundary domains includes the main domain, holes, and subdomains. - Note - Don’t we want to sample bc points for subdomains in a separate function…? - Parameters:
- n ( - int|- list[- int]) – Number of points to sample. If a list, then samples specific number of points for each bc domain.
- Return type:
- tuple[- LabelTensor,- LabelTensor]
- Returns:
- A tensor of sampled points with their labels. 
- Raises:
- ValueError – If the number of points to sample doesn’t match the number of BC domains. 
 
 
- class TensorizedSampler(list_sampler)[source]¶
- Bases: - object- A sampler that combines multiple samplers for tensorized sampling. - This class allows sampling from multiple samplers, with options to handle boundary condition (BC) samplings selectively. - Parameters:
- list_sampler ( - tuple[- DomainSampler|- UniformParametricSampler|- UniformTimeSampler|- UniformVelocitySampler,- ...]) – A tuple of samplers, where each sampler implements sample and bc_sample methods.
 - list_sampler¶
- A tuple of samplers to combine. 
 - n_sampler¶
- Number of samplers in the tuple. 
 - sample(n)[source]¶
- Samples points using each sampler in the list. - Parameters:
- n ( - int) – The number of points to sample per sampler.
- Return type:
- tuple[- LabelTensor,- ...]
- Returns:
- A generator yielding sampled points from each sampler. 
 
 - bc_sample(n, index_bc=-1)[source]¶
- Samples points with special handling for boundary conditions (BC). - Parameters:
- n ( - int) – The number of points to sample per sampler.
- index_bc ( - int) – The index of the sampler to prioritize for BC sampling. Defaults to -1 (no priority).
 
- Return type:
- tuple[- LabelTensor|- tuple[- LabelTensor,- LabelTensor],- ...]
- Returns:
- A generator yielding BC-sampled points for the prioritized sampler and regular samples for the others. 
- Raises:
- TypeError – If samplers are not domain samplers when expected.