torchphysics.problem.domains.domain3D package

Submodules

torchphysics.problem.domains.domain3D.sphere module

class torchphysics.problem.domains.domain3D.sphere.Sphere(space, center, radius)[source]

Bases: Domain

Class for a sphere.

Parameters:
  • space (Space) – The space in which this object lays.

  • center (array_like or callable) – The center of the sphere, e.g. center = [5, 0, 0].

  • radius (number or callable) – The radius of the sphere.

__call__(**data)[source]

Evaluates the domain at the given data.

property boundary

Returns the boundary of this domain. Does not work on boundaries itself, e.g. Circle.boundary.boundary throws an error.

Returns:

boundary – The boundary-object of the domain.

Return type:

torchphysics.domains.Boundarydomain

bounding_box(params=Points: {}, device='cpu')[source]

Computes the bounds of the domain.

Returns:

A torch.Tensor with the length of 2*self.dim. It has the form [axis_1_min, axis_1_max, axis_2_min, axis_2_max, …], where min and max are the minimum and maximum value that the domain reaches in each dimension-axis.

Return type:

tensor

sample_grid(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates an equdistant grid in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

sample_random_uniform(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates random uniformly distributed points in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

class torchphysics.problem.domains.domain3D.sphere.SphereBoundary(domain)[source]

Bases: BoundaryDomain

normal(points, params=Points: {}, device='cpu')[source]

Computes the normal vector at each point in points.

Parameters:
  • points (torch.tensor or torchphysics.problem.Points) – Different points for which the normal vector should be computed. The points should lay on the boundary of the domain, to get correct results. E.g in 2D: points = Points(torch.tensor([[2, 4], [9, 6], ….]), R2(…))

  • params (dict or torchphysics.problem.Points, optional) – Additional parameters that are maybe needed to evaluate the domain.

  • device (str, optional) – The device on which the points should be created. Default is ‘cpu’.

Returns:

The tensor is of the shape (len(points), self.dim) and contains the normal vector at each entry from points.

Return type:

torch.tensor

sample_grid(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates an equdistant grid in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

sample_random_uniform(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates random uniformly distributed points in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

torchphysics.problem.domains.domain3D.trimesh_polyhedron module

class torchphysics.problem.domains.domain3D.trimesh_polyhedron.TrimeshBoundary(domain)[source]

Bases: BoundaryDomain

normal(points, params=Points: {}, device='cpu')[source]

Computes the normal vector at each point in points.

Parameters:
  • points (torch.tensor or torchphysics.problem.Points) – Different points for which the normal vector should be computed. The points should lay on the boundary of the domain, to get correct results. E.g in 2D: points = Points(torch.tensor([[2, 4], [9, 6], ….]), R2(…))

  • params (dict or torchphysics.problem.Points, optional) – Additional parameters that are maybe needed to evaluate the domain.

  • device (str, optional) – The device on which the points should be created. Default is ‘cpu’.

Returns:

The tensor is of the shape (len(points), self.dim) and contains the normal vector at each entry from points.

Return type:

torch.tensor

sample_grid(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates an equdistant grid in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

sample_random_uniform(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates random uniformly distributed points in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

class torchphysics.problem.domains.domain3D.trimesh_polyhedron.TrimeshPolyhedron(space, vertices=None, faces=None, file_name=None, file_type='stl', tol=1e-06)[source]

Bases: Domain

Class for polygons in 3D. Uses the trimesh-package.

Parameters:
  • space (Space) – The space in which this object lays.

  • vertices (list of lists, optional) – The vertices of the polygon.

  • faces (list of lists, optional) – A list that contains which vetrices have to be connected to create the faces of the polygon. If for example the vertices 1, 2 and 3 have should be connected do: faces = [[1, 2, 3]]

  • file_name (str or file-like object, optional) – A data source to load a existing polygon/mesh.

  • file_type (str, optional) – The file type, e.g. ‘stl’. See trimesh.available_formats() for all supported file types.

  • tol (number, optional) – The error tolerance for checking if points at the boundary. And used for projections and slicing the mesh.

Note

This class can not be dependent on other variables.

__call__(**data)[source]

Evaluates the domain at the given data.

property boundary

Returns the boundary of this domain. Does not work on boundaries itself, e.g. Circle.boundary.boundary throws an error.

Returns:

boundary – The boundary-object of the domain.

Return type:

torchphysics.domains.Boundarydomain

bounding_box(params=Points: {}, device='cpu')[source]

Computes the bounds of the domain.

Returns:

A torch.Tensor with the length of 2*self.dim. It has the form [axis_1_min, axis_1_max, axis_2_min, axis_2_max, …], where min and max are the minimum and maximum value that the domain reaches in each dimension-axis.

Return type:

tensor

export_file(name_of_file)[source]

Exports the mesh to a file.

Parameters:

name_of_file (str) – The name of the file.

project_on_plane(new_space, plane_origin=[0, 0, 0], plane_normal=[0, 0, 1])[source]

Projects the polygon on a plane.

Parameters:
  • new_space (Space) – The space in which the projected object should lay.

  • plane_origin (array_like, optional) – The origin of the projection plane.

  • plane_normal (array_like, optional) – The normal vector of the projection plane. It is enough if it points in the direction of normal vector, it does not norm = 1.

Returns:

The polygon that is the outline of the projected original mesh on the plane.

Return type:

ShapelyPolygon

sample_grid(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates an equdistant grid in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

sample_random_uniform(n=None, d=None, params=Points: {}, device='cpu')[source]

Creates random uniformly distributed points in the domain.

Parameters:
  • n (int, optional) – The number of points that should be created.

  • d (float, optional) – The density of points that should be created, if n is not defined.

  • params (torchphysics.problem.Points, optional) – Additional paramters that are maybe needed to evaluate the domain.

  • device (str) – The device on which the points should be created. Default is ‘cpu’.

Returns:

A Points object containing the sampled points.

Return type:

Points

slice_with_plane(new_space, plane_origin=[0, 0, 0], plane_normal=[0, 0, 1])[source]

Slices the polygon with a plane.

Parameters:
  • new_space (Space) – The space in which the projected object should lay.

  • plane_origin (array_like, optional) – The origin of the plane.

  • plane_normal (array_like, optional) – The normal vector of the projection plane. It is enough if it points in the direction of normal vector, it does not norm = 1.

Returns:

The polygon that is the outline of the projected original mesh on the plane.

Return type:

ShapelyPolygon