PINN as a PDE Solver


By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

Table of Contents

1. Lab 3: Euler Beam (Solid Mechanics)

1.1. Problem Setup

  • We will solve a Euler beam problem:



  • Problem properties
$$E = 1 \operatorname{pa}, \quad I = 1 \operatorname{kg\cdot m^2}, \quad q = 1 \operatorname{N/m}, \quad l = 1 \operatorname{m}$$


  • Partial differential equations & boundary conditions


$${\partial^4 y \over \partial x^4} + 1 = 0, \qquad \text{where} \quad x \in [0,1]$$

  • One Dirichlet boundary condition on the left boundary:


$$y(0) = 0$$

  • One Neumann boundary condition on the left boundary:


$$y'(0) = 0$$

  • Two boundary conditions on the right boundary:


$$y''(1) = 0, \quad y'''(1) = 0$$

  • The exact solution is


$$y(x) = -{1 \over 24}x^4 + {1 \over 6}x^3 - {1 \over 4}x^2$$

  • Make a neural network and loss functions like below :




1.2. Solve the Euler Beam problem

In [ ]:
!pip install deepxde
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting deepxde
  Downloading DeepXDE-1.4.0-py3-none-any.whl (132 kB)
     |████████████████████████████████| 132 kB 31.9 MB/s 
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from deepxde) (1.4.1)
Collecting scikit-optimize
  Downloading scikit_optimize-0.9.0-py2.py3-none-any.whl (100 kB)
     |████████████████████████████████| 100 kB 11.6 MB/s 
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from deepxde) (1.21.6)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from deepxde) (3.2.2)
Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from deepxde) (1.0.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->deepxde) (0.11.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->deepxde) (3.0.9)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->deepxde) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->deepxde) (1.4.2)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib->deepxde) (4.2.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->deepxde) (1.15.0)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->deepxde) (1.1.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->deepxde) (3.1.0)
Collecting pyaml>=16.9
  Downloading pyaml-21.10.1-py2.py3-none-any.whl (24 kB)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from pyaml>=16.9->scikit-optimize->deepxde) (3.13)
Installing collected packages: pyaml, scikit-optimize, deepxde
Successfully installed deepxde-1.4.0 pyaml-21.10.1 scikit-optimize-0.9.0
In [ ]:
# from deepxde.backend.set_default_backend import set_default_backend
# set_default_backend("tensorflow")

1.2.1. Import Library

In [ ]:
import deepxde as dde
import numpy as np
Deepxde backend not selected or invalid. Assuming tensorflow.compat.v1 for now.
Using backend: tensorflow.compat.v1

Setting the default backend to "tensorflow.compat.v1". You can change it in the ~/.deepxde/config.json file or export the DDEBACKEND environment variable. Valid options are: tensorflow.compat.v1, tensorflow, pytorch, jax, paddle (all lowercase)
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow/python/compat/v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/deepxde/nn/initializers.py:118: The name tf.keras.initializers.he_normal is deprecated. Please use tf.compat.v1.keras.initializers.he_normal instead.

1.2.2. Define PDE System

In [ ]:
def dy(x, y):
    return dde.grad.jacobian(y, x)

def ddy(x, y):
    return dde.grad.hessian(y, x)

def dddy(x, y):
    return dde.grad.jacobian(ddy(x, y), x)

def pde(x, y):
    dy_xx = ddy(x, y)
    dy_xxxx = dde.grad.hessian(dy_xx, x)
    return dy_xxxx + 1

1.2.3. Define Boundary Condition

In [ ]:
def boundary_left(x, on_boundary):
    return on_boundary and np.isclose(x[0], 0)

def boundary_right(x, on_boundary):
    return on_boundary and np.isclose(x[0], 1)

1.2.4. Define Geometry, Implement Boundary Condition

In [ ]:
geom = dde.geometry.Interval(0, 1)

bc1 = dde.DirichletBC(geom, lambda x: 0, boundary_left) # u(0) = 0
bc2 = dde.OperatorBC(geom, lambda x, y, _: dy(x, y), boundary_left) # u'(0) = 0
bc3 = dde.OperatorBC(geom, lambda x, y, _: ddy(x, y), boundary_right) # u''(1) = 0
bc4 = dde.OperatorBC(geom, lambda x, y, _: dddy(x, y), boundary_right) # u'''(1) = 0

# Reference solution to compute the error
def true_solution(x):
    return -(x ** 4) / 24 + x ** 3 / 6 - x ** 2 / 4

data = dde.data.PDE(geom,
                    pde,
                    [bc1, bc2, bc3, bc4],
                    num_domain = 10,
                    num_boundary = 2,
                    solution = true_solution,
                    num_test = 100)
/usr/local/lib/python3.7/dist-packages/skopt/sampler/sobol.py:250: UserWarning: The balance properties of Sobol' points require n to be a power of 2. 0 points have been previously generated, then: n=0+12=12. 
  total_n_samples))

1.2.5. Define Network and Hyper-parameters

In [ ]:
layer_size = [1] + [20] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"

net = dde.maps.FNN(layer_size, activation, initializer)
In [ ]:
model = dde.Model(data, net)
model.compile("adam", lr = 0.001)
Compiling model...
Building feed-forward neural network...
'build' took 0.061704 s

/usr/local/lib/python3.7/dist-packages/deepxde/nn/tensorflow_compat_v1/fnn.py:110: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.
  kernel_constraint=self.kernel_constraint,
/usr/local/lib/python3.7/dist-packages/keras/legacy_tf_layers/core.py:261: UserWarning: `layer.apply` is deprecated and will be removed in a future version. Please use `layer.__call__` method instead.
  return layer.apply(inputs)
'compile' took 6.221793 s

1.2.6. Train & Prediction

In [ ]:
losshistory, train_state = model.train(epochs = 5000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Initializing variables...
Training model...

Step      Train loss                                            Test loss                                             Test metric
0         [4.03e-01, 0.00e+00, 7.41e-02, 2.80e-02, 3.91e-03]    [3.61e-01, 0.00e+00, 7.41e-02, 2.80e-02, 3.91e-03]    []  
1000      [7.80e-04, 1.59e-08, 7.75e-08, 3.03e-06, 1.07e-06]    [6.18e-04, 1.59e-08, 7.75e-08, 3.03e-06, 1.07e-06]    []  
2000      [4.11e-05, 1.14e-10, 1.63e-09, 1.90e-08, 2.45e-08]    [3.38e-05, 1.14e-10, 1.63e-09, 1.90e-08, 2.45e-08]    []  
3000      [2.34e-05, 4.68e-11, 1.46e-09, 5.34e-09, 1.07e-08]    [1.69e-05, 4.68e-11, 1.46e-09, 5.34e-09, 1.07e-08]    []  
4000      [1.51e-05, 4.16e-09, 3.13e-09, 7.29e-09, 7.22e-08]    [1.01e-05, 4.16e-09, 3.13e-09, 7.29e-09, 7.22e-08]    []  
5000      [9.67e-05, 2.50e-06, 3.95e-07, 4.49e-07, 6.45e-06]    [8.98e-05, 2.50e-06, 3.95e-07, 4.49e-07, 6.45e-06]    []  

Best model at step 4000:
  train loss: 1.52e-05
  test loss: 1.02e-05
  test metric: []

'train' took 18.766083 s

2. Lab 4: Navier-Stokes Equations (Fluid Mechanics)

  • Note: strongly recommend you to use GPU rather than CPU. (you can use CoLab GPU for free)
  • If you use Google Colab, please implement below codes
In [ ]:
# !pip install deepxde
In [ ]:
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
In [ ]:
# from deepxde.backend.set_default_backend import set_default_backend
# set_default_backend("tensorflow")

2.1. Problem Setup

  • We will solve 2D Navier-Stokes Equations to find velocity profile in infinite parallel plates flow
    • Any fluid flowing in plates had to enter at some location. The region of flow near where the fluid enters the plates is termed the entrance region and is illustrated in below figure
    • The fluid typically enters the plates with a nearly uniform velocity profile
    • As the fluid moves through the plates, viscous effects cause it to stick to the plates wall (no-slip boundary condition)
    • Thus, a boundary layer is produced along the plates wall such that the initial velocity profile changes with distance along the plates, $x$, until the fluid reaches the end of the hydrodynamic entrance region (which is also called entrance length) beyond which the velocity profile does not vary with $x$





  • Problem properties


$$\rho = 1\operatorname{kg/m^3}, \quad \mu = 1\operatorname{N\cdot s/m^2}, \quad D = 2h = 1\operatorname{m}, \quad L = 2\operatorname{m}, \quad u_{in} = 1\operatorname{m/s}, \quad \nu = \frac{\mu}{\rho}$$


  • Hydraulic diameter is


$$\quad D_h = \lim\limits_{b\to\infty} {4(2bh) \over {2b+4h}} = 4h = 2\operatorname{m}$$

  • So, the Reynolds number of this system is


$$Re = \frac{\rho u_{in} D_h}{\mu} = 2 $$

  • 2D Navier-Stokes Equations & boundary conditions (for steady state)


$$ \begin{align*} u{\partial u \over \partial x} + v{\partial u \over \partial y} + {1 \over \rho}{\partial p \over \partial x} - \nu \ \left({\partial^2 u \over {\partial x^2}} + {\partial^2 u \over {\partial y^2}}\right) &= 0\\\\ u{\partial v \over \partial x} + v{\partial v \over \partial y} + {1 \over \rho}{\partial p \over \partial y} - \nu \ \left({\partial^2 v \over {\partial x^2}} + {\partial^2 v \over {\partial y^2}}\right) &= 0\\\\ {\partial u \over \partial x} + {\partial v \over \partial y} &= 0 \end{align*} $$


  • Two Dirichlet boundary conditions on the plate boundary (no-slip condition),


$$u(x,y) = 0, \quad v(x,y) = 0 \qquad \text{at} \quad y = \frac{D}{2} \ \; \text{or} \; -\frac{D}{2}$$

  • Two Dirichlet boundary conditions at the inlet boundary


$$u(-1,y) = u_{\text{in}}, \quad v(-1,y) = 0$$

  • Two Dirichlet boundary conditions at the outlet boundary


$$p(1,y) = 0, \quad v(1,y) = 0$$

  • Make a neural network and loss functions like below :




2.2. CFD Solution

  • CFD solution of this problem is illustrated in below figures
    • Velocity u and velocity v, and pressure p, respectively
  • Solve this problem using PINN and then compare with CFD solutions







2.3. Solve the Navier-Stokes Equations

2.3.1. Define Parameters

In [ ]:
# Properties
rho = 1
mu = 1
u_in = 1
D = 1
L = 2

2.3.2. Define PDE with Boundary & Initial Conditions

In [ ]:
def boundary_wall(X, on_boundary):
    on_wall = np.logical_and(np.logical_or(np.isclose(X[1], -D/2), np.isclose(X[1], D/2)), on_boundary)
    return on_wall

def boundary_inlet(X, on_boundary):
    return on_boundary and np.isclose(X[0], -L/2)

def boundary_outlet(X, on_boundary):
    return on_boundary and np.isclose(X[0], L/2)
In [ ]:
def pde(X, Y):
    du_x = dde.grad.jacobian(Y, X, i = 0, j = 0)
    du_y = dde.grad.jacobian(Y, X, i = 0, j = 1)
    dv_x = dde.grad.jacobian(Y, X, i = 1, j = 0)
    dv_y = dde.grad.jacobian(Y, X, i = 1, j = 1)
    dp_x = dde.grad.jacobian(Y, X, i = 2, j = 0)
    dp_y = dde.grad.jacobian(Y, X, i = 2, j = 1)
    du_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 0)
    du_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 0)
    dv_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 1)
    dv_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 1)

    pde_u = Y[:,0:1]*du_x + Y[:,1:2]*du_y + 1/rho * dp_x - (mu/rho)*(du_xx + du_yy)
    pde_v = Y[:,0:1]*dv_x + Y[:,1:2]*dv_y + 1/rho * dp_y - (mu/rho)*(dv_xx + dv_yy)
    pde_cont = du_x + dv_y

    return [pde_u, pde_v, pde_cont]

2.3.3. Define Geometry, Implement Boundary Condition

In [ ]:
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])

bc_wall_u = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 0)
bc_wall_v = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 1)

bc_inlet_u = dde.DirichletBC(geom, lambda X: u_in, boundary_inlet, component = 0)
bc_inlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_inlet, component = 1)

bc_outlet_p = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 2)
bc_outlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 1)
In [ ]:
data = dde.data.PDE(geom,
                    pde,
                    [bc_wall_u, bc_wall_v, bc_inlet_u, bc_inlet_v, bc_outlet_p, bc_outlet_v],
                    num_domain = 3000,
                    num_boundary = 500,
                    num_test = 1000,
                    train_distribution = 'LHS' )
Warning: 1000 points required, but 1035 points sampled.
In [ ]:
plt.figure(figsize = (10,8))
plt.scatter(data.train_x_all[:,0], data.train_x_all[:,1], s = 0.5)
plt.xlabel('x-direction length')
plt.ylabel('Distance from the middle of plates (m)')
plt.show()

2.3.4. Define Network and Hyper-parameters

In [ ]:
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"

net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)
model.compile("adam", lr = 1e-3)
Compiling model...
Building feed-forward neural network...
'build' took 0.088814 s

/usr/local/lib/python3.7/dist-packages/deepxde/nn/tensorflow_compat_v1/fnn.py:110: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.
  kernel_constraint=self.kernel_constraint,
/usr/local/lib/python3.7/dist-packages/keras/legacy_tf_layers/core.py:261: UserWarning: `layer.apply` is deprecated and will be removed in a future version. Please use `layer.__call__` method instead.
  return layer.apply(inputs)
'compile' took 1.730796 s

2.3.5. Train (Adam Optimizer)

In [ ]:
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Initializing variables...
Training model...

Step      Train loss                                                                                    Test loss                                                                                     Test metric
0         [9.38e-02, 1.06e-01, 3.61e-01, 5.28e-02, 4.58e-02, 1.87e+00, 9.10e-02, 3.25e-03, 9.10e-02]    [8.79e-02, 1.01e-01, 3.71e-01, 5.28e-02, 4.58e-02, 1.87e+00, 9.10e-02, 3.25e-03, 9.10e-02]    []  
1000      [5.51e-04, 1.22e-03, 1.05e-02, 3.58e-02, 1.55e-02, 4.15e-02, 3.85e-03, 4.66e-04, 4.62e-05]    [3.18e-04, 7.83e-04, 7.37e-03, 3.58e-02, 1.55e-02, 4.15e-02, 3.85e-03, 4.66e-04, 4.62e-05]    []  
2000      [1.05e-03, 8.49e-04, 5.51e-03, 2.78e-02, 1.24e-02, 3.27e-02, 8.84e-04, 3.47e-04, 4.07e-05]    [7.35e-04, 4.82e-04, 3.82e-03, 2.78e-02, 1.24e-02, 3.27e-02, 8.84e-04, 3.47e-04, 4.07e-05]    []  
3000      [6.18e-04, 8.36e-04, 4.19e-03, 2.36e-02, 1.07e-02, 2.45e-02, 2.15e-03, 1.60e-05, 3.60e-05]    [4.24e-04, 4.89e-04, 2.63e-03, 2.36e-02, 1.07e-02, 2.45e-02, 2.15e-03, 1.60e-05, 3.60e-05]    []  
4000      [8.67e-04, 9.07e-04, 3.21e-03, 2.14e-02, 9.45e-03, 2.02e-02, 3.92e-03, 1.18e-05, 6.74e-06]    [6.09e-04, 6.68e-04, 1.84e-03, 2.14e-02, 9.45e-03, 2.02e-02, 3.92e-03, 1.18e-05, 6.74e-06]    []  
5000      [3.16e-02, 8.34e-03, 3.50e-03, 2.01e-02, 8.18e-03, 1.87e-02, 4.82e-03, 1.68e-02, 8.54e-06]    [3.10e-02, 6.90e-03, 2.08e-03, 2.01e-02, 8.18e-03, 1.87e-02, 4.82e-03, 1.68e-02, 8.54e-06]    []  
6000      [2.02e-03, 6.33e-04, 2.66e-03, 1.97e-02, 7.49e-03, 1.75e-02, 5.34e-03, 1.58e-03, 7.25e-06]    [1.86e-03, 5.09e-04, 1.50e-03, 1.97e-02, 7.49e-03, 1.75e-02, 5.34e-03, 1.58e-03, 7.25e-06]    []  
7000      [2.67e-03, 5.61e-04, 2.19e-03, 1.90e-02, 6.45e-03, 1.75e-02, 5.78e-03, 3.92e-03, 2.06e-05]    [2.68e-03, 4.79e-04, 1.23e-03, 1.90e-02, 6.45e-03, 1.75e-02, 5.78e-03, 3.92e-03, 2.06e-05]    []  
8000      [7.55e-04, 3.40e-04, 2.38e-03, 1.88e-02, 6.60e-03, 1.53e-02, 6.18e-03, 9.45e-05, 1.11e-05]    [6.68e-04, 2.84e-04, 1.27e-03, 1.88e-02, 6.60e-03, 1.53e-02, 6.18e-03, 9.45e-05, 1.11e-05]    []  
9000      [2.74e-03, 1.79e-03, 2.00e-03, 1.88e-02, 6.24e-03, 1.48e-02, 6.30e-03, 7.45e-05, 1.00e-05]    [2.39e-03, 1.50e-03, 1.01e-03, 1.88e-02, 6.24e-03, 1.48e-02, 6.30e-03, 7.45e-05, 1.00e-05]    []  
10000     [5.18e-03, 8.69e-04, 2.11e-03, 1.86e-02, 5.66e-03, 1.50e-02, 6.12e-03, 2.18e-03, 2.46e-05]    [4.47e-03, 7.12e-04, 1.11e-03, 1.86e-02, 5.66e-03, 1.50e-02, 6.12e-03, 2.18e-03, 2.46e-05]    []  

Best model at step 8000:
  train loss: 5.05e-02
  test loss: 4.93e-02
  test metric: []

'train' took 86.591744 s

2.3.6. Plot Results (Adam Optimizer)

In [ ]:
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(samples[:, 0],
                samples[:, 1],
                c = result[:, idx],
                cmap = 'jet',
                s = 2)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()

2.3.7. Train More (L-BFGS Optimizer)

In [ ]:
dde.optimizers.config.set_LBFGS_options(maxiter=3000)

model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Compiling model...
'compile' took 1.003504 s

Training model...

Step      Train loss                                                                                    Test loss                                                                                     Test metric
10000     [5.18e-03, 8.69e-04, 2.11e-03, 1.86e-02, 5.66e-03, 1.50e-02, 6.12e-03, 2.18e-03, 2.46e-05]    [4.47e-03, 7.12e-04, 1.11e-03, 1.86e-02, 5.66e-03, 1.50e-02, 6.12e-03, 2.18e-03, 2.46e-05]    []  
11000     [6.84e-04, 6.77e-04, 1.30e-03, 1.21e-02, 1.33e-03, 5.78e-03, 2.69e-03, 8.80e-06, 1.16e-05]                                                                                                      
12000     [4.72e-04, 5.47e-04, 5.02e-04, 7.94e-03, 1.45e-03, 4.64e-03, 2.11e-03, 1.26e-05, 2.06e-05]                                                                                                      
13000     [3.95e-04, 4.99e-04, 5.14e-04, 6.36e-03, 1.51e-03, 3.67e-03, 1.74e-03, 1.62e-05, 8.28e-06]                                                                                                      
INFO:tensorflow:Optimization terminated with:
  Message: b'STOP: TOTAL NO. of ITERATIONS REACHED LIMIT'
  Objective function value: 0.014583
  Number of iterations: 3000
  Number of functions evaluations: 3067
13067     [4.12e-04, 4.56e-04, 4.96e-04, 6.22e-03, 1.52e-03, 3.69e-03, 1.76e-03, 1.99e-05, 9.94e-06]    [4.40e-04, 4.18e-04, 3.29e-04, 6.22e-03, 1.52e-03, 3.69e-03, 1.76e-03, 1.99e-05, 9.94e-06]    []  

Best model at step 13067:
  train loss: 1.46e-02
  test loss: 1.44e-02
  test metric: []

'train' took 92.642951 s

2.3.8. Plot Results (Adam + L-BFGS)

In [ ]:
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(samples[:, 0],
                samples[:, 1],
                c = result[:, idx],
                cmap = 'jet',
                s = 2)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()

2.3.9. Validation: Plot Velocity Profile at the End of the Plate

  • Fully developed velocity profile at the infinite parallel plates flow are known as


$$u(y) = {3V_{avg} \over 2} \left[ 1- \left( \frac{y}{h} \right)^2 \right]$$




In [ ]:
# Analytic solution
x = np.ones([1000,1])
y = np.linspace(-0.5, 0.5, 1000).reshape(1000,1)
outlet = np.hstack([x, y])

analytic_solution = u_in * 1.5 * (1 - ((y)/(D/2))**2)

PINN_solution = model.predict(outlet)
In [ ]:
plt.figure(figsize = (10,8))
plt.plot(y, PINN_solution[:, 0], c = 'tomato', linewidth = 3, label = 'PINN solution')
plt.plot(y, analytic_solution, c = 'k', linestyle = '--', label = 'Analytic solution')
plt.xticks(np.linspace(-0.5, 0.5, 5), fontsize = 15)
plt.yticks(np.linspace(0, 1.5, 11), fontsize = 15)
plt.legend(fontsize = 12)
plt.xlabel('Distance from the middle of plates (m)', fontsize = 15)
plt.ylabel('Velocity ($u$)', fontsize = 15)
plt.show()
In [1]:
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')