Skip to content

From Mesh Generation to Adaptive Simulation: A Journey in Julia at JuliaCon 2022

License

Notifications You must be signed in to change notification settings

trixi-framework/talk-2022-juliacon_toolchain

Repository files navigation

JuliaCon 2022: From Mesh Generation to Adaptive Simulation: A Journey in Julia

License: MIT YouTube

This is the companion repository for the JuliaCon 2022 talk

From Mesh Generation to Adaptive Simulation: A Journey in Julia
Andrew R. Winters
Recorded talk on YouTube

(see abstract below). Here you can find the presentation slides in talk.pdf as well as Julia scripts in the examples directory to locally create results of mesh generation with HOHQMesh.jl and Trixi.jl simulations presented in the talk.

To reduce the size of the file for the talk.pdf, the video is not embedded. Instead, the video shown in the presentation is available here.

Abstract

We present a Julia toolchain for the adaptive simulation of hyperbolic PDEs such as flow equations on complex domains. It begins with using HOHQMesh.jl to create a curved, unstructured mesh. This mesh is then used in Trixi.jl, a numerical simulation framework for conservation laws. We visualize the results using Julia’s plotting packages. We highlight select features in Trixi.jl, like adaptive mesh refinement (AMR) or shock capturing, useful for practical applications with complex transient behavior.

More detailed description

Applications of interest in computational fluid mechanics typically occur on domains with curved boundaries. Further, the solution of a non-linear physical model can develop complex phenomena such as discontinuities, singularities, and turbulence.

Attacking such complex flow problems may seem daunting. In this talk, however, we present a toolchain with components entirely available in the Julia ecosystem to do just that. In broad strokes the workflow is:

  1. Use HOHQMesh.jl to interactively prototype and visualize a domain with curved boundaries.
  2. HOHQMesh generates an all quadrilateral mesh amenable for high-order numerical methods.
  3. The mesh file is passed to Trixi.jl, a numerical simulation framework for conservation laws.
  4. Solution-adaptive refinement of the mesh within Trixi is handled by P4est.jl.
  5. After the simulation, interactive visualization can be done using Makie.jl.
  6. Solution data can also be exported with Trixi2Vtk.jl for visualization in external software like ParaView.

The strength and simplicity of this workflow is through the combination of several packages either originally written in Julia, like Trixi.jl, or wrappers, like P4est.jl or HOHQMesh.jl, that provide Julia users access to powerful, well-developed numerical libraries and tools written in other programming languages.

Getting started

Installing Julia

To obtain Julia, go to https://julialang.org/downloads/ and download the latest stable release (v1.7.3 as of 2022-06-28). Then, follow the platform-specific instructions to install Julia on your machine. Note that there is no need to compile anything if you are using Linux, MacOS, or Windows. Avoid the JuliaPro distribution or the LTS release as Trixi may not work with them.

After the installation, open a terminal and start the Julia REPL (i.e., the interactive prompt) with

julia

Installing the required Julia packages

To run the scripts in the examples directory and allow for fully reproducible results, we have used Julia's package manager to pin all packages to a fixed release. This makes it straightforward to reproduce the Julia environment in which all the results presented were created.

If you have not done it yet, clone the repository where this code is stored:

git clone https://github.com/trixi-framework/talk-2022-juliacon_toolchain.git

Then, navigate to your repository folder and install the required packages:

cd talk-2022-juliacon_toolchain
julia --project=. -e 'using Pkg; Pkg.instantiate()'

This will download and build all required packages, including the ODE package OrdinaryDiffEq, the visualization package GLMakie, the mesh generator HOHQMesh.jl, and Trixi. The --project=. argument tells Julia to use the Project.toml and Manifest.toml files from this repository to figure out which packages to install.

Once the initialization and installation is complete you must start Julia with the --project flag set to your local clone of this repository

julia --project=@.

Mesh created with tools from HOHQMesh.jl

To reproduce the figures and create the mesh file output execute from the REPL

include(joinpath("examples", "interactive_cylinder_with_sine_walls.jl"))

This will create the directory out where the mesh file is saved.

Simulation with Trixi.jl

The elixir file described in the presentation to setup and run a simulation of Mach 2 flow over a cylinder is elixir_euler_mach2_cylinder.jl. To run the simulation up to a final time of 0.5, execute from the REPL

using Trixi
trixi_include(joinpath("examples", "elixir_euler_mach2_cylinder.jl"), tspan=(0.0,0.5))

where the final time is adjusted within the trixi_include call. This simulation to the final time 0.5 takes approximately 20 minutes on a single thread. To visualize the solution sol at the final time execute

using GLMakie
pd = PlotData2D(sol)
plot(pd["rho"])

Combined script

The script build_mesh_and_run_mach2_cylinder.jl executes the entire toolchain described in the talk. That is, the script generates the mesh, runs the simulation, visualizes the final result in Makie, converts the output files to VTK format using Trixi2Vtk, and saves them to the plot_files directory. Execute this script with

include(joinpath("examples", "build_mesh_and_run_mach2_cylinder.jl"))

As written, the script elixir_euler_mach2_cylinder.jl sets tspan = (0.0, 0.0) on line 94. This can be adjusted to take a different final time, e.g., the final time for the video is 2.25.

To reproduce the ParaView visualization, first open ParaView (after downloading and installing it if necessary). Then load the ParaView state by clicking through File -> Load State and open supersonic_cylinder_state.pvsm. Next, from the prompt "Load State Data File Options" select "Choose File Names", navigate to the plot_files directory and select the appropriate solution.pvd and solution_celldata.pvd files.

Authors

This repository was initiated by Andrew R. Winters.

License

The contents of this repository are licensed under the MIT license (see LICENSE.md).

About

From Mesh Generation to Adaptive Simulation: A Journey in Julia at JuliaCon 2022

Resources

License

Stars

Watchers

Forks