Release FemLite 0.3.3 stage baseline

This commit is contained in:
shenw
2026-06-24 17:29:36 +08:00
parent 7241b4f2bd
commit 3ad844ab55
73 changed files with 19184 additions and 4676 deletions
+69
View File
@@ -0,0 +1,69 @@
# shell_patch_test
FemLite shell membrane patch test for linear S3 and S4 shell elements.
This example imposes the exact displacement field
```text
ux = 0.01*x
uy = 0
uz = rx = ry = rz = 0
```
on every node of a small distorted 2x2 shell patch. The expected global
plane-stress state is constant:
```text
sigma_x = E/(1 - nu^2)*0.01 = 0.32
sigma_y = nu*E/(1 - nu^2)*0.01 = 0.08
tau_xy = 0
```
Benchmark data:
- Geometry: unit square midsurface in the global x-y plane, with interior nodes
shifted to form a distorted patch.
- Thickness: 0.2.
- Material: E = 30.0, nu = 0.25, density = 1.0.
- Element decks:
- `shell_patch_s3.inp`: 9 nodes, 8 S3 elements.
- `shell_patch_s4.inp`: 9 nodes, 4 S4 elements.
- Analysis: linear static solve with prescribed nodal displacement field.
Regenerate input decks:
```powershell
Python\.venv\Scripts\python.exe examples\shell_patch_test\generate_shell_patch_test.py
```
Run from the repository root:
```powershell
New-Item -ItemType Directory -Force examples\shell_patch_test\results\s3 | Out-Null
build-win-gcc-16\femlite.exe examples\shell_patch_test\shell_patch_s3.inp --output-dir examples\shell_patch_test\results\s3 --static-linear
```
```powershell
New-Item -ItemType Directory -Force examples\shell_patch_test\results\s4 | Out-Null
build-win-gcc-16\femlite.exe examples\shell_patch_test\shell_patch_s4.inp --output-dir examples\shell_patch_test\results\s4 --static-linear
```
Check the results:
```powershell
Python\.venv\Scripts\python.exe examples\shell_patch_test\check_shell_patch_results.py --case s3
Python\.venv\Scripts\python.exe examples\shell_patch_test\check_shell_patch_results.py --case s4
```
The checker compares:
- nodal displacement output against the exact field;
- element-average local shell stresses against the exact global stress tensor
rotated into each element's local shell basis.
Current result:
| Deck | Max displacement error | Max local stress error |
|---|---:|---:|
| `shell_patch_s3.inp` | 8.673617E-19 | 2.498002E-16 |
| `shell_patch_s4.inp` | 8.673617E-19 | 5.551115E-17 |
@@ -0,0 +1,147 @@
#!/usr/bin/env python3
"""Check FemLite shell membrane patch-test results."""
from __future__ import annotations
import argparse
import csv
import math
from pathlib import Path
from typing import Dict, List, Sequence, Tuple
YOUNG_MODULUS = 30.0
POISSON_RATIO = 0.25
EXX = 0.01
DISP_TOL = 1.0e-11
STRESS_TOL = 1.0e-8
Point3 = Tuple[float, float, float]
Element = Tuple[int, ...]
def parse_inp(path: Path) -> Tuple[Dict[int, Point3], List[Element]]:
nodes: Dict[int, Point3] = {}
elements: List[Element] = []
section = ""
for raw in path.read_text(encoding="ascii").splitlines():
line = raw.strip()
if not line or line.startswith("**"):
continue
if line.startswith("*"):
upper = line.upper()
if upper.startswith("*NODE"):
section = "node"
elif upper.startswith("*ELEMENT"):
section = "element"
else:
section = ""
continue
fields = [item.strip() for item in line.split(",") if item.strip()]
if section == "node":
nodes[int(fields[0])] = (
float(fields[1]),
float(fields[2]),
float(fields[3]),
)
elif section == "element":
elements.append(tuple(int(item) for item in fields[1:]))
return nodes, elements
def read_node_csv(path: Path) -> Dict[int, Dict[str, float]]:
with path.open(newline="", encoding="ascii") as f:
return {int(row["node_id"]): {k: float(v) for k, v in row.items() if k != "node_id"} for row in csv.DictReader(f)}
def read_element_csv(path: Path) -> List[Dict[str, float]]:
with path.open(newline="", encoding="ascii") as f:
rows: List[Dict[str, float]] = []
for row in csv.DictReader(f):
parsed = {k: float(v) for k, v in row.items() if k not in ("elem_id", "status")}
parsed["elem_id"] = float(row["elem_id"])
parsed["status"] = float(row["status"])
rows.append(parsed)
return rows
def local_basis(nodes: Dict[int, Point3], elem: Sequence[int]) -> Tuple[Tuple[float, float], Tuple[float, float]]:
x1, y1, _ = nodes[elem[0]]
x2, y2, _ = nodes[elem[1]]
dx = x2 - x1
dy = y2 - y1
length = math.hypot(dx, dy)
if length <= 0.0:
raise ValueError("coincident first edge nodes")
e1 = (dx / length, dy / length)
e2 = (-e1[1], e1[0])
return e1, e2
def expected_local_stress(nodes: Dict[int, Point3], elem: Sequence[int]) -> Tuple[float, float, float]:
factor = YOUNG_MODULUS / (1.0 - POISSON_RATIO * POISSON_RATIO)
sx = factor * EXX
sy = factor * POISSON_RATIO * EXX
txy = 0.0
e1, e2 = local_basis(nodes, elem)
def stress_on(a: Tuple[float, float], b: Tuple[float, float]) -> float:
return (
a[0] * (sx * b[0] + txy * b[1])
+ a[1] * (txy * b[0] + sy * b[1])
)
return stress_on(e1, e1), stress_on(e2, e2), stress_on(e1, e2)
def check_case(inp_path: Path, result_dir: Path) -> Tuple[float, float]:
nodes, elements = parse_inp(inp_path)
node_rows = read_node_csv(result_dir / "nodes_00000001.csv")
elem_rows = read_element_csv(result_dir / "elements_00000001.csv")
if len(elem_rows) != len(elements):
raise RuntimeError(f"element count mismatch for {inp_path.name}")
max_disp_error = 0.0
for nid, (x, _, _) in nodes.items():
row = node_rows[nid]
max_disp_error = max(max_disp_error, abs(row["ux"] - EXX * x))
max_disp_error = max(max_disp_error, abs(row["uy"]))
max_disp_error = max(max_disp_error, abs(row["uz"]))
max_stress_error = 0.0
for elem, row in zip(elements, elem_rows):
s11, s22, s12 = expected_local_stress(nodes, elem)
max_stress_error = max(max_stress_error, abs(row["s11"] - s11))
max_stress_error = max(max_stress_error, abs(row["s22"] - s22))
max_stress_error = max(max_stress_error, abs(row["s12"] - s12))
max_stress_error = max(max_stress_error, abs(row["s13"]))
max_stress_error = max(max_stress_error, abs(row["s23"]))
if max_disp_error > DISP_TOL:
raise RuntimeError(
f"{inp_path.name}: displacement error {max_disp_error:.6E} > {DISP_TOL:.6E}"
)
if max_stress_error > STRESS_TOL:
raise RuntimeError(
f"{inp_path.name}: stress error {max_stress_error:.6E} > {STRESS_TOL:.6E}"
)
return max_disp_error, max_stress_error
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--case", choices=("s3", "s4"), required=True)
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parent)
args = parser.parse_args()
case_name = f"shell_patch_{args.case}.inp"
result_dir = args.root / "results" / args.case
disp_error, stress_error = check_case(args.root / case_name, result_dir)
print(f"{case_name}: max displacement error = {disp_error:.6E}")
print(f"{case_name}: max local stress error = {stress_error:.6E}")
print("PASS")
if __name__ == "__main__":
main()
@@ -0,0 +1,122 @@
#!/usr/bin/env python3
"""Generate FemLite shell membrane patch-test input decks."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, List, Sequence, Tuple
YOUNG_MODULUS = 30.0
POISSON_RATIO = 0.25
DENSITY = 1.0
THICKNESS = 0.2
EXX = 0.01
STATIC_INITIAL_INCREMENT = 1.0
STATIC_TOTAL_TIME = 1.0
STATIC_MIN_INCREMENT = 0.1
STATIC_MAX_INCREMENT = 1.0
SET_LINE_WIDTH = 12
Point3 = Tuple[float, float, float]
Element = Tuple[int, ...]
@dataclass
class Mesh:
nodes: Dict[int, Point3]
elements: List[Element]
element_type: str
def build_nodes() -> Dict[int, Point3]:
return {
1: (0.00, 0.00, 0.0),
2: (0.45, 0.00, 0.0),
3: (1.00, 0.00, 0.0),
4: (0.05, 0.50, 0.0),
5: (0.50, 0.50, 0.0),
6: (0.95, 0.50, 0.0),
7: (0.00, 1.00, 0.0),
8: (0.55, 1.00, 0.0),
9: (1.00, 1.00, 0.0),
}
def build_mesh(element_type: str) -> Mesh:
nodes = build_nodes()
quads = [
(1, 2, 5, 4),
(2, 3, 6, 5),
(4, 5, 8, 7),
(5, 6, 9, 8),
]
elements: List[Element] = []
if element_type == "S4":
elements = list(quads)
elif element_type == "S3":
for n1, n2, n3, n4 in quads:
elements.append((n1, n2, n3))
elements.append((n1, n3, n4))
else:
raise ValueError(f"unsupported element type: {element_type}")
return Mesh(nodes=nodes, elements=elements, element_type=element_type)
def write_id_set(f, ids: Sequence[int]) -> None:
for i in range(0, len(ids), SET_LINE_WIDTH):
f.write(", ".join(str(item) for item in ids[i : i + SET_LINE_WIDTH]))
f.write("\n")
def write_inp(path: Path, mesh: Mesh) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("w", encoding="ascii", newline="\n") as f:
f.write("*HEADING\n")
f.write(f"FemLite shell membrane patch test {mesh.element_type}\n")
f.write(
f"** exact field: ux={EXX:.10E}*x, uy=0, uz=rx=ry=rz=0\n"
)
f.write("*NODE\n")
for nid in sorted(mesh.nodes):
x, y, z = mesh.nodes[nid]
f.write(f"{nid}, {x:.10E}, {y:.10E}, {z:.10E}\n")
f.write(f"*ELEMENT, TYPE={mesh.element_type}, ELSET=PATCH\n")
for eid, elem in enumerate(mesh.elements, start=1):
f.write(f"{eid}, " + ", ".join(str(nid) for nid in elem) + "\n")
f.write("*NSET, NSET=ALL_NODES, GENERATE\n")
f.write(f"1, {len(mesh.nodes)}, 1\n")
f.write("*MATERIAL, NAME=PATCH_MAT\n")
f.write("*DENSITY\n")
f.write(f"{DENSITY:.10E}\n")
f.write("*ELASTIC\n")
f.write(f"{YOUNG_MODULUS:.10E}, {POISSON_RATIO:.10E}\n")
f.write("*SHELL SECTION, ELSET=PATCH, MATERIAL=PATCH_MAT\n")
f.write(f"{THICKNESS:.10E}\n")
f.write("*BOUNDARY\n")
for nid in sorted(mesh.nodes):
x, _, _ = mesh.nodes[nid]
f.write(f"{nid}, 1, 1, {EXX * x:.10E}\n")
f.write(f"{nid}, 2, 6, 0.0\n")
f.write("*STEP\n")
f.write("*STATIC\n")
f.write(
f"{STATIC_INITIAL_INCREMENT:.10E}, {STATIC_TOTAL_TIME:.10E}, "
f"{STATIC_MIN_INCREMENT:.10E}, {STATIC_MAX_INCREMENT:.10E}\n"
)
f.write("*END STEP\n")
def write_all(output_dir: Path) -> None:
write_inp(output_dir / "shell_patch_s3.inp", build_mesh("S3"))
write_inp(output_dir / "shell_patch_s4.inp", build_mesh("S4"))
def main() -> None:
write_all(Path(__file__).resolve().parent)
if __name__ == "__main__":
main()
@@ -0,0 +1,54 @@
*HEADING
FemLite shell membrane patch test S3
** exact field: ux=1.0000000000E-02*x, uy=0, uz=rx=ry=rz=0
*NODE
1, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00
2, 4.5000000000E-01, 0.0000000000E+00, 0.0000000000E+00
3, 1.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00
4, 5.0000000000E-02, 5.0000000000E-01, 0.0000000000E+00
5, 5.0000000000E-01, 5.0000000000E-01, 0.0000000000E+00
6, 9.5000000000E-01, 5.0000000000E-01, 0.0000000000E+00
7, 0.0000000000E+00, 1.0000000000E+00, 0.0000000000E+00
8, 5.5000000000E-01, 1.0000000000E+00, 0.0000000000E+00
9, 1.0000000000E+00, 1.0000000000E+00, 0.0000000000E+00
*ELEMENT, TYPE=S3, ELSET=PATCH
1, 1, 2, 5
2, 1, 5, 4
3, 2, 3, 6
4, 2, 6, 5
5, 4, 5, 8
6, 4, 8, 7
7, 5, 6, 9
8, 5, 9, 8
*NSET, NSET=ALL_NODES, GENERATE
1, 9, 1
*MATERIAL, NAME=PATCH_MAT
*DENSITY
1.0000000000E+00
*ELASTIC
3.0000000000E+01, 2.5000000000E-01
*SHELL SECTION, ELSET=PATCH, MATERIAL=PATCH_MAT
2.0000000000E-01
*BOUNDARY
1, 1, 1, 0.0000000000E+00
1, 2, 6, 0.0
2, 1, 1, 4.5000000000E-03
2, 2, 6, 0.0
3, 1, 1, 1.0000000000E-02
3, 2, 6, 0.0
4, 1, 1, 5.0000000000E-04
4, 2, 6, 0.0
5, 1, 1, 5.0000000000E-03
5, 2, 6, 0.0
6, 1, 1, 9.5000000000E-03
6, 2, 6, 0.0
7, 1, 1, 0.0000000000E+00
7, 2, 6, 0.0
8, 1, 1, 5.5000000000E-03
8, 2, 6, 0.0
9, 1, 1, 1.0000000000E-02
9, 2, 6, 0.0
*STEP
*STATIC
1.0000000000E+00, 1.0000000000E+00, 1.0000000000E-01, 1.0000000000E+00
*END STEP
@@ -0,0 +1,50 @@
*HEADING
FemLite shell membrane patch test S4
** exact field: ux=1.0000000000E-02*x, uy=0, uz=rx=ry=rz=0
*NODE
1, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00
2, 4.5000000000E-01, 0.0000000000E+00, 0.0000000000E+00
3, 1.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00
4, 5.0000000000E-02, 5.0000000000E-01, 0.0000000000E+00
5, 5.0000000000E-01, 5.0000000000E-01, 0.0000000000E+00
6, 9.5000000000E-01, 5.0000000000E-01, 0.0000000000E+00
7, 0.0000000000E+00, 1.0000000000E+00, 0.0000000000E+00
8, 5.5000000000E-01, 1.0000000000E+00, 0.0000000000E+00
9, 1.0000000000E+00, 1.0000000000E+00, 0.0000000000E+00
*ELEMENT, TYPE=S4, ELSET=PATCH
1, 1, 2, 5, 4
2, 2, 3, 6, 5
3, 4, 5, 8, 7
4, 5, 6, 9, 8
*NSET, NSET=ALL_NODES, GENERATE
1, 9, 1
*MATERIAL, NAME=PATCH_MAT
*DENSITY
1.0000000000E+00
*ELASTIC
3.0000000000E+01, 2.5000000000E-01
*SHELL SECTION, ELSET=PATCH, MATERIAL=PATCH_MAT
2.0000000000E-01
*BOUNDARY
1, 1, 1, 0.0000000000E+00
1, 2, 6, 0.0
2, 1, 1, 4.5000000000E-03
2, 2, 6, 0.0
3, 1, 1, 1.0000000000E-02
3, 2, 6, 0.0
4, 1, 1, 5.0000000000E-04
4, 2, 6, 0.0
5, 1, 1, 5.0000000000E-03
5, 2, 6, 0.0
6, 1, 1, 9.5000000000E-03
6, 2, 6, 0.0
7, 1, 1, 0.0000000000E+00
7, 2, 6, 0.0
8, 1, 1, 5.5000000000E-03
8, 2, 6, 0.0
9, 1, 1, 1.0000000000E-02
9, 2, 6, 0.0
*STEP
*STATIC
1.0000000000E+00, 1.0000000000E+00, 1.0000000000E-01, 1.0000000000E+00
*END STEP