#!/bin/bash

# This script runs VMEC only examples. This script is used by the Github
# Actions continuous integration. Examples that can use MPI are run
# for various numbers of processes.

set -ex

# In the next line, ${GITHUB_ACTIONS:+--oversubscribe} evaluates to
# --oversubscribe if the environment variable GITHUB_ACTIONS is set,
# and evaluates to nothing if the variable is not set.  The motivation
# is that Github Actions only gives you 2 processors, so we have to
# "oversubscribe" to test on >2 mpi processes. But we don't want to
# set --oversubscribe when outside Github Actions, since other
# versions of mpi like mpich do not have this flag.
MPI_OPTIONS=${GITHUB_ACTIONS:+--oversubscribe}
echo MPI_OPTIONS=$MPI_OPTIONS

./2_Intermediate/B_external_normal.py

./stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py
mpiexec $MPI_OPTIONS -n 2 ./stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py
mpiexec $MPI_OPTIONS -n 3 ./stellarator_benchmarks/1DOF_circularCrossSection_varyAxis_targetIota.py

./stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py
mpiexec $MPI_OPTIONS -n 2 ./stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py
mpiexec $MPI_OPTIONS -n 3 ./stellarator_benchmarks/1DOF_circularCrossSection_varyR0_targetVolume.py

./stellarator_benchmarks/2DOF_circularCrossSection_varyAxis_targetIotaAndQuasisymmetry.py

./stellarator_benchmarks/2DOF_vmecOnly_targetIotaAndVolume.py
mpiexec $MPI_OPTIONS -n 2 ./stellarator_benchmarks/2DOF_vmecOnly_targetIotaAndVolume.py
mpiexec $MPI_OPTIONS -n 3 ./stellarator_benchmarks/2DOF_vmecOnly_targetIotaAndVolume.py

mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/resolution_increase.py
mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/resolution_increase_boozer.py

mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/constrained_optimization.py

mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/QH_fixed_resolution.py
mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/QH_fixed_resolution_boozer.py
mpiexec $MPI_OPTIONS -n 2 ./2_Intermediate/free_boundary_vmec.py

mpiexec $MPI_OPTIONS -n 2 ./3_Advanced/single_stage_optimization.py
mpiexec $MPI_OPTIONS -n 2 ./3_Advanced/single_stage_optimization_finite_beta.py

./2_Intermediate/vmec_adjoint.py
./2_Intermediate/tracing_boozer.py

./stellarator_benchmarks/7dof.py
mpiexec $MPI_OPTIONS -n 2 ./stellarator_benchmarks/7dof.py
