Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 25 additions & 17 deletions deepxde/geometry/geometry_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def random_points(self, n, random="pseudo"):
return self.radius * (np.sqrt(r) * np.vstack((x, y))).T + self.center

def uniform_boundary_points(self, n):
theta = np.linspace(0, 2 * np.pi, num=n, endpoint=False)
theta = np.linspace(0, 2 * np.pi, num=n, endpoint=False, dtype=config.real(np))
X = np.vstack((np.cos(theta), np.sin(theta))).T
return self.radius * X + self.center

Expand Down Expand Up @@ -214,30 +214,34 @@ def uniform_boundary_points(self, n):
nx, ny = np.ceil(n / self.perimeter * (self.xmax - self.xmin)).astype(int)
xbot = np.hstack(
(
np.linspace(self.xmin[0], self.xmax[0], num=nx, endpoint=False)[
np.linspace(self.xmin[0], self.xmax[0], num=nx, endpoint=False,
dtype=config.real(np))[
:, None
],
np.full([nx, 1], self.xmin[1]),
np.full([nx, 1], self.xmin[1], dtype=config.real(np)),
)
)
yrig = np.hstack(
(
np.full([ny, 1], self.xmax[0]),
np.linspace(self.xmin[1], self.xmax[1], num=ny, endpoint=False)[
np.full([ny, 1], self.xmax[0], dtype=config.real(np)),
np.linspace(self.xmin[1], self.xmax[1], num=ny, endpoint=False,
dtype=config.real(np))[
:, None
],
)
)
xtop = np.hstack(
(
np.linspace(self.xmin[0], self.xmax[0], num=nx + 1)[1:, None],
np.full([nx, 1], self.xmax[1]),
np.linspace(self.xmin[0], self.xmax[0], num=nx + 1,
dtype=config.real(np))[1:, None],
np.full([nx, 1], self.xmax[1], dtype=config.real(np)),
)
)
ylef = np.hstack(
(
np.full([ny, 1], self.xmin[0]),
np.linspace(self.xmin[1], self.xmax[1], num=ny + 1)[1:, None],
np.full([ny, 1], self.xmin[0], dtype=config.real(np)),
np.linspace(self.xmin[1], self.xmax[1], num=ny + 1,
dtype=config.real(np))[1:, None],
)
)
x = np.vstack((xbot, yrig, xtop, ylef))
Expand Down Expand Up @@ -268,7 +272,7 @@ def random_boundary_points(self, n, random="pseudo"):
x.append([self.xmax[0] - l + l2, self.xmax[1]])
else:
x.append([self.xmin[0], self.xmax[1] - l + l3])
return np.vstack(x)
return np.vstack(x).astype(config.real(np))

def _boundary_constraint_factor_inside(
self,
Expand Down Expand Up @@ -465,7 +469,7 @@ def __init__(self, center, radius, coeffs_cos, coeffs_sin):

def _r_theta(self, theta):
"""Define the parametrization r(theta) at angles theta."""
result = self.radius * np.ones(theta.shape)
result = self.radius * np.ones(theta.shape, dtype=config.real(np))
for i, (coeff_cos, coeff_sin) in enumerate(
zip(self.coeffs_cos, self.coeffs_sin), start=1
):
Expand All @@ -474,7 +478,7 @@ def _r_theta(self, theta):

def _dr_theta(self, theta):
"""Evalutate the polar derivative r'(theta) at angles theta"""
result = np.zeros(theta.shape)
result = np.zeros(theta.shape, dtype=config.real(np))
for i, (coeff_cos, coeff_sin) in enumerate(
zip(self.coeffs_cos, self.coeffs_sin), start=1
):
Expand Down Expand Up @@ -517,7 +521,7 @@ def random_points(self, n, random="pseudo"):
return x[:n]

def uniform_boundary_points(self, n):
theta = np.linspace(0, 2 * np.pi, num=n, endpoint=False)
theta = np.linspace(0, 2 * np.pi, num=n, endpoint=False, dtype=config.real(np))
r_theta = self._r_theta(theta)
X = np.vstack((r_theta * np.cos(theta), r_theta * np.sin(theta))).T
return X + self.center
Expand Down Expand Up @@ -635,21 +639,24 @@ def random_points(self, n, random="pseudo"):
def uniform_boundary_points(self, n):
density = n / self.perimeter
x12 = (
np.linspace(0, 1, num=int(np.ceil(density * self.l12)), endpoint=False)[
np.linspace(0, 1, num=int(np.ceil(density * self.l12)), endpoint=False,
dtype=config.real(np))[
:, None
]
* self.v12
+ self.x1
)
x23 = (
np.linspace(0, 1, num=int(np.ceil(density * self.l23)), endpoint=False)[
np.linspace(0, 1, num=int(np.ceil(density * self.l23)), endpoint=False,
dtype=config.real(np))[
:, None
]
* self.v23
+ self.x2
)
x31 = (
np.linspace(0, 1, num=int(np.ceil(density * self.l31)), endpoint=False)[
np.linspace(0, 1, num=int(np.ceil(density * self.l31)), endpoint=False,
dtype=config.real(np))[
:, None
]
* self.v31
Expand Down Expand Up @@ -891,6 +898,7 @@ def uniform_boundary_points(self, n):
1,
num=int(np.ceil(density * self.diagonals[i, i + 1])),
endpoint=False,
dtype=config.real(np),
)[:, None]
* (self.vertices[i + 1] - self.vertices[i])
+ self.vertices[i]
Expand Down Expand Up @@ -924,7 +932,7 @@ def random_boundary_points(self, n, random="pseudo"):
l0, l1 = l1, l1 + self.diagonals[i, i + 1]
v = (self.vertices[i + 1] - self.vertices[i]) / self.diagonals[i, i + 1]
x.append((l - l0) * v + self.vertices[i])
return np.vstack(x)
return np.vstack(x).astype(config.real(np))


def polygon_signed_area(vertices):
Expand Down
19 changes: 10 additions & 9 deletions deepxde/geometry/geometry_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .geometry_2d import Rectangle
from .geometry_nd import Hypercube, Hypersphere
from .. import backend as bkd
from .. import config


class Cuboid(Hypercube):
Expand All @@ -26,15 +27,15 @@ def random_boundary_points(self, n, random="pseudo"):
rect = Rectangle(self.xmin[:-1], self.xmax[:-1])
for z in [self.xmin[-1], self.xmax[-1]]:
u = rect.random_points(int(np.ceil(density * rect.area)), random=random)
pts.append(np.hstack((u, np.full((len(u), 1), z))))
pts.append(np.hstack((u, np.full((len(u), 1), z, dtype=config.real(np)))))
rect = Rectangle(self.xmin[::2], self.xmax[::2])
for y in [self.xmin[1], self.xmax[1]]:
u = rect.random_points(int(np.ceil(density * rect.area)), random=random)
pts.append(np.hstack((u[:, 0:1], np.full((len(u), 1), y), u[:, 1:])))
pts.append(np.hstack((u[:, 0:1], np.full((len(u), 1), y, dtype=config.real(np)), u[:, 1:])))
rect = Rectangle(self.xmin[1:], self.xmax[1:])
for x in [self.xmin[0], self.xmax[0]]:
u = rect.random_points(int(np.ceil(density * rect.area)), random=random)
pts.append(np.hstack((np.full((len(u), 1), x), u)))
pts.append(np.hstack((np.full((len(u), 1), x, dtype=config.real(np)), u)))
pts = np.vstack(pts)
if len(pts) > n:
return pts[np.random.choice(len(pts), size=n, replace=False)]
Expand All @@ -43,22 +44,22 @@ def random_boundary_points(self, n, random="pseudo"):
def uniform_boundary_points(self, n):
h = (self.area / n) ** 0.5
nx, ny, nz = np.ceil((self.xmax - self.xmin) / h).astype(int) + 1
x = np.linspace(self.xmin[0], self.xmax[0], num=nx)
y = np.linspace(self.xmin[1], self.xmax[1], num=ny)
z = np.linspace(self.xmin[2], self.xmax[2], num=nz)
x = np.linspace(self.xmin[0], self.xmax[0], num=nx, dtype=config.real(np))
y = np.linspace(self.xmin[1], self.xmax[1], num=ny, dtype=config.real(np))
z = np.linspace(self.xmin[2], self.xmax[2], num=nz, dtype=config.real(np))

pts = []
for v in [self.xmin[-1], self.xmax[-1]]:
u = list(itertools.product(x, y))
pts.append(np.hstack((u, np.full((len(u), 1), v))))
pts.append(np.hstack((u, np.full((len(u), 1), v, dtype=config.real(np)))))
if nz > 2:
for v in [self.xmin[1], self.xmax[1]]:
u = np.array(list(itertools.product(x, z[1:-1])))
pts.append(np.hstack((u[:, 0:1], np.full((len(u), 1), v), u[:, 1:])))
pts.append(np.hstack((u[:, 0:1], np.full((len(u), 1), v, dtype=config.real(np)), u[:, 1:])))
if ny > 2 and nz > 2:
for v in [self.xmin[0], self.xmax[0]]:
u = list(itertools.product(y[1:-1], z[1:-1]))
pts.append(np.hstack((np.full((len(u), 1), v), u)))
pts.append(np.hstack((np.full((len(u), 1), v, dtype=config.real(np)), u)))
pts = np.vstack(pts)
if n != len(pts):
print(
Expand Down
6 changes: 3 additions & 3 deletions deepxde/geometry/timedomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def on_initial(self, x):

def boundary_normal(self, x):
_n = self.geometry.boundary_normal(x[:, :-1])
return np.hstack([_n, np.zeros((len(_n), 1))])
return np.hstack([_n, np.zeros((len(_n), 1), dtype=config.real(np))])

def uniform_points(self, n, boundary=True):
"""Uniform points on the spatio-temporal domain.
Expand Down Expand Up @@ -67,7 +67,7 @@ def uniform_points(self, n, boundary=True):
)[:, None]
xt = []
for ti in t:
xt.append(np.hstack((x, np.full([nx, 1], ti[0]))))
xt.append(np.hstack((x, np.full([nx, 1], ti[0], dtype=config.real(np)))))
xt = np.vstack(xt)
if n != len(xt):
print(
Expand Down Expand Up @@ -132,7 +132,7 @@ def uniform_boundary_points(self, n):
)
xt = []
for ti in t:
xt.append(np.hstack((x, np.full([nx, 1], ti))))
xt.append(np.hstack((x, np.full([nx, 1], ti, dtype=config.real(np)))))
xt = np.vstack(xt)
if n != len(xt):
print(
Expand Down