# -*- coding: utf-8 -*-
# TorsoCAE Macro Journal — SDOF step response validation case (best settings)
#
# Steel cantilever under a suddenly applied constant tip traction, released
# from rest. EDMC-1 (chi=0) gives exact energy/momentum conserving time
# integration (no numerical damping), so the transient tip response should
# oscillate cleanly between 0 and ~2x the static deflection with period
# ~= 1/f1 (Euler-Bernoulli fundamental frequency). See run_validation.py for
# the closed-form comparison and time-history extraction.

import sys

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

L, DY, DZ = 2.0, 0.1, 0.1            # m
E, NU, RHO = 210e9, 0.3, 7800.0      # Pa, -, kg/m^3
F_TOTAL = 1000.0                     # N
TRACTION_Y = F_TOTAL / (DY * DZ)

session = TorsoCAESession()
session.csg_make_shape("box", {"dx": L, "dy": DY, "dz": DZ, "cx": 0, "cy": 0, "cz": 0},
                        name="DynBeam", body_id="body_0")
session.csg_select("body_0")
session.mesh(mesh_id="mesh_0", algo_id="hex_transfinite", size_factor=1.5,
             size_min=0, size_max=0, order=2, dim=3)
session.solid("DynBeam").material(E=E, nu=NU, rho=RHO)
session.surface(1, scope_id="body_0").bc("fixed")
session.surface(2, scope_id="body_0").bc("traction", values=[0, TRACTION_Y, 0])
session.set_physics("structural", submodel="structural_dynamics", backend="dolfinx")
session.set_solver_options(
    algo="auto", tol=1e-9, max_iter=1000,
    num_steps=170, dt=0.04772206951856904 / 80.0, time_scheme="edmc-1", edmc_chi=0.0,
    n_cores=1, device="cpu",
)
session.compute(mesh_ids=["mesh_0"])
