1- """Backend supported: tensorflow.compat.v1
1+ """Backend supported: tensorflow.compat.v1, tensorflow
22
33Documentation: https://deepxde.readthedocs.io/en/latest/demos/poisson.1d.dirichlet.html
44"""
@@ -21,42 +21,38 @@ def func(x):
2121 return np .sin (np .pi * x )
2222
2323
24- def main ():
25- geom = dde .geometry .Interval (- 1 , 1 )
26- bc = dde .DirichletBC (geom , func , boundary )
27- data = dde .data .PDE (geom , pde , bc , 16 , 2 , solution = func , num_test = 100 )
28-
29- layer_size = [1 ] + [50 ] * 3 + [1 ]
30- activation = "tanh"
31- initializer = "Glorot uniform"
32- net = dde .maps .FNN (layer_size , activation , initializer )
33-
34- model = dde .Model (data , net )
35- model .compile ("adam" , lr = 0.001 , metrics = ["l2 relative error" ])
36-
37- checkpointer = dde .callbacks .ModelCheckpoint (
38- "model/model.ckpt" , verbose = 1 , save_better_only = True
39- )
40- # ImageMagick (https://imagemagick.org/) is required to generate the movie.
41- movie = dde .callbacks .MovieDumper (
42- "model/movie" , [- 1 ], [1 ], period = 100 , save_spectrum = True , y_reference = func
43- )
44- losshistory , train_state = model .train (
45- epochs = 10000 , callbacks = [checkpointer , movie ]
46- )
47-
48- dde .saveplot (losshistory , train_state , issave = True , isplot = True )
49-
50- # Plot PDE residual
51- model .restore ("model/model.ckpt-" + str (train_state .best_step ), verbose = 1 )
52- x = geom .uniform_points (1000 , True )
53- y = model .predict (x , operator = pde )
54- plt .figure ()
55- plt .plot (x , y )
56- plt .xlabel ("x" )
57- plt .ylabel ("PDE residual" )
58- plt .show ()
59-
60-
61- if __name__ == "__main__" :
62- main ()
24+ geom = dde .geometry .Interval (- 1 , 1 )
25+ bc = dde .DirichletBC (geom , func , boundary )
26+ data = dde .data .PDE (geom , pde , bc , 16 , 2 , solution = func , num_test = 100 )
27+
28+ layer_size = [1 ] + [50 ] * 3 + [1 ]
29+ activation = "tanh"
30+ initializer = "Glorot uniform"
31+ net = dde .maps .FNN (layer_size , activation , initializer )
32+
33+ model = dde .Model (data , net )
34+ model .compile ("adam" , lr = 0.001 , metrics = ["l2 relative error" ])
35+
36+ losshistory , train_state = model .train (epochs = 10000 )
37+ # Optional: Save the model during training.
38+ # checkpointer = dde.callbacks.ModelCheckpoint(
39+ # "model/model.ckpt", verbose=1, save_better_only=True
40+ # )
41+ # Optional: Save the movie of the network solution during training.
42+ # ImageMagick (https://imagemagick.org/) is required to generate the movie.
43+ # movie = dde.callbacks.MovieDumper(
44+ # "model/movie", [-1], [1], period=100, save_spectrum=True, y_reference=func
45+ # )
46+ # losshistory, train_state = model.train(epochs=10000, callbacks=[checkpointer, movie])
47+
48+ dde .saveplot (losshistory , train_state , issave = True , isplot = True )
49+
50+ # Plot PDE residual
51+ model .restore ("model/model.ckpt-" + str (train_state .best_step ), verbose = 1 )
52+ x = geom .uniform_points (1000 , True )
53+ y = model .predict (x , operator = pde )
54+ plt .figure ()
55+ plt .plot (x , y )
56+ plt .xlabel ("x" )
57+ plt .ylabel ("PDE residual" )
58+ plt .show ()
0 commit comments