AbstractGeometry#
- class pinnx.geometry.AbstractGeometry(dim)[source]#
- background_points(x, dirn, dist2npt, shift)[source]#
Compute the background points for the collocation points.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
dirn – The direction of the background points. One of the following: -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='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 (
Literal['C0','C0+','Cinf']) –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.
- boundary_normal(x)[source]#
Compute the unit normal at x for Neumann or Robin boundary conditions.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
- distance2boundary(x, dirn)[source]#
Compute the distance to the boundary.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
dirn – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry. The direction of the distance computation. If dirn is not provided, the distance is computed in the normal direction.
- abstractmethod inside(x)[source]#
Check if x is inside the geometry (including the boundary).
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
- Return type:
ndarray[bool]- Returns:
A boolean array of shape (n,) where each element is True if the point is inside the geometry.
- mindist2boundary(x)[source]#
Compute the minimum distance to the boundary.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
- abstractmethod on_boundary(x)[source]#
Check if x is on the geometry boundary.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
- Return type:
ndarray[bool]- Returns:
A boolean array of shape (n,) where each element is True if the point is on the boundary.
- periodic_point(x, component)[source]#
Compute the periodic image of x for periodic boundary condition.
- Parameters:
x – A 2D array of shape (n, dim), where n is the number of points and dim is the dimension of the geometry.
component – The component of the periodic direction.
- abstractmethod random_boundary_points(n, random='pseudo')[source]#
Compute the random point locations on the boundary.
- Return type:
ndarray
- abstractmethod random_points(n, random='pseudo')[source]#
Compute the random point locations in the geometry.
- Parameters:
n – The number of points.
random (
str) – The random distribution. One of the following: “pseudo” (pseudorandom), “LHS” (Latin hypercube sampling), “Halton” (Halton sequence), “Hammersley” (Hammersley sequence), or “Sobol” (Sobol sequence
- Return type:
ndarray
- to_dict_point(*names, **kw_names)[source]#
Convert the geometry to a dictionary geometry.
- Parameters:
names – The names of the coordinates.
kw_names – The names of the coordinates and their physical units.