#! /usr/bin/env python
"""Rectangle model's Geometry and Partition task definitions

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

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


* ``simulation_variables`` - The dictionary of simulation variables with the following required keys

  * ``'width'`` - The rectangle model width
  * ``'height'`` - The rectangle model height

* ``workflow`` - list of targets in the main workflow
* ``datacheck`` - list of targets in the datacheck workflow

Returns the following variables

* ``workflow`` - updated list of targets in the main workflow
* ``datacheck`` - updated list of targets in the datacheck workflow

Example usage:

.. code-block::

   import pathlib

   env = Environment()
   project_dir = pathlib.Path(Dir(".").abspath)

   workflow = []
   datacheck = []

   nominal_workflow, nominal_datacheck = SConscript(
       "rectangle_geometry_partition.scons",
       exports={
           "env": env,
           "simulation_variables": simulation_variables,
           "workflow": workflow,
           "datacheck": datacheck
       },
       duplicate=False)

   for set_name in [f"parmameter_set{number}" for number in range(4)]
       parameters_workflow, parameter_datacheck = SConscript(
           "rectangle_geometry_partition.scons",
           variant_dir=set_name,
           exports={
               "env": env,
               "simulation_variables": simulation_variables,
               "workflow": workflow,
               "datacheck": datacheck
           },
           duplicate=False)
"""

import pathlib

# Inherit the parent construction environment
Import(["env", "simulation_variables", "workflow", "datacheck"])

# Simulation variables
build_directory = pathlib.Path(Dir(".").abspath)

# Geometry
workflow.extend(
    env.AbaqusJournal(
        target=["rectangle_geometry.cae", "rectangle_geometry.jnl"],
        source=["#/modsim_package/abaqus/rectangle_geometry.py"],
        subcommand_options="--width ${width} --height ${height}",
        **simulation_variables,
    )
)

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

Return(["workflow", "datacheck"])
