Skip to content

Commit

Permalink
Add laplace FEM solution
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Freudenberg <[email protected]>
  • Loading branch information
Tom Freudenberg committed Nov 4, 2023
1 parent 0224624 commit 9b4f735
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 24 deletions.
32 changes: 32 additions & 0 deletions examples/new_examples/Exercise_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,38 @@
"plot_sampler = tp.samplers.PlotSampler(plot_domain=omega, n_points=2000)\n",
"fig = tp.utils.plot(model, lambda u : u, plot_sampler)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And compare PINNs with the FEM-solution:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# Get data from Github:\n",
"!wget https://github.com/TomF98/torchphysics/raw/main/examples/workshop/FEMData/LaplaceData/solution.npy\n",
"!wget https://github.com/TomF98/torchphysics/raw/main/examples/workshop/FEMData/LaplaceData/coordinates.npy\n",
"\n",
"# Read data:\n",
"coords = torch.tensor(np.load(\"coordinates.npy\"), dtype=torch.float32)\n",
"fem_sol = torch.tensor(np.load(\"solution.npy\"), dtype=torch.float32).reshape(-1, 1)\n",
"\n",
"# Evaluate Network:\n",
"model_out = model(tp.spaces.Points(coords, X)).as_tensor\n",
"\n",
"print(\"Difference to FEM in Sup-norm:\")\n",
"difference_sup = torch.max(torch.abs(fem_sol - model_out))\n",
"print(\"Absolute:\", difference_sup)\n",
"print(\"Relative:\", difference_sup / torch.max(torch.abs(fem_sol)))"
]
}
],
"metadata": {
Expand Down
Binary file added examples/new_examples/LaplaceData/coordinates.npy
Binary file not shown.
Binary file added examples/new_examples/LaplaceData/solution.npy
Binary file not shown.
140 changes: 116 additions & 24 deletions examples/new_examples/Sol_1.ipynb

Large diffs are not rendered by default.

0 comments on commit 9b4f735

Please sign in to comment.