Update tutorials 8 through 14
This commit is contained in:
committed by
Nicola Demo
parent
17792caa34
commit
9e55746546
94
tutorials/tutorial8/tutorial.ipynb
vendored
94
tutorials/tutorial8/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
13
tutorials/tutorial8/tutorial.py
vendored
13
tutorials/tutorial8/tutorial.py
vendored
@@ -16,7 +16,7 @@
|
||||
# Let's start with the necessary imports.
|
||||
# It's important to note the minimum PINA version to run this tutorial is the `0.1`.
|
||||
|
||||
# In[1]:
|
||||
# In[ ]:
|
||||
|
||||
|
||||
## routine needed to run the notebook on Google Colab
|
||||
@@ -31,9 +31,9 @@ if IN_COLAB:
|
||||
get_ipython().run_line_magic('matplotlib', 'inline')
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
plt.style.use('tableau-colorblind10')
|
||||
import torch
|
||||
import pina
|
||||
import warnings
|
||||
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.optim import TorchOptimizer
|
||||
@@ -43,6 +43,8 @@ from pina import Condition, LabelTensor, Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.solver import SupervisedSolver
|
||||
|
||||
warnings.filterwarnings('ignore')
|
||||
|
||||
|
||||
# We exploit the [Smithers](https://github.com/mathLab/Smithers) library to collect the parametric snapshots. In particular, we use the `NavierStokesDataset` class that contains a set of parametric solutions of the Navier-Stokes equations in a 2D L-shape domain. The parameter is the inflow velocity.
|
||||
# The dataset is composed by 500 snapshots of the velocity (along $x$, $y$, and the magnitude) and pressure fields, and the corresponding parameter values.
|
||||
@@ -52,7 +54,6 @@ from pina.solver import SupervisedSolver
|
||||
# In[2]:
|
||||
|
||||
|
||||
get_ipython().system('pip install git+https://github.com/mathLab/Smithers.git')
|
||||
import smithers
|
||||
from smithers.dataset import NavierStokesDataset
|
||||
dataset = NavierStokesDataset()
|
||||
@@ -83,7 +84,7 @@ u_train, u_test = u[:n_train], u[n_train:]
|
||||
p_train, p_test = p[:n_train], p[n_train:]
|
||||
|
||||
|
||||
# It is now time to define the problem! We inherit from `ParametricProblem` (since the space invariant typically of this methodology), just defining a simple *input-output* condition.
|
||||
# It is now time to define the problem! We inherit from `ParametricProblem` (since the space invariance typical of this methodology), just defining a simple *input-target* condition.
|
||||
|
||||
# In[4]:
|
||||
|
||||
@@ -93,7 +94,7 @@ class SnapshotProblem(ParametricProblem):
|
||||
parameter_domain = CartesianDomain({'mu': [0, 100]})
|
||||
|
||||
conditions = {
|
||||
'io': Condition(input_points=p_train, output_points=u_train)
|
||||
'io': Condition(input=p_train, target=u_train)
|
||||
}
|
||||
|
||||
poisson_problem = SnapshotProblem()
|
||||
@@ -158,7 +159,7 @@ pod_nn.fit_pod(u_train)
|
||||
pod_nn_stokes = SupervisedSolver(
|
||||
problem=poisson_problem,
|
||||
model=pod_nn,
|
||||
optimizer=TorchOptimizer(torch.optim.Adam))
|
||||
optimizer=TorchOptimizer(torch.optim.Adam, lr=0.0001))
|
||||
|
||||
|
||||
# Now that we have set the `Problem` and the `Model`, we have just to train the model and use it for predicting the test snapshots.
|
||||
|
||||
Reference in New Issue
Block a user