A program for RF heating simulation in biological tissue. Given an arbitrary electrode geometry and boundary conditions, it computes the electric potential, electric field, and ohmic heat dissipation in the tissue, and then uses that dissipation as a source term to evolve the temperature field over time.
- Julia ≥ 1.10
- Dependencies are listed in
Project.tomland managed by Julia's built-in package manager. To install them, open a Julia REPL in the project directory and run:
using Pkg
Pkg.instantiate()The RF heating procedure uses two or more electrodes to apply alternating electrical current to tissue — one electrode applies an alternating electrical potential, while the other acts as an electrical ground.
The governing equation for the electric potential in the tissue is:
Considering
Here,
Note that
Once
The temperature field
where VHC
The simulation follows an arbitrary heating schedule — an ordered list of (:on, duration) and (:off, duration) phases, for example:
schedule = [(:on, 30.0), (:off, 60.0), (:on, 15.0)]During :on phases :off phases
The time step
evaluated over all cells, with a safety factor of 0.45.
The Laplacian and Euler update kernels are parallelised (if this is enabled, see section Enabling Multiple Threads below) by partitioning the grid's z-dimension into chunks, one per worker thread. The worker count is set automatically to
The workflow consists of two steps that can be run independently.
Run run_simulation to obtain the electric field results and the ohmic heat source Qel:
grid, V_dof, Qel, E_mag, E_vec, V = run_simulation(grid_params, rf_params, boundary_conditions)Pass Qel to run_heat_simulation to evolve the temperature field:
T_final = run_heat_simulation(Qel, grid_params, heat_params)Set create_timelapse = true to display a live-updating cross-section plot of the temperature field as the simulation runs:
T_final = run_heat_simulation(Qel, grid_params, heat_params; create_timelapse = true)The plot refreshes n_update times per schedule phase. The colour scale is updated automatically to the current field range at each refresh.
To save plots to the Images subfolder, pass a filename to plot_graphs:
plot_graphs(material_indices, grid_params, Qel, E_mag, E_vec, V, "Example6_Franco")Simulation results can be stored with save_simulation in .h5 files using HDF5.jl. This format is efficient, portable, and well-suited for large numerical datasets. The data structure is similar to what you would see in the MATLAB workspace, making it intuitive to explore.
You can inspect these files using HDFView:
By default Julia starts with a single thread, so the parallel kernels described in Section 1.3 have no effect. To enable them, Julia must be launched with multiple threads.
VS Code — add to .vscode/settings.json in the project folder:
{
"julia.additionalArgs": ["--threads", "auto"]
}Command line / other environments — pass the flag directly or set the environment variable:
julia --threads auto example1.jl
# or
export JULIA_NUM_THREADS=autoYou can confirm the thread count inside Julia with Threads.nthreads().
[1] Quasi-Static Electromagnetic Dosimetry: From Basic Principles to Examples of Applications
[2] Quasi-Static Approximation Error of Electric Field Analysis for Transcranial Current Stimulation
[3] Numerical Study of Hyper‐Thermic Laser Lipolysis With 1,064 nm Nd:YAG Laser in Human Subjects