#! /usr/bin/env python
"""Rectangle compression workflow

Requires the following ``SConscript(..., exports={})``

* ``env`` - The SCons construction environment with the following required keys

  * ``modsim_package_abspath`` - String absolute path to the project package

* ``parameters`` - The current simulation parameter set
"""
import inspect
import pathlib

# Inherit the parent construction environment
Import("env", "parameters")

# Set project-wide paths with os-agnostic path separators
modsim_package_abspath = env["modsim_package_abspath"]

# Collect the target nodes to build concise target alias(es)
workflow_file = pathlib.Path(inspect.getfile(lambda: None))
artifacts = [str(workflow_file)]

# Geometry
artifacts.extend(
    env.AbaqusJournal(
        target=["rectangle_geometry.cae", "rectangle_geometry.jnl"],
        source=["rectangle_geometry.py"],
        subcommand_options="--width ${width} --height ${height}",
        **parameters,
    )
)

# Partition
artifacts.extend(
    env.AbaqusJournal(
        target=["rectangle_partition.cae", "rectangle_partition.jnl"],
        source=["rectangle_partition.py", "rectangle_geometry.cae"],
        subcommand_options="--width ${width} --height ${height}",
        **parameters,
    )
)

# Mesh
artifacts.extend(
    env.AbaqusJournal(
        target=["rectangle_mesh.inp", "rectangle_mesh.cae", "rectangle_mesh.jnl"],
        source=["rectangle_mesh.py", "rectangle_partition.cae"],
        subcommand_options="--global-seed ${global_seed}",
        **parameters,
    )
)

Return("artifacts")
