Example a/current_density: Current Density Visualisation in a Potential Grid Field

Shows how to compute the gradient of the potential and multiply it by the conductivity tensor to get the current density vector. This requires a transformation of the diagonal conductivity in material (fibre) space to the generally fully populated conductivity tensor in updated coordinate space. The potential field is grid-based, while a varying fibre field is simulated. Values of potential are similar to those found around the depolarisation wavefront in the heart, while conductivities are also realistic for such tissue.

Screenshot of example a/current_density


The comfile run by this example is as follows:

# Current density visualisation in a deforming cube
# -------------------------------------------------
#
# Create some materials for use later.
#
gfx create material bluey ambient 0 0.25 0.5 diffuse 0 0.4 1 specular 0.5 0.5 0.5 shininess 0.3
gfx create material gold ambient 1 0.4 0 diffuse 1 0.7 0 specular 0.5 0.5 0.5 shininess 0.8
gfx create material jade ambient 0.1 0.56 0 diffuse 0.1 0.39 0 emission 0 0 0 specular 0.8 0.8 0.8 alpha 1 shininess 0.8
gfx create material blue ambient 0 0 0 diffuse 0 0.2 1 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.3
gfx create material green ambient 0 1 0 diffuse 0 1 0 emission 0 0 0 specular 0 0 0 alpha 1 shininess 0
gfx create material red ambient 1 0 0 diffuse 1 0 0 emission 0 0 0 specular 0 0 0 alpha 1 shininess 0
#
# Read in the undeformed cube with the undeformed_coordinates, and
# fibres field defined:
#
gfx read nodes example undeformed_cube.exnode
gfx read elements example undeformed_cube.exelem
#
# Read in the deformed cube with the deformed_coordinates field defined. The
# nodes and potential are read in for time 0. The potential is a grid field
# defined at the corners of 10 x 10 x 10 finite difference "cells" across the
# element, hence there will be 11 x 11 x 11 grid points:
#
gfx read nodes example deformed_cube0000.exnode
gfx read elements example deformed_cube.exelem
gfx read elements example potential0000.exelem
#
# Read in the deformed cube and potential at time 1. This made-up example
# has values changing from -85 mV/mm to +15 mV/mm across a narrow band,
# similar to the transmembrane potential around the depolarisation
# wavefront in the heart.
#
gfx read nodes example deformed_cube0001.exnode
gfx read elements example potential0001.exelem
#
# Show the undeformed cube in green and the deformed cube in white. Use
# coloured crosses to show the potential at the grid points.
# Autorange the spectrum used to colour the potential on the grid points.
#
gfx create spectrum potential
gfx modify g_element cube general clear native_discretization potential;
gfx modify g_element cube lines coordinate undeformed_coordinates select_on material jade selected_material default_selected
gfx modify g_element cube lines coordinate deformed_coordinates select_on material default selected_material default_selected
gfx modify g_element cube element_points as gridpoints coordinate deformed_coordinates glyph cross general size "0.2*0.2*0.2" centre 0,0,0 use_elements cell_corners discretization "1*1*1" native_discretization potential select_on material default data potential spectrum potential selected_material default_selected;
gfx modify spectrum potential autorange
#
# Create the graphics window.
#
if (!$TESTING)
{
	gfx create window 1
}
#
# Now hide the grid points:
#
gfx modify g_element cube element_points as gridpoints invisible;
#
# Get fields calculating gradient of the potential, plus the
# deformation gradient F and its transpose. We use the potential
# gradient to obtain current densities using the conductivity tensor,
# defined below.
#
gfx define field potential_gradient coordinate_system rectangular_cartesian gradient coordinate deformed_coordinates field potential
gfx define field F gradient coordinate undeformed_coordinates field deformed_coordinates
gfx define field F_transpose transpose source_number_of_rows 3 field F
#
# Define the fibre_axes field which returns 9 components. The first 3 are the
# undeformed fibre vector, the second the sheet vector and the final three are
# the sheet normal. From this definition we calculate the deformed fibre axes
# through most-multiplying by F_transpose. The transpose of this gives the
# quantity dx/dnu which, together with its inverse dnu/dx, is used for
# converting tensors between the material (fibre) basis and Cartesian
# coordinates.
#
gfx define field fibre_axes coordinate_system rectangular_cartesian fibre_axes coordinate undeformed_coordinates fibre fibres
gfx define field deformed_fibre_axes coordinate_system rectangular_cartesian matrix_multiply number_of_rows 3 fields fibre_axes F_transpose
gfx define field dx_dnu transpose source_number_of_rows 3 field deformed_fibre_axes
gfx define field dnu_dx matrix_invert field dx_dnu
#
# Show the fibre axes, where x = fibre, y = sheet, z = normal:
#
gfx modify g_element cube element_points as deformed_fibres coordinate deformed_coordinates glyph axes_fsn general size "0*0*0" centre 0,0,0 orientation deformed_fibre_axes scale_factors "1*1*1" use_elements cell_centres discretization "4*4*4" native_discretization NONE select_on material green selected_material default_selected;
#
# Hide the fibres.
#
gfx modify g_element cube element_points as deformed_fibres invisible;
#
# Define conductivities in mS/mm along the fibre, sheet and sheet normal
# material axes. Note these are reasonable figures for conductivity in
# heart tissue.
#
gfx define field fibre_conductivity composite 0.6
gfx define field sheet_conductivity composite 0.2
gfx define field normal_conductivity composite 0.1
#
# This is expanded to give the diagonal conductivity tensor in
# material coordinates:
#
gfx define field S_prime composite fibre_conductivity 0 0 0 sheet_conductivity 0 0 0 normal_conductivity
#
# The conductivity is a mixed tensor:
#     a
#   S'
#     .b
#
# To convert this to Cartesian coordinates we use the following
# formula (in matrix notation):
#   S = A S' A_inverse
# where A = dx/dnu
# This is expressed in field calculations as:
#
gfx define field dx_dnu_S_prime matrix_multiply number_of_rows 3 fields dx_dnu S_prime
gfx define field S matrix_multiply number_of_rows 3 fields dx_dnu_S_prime dnu_dx
#
# Next we calculate the current density = S . potential_gradient, in mA/mm^2
#
gfx define field current_density coordinate_system rectangular_cartesian matrix_multiply number_of_rows 3 fields S potential_gradient
gfx define field current_density_magnitude magnitude field current_density
#
# Draw arrows aligned and scaled with the current_density, with colour based
# on the magnitude. Auto range the spectrum used to colour the arrows.
#
gfx create spectrum current_density
gfx modify g_element cube element_points as current_density_vectors coordinate deformed_coordinates glyph arrow_solid general size "0*0.2*0.2" centre 0,0,0 orientation current_density scale_factors "0.05*0*0" use_elements cell_centres discretization "1*1*1" native_discretization potential select_on material default data current_density_magnitude spectrum current_density selected_material default_selected;
gfx modify spectrum current_density autorange
#
# Note that if you change the orientation/scale field in the above command to
# be the potential_gradient you will see how the conductivity tensor, with
# its higher conductivity in the fibre direction has affected the orientation
# of the arrow to be more in line with the fibres.
#
if ($TESTING)
{
  # For testing, output lines instead of arrows to save space.
	gfx modify g_element cube element_points as current_density_vectors glyph line;
	gfx export vrml file current_density.wrl
}

Files used by this example are:

Name                      Modified     Size

current_density.com 17-Mar-2014 6.9k COPYRIGHT 17-Mar-2014 504 deformed_cube.exelem 17-Mar-2014 3.4k deformed_cube0000.exnode 17-Mar-2014 683 deformed_cube0001.exnode 17-Mar-2014 683 potential0000.exelem 17-Mar-2014 18k potential0001.exelem 17-Mar-2014 19k undeformed_cube.exelem 17-Mar-2014 5.7k undeformed_cube.exnode 17-Mar-2014 1.2k

Download the entire example:

Name                               Modified     Size

examples_a_current_density.tar.gz 09-Mar-2016 230k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:05:28 20160
last breakMon Aug 25 13:11:00 20142
cmgui-wx-debugFailureSun Mar 6 00:05:29 20160
last breakMon Aug 25 13:11:00 20141
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:05:29 20160
last breakMon Aug 25 13:11:00 20141
cmgui-wx-debug-valgrindFailureSun Mar 6 00:35:42 201621
last breakTue Feb 24 00:07:00 201520
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:29 20160
last breakFri Aug 15 00:15:00 20140
cmgui-wx-debugFailureSun Mar 6 00:01:29 20160
last breakFri Aug 15 00:15:00 20140
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:29 20160
last breakFri Aug 15 00:15:00 20140
cmgui-wx-debug-valgrindFailureSun Mar 6 00:04:05 201617
last breakSun Mar 6 00:03:00 201617
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:04:47 201616

Testing status by file:


Html last generated: Wed Mar 9 16:01:34 2016

Input last modified: Wed Mar 9 15:49:37 2016


CMISS Help / Examples / a / current_density