deepxde.geometry¶
deepxde.geometry.csg module¶
-
class
deepxde.geometry.csg.
CSGDifference
(geom1, geom2)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Construct an object by CSG Difference.
-
periodic_point
(x, component)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
-
class
deepxde.geometry.csg.
CSGIntersection
(geom1, geom2)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Construct an object by CSG Intersection.
-
periodic_point
(x, component)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
-
class
deepxde.geometry.csg.
CSGUnion
(geom1, geom2)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Construct an object by CSG Union.
-
periodic_point
(x, component)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
deepxde.geometry.geometry module¶
-
class
deepxde.geometry.geometry.
Geometry
(dim, bbox, diam)[source]¶ Bases:
abc.ABC
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+')[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
periodic_point
(x, component)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
deepxde.geometry.geometry_1d module¶
-
class
deepxde.geometry.geometry_1d.
Interval
(l, r)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
-
background_points
(x, dirn, dist2npt, shift)[source]¶ Parameters: - dirn – -1 (left), or 1 (right), or 0 (both direction).
- dist2npt – A function which converts distance to the number of extra points (not including x).
- shift – The number of shift.
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+', where: Union[None, Literal[left, right]] = None)[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
- where (string, optional) – A string to specify which part of the boundary to compute the distance, e.g., “left”, “right”. If None, compute the distance to the whole boundary. Default is None.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
periodic_point
(x, component=0)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
deepxde.geometry.geometry_2d module¶
-
class
deepxde.geometry.geometry_2d.
Disk
(center, radius)[source]¶
-
class
deepxde.geometry.geometry_2d.
Ellipse
(center, semimajor, semiminor, angle=0)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Ellipse.
Parameters: - center – Center of the ellipse.
- semimajor – Semimajor of the ellipse.
- semiminor – Semiminor of the ellipse.
- angle – Rotation angle of the ellipse. A positive angle rotates the ellipse clockwise about the center and a negative angle rotates the ellipse counterclockwise about the center.
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+')[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
class
deepxde.geometry.geometry_2d.
Polygon
(vertices)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Simple polygon.
Parameters: vertices – The order of vertices can be in a clockwise or counterclockwise direction. The vertices will be re-ordered in counterclockwise (right hand rule).
-
class
deepxde.geometry.geometry_2d.
Rectangle
(xmin, xmax)[source]¶ Bases:
deepxde.geometry.geometry_nd.Hypercube
Parameters: - xmin – Coordinate of bottom left corner.
- xmax – Coordinate of top right corner.
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+', where: Union[None, Literal[left, right, bottom, top]] = None, inside: bool = True)[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
- where (string, optional) – A string to specify which part of the boundary to compute the distance. “left”: x[0] = xmin[0], “right”: x[0] = xmax[0], “bottom”: x[1] = xmin[1], “top”: x[1] = xmax[1]. If None, compute the distance to the whole boundary. Default is None.
- inside (bool, optional) – The x is either inside or outside the geometry. The cases where there are both points inside and points outside the geometry are NOT allowed. Default is True.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
class
deepxde.geometry.geometry_2d.
StarShaped
(center, radius, coeffs_cos, coeffs_sin)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Star-shaped 2d domain, i.e., a geometry whose boundary is parametrized in polar coordinates as:
$$ r(theta) := r_0 + sum_{i = 1}^N [a_i cos( i theta) + b_i sin(i theta) ], theta in [0,2 pi]. $$
For more details, refer to: Hiptmair et al. Large deformation shape uncertainty quantification in acoustic scattering. Adv Comp Math, 2018.
Parameters: - center – Center of the domain.
- radius – 0th-order term of the parametrization (r_0).
- coeffs_cos – i-th order coefficients for the i-th cos term (a_i).
- coeffs_sin – i-th order coefficients for the i-th sin term (b_i).
-
class
deepxde.geometry.geometry_2d.
Triangle
(x1, x2, x3)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
Triangle.
The order of vertices can be in a clockwise or counterclockwise direction. The vertices will be re-ordered in counterclockwise (right hand rule).
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+', where: Union[None, Literal[x1-x2, x1-x3, x2-x3]] = None)[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
- where (string, optional) – A string to specify which part of the boundary to compute the distance. If None, compute the distance to the whole boundary. “x1-x2” indicates the line segment with vertices x1 and x2 (after reordered). Default is None.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
deepxde.geometry.geometry_3d module¶
-
class
deepxde.geometry.geometry_3d.
Cuboid
(xmin, xmax)[source]¶ Bases:
deepxde.geometry.geometry_nd.Hypercube
Parameters: - xmin – Coordinate of bottom left corner.
- xmax – Coordinate of top right corner.
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+', where: Union[None, Literal[back, front, left, right, bottom, top]] = None, inside: bool = True)[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
- where (string, optional) – A string to specify which part of the boundary to compute the distance. “back”: x[0] = xmin[0], “front”: x[0] = xmax[0], “left”: x[1] = xmin[1], “right”: x[1] = xmax[1], “bottom”: x[2] = xmin[2], “top”: x[2] = xmax[2]. If None, compute the distance to the whole boundary. Default is None.
- inside (bool, optional) – The x is either inside or outside the geometry. The cases where there are both points inside and points outside the geometry are NOT allowed. NOTE: currently only support inside=True.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
class
deepxde.geometry.geometry_3d.
Sphere
(center, radius)[source]¶ Bases:
deepxde.geometry.geometry_nd.Hypersphere
Parameters: - center – Center of the sphere.
- radius – Radius of the sphere.
deepxde.geometry.geometry_nd module¶
-
class
deepxde.geometry.geometry_nd.
Hypercube
(xmin, xmax)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0', where: None = None, inside: bool = True)[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
- WARNING
In current implementation, numerical underflow may happen for high dimensionalities when smoothness=”C0+” or smoothness=”Cinf”.
- where (string, optional) – This option is currently not supported for Hypercube.
- inside (bool, optional) – The x is either inside or outside the geometry. The cases where there are both points inside and points outside the geometry are NOT allowed. NOTE: currently only support inside=True.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
periodic_point
(x, component)[source]¶ Compute the periodic image of x for periodic boundary condition.
-
-
class
deepxde.geometry.geometry_nd.
Hypersphere
(center, radius)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
-
boundary_constraint_factor
(x, smoothness: Literal[C0, C0+, Cinf] = 'C0+')[source]¶ Compute the hard constraint factor at x for the boundary.
This function is used for the hard-constraint methods in Physics-Informed Neural Networks (PINNs). The hard constraint factor satisfies the following properties:
- The function is zero on the boundary and positive elsewhere.
- The function is at least continuous.
In the ansatz boundary_constraint_factor(x) * NN(x) + boundary_condition(x), when x is on the boundary, boundary_constraint_factor(x) will be zero, making the ansatz be the boundary condition, which in turn makes the boundary condition a “hard constraint”.
Parameters: - x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. Note that x should be a tensor type of backend (e.g., tf.Tensor or torch.Tensor), not a numpy array.
- smoothness (string, optional) –
A string to specify the smoothness of the distance function, e.g., “C0”, “C0+”, “Cinf”. “C0” is the least smooth, “Cinf” is the most smooth. Default is “C0+”.
- C0
The distance function is continuous but may not be non-differentiable. But the set of non-differentiable points should have measure zero, which makes the probability of the collocation point falling in this set be zero.
- C0+
The distance function is continuous and differentiable almost everywhere. The non-differentiable points can only appear on boundaries. If the points in x are all inside or outside the geometry, the distance function is smooth.
- Cinf
The distance function is continuous and differentiable at any order on any points. This option may result in a polynomial of HIGH order.
Returns: A tensor of a type determined by the backend, which will have a shape of (n, 1). Each element in the tensor corresponds to the computed distance value for the respective point in x.
-
deepxde.geometry.pointcloud module¶
-
class
deepxde.geometry.pointcloud.
PointCloud
(points, boundary_points=None, boundary_normals=None)[source]¶ Bases:
deepxde.geometry.geometry.Geometry
A geometry represented by a point cloud, i.e., a set of points in space.
Parameters: - points – A 2-D NumPy array. If boundary_points is not provided, points can include points both inside the geometry or on the boundary; if boundary_points is provided, points includes only points inside the geometry.
- boundary_points – A 2-D NumPy array.
- boundary_normals – A 2-D NumPy array.
deepxde.geometry.sampler module¶
-
deepxde.geometry.sampler.
sample
(n_samples, dimension, sampler='pseudo')[source]¶ Generate pseudorandom or quasirandom samples in [0, 1]^dimension.
Parameters: - n_samples (int) – The number of samples.
- dimension (int) – Space dimension.
- sampler (string) – One of the following: “pseudo” (pseudorandom), “LHS” (Latin hypercube sampling), “Halton” (Halton sequence), “Hammersley” (Hammersley sequence), or “Sobol” (Sobol sequence).
deepxde.geometry.timedomain module¶
-
class
deepxde.geometry.timedomain.
GeometryXTime
(geometry, timedomain)[source]¶ Bases:
object