torchphysics.problem.domains.domain2D package

Submodules

torchphysics.problem.domains.domain2D.circle module

class torchphysics.problem.domains.domain2D.circle.Circle(space, center, radius)[source]

Bases: Domain

Class for circles.

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

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

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

__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.domain2D.circle.CircleBoundary(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.domain2D.parallelogram module

class torchphysics.problem.domains.domain2D.parallelogram.Parallelogram(space, origin, corner_1, corner_2)[source]

Bases: Domain

Class for arbitrary parallelograms, even if time dependet will always stay a parallelogram.

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

  • origin (array_like or callable) –

    Three corners of the parallelogram, in the following order

    corner_2 ——– x
    / /
    / /
    origin —– corner_1

    E.g. for the unit square: origin = [0,0], corner_1 = [1,0], corner_2 = [0,1].

  • corner_1 (array_like or callable) –

    Three corners of the parallelogram, in the following order

    corner_2 ——– x
    / /
    / /
    origin —– corner_1

    E.g. for the unit square: origin = [0,0], corner_1 = [1,0], corner_2 = [0,1].

  • corner_2 (array_like or callable) –

    Three corners of the parallelogram, in the following order

    corner_2 ——– x
    / /
    / /
    origin —– corner_1

    E.g. for the unit square: origin = [0,0], corner_1 = [1,0], corner_2 = [0,1].

__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.domain2D.parallelogram.ParallelogramBoundary(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.domain2D.shapely_polygon module

class torchphysics.problem.domains.domain2D.shapely_polygon.ShapelyBoundary(domain)[source]

Bases: BoundaryDomain

__call__(**data)[source]

Evaluates the domain at the given data.

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.domain2D.shapely_polygon.ShapelyPolygon(space, vertices=None, shapely_polygon=None)[source]

Bases: Domain

Class for polygons. Uses the shapely-package.

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

  • vertices (list of lists, optional) – The corners/vertices of the polygon. Can be eihter in clockwise or counter- clockwise order.

  • shapely_polygon (shapely.geometry.Polygon, optional) – Instead of defining the corner points, it is also possible to give a already existing shapely.Polygon object.

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(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

outline(device='cpu')[source]

Creates a outline of the domain.

Returns:

The vertices of the domain. Inner vertices are appended in there own list.

Return type:

list of list

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.domain2D.triangle module

class torchphysics.problem.domains.domain2D.triangle.Triangle(space, origin, corner_1, corner_2)[source]

Bases: Domain

Class for triangles.

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

  • origin (array_like or callable) – The three corners of the triangle. The corners have to be ordered counter clockwise, to assure that the normal vectors will point outwards.

  • corner_1 (array_like or callable) – The three corners of the triangle. The corners have to be ordered counter clockwise, to assure that the normal vectors will point outwards.

  • corner_2 (array_like or callable) – The three corners of the triangle. The corners have to be ordered counter clockwise, to assure that the normal vectors will point outwards.

__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.domain2D.triangle.TriangleBoundary(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