Skip to content

Automation with Shell & Python

When you’re working on multiple simulation studies — varying parameters, materials, or geometries — doing everything manually quickly becomes inefficient. Automating parts of the process with Python and shell scripts saves time, prevents errors, and helps you run large-scale studies reproducibly.

Why Automate

Running tens or hundreds of simulations by hand can take hours just to set up. With automation:

  • You can generate parameter variations automatically.
  • Run multiple solver cases in sequence or parallel.
  • Batch-generate meshes in Salome without opening the GUI.
  • Maintain consistent organization and naming across all runs.

This is especially useful for parametric studies (for example, sweeping frequency, material constants, or mesh sizes).

Automating with Python

Python is ideal for automating repetitive tasks like generating solver scripts or mesh configurations. You can create a small script that:

  1. Reads your base solver file (a template).
  2. Replaces parameters such as frequency, permittivity, or geometry size.
  3. Saves multiple versions of the solver script — each for a different case.

Example:

python
for freq in [8.8, 9.0, 9.2]:
    new_code = base_code.replace("{FREQ}", str(freq))
    with open(f"solver_{freq}.py", "w") as f:
        f.write(new_code)

This simple loop can generate all your solver scripts automatically, ready to run.

Running Studies with Shell Scripts

Once your scripts are generated, you can use a shell script to run them sequentially:

  • Create a run_all.sh file that loops through all your generated folders or scripts.
  • Each iteration runs one solver, logs its output, and moves to the next.

For example:

python3 solver_8.8.py
python3 solver_9.0.py
python3 solver_9.2.py

You can also run these scripts on remote servers or in parallel sessions using tools like tmux or nohup.

Automating Salome Mesh Generation

Salome can also be automated using Python scripts in terminal (headless) mode. This allows you to generate multiple meshes for different geometry parameters without opening the GUI.

The workflow is:

  1. Create a parametric geometry script in Salome (e.g., box length, height, or radius as input).

  2. Run it from the terminal with different parameter values.

  3. The script exports the .med mesh for each set of parameters automatically.

You can combine this with a shell loop to run several mesh generations in one go.

Typical Workflow

  1. Python: Generate multiple solver input files or meshes for all parameter combinations.
  2. Shell Script: Sequentially run each generated case automatically.
  3. Post-process: Optionally trigger ParaView or data export scripts after each run.

Summary

Automation allows you to scale from a few runs to hundreds without increasing effort. By combining Python scripts for setup and shell scripts for execution, you can:

  • Maintain consistency across studies.
  • Avoid manual errors.
  • Reproduce results anytime with minimal effort.

This is a standard practice at Avkalan Labs for parametric and optimization studies, helping researchers focus on insights instead of repetitive execution.