Download scripts/check_morphwing_solid_modal.py from Conditiondark/astra-cadfem-failures: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/datasets/Conditiondark/astra-cadfem-failures/resolve/main/scripts/check_morphwing_solid_modal.py
- Command line
-
hf download hf://datasets/Conditiondark/astra-cadfem-failures/scripts/check_morphwing_solid_modal.py
-
curl -L -o check_morphwing_solid_modal.py https://huggingface.co/datasets/Conditiondark/astra-cadfem-failures/resolve/main/scripts/check_morphwing_solid_modal.py
3.38 kB
| """Independent solid modal check of A-MORPHWING-Test5 (validation only): FEniCSx P2 on curved tets, clamp at x = 19 mm, | |
| grip removed, SLEPc shift-invert; modes named by the tip out-of-plane profile (bending: even in y, torsion: odd in y).""" | |
| import json, sys, time | |
| import gmsh, numpy as np, ufl | |
| from dolfinx import fem, io | |
| from dolfinx.fem.petsc import assemble_matrix | |
| from mpi4py import MPI | |
| from petsc4py import PETSc | |
| from slepc4py import SLEPc | |
| step, h = sys.argv[1], float(sys.argv[2]) | |
| E, nu, rho = 2110.0, 0.3, 1180e-12 # MPa, -, t/mm^3 | |
| t0 = time.time() | |
| gmsh.initialize(); gmsh.option.setNumber("General.Terminal", 0) | |
| gmsh.model.occ.importShapes(step); gmsh.model.occ.synchronize() | |
| x0, y0, z0, x1, y1, z1 = gmsh.model.getBoundingBox(-1, -1) | |
| cut = gmsh.model.occ.addBox(x0 - 1, y0 - 1, z0 - 1, 19.0 - x0 + 1, y1 - y0 + 2, z1 - z0 + 2) | |
| gmsh.model.occ.cut(gmsh.model.occ.getEntities(3), [(3, cut)]); gmsh.model.occ.synchronize() | |
| vols = [t for _, t in gmsh.model.getEntities(3)]; assert len(vols) == 1, vols | |
| gmsh.model.addPhysicalGroup(3, vols, 1) | |
| for k, v in (("Mesh.MeshSizeMax", h), ("Mesh.MeshSizeMin", 0.25 * h), ("Mesh.ElementOrder", 2), ("General.NumThreads", 2)): | |
| gmsh.option.setNumber(k, v) | |
| gmsh.model.mesh.generate(3) | |
| dom, _, _ = io.gmshio.model_to_mesh(gmsh.model, MPI.COMM_SELF, 0, gdim=3) | |
| gmsh.finalize() | |
| V = fem.functionspace(dom, ("Lagrange", 2, (3,))) | |
| mu, lam = E / (2 * (1 + nu)), E * nu / ((1 + nu) * (1 - 2 * nu)) | |
| eps = lambda w: ufl.sym(ufl.grad(w)) | |
| u, v = ufl.TrialFunction(V), ufl.TestFunction(V) | |
| clamp = fem.locate_dofs_geometrical(V, lambda x: np.isclose(x[0], 19.0, atol=1e-6)) | |
| bc = fem.dirichletbc(np.zeros(3, dtype=PETSc.ScalarType), clamp, V) | |
| K = assemble_matrix(fem.form(ufl.inner(lam * ufl.tr(eps(u)) * ufl.Identity(3) + 2 * mu * eps(u), eps(v)) * ufl.dx), bcs=[bc], diagonal=1.0); K.assemble() | |
| M = assemble_matrix(fem.form(rho * ufl.inner(u, v) * ufl.dx), bcs=[bc], diagonal=0.0); M.assemble() | |
| es = SLEPc.EPS().create(MPI.COMM_SELF); es.setOperators(K, M); es.setProblemType(SLEPc.EPS.ProblemType.GHEP) | |
| es.setDimensions(10, PETSc.DECIDE); es.setWhichEigenpairs(SLEPc.EPS.Which.TARGET_MAGNITUDE); es.setTarget(0.0) | |
| st = es.getST(); st.setType(SLEPc.ST.Type.SINVERT); st.setShift(0.0) | |
| ksp = st.getKSP(); ksp.setType("preonly"); ksp.getPC().setType("lu"); ksp.getPC().setFactorSolverType("mumps") | |
| es.setTolerances(1e-10, 1000); es.solve() | |
| X = V.tabulate_dof_coordinates(); tip = X[:, 0] > x1 - 5.0; ym = 0.5 * (y0 + y1) | |
| modes = [] | |
| vec = K.createVecRight() | |
| for i in range(es.getConverged()): | |
| w2 = es.getEigenpair(i, vec).real | |
| U = vec.array.reshape(-1, 3) | |
| uz, uy = U[tip, 2], U[tip, 1] | |
| A = np.c_[np.ones(tip.sum()), X[tip, 1] - ym] | |
| (a, b), *_ = np.linalg.lstsq(A, uz, rcond=None) | |
| sym, odd = abs(a), abs(b) * 0.5 * (y1 - y0) | |
| inplane = np.linalg.norm(uy) > np.linalg.norm(uz) | |
| modes.append(dict(f_Hz=float(np.sqrt(max(w2, 0)) / (2 * np.pi)), kind="in-plane" if inplane else ("bending" if sym > odd else "torsion"))) | |
| modes.sort(key=lambda m: m["f_Hz"]) | |
| bend = [m["f_Hz"] for m in modes if m["kind"] == "bending"]; tors = [m["f_Hz"] for m in modes if m["kind"] == "torsion"] | |
| rec = dict(mesh_max_mm=h, cells=dom.topology.index_map(3).size_local, f_1B_Hz=bend[0], f_2B_Hz=bend[1], f_1T_Hz=tors[0], | |
| modes=modes, seconds=round(time.time() - t0, 1), role="independent_validation_only") | |
| print(json.dumps(rec)) | |