Julia API
This page documents the Julia part of libtrixi, which is implemented in the LibTrixi.jl package. LibTrixi.jl provides Julia-based wrappers around Trixi.jl, making simulations controllable through a defined API.
The Julia API provided by LibTrixi.jl is only provided for internal use by libtrixi and to facilitate easier development and debugging of new library features. It is not intended to be used by Julia developers: They should directly utilize Trixi.jl to benefit from its Julia-native implementation.
LibTrixi.SimulationState
— TypeSimulationState
Data structure to store a simulation state that consists of a semidiscretization plus the time integrator.
LibTrixi.trixi_calculate_dt
— Functiontrixi_calculate_dt(simstate_handle::Cint)::Cdouble
Compute, store, and return the time step size for the next time integration step.
LibTrixi.trixi_eval_julia
— Functiontrixi_eval_julia(code::Cstring)::Cvoid
Execute the provided code in the current Julia runtime environment.
Code is not checked prior to execution.
LibTrixi.trixi_finalize_simulation
— Functiontrixi_finalize_simulation(simstate_handle::Cint)::Cvoid
Finalize a simulation and attempt to free the underlying memory.
LibTrixi.trixi_get_t8code_forest
— Functiontrixi_get_t8code_forest(simstate_handle::Cint)::::Ptr{Trixi.t8_forest}
Return t8code forest of the current T8codeMesh.
The interface to t8code is experimental and implementation details may change at any time without warning.
LibTrixi.trixi_initialize_simulation
— Functiontrixi_initialize_simulation(libelixir::Cstring)::Cint
trixi_initialize_simulation(libelixir::AbstractString)::Cint
Initialize a new simulation based on the file libelixir
and return a handle to the corresponding SimulationState
as a Cint
(i.e, a plain C int
).
The libelixir has a similar purpose as a regular "elixir" in Trixi.jl, as it completely defines a simulation setup in Julia code. A key difference (and thus the name libelixir) is that instead of running a simulation directly, it should define an argument-less function named init_simstate()
that returns a SimulationState
with the complete simulation setup. trixi_initialize_simulation
will store the SimulationState
object internally and allow one to use it in subsequent calls to libtrixi via the handle returned from this function.
For convenience, when using LibTrixi.jl directly from Julia, one can also pass a regular String
in the libelixir
argument.
The libelixir file will be evaluated in the Main
module. Thus any previously defined function init_simstate
will be overwritten, and any variables defined outside the function will live throughout the lifetime of the Julia process.
This function is not thread safe. Since the libelixir file will be evaluated in the Main
module, calling trixi_initialize_simulation
simultaneously from different threads can lead to undefined behavior.
LibTrixi.trixi_is_finished
— Functiontrixi_is_finished(simstate_handle::Cint)::Cint
Return 0
if the simulation time has not yet reached the final time, and 1
otherwise.
LibTrixi.trixi_load_cell_averages
— Functiontrixi_load_cell_averages(data::Ptr{Cdouble}, simstate_handle::Cint)::Cvoid
Return cell averaged solution state.
Cell averaged values for each cell and each primitive variable are stored in a contiguous array, where cell values for the first variable appear first and values for the other variables subsequently (structure-of-arrays layout).
The given array has to be of correct size and memory has to be allocated beforehand.
LibTrixi.trixi_ndims
— Functiontrixi_ndims(simstate_handle::Cint)::Cint
Return number of spatial dimensions.
LibTrixi.trixi_nelements
— Functiontrixi_nelements(simstate_handle::Cint)::Cint
Return number of local elements (cells).
LibTrixi.trixi_nelements_global
— Functiontrixi_nelements_global(simstate_handle::Cint)::Cint
Return number of global elements (cells).
LibTrixi.trixi_nvariables
— Functiontrixi_nvariables(simstate_handle::Cint)::Cint
Return number of variables.
LibTrixi.trixi_step
— Functiontrixi_step(simstate_handle::Cint)::Cvoid
Advance the simulation in time by one step.
LibTrixi.trixi_version_julia
— Functiontrixi_version_julia()::Cstring
Return name and version of loaded Julia packages LibTrixi directly depends on.
The return value is a read-only pointer to a NULL-terminated string with the name and version information of the loaded Julia packages, separated by newlines.
The returned pointer is to static memory and must not be used to change the contents of the version string. Multiple calls to the function will return the same address.
This function is thread-safe. It must be run after trixi_initialize
has been called.
LibTrixi.trixi_version_julia_extended
— Functiontrixi_version_julia_extended()::Cstring
Return name and version of all loaded Julia packages.
The return value is a read-only pointer to a NULL-terminated string with the name and version information of all loaded Julia packages, including implicit dependencies, separated by newlines.
The returned pointer is to static memory and must not be used to change the contents of the version string. Multiple calls to the function will return the same address.
This function is thread-safe. It must be run after trixi_initialize
has been called.
LibTrixi.trixi_version_library
— Functiontrixi_version_library()::Cstring
Return full version string of libtrixi.
The return value is a read-only pointer to a NULL-terminated string with the version information. This may include not just MAJOR.MINOR.PATCH but possibly also additional build or development version information.
The returned pointer is to static memory and must not be used to change the contents of the version string. Multiple calls to the function will return the same address.
This function is thread-safe. It must be run after trixi_initialize
has been called.
LibTrixi.trixi_version_library_major
— Functiontrixi_version_library_major()::Cint
Return major version number of libtrixi.
This function is thread-safe. It must be run after trixi_initialize
has been called.
LibTrixi.trixi_version_library_minor
— Functiontrixi_version_library_minor()::Cint
Return minor version number of libtrixi.
This function is thread-safe. It must be run after trixi_initialize
has been called.
LibTrixi.trixi_version_library_patch
— Functiontrixi_version_library_patch()::Cint
Return patch version number of libtrixi.
This function is thread-safe. It must be run after trixi_initialize
has been called.