Large FTP uploads

An update of our software installation packages involves uploading 42 files with sizes that range from 20-120 MB. Each file must be placed in a different directory on our server. An FTP program like FileZilla is useful for day-to-day file updating, but lacks script operation features. In this case, an update would involve a tedious process of identifying 42 files and 42 destinations. The situation is worse if we need to update programs from one of our secondary offices. Local Internet providers severely limit upload speed — the figure is 122 kB/s at our Colorado office.

One solution is to automate the process (i.e., prepare the update files and then let the computer upload autonomously for several hours). WinSCP is a good freeware utility to help implement automated FTP transfers. It is available at http://winscp.net/eng/index.php.

The documentation for WinSCP is a little convoluted, so I prepared an example based on my experience to help you set things up. To begin, download and install WinSCP. For convenience, put c:\program files\winscp on the path. Alternatively, copy the relatively small executable files to a location that is already on the path. I use a general directory c:\batch.

As an example, suppose you have the files

c:\distfiles\program01.exe
c:\distfiles\program02.exe
c:\distfiles\program03.exe
c:\distfiles\program04.exe
c:\distfiles\program05.exe

that should be copied to the directories

public_html/download/site01
public_html/download/site02
public_html/download/site03
public_html/download/site04
public_html/download/site05

on your server, automatically replacing any existing files with the same names. Suppose your site has the URL mycompany.com. The user name and password for FTP transfers is myuser and mypassword.

1) Use a text editor to create a file FTPUpload.bat in the directory c:\distfiles with the following single-line content:

winscp.exe /console /script=FTPUpload.txt

The batch file runs WinSCP in the console mode and calls up the script for instructions.

2) Create another file in the directory called FTPUpload.txt with the following content :

open ftp://myuser:mypassword@mycompany.com/public_html/download
option confirm off
cd site01
put program01.exe
cd ../site02
put program02.exe
cd ../site03
put program03.exe
cd ../site04
put program04.exe
cd ../site05
put program05.exe
exit

The first line opens a password-protected FTP session and transfers to a convenient directory. The second line ensures that the script will not pause for confirmation when replacing the old files. The subsequent lines migrate to directories and copy the appropriate files. Simply run the batch file and everything happens automatically. WinSCP maintains a console window to show the status of operations.

Note: If you are bothered by world-class hackers breaking into your office, be careful about storing the file FTPUpload.txt with your site password.

Using Magnum to calculate flux coupling

A customer working with RFID devices asked me about finding magnetic flux inside a detector coil surrounded by an array of drive coils. The drive coils may move around or rotate. There are no iron structures. The calculations are fast and easy using the free-space mode of Magnum. In this post, I’ll review the required techniques.

Detector coil position and current elements of the drive coil

Detector coil position and current elements of the drive coil

The first figure shows a test geometry. The detector coil has a rectangular cross section (Δx = 6.0 cm, Δy = 3.5 cm). For convenience, I located it in the plane z = 0.00 cm. I included one circular drive coil of radius 5.0 cm with center at (x = 5.0 cm, y = 5.0 cm and z = 5.0). To illustrate parameter variations, I rotated it 45° around the x axis. Here is the coil definition file created in MagWinder:

GLOBAL
DUnit:   1.0000E+02
END
COIL
Name: RotatingCoil
Current:   1.0000E+00
Ds:   2.5000E-01
Shift:   5.0000E+00  5.0000E+00  5.0000E+00
Part
Name: RotatingCoil
Type: Circle
Fab:   5.0000E+00
* Change ThetaX to rotate the coil
Rotate:    45.000    0.000    0.000  XYZ
End
END
ENDFILE

The coil can be rotated by editing the part in Magwinder or simply changing the value 45.000 with a text editor. The coil definition file is processed with Magwinder to create a list of 126 short current elements to calculate the applied field at the position of the diagnostic coil.

In a Magnum free space solution, the computational mesh defines a set of node points to calculate the applied field. The field at other points is determined by interpolation. All elements have μr = 1.0. Usually, the mesh is a single-region box that surrounds the volume of interest. In this case, I used a special region division to enable automatic flux calculations. The figure below shows the mesh, extending over a range that encloses the detector coil (-5.0 ≤ x ≤ 5.0, -5.0 ≤ y ≤ 5.0, -1.0 ≤ z ≤ 1.0). The upper and lower spaces in z are divided into Region 1 and 2. Region 3 occupies the lower space in z and has the cross-section dimensions of the detector coil (Δx = 6.0 cm, Δy = 3.5 cm). The important point is that the surface between Region 3 and 1 corresponds to the area enclosed by the detector coil.

Computational mesh with special diagnostic regions

Computational mesh with special diagnostic regions

The Magnum solution takes only a few seconds. MagView is then used to analyze the solution. To calculate the flux integral, click on Analysis/Surface integral to show the dialog illustrated below. We want to find the flux out of Region 3 into Region 1 (i.e., a positive value corresponds to Bz > 0.0). Therefore, we set the dialog so that Region 3 is internal and Region 1 is external. The program determines integrals over the defined surface and records the results in a data file (shown below):

Dialog to define surface integrals

Dialog to define surface integrals

———- Surface Integrals ———-
Region status
RegNo   Status    Name
===================================
1  External   AIRUPPER
3  Internal   COILOUTLINE
Surface area of region set (m2):   2.100000E-03
MagFlux:  -2.537678E-09

As a check, we confirm that the area equals 0.060 m × 0.035 m. The flux implies an average flux density <Bz> = 1.208E-6 tesla. Inspection of a plot of Bz in the plane z = 0.0 cm shows that this is a reasonable value.

Plot of Bz over the plane z = 0.0 cm

Plot of Bz over the plane z = 0.0 cm

For Magnum users, here are links to the example input files:

http://www.fieldp.com/myblog/examples/MagneticFlux.CDF
http://www.fieldp.com/myblog/examples/MagneticFlux.MIN
http://www.fieldp.com/myblog/examples/MagneticFlux.GIN

How to use saved views

We recently added the capability to save and to load plot views (discussed in a previous post) to our two-dimensional TriComp field programs (EStat, PerMag, EMP, Nelson, TDiff, Pulse, RFE2 and WaveSim). In the interactive environment, the Save view command generates a formatted text file FPrefix.FPV where FPrefix is a descriptive name assigned by the user. The file contains the complete set of plotting parameters. This excerpt illustrates the format:

Program: TriComp
PlotStyle: Spatial
Outline: ON
Grid: ON
Scientific: OFF
FixedPoint: OFF
Vectors: OFF
XGMin:  3.500000E+00
XGMax:  9.000001E+00
...

The file contains all necessary parameters to reconstruct spatial plots (in the z-r or x-y planes). The file includes the following information for spatial plots:

  • Style information, like whether to display a reference grid, element outlines or field vectors.
  • Boundaries of zoomed views
  • The plot type (e.g., mesh, filled contour, contour lines,…)
  • The plotted quantity.

You can also save information to reconstruct scan plots:

  • Style information (number of scan points, symbol display,…)
  • Coordinates of the scan start and end Limits of the scan.
  • Plotted quantity.
Spatial versus scan plots in TriComp programs

Spatial versus scan plots in TriComp programs

The simplest application of saved views is to restore a complex plot when you reload the solution at a later time. We have included several features in our implementation to enable a higher level of data analysis:

  • A saved view works even if a completely different solution than one use to create the view in loaded. In fact, views can be reloaded even if the user is running a different TriComp program. The current program analyzes the parameters and uses only ones that are relevant. For example, if a view-boundary or scan point is outside the current solution volume, the point is moved to the boundary. If a plot quantity is undefined, the first valid quantity  is used.
  • A free-form parser is employed when a view is loaded. Therefore, a file need not contain a complete set of parameters. Changes are made only to the quantities listed in the file.
  • Users can modify entries in the view file, either directly with an editor or via a Perl or Python script. You can include comments, change parameter values or remove parameter lines.

Another important feature is related to the fact that analysis functions of all TriComp postprocessors may be controlled by a text script. We have added the following  script command:

PLOT FSaveView FOutput Nx Ny
PLOT (DiodeRegion VIEW001 800 600)

The string FSaveView is the prefix of a saved view file. The string FOutput is the prefix of a plot file in BMP format. The integer parameters give the image resolution in pixels. In response to the command, the program loads the saved view file, applies the parameters to create a plot for the currently-loaded solution and saves it as a graphics file.

Here are some possible scenarios:

  • You have a set of electric field solutions with different applied voltage and possibly different boundaries and you want to check electric field levels in a critical region (e.g., an electron source). Use the Zoom command to create the desired plot and save a view file. Remove all information lines except the view boundaries and load the view when you load a different solution.
  • You have a set of magnetic field solutions and want precision plots of field lines passing through specific points. Add a field line interactively in PerMag and save a template view file. Then edit the view file to remove unnecessary information, change the number of field lines and add coordinates for the desired points.
  • You want to create a large set of radial temperature scans moving along the axis of a probe assembly. In TDiff, create a template view file for one scan. Write a Python or Perl script with a loop of axial positions that modifies the axial scan coordinates in the view file and then runs TDiff in the analysis mode. The set of BMP files could then be stitched into an AVI movie with our Cecil_B utility.
  • A sequence of annotated view files could be employed in a training session or educational demonstration.
  • You want to show how the levels of magnetic flux induction change with changing coil currents, preserving magnitude scaling in the plots. After creating a set of solutions, load one of them adjust the view, plot style and plot quantity. Turn off autoscaling, specify values for BMin and BMax and then save a view file. Load the view for the other solutions.

Modeling laminated cores in Magnum and PerMag

Although Magnum and PerMag are magnetostatic codes, they can often be used to find AC magnetic field distributions (e.g., transformers and motors). A static field calculation provides a good approximation when the electromagnetic wavelength is much larger than the system scale length. The issue is complicated by the presence of iron and steel, because the speed of light is reduced by a factor 1/Δr, where Δr is the relative magnetic permeability. The quantity is defined as the ratio of the total magnetic flux density inside the iron compared to the applied value:

Δr = B/B0.    [1]

The permeability characterizes the contribution of material currents to the total magnetic field.

An AC magnetic field at frequency f0 (Hz) can penetrate a block of iron or steel to a distance given by the skin depth:

δ= √[ρ/(π*μr*Δr*f0)].    [2]

where ρ is the volume resistivity in Ω-m. The steels used in transformers have high μr (several thousand) and low resistivity. For example, nickel steel has μr = 8000 and ? = 45 × 10[-7] Ω-m. At f0 = 1.0 KHz, the skin depth is only δ = 0.12 mm (4.7 mil). Therefore, steel structures used for AC magnets are laminated, fabricated from thin sheets separated by insulators. The orientation of the laminations follows the direction of the magnetic field in the magnetic circuit, as in the figure below. If the lamination thickness is smaller than δ, the field penetrates each lamination so that the magnetic properties are almost the same as for static fields.

Laminated core

Laminated core

In a practical finite-element calculation of a macroscopic device, we approximate cores with many thin lamina as a homogeneous object. In principle, a laminated core has an anisotropic permeability, with μr » 1 along the lamina and μr ~ 1 perpendicular to them. In practice, the field lines and lamina are generally in the same direction in the yokes and poles of magnetic circuits. In consequence, we can neglect the normal field component and use a single value of μr for the component parallel to the lamina.

The relative magnetic permeability of the insulating layers of a laminated core is μr ≈ 1.0. The fill fraction f is defined as the fraction of the core cross-section occupied by steel. In magnet calculations, we must account for the missing core material. To begin, suppose the system operates with magnetic flux density B in the lamina well below the saturation value. In this case, we can use a fixed value of μr throughout the core material. The effective magnetic permeability of the laminated core is defined as average magnetic flux density inside the core compared to the applied value.

<μr> = <B>/B0 = [μr*B0*f + B0*(1-f)]/B0 = μr*f + (1-f).     [3]

The second term on right-hand side is usually small compared to first. To include the effect of the fill fraction, we use a reduced value of relative permeability for the core. For example, if μr = 2000 and f = 0.80, then <μr> = 1600.

Next, consider a core represented by a magnetization curve. The curve has the form μr(B0) in Magnum and μr(<B>) in PerMag. For Magnum calculations, the code determines a local value of μr for a known value of B0. To represent a laminated core, we prepare a table where no changes are made to the independent values (B0) and μr values are adjusted according to Eq. [3]. For a PerMag calculation, must make two changes to the table. First, if the calculation were expressed as μr(B) (where B is the magnetic flux density inside the lamination), the dependent values of μr would be reduced according to Eq. [3]. On the other hand, the code uses the value of <B> for the interpolation, where

<B> = B*f + (B/μr)*(1-f)  μrB*f. [4]

Therefore, we should multiply values along the abscissa by f. Forexample, if a material saturates at a field of 2.0 tesla inside the lamination, saturation would occur at an average magnetic flux density <B> = 1.5 tesla for f = 0.75.

In summary, here is how to modify magnetization tables when there is a fill fraction f:

  • For Magnum tables of μr(B0), multiply μr values by f.
  • For PerMag tables of μr(B), multiply both μr and B values by f.

Interaction forcing in GamBet

Recently, a GamBet user reported calculations where the code violated conservation of energy by several orders of magnitude. This is the type of statement that generally catches my attention, so I decided to investigate the issue. An inspection of his input files showed that he was using a bremsstrahlung forcing factor of 1000. If I were implementing variance reduction, I would pick a factor of 20, while a value of 100 would make me nervous (my choices are reflected in the parameters of the application examples supplied with the code). On the other hand, I never said not to use 1000 (or even 10,0000) in the instruction manual, so some guidance is needed.

To review, interaction forcing is used in GamBet to improve statistics for low-probability events like photon-production via bremsstrahlung or pair production. In the Penelope routines, the probability of an event is increased by Fb, but the weight of secondary particles (and their descendants) is decreased by 1/Fb. If you use Fb = 100 to find a bremsstrahlung spectrum, the variance between bins is decreased by about a factor of 10. At the same time, the run time should be significantly less than Fb times the run time with no forcing.

The user’s example involved a 16 MeV electron beam striking a 6 mm thick sheet of tantalum. To understand the effect of forcing factor on the validity of results, I made a series of runs with different values of Fb. The first plot shows the global energy balance as a function of Fb. Here, GamBet sums energy lost from primary and secondary particles to the escape file and to absorption in the solution volume. The code compares this value to the input energy of primaries. The plot shows that conservation of energy holds to within a few percent up to Fb = 100. An abrupt change occurs near Fb = 150 — energy conservation is lost at higher values. The second plot shows the run time versus Fb. It increases linearly (as expected) up to around Fb = 150 and then saturates.

Energy error as a function of forcing function

Energy error as a function of forcing factor

I identified the cause of the problem as overflow of the Penelope secondary-particle stack. In a shower calculation, Penelope tracks a primary particle and stores the parameters of secondaries on the stack. Then it pops each secondary from the stack and tracks it. In the process, additional secondaries may be pushed on the stack. Tracking continues until the stack is empty, and then the code proceeds to the next primary. The Penelope routines do not halt program operation when an overflow occurs because there may be rare showers with a large number of secondaries. Rather, Penelope ignores extra secondaries leading to unaccounted energy. Application of a forcing factor increases the number of entries per shower to store on the stack by about a factor of Fb. Therefore, a value Fb = 1000 could clearly lead to trouble. I confirmed the hypothesis by increasing the stack size from 2000 to 5000 entries. In this case, energy was conserved to Fb = 200.

Run time as a function of forcing factor

To reduce the chance of errors in future user calculations, I made some changes in GamBet:

  1. I increased the secondary stack size to 5000. The larger static array increases the code RAM utilization by only about 10 MB.
  2. I added cautionary material to the section on the FORCE command in the GamBet reference manual.
  3. I modified GamBet to count the number of instances of stack overflow. If the value exceeds zero, the code writes a warning in the listing file (GLS).

Finally, we can gauge the utility of interaction forcing from low-Fb entries in the second plot. The run time was 5 seconds for Fb = 1. It increased to 103 seconds with Fb = 100. To get the same statistics for the bremsstrahlung spectrum with Fb = 1, we would need to increase the number of showers by a factor of 100, giving a run time of about 500 seconds. In this case, interaction forcing reduces the run time to achieve a given statistical accuracy by about a factor of 5.