Update tutorial 1,3,4,9 plots
This commit is contained in:
28124
tutorials/tutorial3/tutorial.ipynb
vendored
28124
tutorials/tutorial3/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
25
tutorials/tutorial3/tutorial.py
vendored
25
tutorials/tutorial3/tutorial.py
vendored
@@ -9,7 +9,7 @@
|
||||
#
|
||||
# First of all, some useful imports.
|
||||
|
||||
# In[12]:
|
||||
# In[1]:
|
||||
|
||||
|
||||
## routine needed to run the notebook on Google Colab
|
||||
@@ -50,7 +50,7 @@ from pina import Condition, LabelTensor
|
||||
|
||||
# Now, the wave problem is written in PINA code as a class, inheriting from `SpatialProblem` and `TimeDependentProblem` since we deal with spatial, and time dependent variables. The equations are written as `conditions` that should be satisfied in the corresponding domains. `truth_solution` is the exact solution which will be compared with the predicted one.
|
||||
|
||||
# In[13]:
|
||||
# In[2]:
|
||||
|
||||
|
||||
class Wave(TimeDependentProblem, SpatialProblem):
|
||||
@@ -96,7 +96,7 @@ problem = Wave()
|
||||
#
|
||||
# where $NN$ is the neural net output. This neural network takes as input the coordinates (in this case $x$, $y$ and $t$) and provides the unknown field $u$. By construction, it is zero on the boundaries. The residuals of the equations are evaluated at several sampling points (which the user can manipulate using the method `discretise_domain`) and the loss minimized by the neural network is the sum of the residuals.
|
||||
|
||||
# In[14]:
|
||||
# In[3]:
|
||||
|
||||
|
||||
class HardMLP(torch.nn.Module):
|
||||
@@ -120,7 +120,7 @@ class HardMLP(torch.nn.Module):
|
||||
|
||||
# In this tutorial, the neural network is trained for 1000 epochs with a learning rate of 0.001 (default in `PINN`). Training takes approximately 3 minutes.
|
||||
|
||||
# In[15]:
|
||||
# In[4]:
|
||||
|
||||
|
||||
# generate the data
|
||||
@@ -136,16 +136,13 @@ trainer.train()
|
||||
|
||||
# Notice that the loss on the boundaries of the spatial domain is exactly zero, as expected! After the training is completed one can now plot some results using the `Plotter` class of **PINA**.
|
||||
|
||||
# In[16]:
|
||||
# In[5]:
|
||||
|
||||
|
||||
#plotter = Plotter()
|
||||
|
||||
method='contourf'
|
||||
# plotting at fixed time t = 0.0
|
||||
print('Plotting at t=0')
|
||||
#plotter.plot(pinn, fixed_variables={'t': 0.0})
|
||||
fixed_variables={'t': 0.0}
|
||||
method='contourf'
|
||||
pts = pinn.problem.spatial_domain.sample(256, 'grid', variables=['x','y'])
|
||||
grids = [p_.reshape(256, 256) for p_ in pts.extract(['x','y']).T]
|
||||
fixed_pts = torch.ones(pts.shape[0], len(fixed_variables))
|
||||
@@ -228,7 +225,7 @@ ax[2].title.set_text('Residual')
|
||||
#
|
||||
# Let us build the network first
|
||||
|
||||
# In[17]:
|
||||
# In[6]:
|
||||
|
||||
|
||||
class HardMLPtime(torch.nn.Module):
|
||||
@@ -251,7 +248,7 @@ class HardMLPtime(torch.nn.Module):
|
||||
|
||||
# Now let's train with the same configuration as thre previous test
|
||||
|
||||
# In[18]:
|
||||
# In[7]:
|
||||
|
||||
|
||||
# generate the data
|
||||
@@ -267,16 +264,12 @@ trainer.train()
|
||||
|
||||
# We can clearly see that the loss is way lower now. Let's plot the results
|
||||
|
||||
# In[19]:
|
||||
# In[8]:
|
||||
|
||||
|
||||
#plotter = Plotter()
|
||||
|
||||
# plotting at fixed time t = 0.0
|
||||
print('Plotting at t=0')
|
||||
#plotter.plot(pinn, fixed_variables={'t': 0.0})
|
||||
fixed_variables={'t': 0.0}
|
||||
method='contourf'
|
||||
pts = pinn.problem.spatial_domain.sample(256, 'grid', variables=['x','y'])
|
||||
grids = [p_.reshape(256, 256) for p_ in pts.extract(['x','y']).T]
|
||||
fixed_pts = torch.ones(pts.shape[0], len(fixed_variables))
|
||||
|
||||
Reference in New Issue
Block a user