scimba_torch.domain.mesh_based_domain.cuboid¶
Defines the Cuboid domain and its components.
Classes
|
Cuboid domain in n dimensions. |
- class Cuboid(bounds, is_main_domain=True, **kwargs)[source]¶
Bases:
objectCuboid domain in n dimensions.
At the moment, boundaries, inclusions and holes are not supported.
- Parameters:
bounds (
list[tuple[float,float]]) – The bounds of the cuboid.is_main_domain (
bool) – Whether the domain is the main domain or not.**kwargs (
Any) – Additional arguments.
Examples
1D Cuboid
import torch from scimba_torch.domain.meshless_domain.domain_1d import Segment1D from scimba_torch.domain.mesh_based_domain.cuboid import Cuboid n = 10 domain_1d = Cuboid([(0, 1)], is_main_domain=True) mesh_1d = domain_1d.uniform_mesh(n) assert mesh_1d.shape == (n, 1) V_domain_1d = domain_1d.to_volumetric_domain() assert isinstance(V_domain_1d, Segment1D) assert torch.all(domain_1d.bounds == V_domain_1d.bounds)
2D Cuboid
import torch from scimba_torch.domain.meshless_domain.domain_2d import Square2D from scimba_torch.domain.mesh_based_domain.cuboid import Cuboid n, n_2 = 10, 5 domain_2d = Cuboid([(0, 1), (-1, 2)], is_main_domain=True) mesh_2d = domain_2d.uniform_mesh(n**2) assert mesh_2d.shape == (n**2, 2) V_domain_2d = domain_2d.to_volumetric_domain() assert isinstance(V_domain_2d, Square2D) assert torch.all(domain_2d.bounds == V_domain_2d.bounds) domain_2d = Cuboid([(0, 1), (-1, 2)], is_main_domain=True) mesh_2d = domain_2d.uniform_mesh((n, n_2)) assert mesh_2d.shape == (n * n_2, 2)
3D Cuboid
import torch from scimba_torch.domain.meshless_domain.domain_3d import Cube3D from scimba_torch.domain.mesh_based_domain.cuboid import Cuboid n, n_2, n_3 = 10, 5, 3 domain_3d = Cuboid([(0, 1), (-1, 2), (-10, 10)], is_main_domain=True) mesh_3d = domain_3d.uniform_mesh(n**3) assert mesh_3d.shape == (n**3, 3) domain_3d = Cuboid([(0, 1), (-1, 2), (-10, 10)], is_main_domain=True) mesh_3d = domain_3d.uniform_mesh((n, n_2, n_3)) assert mesh_3d.shape == (n * n_2 * n_3, 3) V_domain_3d = domain_3d.to_volumetric_domain() assert isinstance(V_domain_3d, Cube3D) assert torch.all(domain_3d.bounds == V_domain_3d.bounds)
- uniform_mesh(n, **kwargs)[source]¶
Uniformly meshes the domain.
- Parameters:
n (
int|list|tuple) – Total number of mesh points. If the same number of points is used in each dimension, equal to n ** (1 / dim). If list or tuple, the number of points in each dimension.**kwargs (
Any) – Additional arguments.
- Return type:
- Returns:
The mesh points.
- flatten_mesh(mesh, mesh_size)[source]¶
Flattens a mesh.
- Parameters:
mesh (
tuple[Tensor,...]) – The mesh.mesh_size (
int) – The size of the mesh.
- Return type:
Tensor- Returns:
The flattened mesh.