The field and particle trajectory simulator
Industry standard charged particle optics software
Refine your design: model > simulate > view > analyze > program > optimize it.
SIMION v8.1.3.1-TEST posted - EA with new GEM features!
About | Documentation | Community/Support | Downloads | Ordering

simionx.MField - Biot-Savart magetic field calculations


-- mag.lua (assumes workbench is similarly named mag.iob)
-- Example SIMION workbench program applying calculated
-- solenoid magnetic field.

local MField = require "simionx.MField"  -- load module

-- Define solenoid magnetic field.
local field = MField.solenoid_hoops {
  first  = MField.vector(-10,0,0),
  last   = MField.vector(-10,0,0)
  radius = 1.2,
  nturns = 200

-- Draw wires in SIMION 8.1

-- SIMION mfield_adjust segment overrides
-- magnetic fields in magnetic PA at current
-- particle position.
function segment.mfield_adjust()
  -- Calculate solenoid magnetic field at current
  -- particle position (with Biot-Savart calculation).
  ion_bfieldx_gu, ion_bfieldy_gu, ion_bfieldz_gu
    = field(ion_px_mm, ion_py_mm, ion_pz_mm)


This module calculates various magnetic fields from wire currents using the Biot-Savart Law. The magnetic fields calculated can be used directly or, as often done, applied in a workbench via an mfield_adjust user program segment.

The module is loaded with

local MField = require "simionx.MField"

This module is typically used by first constructing an object defining the wire current configuration:

local field = MField.line_segment {
  current = 2,
  first = MField.vector(-50,0,0),
  last = MField.vector(50,0,0)

This defines an infinitely thin line segment of wire with 2 amps going from point (x,y,z) = (-50,0,0) to point (x,y,z) = (50,0,0) mm. It does not yet calculate the magnetic field though.

To calculate the magnetic field at some arbitrary point from this magnetic system, we call the object as a function, passing it the x, y, and z components of the observation point:

local bx, by, bz = field(0,0,1)
print(bx,by,bz)  --> 0 -3.99920023992 0

In SIMION 8.1.0, wires from the field object can be drawn on the View screen with the draw method:


The above does nothing in previous SIMION versions, but you can test whether it will do anything by checking the MField.can_draw boolean variable.


This page is abridged from the full SIMION 8.1.1 “Supplemental Documentation” (Help file). The following additional sections can be found in the full version of this page accessible via the “Help > Supplemental Documentation” menu in SIMION 8.1.1:


20110826 - Added mfield:draw method to draw wires on the SIMION View screen in SIMION 8.1.0.


(c) 2007-2011 Scientific Instrument Services, Inc. Licensed under the terms of SIMION 8.0/8.1. D.Manura-200704.

version: 20110826

Any comments on this web page? (will be sent to SIS SIMION Support)
[Optional] Your name: email: phone/fax: