initial commit FESurrogateModelTutorial
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7e3ade70",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 00 Beam2D FEM Dataset\n",
|
||||
"\n",
|
||||
"BeamExamples ?? ??? ?? ??? ? LHS sample? ???, repository solver? FEM surrogate ??? dataset? ????."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "71929240",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"from femsurrogate.data.bounds import DEFAULT_PARAMETER_BOUNDS\n",
|
||||
"from femsurrogate.data.dataset import build_dataset\n",
|
||||
"from femsurrogate.data.sampling import generate_lhs_samples\n",
|
||||
"from femsurrogate.data.schema import DEFAULT_RANDOM_SEED, TARGET_COLUMNS\n",
|
||||
"from femsurrogate.fea.io import read_beam_example, read_expected_displacements\n",
|
||||
"from femsurrogate.fea.solver import solve_linear_static\n",
|
||||
"\n",
|
||||
"ROOT = Path.cwd().resolve()\n",
|
||||
"if not (ROOT / \"pyproject.toml\").exists():\n",
|
||||
" ROOT = ROOT.parent\n",
|
||||
"assert (ROOT / \"pyproject.toml\").exists(), ROOT\n",
|
||||
"REFERENCE_DIR = ROOT / \"data\" / \"reference\"\n",
|
||||
"REFERENCE_DIR.mkdir(parents=True, exist_ok=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "df256ebc",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## BeamExamples ?? ??\n",
|
||||
"\n",
|
||||
"Fixture? ?? node? ?? `Ux`, `Uy`, `Rz`? ???? ???? ?? ????? ????."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0a8c947c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = read_beam_example(ROOT / \"BeamExamples\" / \"CantileverBeam.txt\")\n",
|
||||
"expected = read_expected_displacements(ROOT / \"BeamExamples\" / \"CantileverBeam_Displacements.txt\")\n",
|
||||
"actual = solve_linear_static(model)\n",
|
||||
"\n",
|
||||
"max_abs_error = 0.0\n",
|
||||
"for node_id, expected_displacement in expected.items():\n",
|
||||
" actual_displacement = actual[node_id]\n",
|
||||
" actual_values = np.array(\n",
|
||||
" [actual_displacement.ux, actual_displacement.uy, actual_displacement.rz]\n",
|
||||
" )\n",
|
||||
" expected_values = np.array(\n",
|
||||
" [expected_displacement.ux, expected_displacement.uy, expected_displacement.rz]\n",
|
||||
" )\n",
|
||||
" error = float(np.max(np.abs(actual_values - expected_values)))\n",
|
||||
" max_abs_error = max(max_abs_error, error)\n",
|
||||
"\n",
|
||||
"assert max_abs_error <= 5e-7\n",
|
||||
"max_abs_error"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6620d0ee",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## LHS sampling? FEM batch ??"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9923fd04",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"N_SAMPLES = 300\n",
|
||||
"\n",
|
||||
"samples = generate_lhs_samples(DEFAULT_PARAMETER_BOUNDS, n=N_SAMPLES, seed=DEFAULT_RANDOM_SEED)\n",
|
||||
"dataset = build_dataset(samples)\n",
|
||||
"\n",
|
||||
"assert len(dataset) == N_SAMPLES\n",
|
||||
"assert set(TARGET_COLUMNS).issubset(dataset.columns)\n",
|
||||
"dataset.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c0efee15",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Dataset ??\n",
|
||||
"\n",
|
||||
"?? notebook? ?? CSV? metadata? ??? `data/reference/`? ????."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d80890bd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dataset_path = REFERENCE_DIR / \"beam2d_lhs_300.csv\"\n",
|
||||
"metadata_path = REFERENCE_DIR / \"beam2d_lhs_300_metadata.json\"\n",
|
||||
"\n",
|
||||
"dataset.to_csv(dataset_path, index=False)\n",
|
||||
"metadata = {\n",
|
||||
" \"dataset_name\": \"beam2d_lhs_300\",\n",
|
||||
" \"sample_count\": N_SAMPLES,\n",
|
||||
" \"random_seed\": DEFAULT_RANDOM_SEED,\n",
|
||||
" \"unit_system\": \"SI\",\n",
|
||||
" \"fea_model\": \"2D Euler-Bernoulli beam/frame, linear static\",\n",
|
||||
" \"target_columns\": list(TARGET_COLUMNS),\n",
|
||||
" \"parameter_bounds\": {\n",
|
||||
" name: {\"lower\": bound.lower, \"upper\": bound.upper}\n",
|
||||
" for name, bound in DEFAULT_PARAMETER_BOUNDS.items()\n",
|
||||
" },\n",
|
||||
" \"notes\": \"Generated by notebooks/00_beam2d_fea_dataset.ipynb using src/femsurrogate.\",\n",
|
||||
"}\n",
|
||||
"metadata_path.write_text(json.dumps(metadata, indent=2), encoding=\"utf-8\")\n",
|
||||
"\n",
|
||||
"{\"dataset_path\": str(dataset_path), \"metadata_path\": str(metadata_path)}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d56bcddb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ?? sanity check"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e560e50c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dataset.describe().T.loc[[\"L_m\", \"b_m\", \"h_m\", \"E_pa\", \"P_n\", *TARGET_COLUMNS]]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"pygments_lexer": "ipython3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user