Run Your First Simulation

Step-by-step guide to run your first SWAN simulation on Inductiva.AI. Easily launch, monitor and analyse results.

This tutorial will show you how to run SWAN simulations using the Inductiva API.

We will cover the ring use case from the official SWAN documentation to help you get started with simulations.

Prerequisites

Download the required files here and place them in a folder called Ring. Then, youโ€™ll be ready to send your simulation to the Cloud.

Running an SWAN Simulation

Here is the code required to run a SWAN simulation using the Inductiva API:

"""SWAN example"""
import inductiva

# Allocate cloud machine on Google Cloud Platform
cloud_machine = inductiva.resources.MachineGroup( \
    provider="GCP",
    machine_type="c2d-highcpu-4",
    spot=True)

# Initialize the Simulator
swan = inductiva.simulators.SWAN(\
    version="41.51")

# Run simulation
task = swan.run(input_dir="/Path/to/Ring",
    sim_config_filename="ring.swn",
    on=cloud_machine)

# Wait for the simulation to finish and download the results
task.wait()
cloud_machine.terminate()

task.download_outputs()

task.print_summary()

In this basic example, we're using a cloud machine (c2d-highcpu-4) equipped with 4 virtual CPUs. For larger or more compute-intensive simulations, consider adjusting the machine_type parameter to select a machine with more virtual CPUs and increased memory capacity. You can explore the full range of available machines here.

Note: Setting spot=True enables the use of spot machines, which are available at substantial discounts. However, your simulation may be interrupted if the cloud provider reclaims the machine.

To adapt this script for other SWAN simulations, replace input_dir with the path to your SWAN input files and set the sim_config_filename accordingly. Be sure to specify the SWAN version compatible with your input files.

When the simulation is complete, we terminate the machine, download the results and print a summary of the simulation as shown below.

Task status: Success

Timeline:
    Waiting for Input         at 21/04, 18:56:15      1.571 s
    In Queue                  at 21/04, 18:56:17      38.79 s
    Preparing to Compute      at 21/04, 18:56:56      2.99 s
    In Progress               at 21/04, 18:56:59      55.349 s
        โ”œ> 1.095 s         dd if=/dev/stdin of=machinefile
        โ””> 54.101 s        swanrun -input ring.swn -mpi 4
    Finalizing                at 21/04, 18:57:54      0.416 s
    Success                   at 21/04, 18:57:54

Data:
    Size of zipped output:    118.60 KB
    Size of unzipped output:  488.62 KB
    Number of output files:   19

Total estimated cost (US$): 0.01053 US$
    Estimated computation cost (US$): 0.00053 US$
    Task orchestration fee (US$): 0.010 US$

Note: A per-run orchestration fee (0.010 US$) applies to tasks run from 01 Dec 2025, in addition to the computation costs.
Learn more about costs at: https://inductiva.ai/guides/basics/how-much-does-it-cost

As you can see in the "In Progress" line, the part of the timeline that represents the actual execution of the simulation, the core computation time of this simulation was 55.3 seconds.