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:
- Click
File -> Open
. - Navigate to the
out
directory (relative to the directory that you are running Julia from). - Open both
boundary_1.pvd
andfluid_1.pvd
. - Click "Apply", which by default is on the left pane below the "Pipeline Browser".
- Hold the left mouse button to move the solution around.
You will now see the following:
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:
- "Representation" to "Point Gaussian".
- Choose the right "Shader Preset": "Plain Circle" for 2D and "Sphere" for 3D.
- Activate "Scale by Array" and select "
particle_spacing
" in "Gaussian Scale Array". - Deactivate "Use Scale Function".
- Set the "Gaussian Radius" to "
0.5
".
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.
- Save the macro code (see below) as a
.py
file, e.g.PointGaussianMacro.py
. - Open ParaView and go to the top menu: Macros → Import New Macro... → Select the saved
.py
file. - The macro will now appear in the Macros menu and can optionally be pinned to the toolbar.
- Load your dataset into ParaView.
- Select the dataset in the Pipeline Browser.
- Click on the macro name in the Macros menu (or toolbar, if pinned) to run it.
- 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).
API
TrixiParticles.vtk2trixi
— Methodvtk2trixi(file::String)
Load VTK file and convert data to an InitialCondition
.
Arguments
file
: Name of the VTK file to be loaded.
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 │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘
TrixiParticles.trixi2vtk
— Methodtrixi2vtk(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 anArrayPartition
as returned in the examples assol.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, wheredata
is a named tuple with fields depending on the system type, andt
is the current simulation time. Check the available data for each system withavailable_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)
TrixiParticles.trixi2vtk
— Methodtrixi2vtk(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.
TrixiParticles.trixi2vtk
— Methodtrixi2vtk(initial_condition::InitialCondition; output_directory="out",
prefix="", filename="initial_condition", custom_quantities...)
Convert InitialCondition
data to VTK format.
Arguments
initial_condition
:InitialCondition
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.