torchphysics.problem.domains.domain1D package

Submodules

torchphysics.problem.domains.domain1D.interval module

class torchphysics.problem.domains.domain1D.interval.Interval(space, lower_bound, upper_bound)[source]

Bases: Domain

Creates a Interval of the form [a, b].

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

  • lower_bound (Number or callable) – The left/lower bound of the interval.

  • upper_bound (Number or callable) – The right/upper bound of the interval.

__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

property boundary_left

Returns only the left boundary value, useful for the definintion of inital conditions.

property boundary_right

Returns only the left boundary value, useful for the definintion of end conditions.

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.domain1D.interval.IntervalBoundary(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.domain1D.interval.IntervalSingleBoundaryPoint(domain, side, normal_vec=-1)[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