# Use the existing connected PyFluent variable solver.
task_directory = r"C:\Users\13977\AppData\Local\FluentAGI\data\runs\20261018-142547-90d0a4"
s = solver.settings

if not s.setup.models.is_active():
    raise RuntimeError("当前网格未激活。")

bc = s.setup.boundary_conditions
print("WALL_ZONES", bc.wall.get_object_names())
print("ITERATION_COUNT", s.solution.run_calculation.iter_count.get_state())

modify = s.mesh.modify_zones
print("MODIFY_ZONE_CHILDREN", getattr(modify, "child_names", []))
commands = getattr(modify, "command_names", [])
print("SEPARATION_COMMAND_NAMES", [
    name for name in commands
    if any(word in name for word in ["sep", "split", "rename"])
])

for name in commands:
    if any(word in name for word in ["sep", "split", "rename"]):
        command = getattr(modify, name)
        arguments = getattr(command, "argument_names", [])
        print("SEPARATION_COMMAND", name, arguments)
        for argument_name in arguments:
            argument = getattr(command, argument_name)
            print(
                "SEPARATION_ARGUMENT",
                name,
                argument_name,
                getattr(argument, "child_names", []),
            )

for child_name in getattr(modify, "child_names", []):
    child = getattr(modify, child_name)
    for name in getattr(child, "command_names", []):
        if any(word in name for word in ["sep", "split", "rename"]):
            command = getattr(child, name)
            print(
                "NESTED_SEPARATION_COMMAND",
                child_name,
                name,
                getattr(command, "argument_names", []),
            )

reports = s.solution.report_definitions.force
for name, direction in [
    ("front_wing_drag_interface", [1.0, 0.0, 0.0]),
    ("front_wing_lift_interface", [0.0, 1.0, 0.0]),
]:
    if name not in reports.get_object_names():
        reports[name] = {}
    reports[name].force_vector = direction
    print("FORCE_DEFINITION", name, reports[name].get_state())

momentum = bc.wall["walls"].momentum if "walls" in bc.wall.get_object_names() else None
if momentum is not None:
    print("MOVING_WALL_FIELDS", [
        name for name in getattr(momentum, "child_names", [])
        if any(word in name for word in [
            "motion", "velocity", "speed", "direction"
        ])
    ])

s.file.write_case(
    file_name=task_directory + r"\front_wing_separation_arguments.cas.h5"
)
print("STAGE", "targeted_boundary_separation_arguments")