#!/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()