Code Monkey home page Code Monkey logo

wind-tunnel's Introduction

Wind Tunnel via Inductiva API

Wind tunnels are central for the development and testing of vehicle aerodynamics - from your everyday commuter car to the high-performance F1 car. With Inductiva API users can simplify their simulation workflow and build their custom virtual wind tunnels to accelerate the discovery of new designs.

F1 simulation

In this repository, we assume users are familiar with one of the most popular open-source simulators for virtual wind tunnels, OpenFOAM. If not, we advise to get acquainted with it through the classical motorbike tutorial.

Virtual wind tunnel simulations

When performing wind tunnel tests - virtual or physical - only a few parameters are tweaked, for example, changing the airflow velocity for the same vehicle. Inductiva API provides a powerful mechanism to configure this simulation from this set of parameters, this workflow is designated as a simulation scenario.

Let's set an F1 car in a toy wind tunnel and run a simulation scenario:

import windtunnel

# Create wind tunnel object
wind_tunnel = windtunnel.WindTunnel(dimensions=(20,10,8))

# Set the object in the windtunnel
wind_tunnel.set_object(
    object_path="assets/f1_car.obj",
    rotate_z_degrees=0,
    normalize=False,
    center=True,
)

# Display the Windtunnel with the object
wind_tunnel.display()

# Submit a simulation task
task = wind_tunnel.simulate(wind_speed_ms=20,
                            num_iterations=50,
                            resolution=3)

# Wait for the task to finish
task.wait()

# Download all of the output files of the simulation
output_dir = task.download_outputs()

In this code snippet, we are using the WindTunnel to configure the simulation files for OpenFOAM, the F1 car and simulation parameters and simulating via Inductiva API. This scenario is a toy example that can be extended to more complex simulation scenarios.

For more detailed information, please visit the Wind Tunnel Documentation.

Installation

  1. Clone the repository:
git clone https://github.com/inductiva/wind-tunnel.git
cd wind-tunnel
  1. Install the package:
pip install .

Scripts Overview

The repository includes several scripts to facilitate running and managing your wind tunnel simulations:

run.py

Quickly run standalone wind tunnel simulations using this script. It accepts the following arguments:

  • --display: Opens a pyvista window with the windtunnel simulation
  • --object_path: Path to the input object file
  • --wind_speed_ms: Wind speed in meters per second (default: 10)
  • --resolution: Resolution of the OpenFOAM simulation (default: 3, max: 5)
  • --rotate_z_degrees: Rotation angle around the Z-axis in degrees (default: 0)
  • --num_iterations: Number of iterations to run the simulation (default: 50)
  • --machine_group_name: Machine group to run the simulation on (default: default queue)

Example usage:

python run.py --object_path assets/f1_car.obj --display

batch_run:

Submit multiple simulations with varying arguments. This script is useful for exploring different scenarios efficiently. Inside the script you can change the simulation arguments.

  • --object_path: Path to the input object file
  • --machine_group_name: Machine group to run the simulation on (default: default queue)
python batch_run.py --object_path assets/f1_car.obj 

view_outputs.py

Display the results of a completed simulation in a PyVista window and print the resulting force coefficients. This script waits for the task to finish and requires a task_id argument.

python view_outputs.py --task_id <task_id>

Running Simulations on Dedicated Hardware

To run simulations on dedicated hardware, you need to start a machine group.

First, list all available machine types with:

inductiva resources available

Starting a Machine Group

Note: Spot machines are preemptible but are approximately 5x cheaper. If a machine becomes unavailable during use, the simulation will automatically restart.

Instantiating a MachineGroup object with 5 preemptible machines of type c2-standard-32:

import inductiva

machine_group = inductiva.resources.MachineGroup(
    machine_type="c2-standard-30", num_machines=5, spot=True)
machine_group.start()

print(machine_group.name)

# Don't forget to terminate the machine group after using it:
machine_group.terminate()

Using the Machine Group

After starting the machine group, pass its name to the run.py or batch_run.py scripts.

python run.py --object_path assets/f1_car.obj --machine_group_name <machine_group_name>

Elastic Machine Groups

You can also create an ElasticMachineGroup, which scales machines up or down automatically based on the simulation queue.

For more details on running simulations on dedicated hardware, refer to the Inductiva Machine Group documentation


Disclaimer: For the sake of time the simulations performed here are low resolution and don't represent any practical real-world application.

To learn more about the inductiva package, check the Inductiva API documentation.

wind-tunnel's People

Contributors

rcvalerio avatar hpenedones avatar ivanpombo avatar augustoperes avatar

Watchers

 avatar Luis Sarmento avatar

wind-tunnel's Issues

How to get used transformations

Current:

Has no inverse transformation:

wind_tunnel = windtunnel.WindTunnel()
task = wind_tunnel.simulate(object_path="assets/f1_car.obj",
                            wind_speed_ms=10,
                            rotate_z_degrees=0,
                            num_iterations=50,
                            resolution=3,
                            display=True)

Add normalization parameter #9 :

Return is weird but simulate is intuitive:

wind_tunnel = windtunnel.WindTunnel()
task, displace_vector, scaling_factor = wind_tunnel.simulate(object_path="assets/f1_car.obj",
                            wind_speed_ms=10,
                            rotate_z_degrees=0,
                            num_iterations=50,
                            resolution=3,
                            normalize_mesh=True,
                            display=True)

Add normalization parameter and dict return :

Return is weird but simulate is intuitive:

wind_tunnel = windtunnel.WindTunnel()
output = wind_tunnel.simulate(object_path="assets/f1_car.obj",
                            wind_speed_ms=10,
                            rotate_z_degrees=0,
                            num_iterations=50,
                            resolution=3,
                            normalize_mesh=True,
                            display=True)
 task = output["task"]
 displace_vector = output["displace_vector"]
 scaling_factor = scaling_factor["scaling_factor"]

Add normalization before simulate:

Code becomes complex, mesh dependency, return is good:

wind_tunnel = windtunnel.WindTunnel()
mesh, displace_vector, scaling_factor = preprocessing.preprocess(
        object_path="assets/f1_car.obj", rotate_z_degrees=0, normalize_mesh=True, center_mesh=True)
task  = wind_tunnel.simulate(object_mesh=mesh,
                            wind_speed_ms=10,
                            num_iterations=50,
                            resolution=3,
                            display=True)

Improve reverse transformation

Currently we return the transformations during windtunnel.set_object() and its the user responsibility to apply the reverse transformations to the outputs (e.g streamlines, pressure map..).

I believe it is better to add an optional transformations argument to the WindTunnelOutputs class. This allows us to have a optional argument "apply_reverse_transformations: bool" to output functions such as get_streamlines(apply_reverse_transformations=True).

If the transformations had not been passed to the WindTunnelOutputs class then an exception would be raised when the user tries to use the argument apply_reverse_transformations.

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.