# -*- coding: utf-8 -*-
# TorsoCAE Validation Journal — modal_analysis case 2: simply-supported plate natural frequencies
# See README.md in this directory for theory and results.
# Requires the local TorsoHPC compute server (hpc/torsohpc.sh start, port 9000) --
# the default FEAST eigensolver routes through it.

import sys
sys.path.insert(0, "./server/")
from pytorsocae import TorsoCAESession

session = TorsoCAESession()
session.csg_make_shape("box", {"dx": 1.0, "dy": 0.7, "dz": 0.01, "cx": 0, "cy": 0, "cz": 0},
                        name="Plate", body_id="body_0")
session.csg_select("body_0")
session.mesh(mesh_id="mesh_0", algo_id="hex_transfinite", size_factor=1.0, size_min=0, size_max=0, order=2, dim=3)
session.solid("Plate").material(E=210e9, nu=0.3, rho=7850.0)
session.surface(1, scope_id="body_0").bc("fixed", frame="global", components=["y", "z"])   # x=0
session.surface(2, scope_id="body_0").bc("fixed", frame="global", components=["y", "z"])   # x=a
session.surface(3, scope_id="body_0").bc("fixed", frame="global", components=["x", "z"])   # y=0
session.surface(4, scope_id="body_0").bc("fixed", frame="global", components=["z"])        # y=b
session.set_physics("structural", submodel="modal_analysis", backend="dolfinx")
session.set_solver_options(algo="cg", precond="gamg", tol=1e-10, max_iter=2000,
                            n_cores=1, device="cpu", num_modes=6, max_frequency_hz=400.0)
session.compute(mesh_ids=["mesh_0"])
