scimba_torch.domain.meshless_domain.base

Base module for meshless domains.

Classes

SurfacicDomain(domain_type, ...)

Base class for representing the boundary of a domain.

VolumetricDomain(domain_type, dim, sdf, bounds)

Base class for the volumetric meshless domains.

class VolumetricDomain(domain_type, dim, sdf, bounds, is_main_domain=False)[source]

Bases: object

Base class for the volumetric meshless domains.

\[\Omega = \{ x \in \text{bounds} \subset \mathbb{R}^n \, | \, \text{sdf}(x) < - \text{sdf.threshold} \}\]

Note

  • Mapped domain is only allowed on the main domain.

  • You should only call the domain.set_mapping once on the main domain (it will be applied to all subdomains and bc_domain).

  • For holes, if you want them unmapped you should use copy_mapping=False when adding the hole.

  • If some holes are already added, you can specified to_holes=False when setting the mapping to the main domain, it wont be applied to any of the holes already added.

  • The best pratices is to create the main domain, set the mapping if any, then add subdomains/holes/boundary domains.

  • If you want to change the mapping, it will be applied only to the holes that were mapped if you pass to_holes=False.

  • So basically a hole will always have the main domain mapping or never be mapped

Parameters:
  • domain_type (str) – Type of the domain.

  • dim (int) – Dimension of the domain.

  • sdf (SignedDistance) – Signed distance function that defines the domain.

  • bounds (list[tuple[float, float]] | Tensor) – Tensor of shape (dim, 2) representing an hypercube that contains the domain.

  • is_main_domain (bool) – A flag to indicate if the domain can have subdomains and holes.

domain_type: str

Type of the domain.

dim: int

Dimension of the domain (before mapping).

list_bc_domains: list[SurfacicDomain]

The list of boundary domains specified by the user.

is_mapped: bool

Flag to indicate if the domain is mapped.

dim_postmap: int

The dimension of the domain (after mapping).

mapping: None | Mapping

The mapping of the domain (if any).

bounds_postmap: Tensor

Tensor of shape (dim_postmap, 2) representing a box that contains the domain (after mapping).

is_main_domain: bool

A flag to indicate if the domain can have subdomains and holes.

list_subdomains: list[VolumetricDomain]

A list of subdomains that are inside the main domain (ONLY IF is_main_domain is True).

list_holes: list[VolumetricDomain]

A list of holes that are inside the main domain (ONLY IF is_main_domain is True).

is_inside(x)[source]

Test if N points x are inside the domain (before mapping if any).

Parameters:

x (Tensor) – Tensor of shape (N, dim) representing the points to test.

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are inside the domain.

is_outside(x)[source]

Test if N points x are outside the domain (before mapping if any).

Parameters:

x (Tensor) – Tensor of shape (N, dim) representing the points to test.

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are outside

the domain.

is_outside_np(x)[source]

Test if N points x are outside the domain (before mapping if any).

Parameters:

x (ndarray) – Tensor of shape (N, dim) representing the points to test.

Return type:

ndarray

Returns:

Boolean tensor of shape (N,) indicating if the points are outside

the domain.

is_on_boundary(x, tol=0.0001)[source]

Test if N points x are on the boundary of the domain (before mapping if any).

Parameters:
  • x (Tensor) – Tensor of shape (N, dim) representing the points to test.

  • tol (float) – Tolerance for the test (Default value = 1e-4).

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are on the boundary.

is_inside_postmap(x)[source]

Test if N points x are inside the domain (after mapping if any).

Parameters:

x (Tensor) – Tensor of shape (N, dim_postmap) representing the points to test.

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are inside the domain.

is_inside_postmap_np(x)[source]

Test if N points x are inside the domain (after mapping if any).

Parameters:

x (ndarray) – Tensor of shape (N, dim_postmap) representing the points to test.

Return type:

ndarray

Returns:

Boolean tensor of shape (N,) indicating if the points are inside the domain.

is_outside_postmap(x)[source]

Test if N points x are outside the domain (after mapping if any).

Parameters:

x (Tensor) – Tensor of shape (N, dim_postmap) representing the points to test.

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are outside

the domain.

is_outside_postmap_np(x)[source]

Test if N points x are outside the domain (after mapping if any).

Parameters:

x (ndarray) – Array of shape (N, dim_postmap) representing the points to test.

Return type:

ndarray

Returns:

Boolean array of shape (N,) indicating if the points are outside the domain.

is_on_boundary_postmap(x, tol=0.0001)[source]

Test if N points x are on the boundary of the domain (after mapping if any).

Parameters:
  • x (Tensor) – Tensor of shape (N, dim_postmap) representing the points to test.

  • tol (float) – Tolerance for the test. (Default value = 1e-4)

Return type:

Tensor

Returns:

Boolean tensor of shape (N,) indicating if the points are on the boundary

of the domain.

set_mapping(map, bounds_postmap, to_holes=True)[source]

Set the mapping of the main domain.

The mapping is applied to the main domain, subdomains, holes and boundary domains.

If to_holes is False, the mapping is also applied to none of the holes.

Parameters:
  • map (Mapping) – The mapping to apply to the domain.

  • bounds_postmap (Tensor) – Tensor of shape (dim_postmap, 2) representing a box that contains the main domain after the mapping.

  • to_holes (bool) – A flag to indicate if we apply the mapping to the holes. (Default value = True)

del_mapping()[source]

Delete the mapping of the domain.

The mapping is removed from the domain and the boundary domains.

When working on a main domain, the mapping is also removed from the subdomains.

add_bc_domain(bc_domain)[source]

Add a boundary domain to the domain.

If the domain is mapped, the boundary domain will have the same mapping.

Parameters:

bc_domain (SurfacicDomain) – The boundary domain to add.

add_subdomain(subdomain)[source]

Add a subdomain to the domain.

If the domain is mapped, the subdomain will have the same mapping.

Parameters:

subdomain (VolumetricDomain) – The subdomain to add.

add_hole(hole, copy_mapping=True)[source]

Add a hole to the domain.

Parameters:
  • hole (VolumetricDomain) – The hole to add.

  • copy_mapping (bool) – A flag to indicate if we copy the mapping of the domain to the hole. (Default value = True)

full_bc_domain()[source]

Return a list of boundary domains that make up the full domain boundary.

Return type:

list[SurfacicDomain]

Returns:

The list of boundary subdomains.

Raises:

NotImplementedError – If the method is not implemented for the specific class.

property has_bc_domain: bool

Check if the domain has boundary domains.

Returns:

True if the domain has boundary domains, False otherwise.

get_all_bc_domains()[source]

Return the lists containing all boundary domains.

Return type:

tuple[list[SurfacicDomain], list[SurfacicDomain], list[SurfacicDomain]]

Returns:

The list of boundary domains of the main domain, the holes and the subdomains (if called on the main domain). Otherwise, just the list of boundary domains.

get_extended_bounds(factor=0.05)[source]

Return extended bounds of the domain (before mapping if any).

Parameters:

factor (float) – The factor by which to extend the bounds. (Default value = 0.05)

Return type:

ndarray

Returns:

The extended bounds as a numpy array of shape (dim, 2).

get_extended_bounds_postmap(factor=0.05)[source]

Return extended bounds of the domain (after mapping if any).

Parameters:

factor (float) – The factor by which to extend the bounds. (Default value = 0.05)

Return type:

ndarray

Returns:

The extended bounds as a numpy array of shape (dim_postmap, 2).

class SurfacicDomain(domain_type, parametric_domain, surface)[source]

Bases: object

Base class for representing the boundary of a domain.

\[\partial \Omega = \text{surface}(\text{parametric_domain})\]
Parameters:
  • domain_type (str) – Type of the domain.

  • parametric_domain (VolumetricDomain) – The parametric domain.

  • surface (Mapping) – Mapping from the parametric domain to the domain.

domain_type: str

Type of the domain.

dim_parametric: int

Dimension of the parametric domain.

dim: int

Dimension of the domain (before mapping, =dim_parametric+1).

dim_postmap: int

Dimension of the domain (after mapping).

mapping: Mapping | None

The mapping of the domain (if any).

surface_o_mapping: Mapping

The composition of the surface and the mapping.

del_mapping()[source]

Delete the mapping of the domain.

compute_normals(t, **kwargs)[source]

Compute the normals of the surface at the points t in the parametric domain.

Parameters:
  • t (Tensor) – Tensor of shape (N, dim_parametric) representing the points in the parametric domain.

  • **kwargs (Any) – Additional arguments for the mapping.

Return type:

Tensor

Returns:

Tensor of shape (N, dim_postmap) representing the normals.

get_sdf()[source]

Return the signed distance function of the domain.

Return type:

Callable[[Tensor], Tensor]

Returns:

The signed distance function of the domain.

Raises:

NotImplementedError – the domain does not support this method.

is_valid_parametric_point_np(x)[source]

Check wether tensor is a valid (batch of) point(s) in the parametric domain.

Parameters:

x (ndarray | Any) – input point

Return type:

bool

Returns:

True if and only if x is a valid point not outside the parametric domain.

Raises:

ValueError – if the input value can not be broadcasted to a valid shape.