Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9f85491
add `pinnx` submodule
chaoming0625 Jan 15, 2025
598518b
update
chaoming0625 Jan 15, 2025
5f9e757
make changes
chaoming0625 Jan 20, 2025
b25c5d1
change the geometry hierarchy
chaoming0625 Jan 21, 2025
a5a16b4
fix bugs, check most models can successfully run
chaoming0625 Jan 21, 2025
a4eec8c
Change to LGPL-2.1 license
Routhleck Jan 23, 2025
56303eb
Updated copyright information to DeepXDE Limited
Routhleck Jan 23, 2025
1985723
Update installation.rst
Routhleck Jan 23, 2025
ce55b50
Remove license info in source code
Routhleck Jan 27, 2025
b31a795
Add optional dependencies for pinnx
chaoming0625 Feb 24, 2025
fdeaf33
reuse functional spaces in `deepxde.data`
chaoming0625 Feb 24, 2025
79447ff
update dependency
chaoming0625 Feb 24, 2025
0594016
remove `pinnx/utils/sampler`, `pinnx/utils/sampling`, and `pinnx/util…
chaoming0625 Feb 24, 2025
6998785
reuse `deepxde.callbacks`
chaoming0625 Feb 24, 2025
546a222
reuse `deepxde.model.LossHistory`
chaoming0625 Feb 24, 2025
f78c63d
reuse most functions in `deepxde.utils.internal`
chaoming0625 Feb 24, 2025
4bd6c95
reuse models in `deepxde.nn.deeponet_strategy`
chaoming0625 Feb 24, 2025
bf8c84c
add detailed docstring for most apis
chaoming0625 Feb 24, 2025
f1220ea
fix bugs, most models can run successfully
chaoming0625 Feb 24, 2025
a585887
fix
chaoming0625 Feb 24, 2025
fe92439
fix
chaoming0625 Feb 24, 2025
26beb21
fix code
chaoming0625 Feb 26, 2025
4c06efc
import `deeponet_strategy` in `deepxde.nn` module
chaoming0625 Mar 3, 2025
65a45e9
import `deeponet_strategy` in `__init__.py`
chaoming0625 Mar 4, 2025
f4790dd
update README to include installation instructions for pinnx module
chaoming0625 Mar 4, 2025
512f008
remove unnecessary blank line in pyproject.toml
chaoming0625 Mar 4, 2025
35e38bb
refactor: rename pinnx module to deepxde.experimental and update imports
chaoming0625 Mar 13, 2025
a78ce45
refactor: rename pinnx examples and documentation files to improve or…
chaoming0625 Mar 13, 2025
db64006
refactor: remove redundant comments from multiple files
chaoming0625 Mar 18, 2025
64658d9
refactor: remove unnecessary blank lines and improve code formatting …
chaoming0625 Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 177 additions & 1 deletion deepxde/geometry/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,184 @@
import numpy as np


class Geometry(abc.ABC):
class AbstractGeometry(abc.ABC):
def __init__(self, dim: int):
assert isinstance(dim, int), "dim must be an integer"
self.dim = dim
self.idstr = type(self).__name__

@abc.abstractmethod
def inside(self, x) -> np.ndarray[bool]:
"""
Check if x is inside the geometry (including the boundary).
Args:
x: A 2D array of shape (n, dim), where `n` is the number of points and
`dim` is the dimension of the geometry.
Returns:
A boolean array of shape (n,) where each element is True if the point is inside the geometry.
"""

@abc.abstractmethod
def on_boundary(self, x) -> np.ndarray[bool]:
"""
Check if x is on the geometry boundary.
Args:
x: A 2D array of shape (n, dim), where `n` is the number of points and
`dim` is the dimension of the geometry.
Returns:
A boolean array of shape (n,) where each element is True if the point is on the boundary.
"""

def distance2boundary(self, x, dirn):
"""
Compute the distance to the boundary.
Args:
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.
"""
raise NotImplementedError("{}.distance2boundary to be implemented".format(self.idstr))

def mindist2boundary(self, x):
"""
Compute the minimum distance to the boundary.
Args:
x: A 2D array of shape (n, dim), where `n` is the number of points and
`dim` is the dimension of the geometry.
"""
raise NotImplementedError("{}.mindist2boundary to be implemented".format(self.idstr))

def boundary_constraint_factor(
self,
x,
smoothness: Literal["C0", "C0+", "Cinf"] = "C0+"
):
"""
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".
Args:
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`.
"""
raise NotImplementedError("{}.boundary_constraint_factor to be implemented".format(self.idstr))

def boundary_normal(self, x):
"""
Compute the unit normal at x for Neumann or Robin boundary conditions.
Args:
x: A 2D array of shape (n, dim), where `n` is the number of points and
`dim` is the dimension of the geometry.
"""
raise NotImplementedError("{}.boundary_normal to be implemented".format(self.idstr))

@abc.abstractmethod
def uniform_points(self, n, boundary: bool = True) -> np.ndarray:
"""
Compute the equispaced point locations in the geometry.
Args:
n: The number of points.
boundary: If True, include the boundary points.
"""

@abc.abstractmethod
def random_points(self, n, random: str = "pseudo") -> np.ndarray:
"""
Compute the random point locations in the geometry.
Args:
n: The number of points.
random: The random distribution. One of the following: "pseudo" (pseudorandom),
"LHS" (Latin hypercube sampling), "Halton" (Halton sequence),
"Hammersley" (Hammersley sequence), or "Sobol" (Sobol sequence
"""

@abc.abstractmethod
def uniform_boundary_points(self, n) -> np.ndarray:
"""
Compute the equispaced point locations on the boundary.
Args:
n: The number of points.
"""

@abc.abstractmethod
def random_boundary_points(self, n, random: str = "pseudo") -> np.ndarray:
"""Compute the random point locations on the boundary."""

def periodic_point(self, x, component):
"""
Compute the periodic image of x for periodic boundary condition.
Args:
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.
"""
raise NotImplementedError("{}.periodic_point to be implemented".format(self.idstr))

def background_points(self, x, dirn, dist2npt, shift):
"""
Compute the background points for the collocation points.
Args:
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.
"""
raise NotImplementedError("{}.background_points to be implemented".format(self.idstr))



class Geometry(AbstractGeometry):
def __init__(self, dim, bbox, diam):
super().__init__(dim)
self.dim = dim
self.bbox = bbox
self.diam = min(diam, np.linalg.norm(bbox[1] - bbox[0]))
Expand Down
Loading