Example a/magnetic_field: Magnetic Field Visualisation from Vector Potential Data

Given a computed magnetic vector potential field from cmiss, this example shows how to calculate the corresponding magnetic fields and the magnetization using computed fields. This example shows the fields around and within a U shaped conductor situated close to a square current carrying wire.

Screenshot of example a/magnetic_field


The comfile run by this example is as follows:

# Magnetic field calculation and display.

if( !defined $example ) {
  $example = ".";
}

sub calcSolution {

  # Calculate B from curl(A)
  gfx define field B curl coordinate coordinates vector A;

  # Calculate H from B/(mu0*muR)
  gfx define field B_over_mu0 divide_components fields B mu0_vect;
  gfx define field H divide_components fields B_over_mu0 muR_vect;

  # Calculate M from (B/mu0)*(1-1/muR)
  gfx define field unit constant 1.0 1.0 1.0;
  gfx define field one_over_muR divide_components fields unit muR_vect;
  gfx define field one_minus_one_over_muR add fields unit one_over_muR scale_factors 1 -1;
  gfx define field M multiply_components fields B_over_mu0 one_minus_one_over_muR;

  # Store the magnitude of each vector fields
  gfx define field magJ magnitude field J;
  gfx define field magA magnitude field A;
  gfx define field magB magnitude field B;
  gfx define field magH magnitude field H;
  gfx define field magM magnitude field M;

}

sub drawMagnetElems {

  # Create a transparent red material
  gfx create material red_alpha ambient 0.5 0 0 diffuse 1 0 0 emission 0 0 0 specular 0.2 0.2 0.2 alpha 0.5 shininess 0.2;

  gfx create egroup magnet1 add 56..60;
  gfx modify g_element magnet1 general clear element_discretization "1*1*1";
  gfx modify g_element magnet1 lines invisible;
  gfx modify g_element magnet1 surfaces face xi2_0 material red_alpha;
  gfx modify g_element magnet1 surfaces face xi2_1 material red_alpha;
  gfx modify g_element magnet1 surfaces face xi3_0 material red_alpha;

  gfx create egroup magnet2 add 66..70;
  gfx modify g_element magnet2 general clear element_discretization "1*1*1";
  gfx modify g_element magnet2 lines invisible;
  gfx modify g_element magnet2 surfaces face xi2_0 material red_alpha;
  gfx modify g_element magnet2 surfaces face xi2_1 material red_alpha;
  gfx modify g_element magnet2 surfaces face xi3_0 material red_alpha;

  gfx create egroup magnet3 add 81..85;
  gfx modify g_element magnet3 general clear element_discretization "1*1*1";
  gfx modify g_element magnet3 lines invisible;
  gfx modify g_element magnet3 surfaces face xi2_0 material red_alpha;
  gfx modify g_element magnet3 surfaces face xi3_1 material red_alpha;

  gfx create egroup magnet4 add 86..90;
  gfx modify g_element magnet4 general clear element_discretization "1*1*1";
  gfx modify g_element magnet4 lines invisible;
  gfx modify g_element magnet4 surfaces face xi3_0 material red_alpha;
  gfx modify g_element magnet4 surfaces face xi3_1 material red_alpha;

  gfx create egroup magnet5 add 91..95;
  gfx modify g_element magnet5 general clear element_discretization "1*1*1";
  gfx modify g_element magnet5 lines invisible;
  gfx modify g_element magnet5 surfaces face xi2_1 material red_alpha;
  gfx modify g_element magnet5 surfaces face xi3_1 material red_alpha;

}

sub drawSolution {

  # Draw the exterior lines on the domain
  gfx modify g_element cubes general clear element_discretization "4*4*4";
  gfx modify g_element cubes lines position 1 coordinate coordinates exterior material default;

  # Draw the source field J
  gfx modify g_element cubes element_points position 2 coordinate coordinates glyph line general size "0*0*0" centre 0.5,0,0 orientation J scale_factors "0.05*0.05*0.05" use_elements cell_centres discretization "5*5*5" material green;

  # Draw the magnetisation field M
  gfx modify g_element cubes element_points position 3 coordinate coordinates glyph line general size "0*0*0" centre 0.5,0,0 orientation M scale_factors "1.5*1.5*1.5" use_elements cell_centres discretization "3*3*3" material silver;

  # Draw the vector potential field A (invisible)
  gfx modify g_element cubes element_points position 4 coordinate coordinates glyph line general size "0*0*0" centre 0.5,0,0 orientation A scale_factors "7e+09*7e+09*7e+09" use_elements cell_centres discretization "3*3*3" invisible material blue;

  # Draw the magnetic flux density B
  gfx modify g_element cubes element_points position 5 coordinate coordinates glyph line general size "0*0*0" centre 0.5,0,0 orientation B scale_factors "1e+09*1e+09*1e+09" use_elements cell_centres discretization "3*3*3" invisible material gold;

  # Draw the magnetic field intensity H
  gfx modify g_element cubes element_points position 6 coordinate coordinates glyph line general size "0*0*0" centre 0.5,0,0 orientation H scale_factors "1.5*1.5*1.5" use_elements cell_centres discretization "3*3*3" invisible material tissue;

}

sub drawSourceElems {

  # Create a transparent green material
  gfx create material green_alpha ambient 0 0.5 0 diffuse 0 1 0 emission 0 0 0 specular 0.2 0.2 0.2 alpha 0.5 shininess 0.1;

  gfx create egroup source add 36..40;
  gfx modify g_element source general clear element_discretization "1*1*1";
  gfx modify g_element source lines invisible;
  gfx modify g_element source surfaces face xi2_0 material green_alpha;
  gfx modify g_element source surfaces face xi2_1 material green_alpha;
  gfx modify g_element source surfaces face xi3_0 material green_alpha;
  gfx modify g_element source surfaces face xi3_1 material green_alpha;

}

sub readGeometry {

  # Read in the geometry
  gfx read node $example/cubes.exnode;
  gfx read elem $example/cubes.exelem;

  # Create a 3d window
  if( !$TESTING ) {
    gfx create window;
    gfx modify window 1 set slow_transp;
  }

}

sub readSolution {

  # Read in A
  gfx read node $example/field.exnode;
  gfx read elem $example/field.exelem;
  gfx define field A composite potential nh_2 nh_3;

  # Read in mu_0
  gfx read elem $example/mu0.exelem;
  gfx define field mu0_vect composite mu0 mu0 mu0;

  # Read in mu_R
  gfx read elem $example/muR.exelem;
  gfx define field muR_vect composite muR muR muR;

  # Read in J
  gfx read elem $example/Jx.exelem;
  gfx read elem $example/Jy.exelem;
  gfx read elem $example/Jz.exelem;
  gfx define field J composite Jx Jy Jz;

}

# ---------------------------------------------------------------
#
# This example reads in the magnetic vector potential field (A)
# which has been calculated in CMISS in response to a current
# source field (J). It then uses computed fields to calculate the
# magnetic flux density (B), the magnetic field intensity (H) and 
# the magnetisation (M).
#
# Definitions
# -----------
#  A  is the magnetic vector potential
#  B  is the magnetic flux density
#  H  is the magnetic field intensity
#  M  is the magnetisation
#  J  is the current density
# mu0 is the magnetic permeability of free space
# muR is the relative permeability
#

# Read in the solution geometry which is a 5x5x5 set of
# finite element cubes. Also create a 3d graphics window.
&readGeometry();

# Read in the solution from CMISS along with the current
# field and fields describing the required material properties.
&readSolution();

# Use computed fields to calculate the quantities of interest
# (B,H,M) throughout the mesh.
&calcSolution();

# Colour the surfaces that define the boundaries of the source
# region a transparent green.
&drawSourceElems();

# Colour the surfaces that define the boundaries of the ferrous
# material that can be magnetised a transparent red.
&drawMagnetElems();

# Draw the current source field (J) and the magnetisation field (M).
# Note how only the ferrous material has been magnetised.
&drawSolution();

# Graphics for displaying the A, B and H fields have been calculated
# but are invisible at present. These can be toggled on and off using
# the scene editor.

# Test output
if( $TESTING ) {
  gfx export vrml file magnetic_field.wrl
}



Files used by this example are:

Name                Modified     Size

magnetic_field.com 17-Mar-2014 7.4k COPYRIGHT 17-Mar-2014 504 Jx.exelem 17-Mar-2014 23k Jy.exelem 17-Mar-2014 23k Jz.exelem 17-Mar-2014 23k cubes.exelem 17-Mar-2014 106k cubes.exnode 17-Mar-2014 22k field.exelem 17-Mar-2014 106k field.exnode 17-Mar-2014 22k mu0.exelem 17-Mar-2014 23k muR.exelem 17-Mar-2014 23k

Download the entire example:

Name                              Modified     Size

examples_a_magnetic_field.tar.gz 09-Mar-2016 291k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:05:42 20160
last breakThu Sep 11 00:02:00 20141
last successWed Sep 10 00:02:00 20140
cmgui-wx-debugFailureSun Mar 6 00:05:49 20160
last breakThu Sep 11 00:02:00 20141
last successWed Sep 10 00:02:00 20141
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:05:42 20161
last breakThu Sep 11 00:02:00 20140
last successWed Sep 10 00:02:00 20141
cmgui-wx-debug-valgrindFailureSun Mar 6 00:44:04 201627
last breakTue Feb 24 00:09:00 201532
last successWed Sep 10 00:36:00 201427
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:31 20160
last breakThu Sep 11 00:03:00 20141
last successWed Sep 10 00:03:00 20140
cmgui-wx-debugFailureSun Mar 6 00:01:31 20160
last breakThu Sep 11 00:03:00 20140
last successWed Sep 10 00:03:00 20140
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:31 20160
last breakThu Sep 11 00:03:00 20140
last successWed Sep 10 00:03:00 20140
cmgui-wx-debug-valgrindFailureSun Mar 6 00:04:44 201624
last breakThu Sep 11 00:17:00 201423
last successWed Sep 10 00:17:00 201422
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:05:45 201622

Testing status by file:


Html last generated: Wed Mar 9 16:02:20 2016

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


CMISS Help / Examples / a / magnetic_field