Visualization

Export VTK files

You can export particle data as VTK files by using the SolutionSavingCallback. All our predefined examples are already using this callback to export VTK files to the out directory (relative to the directory that you are running Julia from). VTK files can be read by visualization tools like ParaView and VisIt.

ParaView

Follow these steps to view the exported VTK files in ParaView:

  1. Click File -> Open.
  2. Navigate to the out directory (relative to the directory that you are running Julia from).
  3. Open both boundary_1.pvd and fluid_1.pvd.
  4. Click "Apply", which by default is on the left pane below the "Pipeline Browser".
  5. Hold the left mouse button to move the solution around.

You will now see the following: image

It is useful to make the dot size dependent on the actual particle size. For this, first make sure you have "fluid_1.pvd" highlighted in the "Pipeline Browser". Then, in the Properties panel (bottom left), adjust the following settings:

  1. "Representation" to "Point Gaussian".
  2. Choose the right "Shader Preset": "Plain Circle" for 2D and "Sphere" for 3D.
  3. Activate "Scale by Array" and select "particle_spacing" in "Gaussian Scale Array".
  4. Deactivate "Use Scale Function".
  5. Set the "Gaussian Radius" to "0.5".

image

Visualization with Macro

To simplify the visualization of your particle data in ParaView, you can use a macro. This macro automates the manual steps in the previous section to a single click of a button. Install the macro as follows.

  1. Save the macro code (see below) as a .py file, e.g. PointGaussianMacro.py.
  2. Open ParaView and go to the top menu: MacrosImport New Macro... → Select the saved .py file.
  3. The macro will now appear in the Macros menu and can optionally be pinned to the toolbar.
  4. Load your dataset into ParaView.
  5. Select the dataset in the Pipeline Browser.
  6. Click on the macro name in the Macros menu (or toolbar, if pinned) to run it.
  7. The Point Gaussian representation with particle_spacing scaling will be applied automatically.

Macro Code

# trace generated using paraview version 5.13.1
#from paraview
#paraview.compatibility.major = 5
#paraview.compatibility.minor = 13

from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

# get active source
source = GetActiveSource()

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

# get display properties
sourceDisplay = GetDisplayProperties(source, view=renderView1)

# change representation type
sourceDisplay.SetRepresentationType('Point Gaussian')

# modified display properties
sourceDisplay.ShaderPreset = 'Plain circle' # for 2D, change to 'Sphere' for 3D
sourceDisplay.ScaleByArray = 1
sourceDisplay.SetScaleArray = ['POINTS', 'particle_spacing']
sourceDisplay.UseScaleFunction = 0
sourceDisplay.GaussianRadius = 0.5

Show results

To now view the result variables first make sure you have "fluid_1.pvd" highlighted in the "Pipeline Browser" then select them in the variable selection combo box (see picture below). Let's, for example, pick "density". To now view the time progression of the result hit the "play button" (see picture below). image

API

TrixiParticles.vtk2trixiMethod
vtk2trixi(file::String)

Load VTK file and convert data to an InitialCondition.

Arguments

  • file: Name of the VTK file to be loaded.
Experimental Implementation

This is an experimental feature and may change in any future releases.

Example

```jldoctest; output = false

Create a rectangular shape

rectangular = RectangularShape(0.1, (10, 10), (0, 0), density=1.5, velocity=(1.0, -2.0), pressure=1000.0)

Write the InitialCondition to a vtk file

trixi2vtk(rectangular; filename="rectangular", output_directory="out")

Read the vtk file and convert it to InitialCondition

ic = vtk2trixi(joinpath("out", "rectangular.vtu"))

output

┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ │ InitialCondition{Float64} │ │ ═════════════════════════ │ │ #dimensions: ……………………………………………… 2 │ │ #particles: ………………………………………………… 100 │ │ particle spacing: ………………………………… 0.1 │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘

source
TrixiParticles.trixi2vtkMethod
trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="",
          write_meta_data=true, max_coordinates=Inf, custom_quantities...)

Convert Trixi simulation data to VTK format.

Arguments

  • vu_ode: Solution of the TrixiParticles ODE system at one time step. This expects an ArrayPartition as returned in the examples as sol.u[end].
  • semi: Semidiscretization of the TrixiParticles simulation.
  • t: Current time of the simulation.

Keywords

  • iter=nothing: Iteration number when multiple iterations are to be stored in separate files. This number is just appended to the filename.
  • output_directory="out": Output directory path.
  • prefix="": Prefix for output files.
  • write_meta_data=true: Write meta data.
  • max_coordinates=Inf The coordinates of particles will be clipped if their absolute values exceed this threshold.
  • custom_quantities...: Additional custom quantities to include in the VTK output. Each custom quantity must be a function of (system, data, t), which will be called for every system, where data is a named tuple with fields depending on the system type, and t is the current simulation time. Check the available data for each system with available_data(system). See Custom Quantities for a list of pre-defined custom quantities that can be used here.

Example

trixi2vtk(sol.u[end], semi, 0.0, iter=1, output_directory="output", prefix="solution")

# Additionally store the kinetic energy of each system as "my_custom_quantity"
trixi2vtk(sol.u[end], semi, 0.0, iter=1, my_custom_quantity=kinetic_energy)
source
TrixiParticles.trixi2vtkMethod
trixi2vtk(coordinates; output_directory="out", prefix="", filename="coordinates",
          custom_quantities...)

Convert coordinate data to VTK format.

Arguments

  • coordinates: Coordinates to be saved.

Keywords

  • output_directory="out": Output directory path.
  • prefix="": Prefix for the output file.
  • filename="coordinates": Name of the output file.
  • custom_quantities...: Additional custom quantities to include in the VTK output.

Returns

  • file::AbstractString: Path to the generated VTK file.
source
TrixiParticles.trixi2vtkMethod
trixi2vtk(initial_condition::InitialCondition; output_directory="out",
          prefix="", filename="initial_condition", custom_quantities...)

Convert InitialCondition data to VTK format.

Arguments

Keywords

  • output_directory="out": Output directory path.
  • prefix="": Prefix for the output file.
  • filename="coordinates": Name of the output file.
  • custom_quantities...: Additional custom quantities to include in the VTK output.

Returns

  • file::AbstractString: Path to the generated VTK file.
source