Skip to content

Commit 1980d59

Browse files
committed
Refactor FPDE scheme
1 parent f1cd039 commit 1980d59

File tree

7 files changed

+44
-50
lines changed

7 files changed

+44
-50
lines changed

deepxde/data/fpde.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@
1313
from ..utils import run_if_all_none
1414

1515

16-
class Discretization(object):
17-
"""Space discretization scheme parameters."""
16+
class Scheme(object):
17+
"""Fractional Laplacian discretization.
1818
19-
def __init__(self, dim, meshtype, resolution):
20-
self.dim = dim
21-
self.meshtype, self.resolution = meshtype, resolution
19+
Discretize fractional Laplacian uisng quadrature rule for the integral with respect to the directions
20+
and Grunwald-Letnikov (GL) formula for the Riemann-Liouville directional fractional derivative.
2221
22+
Args:
23+
meshtype (string): "static" or "dynamic".
24+
resolution: A list of integer. The first number is the number of quadrature points in the first direction, ...,
25+
and the last number is the GL parameter.
26+
"""
27+
28+
def __init__(self, meshtype, resolution):
29+
self.meshtype = meshtype
30+
self.resolution = resolution
31+
32+
self.dim = len(resolution)
2333
self._check()
2434

2535
def _check(self):
@@ -29,11 +39,6 @@ def _check(self):
2939
raise ValueError(
3040
"Do not support meshtype static for dimension %d" % self.dim
3141
)
32-
if self.dim != len(self.resolution):
33-
raise ValueError(
34-
"Resolution %s does not math dimension %d."
35-
% (self.resolution, self.dim)
36-
)
3742

3843

3944
class FPDE(PDE):
@@ -58,7 +63,8 @@ def __init__(
5863
fpde,
5964
alpha,
6065
bcs,
61-
disc,
66+
resolution,
67+
meshtype="dynamic",
6268
num_domain=0,
6369
num_boundary=0,
6470
train_distribution="random",
@@ -67,7 +73,7 @@ def __init__(
6773
num_test=None,
6874
):
6975
self.alpha = alpha
70-
self.disc = disc
76+
self.disc = Scheme(meshtype, resolution)
7177
self.frac_train, self.frac_test = None, None
7278

7379
super(FPDE, self).__init__(
@@ -118,10 +124,6 @@ def train_next_batch(self, batch_size=None):
118124
if self.disc.meshtype == "static":
119125
if self.geom.idstr != "Interval":
120126
raise ValueError("Only Interval supports static mesh.")
121-
if self.num_domain + 2 != self.disc.resolution[0]:
122-
raise ValueError(
123-
"Mesh resolution does not match the number of points inside the domain."
124-
)
125127

126128
self.frac_train = Fractional(self.alpha, self.geom, self.disc, None)
127129
X = self.frac_train.get_x()
@@ -198,7 +200,8 @@ def __init__(
198200
fpde,
199201
alpha,
200202
ic_bcs,
201-
disc,
203+
resolution,
204+
meshtype="dynamic",
202205
num_domain=0,
203206
num_boundary=0,
204207
num_initial=0,
@@ -213,7 +216,8 @@ def __init__(
213216
fpde,
214217
alpha,
215218
ic_bcs,
216-
disc,
219+
resolution,
220+
meshtype=meshtype,
217221
num_domain=num_domain,
218222
num_boundary=num_boundary,
219223
train_distribution=train_distribution,

examples/fractional_Poisson_1d.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ def func(x):
3838
bc = dde.DirichletBC(geom, func, lambda _, on_boundary: on_boundary)
3939

4040
# Static auxiliary points
41-
disc = dde.data.fpde.Discretization(1, "static", [101])
42-
data = dde.data.FPDE(
43-
geom, fpde, alpha, bc, disc, num_domain=99, num_boundary=2, solution=func
44-
)
41+
data = dde.data.FPDE(geom, fpde, alpha, bc, [101], meshtype="static", solution=func)
4542
# Dynamic auxiliary points
46-
# disc = dde.data.fpde.Discretization(1, "dynamic", [100])
4743
# data = dde.data.FPDE(
48-
# geom, fpde, alpha, bc, disc, num_domain=20, num_boundary=2, solution=func, num_test=100
44+
# geom, fpde, alpha, bc, [100], meshtype="dynamic", num_domain=20, num_boundary=2, solution=func, num_test=100
4945
# )
5046

5147
net = dde.maps.FNN([1] + [20] * 4 + [1], "tanh", "Glorot normal")

examples/fractional_Poisson_1d_inverse.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,29 @@ def func(x):
3737
)
3838

3939
# Static auxiliary points
40-
disc = dde.data.fpde.Discretization(1, "static", [101])
41-
data = dde.data.FPDE(
42-
geom,
43-
fpde,
44-
alpha,
45-
observe_y,
46-
disc,
47-
num_domain=99,
48-
anchors=observe_x,
49-
solution=func,
50-
)
51-
# Dynamic auxiliary points
52-
# disc = dde.data.fpde.Discretization(1, "dynamic", [100])
5340
# data = dde.data.FPDE(
5441
# geom,
5542
# fpde,
5643
# alpha,
5744
# observe_y,
58-
# disc,
59-
# num_domain=20,
45+
# [101],
46+
# meshtype="static",
6047
# anchors=observe_x,
6148
# solution=func,
62-
# num_test=100,
6349
# )
50+
# Dynamic auxiliary points
51+
data = dde.data.FPDE(
52+
geom,
53+
fpde,
54+
alpha,
55+
observe_y,
56+
[100],
57+
meshtype="dynamic",
58+
num_domain=20,
59+
anchors=observe_x,
60+
solution=func,
61+
num_test=100,
62+
)
6463

6564
net = dde.maps.FNN([1] + [20] * 4 + [1], "tanh", "Glorot normal")
6665
net.apply_output_transform(lambda x, y: (1 - x ** 2) * y)

examples/fractional_Poisson_2d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def func(x):
3737
geom = dde.geometry.Disk([0, 0], 1)
3838
bc = dde.DirichletBC(geom, func, lambda _, on_boundary: on_boundary)
3939

40-
disc = dde.data.fpde.Discretization(2, "dynamic", [8, 100])
4140
data = dde.data.FPDE(
42-
geom, fpde, alpha, bc, disc, num_domain=100, num_boundary=1, solution=func
41+
geom, fpde, alpha, bc, [8, 100], num_domain=100, num_boundary=1, solution=func
4342
)
4443

4544
net = dde.maps.FNN([2] + [20] * 4 + [1], "tanh", "Glorot normal")

examples/fractional_Poisson_2d_inverse.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ def func(x):
4343
geom, ptset.values_to_func(func(observe_x)), lambda x, _: ptset.inside(x)
4444
)
4545

46-
disc = dde.data.fpde.Discretization(2, "dynamic", [8, 100])
4746
data = dde.data.FPDE(
4847
geom,
4948
fpde,
5049
alpha,
5150
observe_y,
52-
disc,
51+
[8, 100],
5352
num_domain=64,
5453
anchors=observe_x,
5554
solution=func,

examples/fractional_Poisson_3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def func(x):
3737
geom = dde.geometry.Sphere([0, 0, 0], 1)
3838
bc = dde.DirichletBC(geom, func, lambda _, on_boundary: on_boundary)
3939

40-
disc = dde.data.fpde.Discretization(3, "dynamic", [8, 8, 100])
4140
data = dde.data.FPDE(
42-
geom, fpde, alpha, bc, disc, num_domain=256, num_boundary=1, solution=func
41+
geom, fpde, alpha, bc, [8, 8, 100], num_domain=256, num_boundary=1, solution=func
4342
)
4443

4544
net = dde.maps.FNN([3] + [20] * 4 + [1], "tanh", "Glorot normal")

examples/fractional_diffusion_1d.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ def func(x):
4343
ic = dde.IC(geomtime, func, lambda _, on_initial: on_initial)
4444

4545
# Static auxiliary points
46-
disc = dde.data.fpde.Discretization(1, "static", [52])
4746
data = dde.data.TimeFPDE(
48-
geomtime, fpde, alpha, [bc, ic], disc, num_domain=400, solution=func
47+
geomtime, fpde, alpha, [bc, ic], [52], meshtype="static", num_domain=400, solution=func
4948
)
5049
# Dynamic auxiliary points
51-
# disc = dde.data.fpde.Discretization(1, "dynamic", [100])
5250
# data = dde.data.TimeFPDE(
5351
# geomtime,
5452
# fpde,
5553
# alpha,
5654
# [bc, ic],
57-
# disc,
55+
# [100],
5856
# num_domain=20,
5957
# num_boundary=1,
6058
# num_initial=1,

0 commit comments

Comments
 (0)