Skip to content

Commit

Permalink
[doc] Update docs (#4)
Browse files Browse the repository at this point in the history
* Update

* Update

* Find bug in Allen_Cahn.ipynb

* Update

* Update

* Update heat.py

* Update

* Update Burgers_RAR.py

* Fix heat_resample.py

* Fix bugs in `heat_resample.py`

* Fix `Laplace_disk.py`

* Add `Burgers_RAR.ipynb`

* Add `heat_resample.ipynb`

* Add `Laplace_disk.ipynb`
  • Loading branch information
Routhleck authored Dec 13, 2024
1 parent 444b234 commit 21680e5
Show file tree
Hide file tree
Showing 25 changed files with 4,209 additions and 189 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ pinnx/_version.py
.idea/

related-projects.md

# .dat files in the docs folder and it's subfolders
docs/**/*.dat
docs/**/*.npz
277 changes: 277 additions & 0 deletions docs/examples-function/dataset.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/examples-function/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import os

import brainstate as bst
import numpy as np

import pinnx

train_data = np.loadtxt("../dataset/dataset.train")
test_data = np.loadtxt("../dataset/dataset.test")
PATH = os.path.dirname(os.path.abspath(__file__))
train_data = np.loadtxt(os.path.join(PATH, '..', 'dataset', 'dataset.train'))
test_data = np.loadtxt(os.path.join(PATH, '..', 'dataset', 'dataset.test'))

net = pinnx.nn.Model(
pinnx.nn.DictToArray(x=None),
Expand Down
245 changes: 245 additions & 0 deletions docs/examples-function/func.ipynb

Large diffs are not rendered by default.

380 changes: 380 additions & 0 deletions docs/examples-pinn-forward/Allen_Cahn.ipynb

Large diffs are not rendered by default.

1,321 changes: 1,321 additions & 0 deletions docs/examples-pinn-forward/Burgers_RAR.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples-pinn-forward/Burgers_RAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pde(x, y):

X = geomtime.random_points(100000)
err = 1
while u.get_magnitude(err) > 0.005:
while u.get_magnitude(err) > 0.012:
f = trainer.predict(X, operator=pde)
err_eq = u.math.absolute(f)
err = u.math.mean(err_eq)
Expand Down
44 changes: 44 additions & 0 deletions docs/examples-pinn-forward/Euler_beam.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Euler beam\n",
"## Problem setup\n",
"\n",
"We will solve a Euler beam problem:\n",
"$$\n",
"\\frac{\\partial^{4} u}{\\partial x^4} + 1 = 0, \\qquad x \\in [0, 1],\n",
"$$\n",
"with two boundary conditions on the right boundary,\n",
"\n",
"$$\n",
"u''(1)=0, u'''(1)=0\n",
"$$\n",
"\n",
"and one Dirichlet boundary condition on the left boundary,\n",
"\n",
"$$\n",
"u(0)=0\n",
"$$\n",
"\n",
"along with one Neumann boundary condition on the left boundary,\n",
"\n",
"$$\n",
"u'(0)=0\n",
"$$\n",
"\n",
"The exact solution is $u(x) = -\\frac{1}{24}x^4+\\frac{1}{6}x^3-\\frac{1}{4}x^2.$\n",
"\n"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
44 changes: 44 additions & 0 deletions docs/examples-pinn-forward/Helmholtz_Dirichlet_2d.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Helmholtz equation over a 2D square domain\n",
"\n",
"## Problem setup\n",
"For a wavenumber $k_0 = 2\\pi n$ with $n = 2$, we will solve a Helmholtz equation:\n",
"\n",
"$$\n",
"- u_{xx}-u_{yy} - k_0^2 u = f, \\qquad \\Omega = [0,1]^2\n",
"$$\n",
"\n",
"with the Dirichlet boundary conditions\n",
"\n",
"$$\n",
"u(x,y)=0, \\qquad (x,y)\\in \\partial \\Omega\n",
"$$\n",
"\n",
"and a source term $f(x,y) = k_0^2 \\sin(k_0 x)\\sin(k_0 y)$.\n",
"\n",
"Remark that the exact solution reads:\n",
"$$\n",
"u(x,y)= \\sin(k_0 x)\\sin(k_0 y)\n",
"$$"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pinnx",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
52 changes: 52 additions & 0 deletions docs/examples-pinn-forward/Klein_Gordon.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Klein-Gordon equation\n",
"\n",
"## Problem setup\n",
"\n",
"We will solve a Klein-Gordon equation:\n",
"\n",
"$$\n",
"\\frac{\\partial^2y}{\\partial t^2} + \\alpha \\frac{\\partial^2y}{\\partial x^2} + \\beta y + \\gamma y^k = -x\\cos(t) + x^2\\cos^2(t), \\qquad x \\in [-1, 1], \\quad t \\in [0, 10]\n",
"$$\n",
"\n",
"with initial conditions\n",
"\n",
"$$\n",
"y(x, 0) = x, \\quad \\frac{\\partial y}{\\partial t}(x, 0) = 0\n",
"$$\n",
"\n",
"and Dirichlet boundary conditions\n",
"\n",
"$$\n",
"y(-1, t) = -\\cos(t), \\quad y(1, t) = \\cos(t)\n",
"$$\n",
"\n",
"We also specify the following parameters for the equation:\n",
"\n",
"$$\n",
"\\alpha = -1, \\beta = 0, \\gamma = 1, k = 2.\n",
"$$\n",
"\n",
"The reference solution is $y(x, t) = x\\cos(t)$."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pinnx",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
44 changes: 44 additions & 0 deletions docs/examples-pinn-forward/Kovasznay_flow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Kovasznay flow\n",
"\n",
"## Problem setup\n",
"\n",
"We will solve the Kovasznay flow equation on $\\Omega = [0, 1]^2$:\n",
"\n",
"$$\n",
"u\\frac{\\partial u}{\\partial x} + v\\frac{\\partial u}{\\partial y}= -\\frac{\\partial p}{\\partial x} + \\frac{1}{Re}(\\frac{\\partial^2u}{\\partial x^2} + \\frac{\\partial^2u}{\\partial y^2}),\n",
"$$\n",
"\n",
"$$\n",
"u\\frac{\\partial v}{\\partial x} + v\\frac{\\partial v}{\\partial y}= -\\frac{\\partial p}{\\partial y} + \\frac{1}{Re}(\\frac{\\partial^2v}{\\partial x^2} + \\frac{\\partial^2v}{\\partial y^2}),\n",
"$$\n",
"\n",
"with the Dirichlet boundary conditions\n",
"\n",
"$$\n",
"u(x,y)=0, \\qquad (x,y)\\in \\partial \\Omega\n",
"$$\n",
"\n",
"The reference solution is $u = 1 - e^{\\lambda x} \\cos(2\\pi y), v = \\frac{\\lambda}{2\\pi}e^{\\lambda x} \\sin(2\\pi x)$, $p =\\frac{1}{2}(1 - e^{2\\lambda x})$, where $\\lambda = \\frac{1}{2\\nu}-\\sqrt{\\frac{1}{4\\nu^2}+4\\pi^2}$."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pinnx",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 21680e5

Please sign in to comment.