#! /usr/bin/env python
import pathlib

import waves


Import("env", "envQuinoa")

# TODO: move parameters to a dedicated dictionary file read
simulation_variables = {
    "xlength": 1.0,
    "ylength": 0.5,
    "zlength": 0.5,
}

workflow = []
remote_directory_prefix = env["remote_directory"]

# Geometry/partition/mesh
# TODO: separate the local and remote workflows into dedicated SConscript files that re-use the cubit workflow as in the
# Cubit+Abaqus and Cubit+Sierra tutorials
mesh = env.PythonScript(
    target=["box.cub", "box.exo"],
    source=["box.py"],
    subcommand_options="--output-file ${TARGET.abspath} --xlength ${xlength} --ylength ${ylength} --zlength ${zlength}",
    **simulation_variables,
)
workflow.extend(mesh)
env.Alias("mesh", mesh)

# SSH remote build on HPC
remote_directory = remote_directory_prefix / "remote"
remote_target = env.SSHQuinoaSolver(
    target=["remote.stdout"],
    source=["flow.lua", "box.exo"],
    charmrun="charmrun",
    inciter="inciter",
    remote_directory=remote_directory,
)
env.Alias("quinoa-remote", remote_target)

# Local build on local server
local_target = envQuinoa.QuinoaSolver(
    target=["local.stdout"],
    source=["flow.lua", "box.exo"],
    charmrun=envQuinoa["charmrun"],
    inciter=envQuinoa["inciter"],
)
envQuinoa.Alias("quinoa-local", local_target)

if not env["unconditional_build"] and not envQuinoa["inciter"]:
    print(f"Program 'inciter' was not found in construction environment. Ignoring 'quinoa-local' target(s)")
    Ignore([".", "quinoa-local"], local_target)
