|
| |
SL Libraries -- Perl |
|
SIMION::PA (v. 2.00beta1) - Perl module for reading/writing/modifying SIMION potential arrays.
use SIMION::PA; #-- read an existing array my $pa = new SIMION::PA(file => 'buncher.pa#'); # print header parameters the simple way print $pa->header_string;
#-- create an array from scratch
my $pa2 = new SIMION::PA(nx => 100, ny => 20,
symmetry => 'cylindrical');
my $z = 0;
for my $x (0..$pa2->nx-1) {
for my $y (0..$pa2->ny-1) {
my $inside = ($x + $y) < 10;
if($inside) {
$pa2->point($x, $y, $z, 1, 5.0); # electrode, 5V
}
}}
$pa2->save('myarray.pa#');
#-- create a magnetic field from scratch
my $pa3 = new SIMION::PA(nx => 50, ny => 50, field_type => 'magnetic');
my $z = 0;
for my $x (0..$pa3->nx-1) {
for my $y (0..$pa3->ny-1) {
my $ex = $x;
my $ey = $y**2;
my $ez = 0;
$pa3->field($x, $y, $z, $ex, $ey, $ez);
}}
$pa3->save('mag1.pa');
This module is for manipulating SIMION potential array (PA/PA?) files (including creating, loading, modifying, and saving). See Appendix D-5 of the SIMION 7.0 manual for the PA file format specification.
This modules is intended to be very robust and has been put through an extensive test suite. It is also intended to be simple to use and very Perl-ish. The module is, however, not as fast as the corresponding C++ implementation, even though speed has been considered, so use the C++ implementation if speed is critical.
new(...)my $pa = new SIMION::PA(file => 'buncher.pa#');
To create an array from scratch (with all points initially set to 0V non-electrodes) do
my $pa = new SIMION::PA(
mode => -1, # mode (always -1)
symmetry => 'planar', # symmetry type: 'planar' or 'cylindrical'
max_voltage => 100000, # this affects the interpretation
# of point values
nx => 100, # x dimension in grid units
ny => 100, # y dimension in grid units
nz => 1, # z dimension in grid units
mirror => '', # mirroring (subset of "xyz")
field_type => # field type: 'electrostatic' or 'magnetic'
'electrostatic', #
ng => 100, # ng scaling factor for magnetic arrays.
fast_adjustable => 0, # Boolean indicating whether is fast-adj.
);
See p. 2-10 of the SIMION 7.0 manual for details on these parameters. The parameters given above are default values, and any/all can be omitted:
my $pa = new SIMION::PA(); my $pa = new SIMION::PA(nx => 100, ny => 20, field_type => 'magnetic');
header_string()
begin_header
mode -1
symmetry planar
max_voltage 20000
nx 77
ny 39
nz 1
mirror_x 0
mirror_y 1
mirror_z 0
field_type electrostatic
ng 100
fast_adjustable 1
end_header
This method is also very useful for debugging to quickly display the information on a given potential array.
load($path)
$pa->load('myfile.pa#');
Note: Arrays can also be loaded in the new method.
save($path)
$pa->save('myfile.pa#');
fast_adjustable($fast_adjustable)$pa->fast_adjustable(1); print $pa->fast_adjustable;
field_type($field_type)
$pa->field_type('magnetic');
print $pa->field_type;
max_voltage($max_voltage)$pa->max_voltage(100000); print $pa->max_voltage;
mirror($mirror)
$pa->mirror('yz');
print $pa->mirror;
Provides an error is not thrown, the above is equivalent to
$pa->set(mirror_y => 1, mirror_z => 1);
mirror_x($mirror_x)$pa->mirror_x(1); print $pa->mirror_x;
mirror_y($mirror_y)$pa->mirror_y(1); print $pa->mirror_y;
mirror_z($mirror_z)$pa->mirror_z(1); print $pa->mirror_z;
Here is an example of failure:
my $pa = new SIMION::PA(symmetry => 'cylindrical'); $pa->mirror_z(1); # dies: z mirroring not allowed in cylindrical symmetry.
mode($mode)$pa->mode(-1); print $pa->mode;
ng($ng)$pa->ng(100); print $pa->ng();
num_points()nx() * ny() * nz().
my $pa = new SIMION::PA(nx => 3, ny => 4); print $pa->num_points(); # prints 12
num_voxels()my $pa = new SIMION::PA(nx => 3, ny => 4); print $pa->num_voxels(); # prints 6
nx($nx)$pa->nx(100); print $pa->nx;
ny($ny)$pa->ny(100); print $pa->ny;
nz($nz)$pa->nz(100); print $pa->nz;
pasharp($pasharp)
my $pasharp = new SIMION::PA(file => "test.pa#");
my $pa0 = new SIMION::PA();
# ... add code to create pa0 array here.
pa0->pasharp(&pasharp);
pa0->save("test.pa0");
set(...)new() method. This method is useful when the
attributes are interdependent.
$pa->set(nz => 1, symmetry => 'cylindrical');
$pa->size(10, 20, 30); my($nx, $ny, $nz) = $pa->size;
symmetry($symmetry)
$pa->symmetry('cylindrical');
print $pa->symmetry;
print 'inside' if $pa->inside(10, 20, 30);
print $pa->inside(-10.1, 20.2, 30.3);
print $pa->voxel_inside(10, 20, 30);
$pa->electrode(10, 20, 30, 1); print $pa->electrode(10, 20, 30);
The setting function internally performs the numerical integration on the given field vectors to generate the corresponding scalar potentials that must be stored in the PA file. The setting function also has some special calling requirements. First, the all points must initially be zero volt, nonelectrodes. Second, the field setting method must be called for all points in the array in lexographic order (e.g. (0,0,0), (0,0,1), ... (0,0,nx()-1), (0,1,0), (0,1,1), (0,1,nx()-1), ...). Dies on error.
# set
for my $z (0..$pa->nz-1) {
for my $y (0..$pa->ny-1) {
for my $x (0..$pa->nx-1) {
my $ex = $x;
my $ey = $y**2;
my $ez = 0;
$pa->field($x, $y, $z, $ex, $ey, $ez);
}}}
my($ex, $ey, $ez) = $pa->field(10, 20, 30); # get
my($ex, $ey, $ez) = $pa->field_real(-10.3, 20.2, 30.7); # assuming mirror_x
$pa->point(10, 20, 30, 1, 2.15); my($is_electrode, $potential) = $pa->point(10, 20, 30);
The first line above is the same as
$pa->electrode(10, 20, 30, 1); $pa->potential(10, 20, 30, 2.15);
$pa->potential(10, 20, 30, 2.15); print $pa->potential(10, 20, 30);
print $pa->potential(10.3, 20.2, 30.7);
potential($x,$y,$z) + is_electrode($x,$y,$z)
? 2 * max_voltage() : 0. Dies on error.
$pa->raw(10, 20, 30, 100002.15); print $pa->raw(10, 20, 30);
$pa->solid(10, 20, 30, 1); print $pa->solid(10, 20, 30);
The first line above is the same as
$pa->electrode(10, 20, 30, 1); $pa->electrode(10, 20, 31, 1); $pa->electrode(10, 21, 30, 1); $pa->electrode(10, 21, 31, 1); $pa->electrode(11, 20, 30, 1); $pa->electrode(11, 20, 31, 1); $pa->electrode(11, 21, 30, 1); $pa->electrode(11, 21, 31, 1);
The second line above is analogous, requiring all eight points to be electrodes.
$pa->check(symmetry => 'cylindrical', nz => 2) or die $pa->{error};
$pa->check(mirror_z => 1, nz => 1); or die $pa->{error};
$pa->check(symmetry => 'cylindrical, mirror => 'xz') or die $pa->{error};
check_field_type($field_type)
$pa->check_field_type('magnetic') or die $pa->{error};
check_max_voltage($voltage)
$pa->check_max_voltage(100000) or die $pa->{error};
check_mirror($mirror)
$pa->check_mirror('yz') or die $pa->{error};
check_mode($mode)
$pa->check_mode(-1) or die $pa->{error};
check_ng($ng)
$pa->check_symmetry(100) or die $pa->{error};
check_nx($nx)
$pa->check_nx(100) or die $pa->{error};
check_ny($ny)
$pa->check_ny(100) or die $pa->{error};
check_nz($nz)
$pa->check_nz(100) or die $pa->{error};
check_nx($nx) && check_ny($ny) && check_nz($nz) implies
check_size($nx, $ny, $nz), although the converse is not necessarily
true. On false, the error string ($pa->{error}) is also set.
$pa->check_size(3, 3, 1) or die $pa->{error};
check_symmetry($symmetry)
$pa->check_symmetry('cylindrical') or die $pa->{error};
error()error() is equivalent to $pa->{error}.
David Manura (c) 2003-2004 Scientific Instrument Services, Inc. Licensed under the terms of the SIMION SL Toolkit. $Revision: 1.3 $ $Date: 2004/07/17 20:36:32 $ Created 2003-11.