File size: 3,383 Bytes
6d52e65 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | """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))
|