# -*- coding: utf-8 -*-
# TorsoCAE Validation Journal — hyperelastic case 1: Treloar-style uniaxial tension (3-term Ogden)
# See README.md in this directory for theory and results.
# disp_x=8.0 m drives this 4m bar to lambda1=3.0 (displacement-controlled, matching
# run_validation.py's approach -- see that file for the fitted material and closed-form checks).

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

session = TorsoCAESession()
session.csg_make_shape("box", {"dx": 4.0, "dy": 2.0, "dz": 2.0, "cx": 0, "cy": 0, "cz": 0},
                        name="UniaxialBar", body_id="body_0")
session.csg_select("body_0")
session.mesh(mesh_id="mesh_0", algo_id="hex_transfinite", size_factor=1.2, size_min=0, size_max=0, order=1, dim=3)
session.solid("UniaxialBar").material(E=210e9, nu=0.49,
                                       ogden_mu=[230881.77, 100.0, 100.0],
                                       ogden_alpha=[0.3192, 5.8917, -3.0290])
session.surface(1, scope_id="body_0").bc("fixed", frame="global", components=["x"])
session.surface(3, scope_id="body_0").bc("fixed", frame="global", components=["y"])
session.surface(5, scope_id="body_0").bc("fixed", frame="global", components=["z"])
session.surface(2, scope_id="body_0").bc("displacement", values=[8.0, 0, 0], components=["x"])   # -> lambda1 = 3.0
session.set_physics("structural", submodel="hyperelastic-ogden", backend="dolfinx")
session.set_solver_options(algo="direct", precond="none", tol=1e-10, max_iter=1000,
                            num_steps=20, inner_tol=1e-9, max_inner_iter=30, n_cores=2, device="cpu")
session.compute(mesh_ids=["mesh_0"])
