Multitasking made easy

Field Precision programs are optimized for the latest generation of multi-core or multi-processor PCs. The 64-bit major solution programs (HiPhi, Magnum, GamBet,…) feature true parallel operation. The time-intensive subroutines have been coded in OpenMP, giving significant improvements in speed (see magnum-in-parallel or multicore-gambet). A second feature is the capability to run multiple independent calculations simultaneously. All the solution programs can run in the background if launched from a Windows batch file. Background operation is automatic and faster than running in a window. Unfortunately, this capability is often overlooked because of the effort required to create batch files and to keep track of what tasks are running. The problem was brought home to me during a recent consulting project where I needed to make an extended sequence of Trak calculations with small changes in geometry. Each step involved re-running three programs. Even though I was well aware of the batch file capability, laziness prevailed and I ran each calculation interactively. My irritation level was not quite high enough to overcome my inertia. We recently added a new feature to our program launchers (TC, AMaze, GBLaunch and Xenos) that should tip the balance — the ability to create and to run Tasks. A Task is any sequence of installed programs and input files for a background run. With the feature you can 1) quickly define Tasks in an interactive dialog, 2) launch simultaneous Tasks in the background and 3) find out which tasks are running. I’ll discuss how it works in this article.

Figure 1. Task control group in the TC program launcher.

Figure 1. Task control group in the TC program launcher.

Figure 1 shows the new Task control group in the TC program launcher. The CREATE TASK button calls up the dialog of Figure 2. The user supplies a file prefix FPREFIX that indicates the function of the Task. The Task information will be stored in a DOS batch file FPREFIX.BAT created in the current TC data directory. Commands in the file are compatible with all recent Windows versions including Windows 7.

Figure 2. Create task dialog

Figure 2. Create task dialog

Each row represents an operation (batch file command). The first column defines the action. Clicking on a cell brings up a menu that includes all TriComp programs capable of background operation that are installed on the user’s computer. In addition, several relatively safe DOS commands are included (ERASE, COPY, MOVE, RENAME and REM). All commands operate on a file (FILEIN). The DOS commands COPY, MOVE and RENAME require a second file name (FILEOUT). You can type file names in the cells. By default, the files are in the TC working directory, but you can include path information if the files are in other directories. Alternatively, you can click in a cell and pick the SELECT FILE command to raise the standard Windows dialog for choosing files anywhere on the computer. There is a nice feature for the TriComp programs — only files with appropriate suffixes are displayed (e.g., *.EIN or *.SCR for EStat).

Click the OK button when the sequence is complete to create the batch file. Here is an example:

REM TriComp batch file, Field Precision
START /B /WAIT C:\fieldp\tricomp\mesh64.exe C:\Temp\convergegun
START /B /WAIT C:\fieldp\tricomp\estat64.exe C:\Temp\convergegun
START /B /WAIT C:\fieldp\tricomp\trak64.exe C:\Temp\convergegun
ERASE *.?ls
START /B /WAIT C:\fieldp\tricomp\notify.exe
IF EXIST Electrode01.ACTIVE ERASE Electrode01.ACTIVE

The operations listed perform a complete Trak calculation in the background and then erase all listing files. Here are some notable features:

  • The operations are performed sequentially because data from one operation may be used in the next. To run calculations in parallel, define and run multiple Tasks.
  • You can modify the file with an editor if you are familiar with DOS commands.
  • The DOS commands recognize the standard wildcard conventions (* for any character grouping, ? for any character).
  • The programs adds the command notify.exe to the task sequence if AUDIO ALARM is checked. In this case, the computer beeps when a task is completed.
  • The final command to erase a file FPREFIX.ACTIVE is added to all batch files. The presence of an activate file indicates that the task is running.
Figure 3. Run task dialog

Figure 3. Run task dialog

Click the RUN TASK button when you have created Tasks or moved predefined task files to the data directory. The dialog (Figure 3) organizes tasks into two groups: ones that are available to run and ones that are currently running (i.e., FPREFIX.ACTIVE has been detected). To launch a task, choose one from the top list and click OK. The program creates a file FPREFIX.ACTIVE and runs the batch file. The program sequence runs silently in the background and the results appear almost magically. In the meantime, you can prepare other inputs or run other tasks.

This year, we’re concentrating on program features to improve the user experience. We have two goals: 1) increase the computation speed and efficiency and 2) reduce the setup times. Clearly, users should worry less about program details so they can concentrate on physic issues. Our next job is to add macro capabilities to the 2D and 3D postprocessors. With this feature, the programs will remember the steps in a session to create an analysis script.

Popup menus in RealBasic

Popup (or contextual) menus appear when you right-click the mouse. They are a part of almost every Windows program. Nonetheless, it took me some effort to find out how to create popup menus in RealBasic with all the features that I needed. The examples supplied by Real Studio were either out-of-date or simplistic. The only other alternative was the user forum. I find it difficult to get useful information from forum threads, and I wish search engines didn’t include them. Many of the answers are off-the-point or even totally wrong. Spelling is iffy and grammar is almost non-existent. The layout is often confusing (i.e., each answer often shows all the previous correspondence), so it’s difficult to gauge where you are on the path to a solution. Finally, the worst case is when you have to register to see the answer. Registering gets old after the first 1500 sites.

Example of a popup menu in RealBasic

Example of a popup menu in RealBasic

This article shows how to set up a popup menu using the current routines of RealBasic. An important feature is setting the enable status of menu entries. Except in the simplest programs, entries must be disabled depending on the program context to avoid illegal operations (i.e., save a entity that hasn’t yet been created).

The example produces the popup menu shown in Fig. 1. Notice that some entries are grayed because rulers do not exist when the program opens. The code listed below is included in the MouseDown event of the associated window. Note the comment numbers added to the Append statement documenting the order of entries (separators don’t count). These indices are used in the code lines that set the enable status. It’s important to include the test

if (HitItem <> nil) then
end if

to avoid an error if the user clicks on a disabled menu entry.

if IsContextualClick then
// ===============================
// Define menu extries
// ===============================
dim base as new MenuItem
base.Append( new MenuItem( "Create ruler" ) )  '1
base.Append( new MenuItem( "Analyze graph" ) )  '2
base.Append( new MenuItem( "Analyze drawing" ) )  '3
base.Append( new MenuItem( MenuItem.TextSeparator ) )
base.Append( new MenuItem( "Flip ruler" ) )  '4
base.Append( new MenuItem( "Hide/show rulers" ) )  '5
base.Append( new MenuItem( "Close ruler" ) )  '6
base.Append( new MenuItem( "Save ruler" ) )  '7
base.Append( new MenuItem( "Load ruler" ) )  '8
base.Append( new MenuItem( MenuItem.TextSeparator ) )
base.Append( new MenuItem( "Instruction manual" ) )  '9
base.Append( new MenuItem( "About FP UniScale" ) )  '10
base.Append( new MenuItem( MenuItem.TextSeparator ) )
base.Append( new MenuItem( "Exit program" ) )  '11

// ===============================
// Set the enabled status
// ===============================
if (RulersHidden) then
base.item(4).enabled = False   'Flip ruler
base.item(5).enabled = True    'Hide/show rulers
base.item(6).enabled = False   'Close ruler
base.item(7).enabled = False   'Save ruler
base.item(8).enabled = False   'Load ruler
else
// Ruler1 closed, Ruler2 closed
if ((not RulerOpen1) and (not RulerOpen2)) then
base.item(4).enabled = False  'Flip ruler
base.item(5).enabled = False  'Hide/show rulers
base.item(6).enabled = False  'Close ruler
base.item(7).enabled = False  'Save ruler
base.item(8).enabled = True   'Load ruler
// Ruler1 open, Ruler2 closed
elseif (RulerOpen1 and (not RulerOpen2)) then
base.item(4).enabled = True   'Flip ruler
base.item(5).enabled = True   'Hide/show rulers
base.item(6).enabled = True   'Close ruler
base.item(7).enabled = True   'Save ruler
base.item(8).enabled = True   'Load ruler

// Ruler1 closed, Ruler2 open
elseif ((not RulerOpen1) and RulerOpen2) then
base.item(4).enabled = True   'Flip ruler
base.item(5).enabled = True   'Hide/show rulers
base.item(6).enabled = True   'Close ruler
base.item(7).enabled = True   'Save ruler
base.item(8).enabled = True   'Load ruler
// Ruler1 open, Ruler2 open
else
base.item(4).enabled = True   'Flip ruler
base.item(5).enabled = True   'Hide/show rulers
base.item(6).enabled = True   'Close ruler
base.item(7).enabled = True   'Save ruler
base.item(8).enabled = False  'Load ruler
end if
end if

// ===============================
// Carry out actions
// ===============================
dim hitItem as MenuItem
hitItem = base.PopUp
if (HitItem <> nil) then
select case (HitItem.Text)
case("Analyze graph")
// Action code
case("Analyze drawing")
// Action code
case("Create ruler")
// Action code
case ("Flip ruler")
// Action code
case ("Load ruler")
// Action code
case ("Save ruler")
// Action code
case ("Close ruler")
// Action code
case("Instruction manual")
// Action code
case("About FP UniScale")
// Action code
case("Exit program")
// Action code
end select
end if
return true
end if

Measure anything on your computer screen

One of my all-time treasured possessions is a Gerber Variable Scale [1] (Fig. 1). It was an absolute must-have if you were doing science in the 60s and 70s. The idea was straightforward — the device was a ruler consisting of a precision spring that you could adjust to any length to match graphs or oscillographs [2]. Simple but remarkably useful!

Figure 1. The Gerber Variable Scale (circa 1970)

Figure 1. The Gerber Variable Scale (circa 1970)

Nowadays, practically everything I measure is on a computer screen. For this application, it’s almost impossible to use my old Gerber scale, although I have tried many times. For a couple decades, my dream has been to make something I could use on the computer that would be as useful and (hopefully) as simple. I tried several freeware screen rulers, but the results were disappointing. They were designed to measure literal distances on the computer screen (in pixels, mm, …) rather than the lengths of objects displayed on the screen. The situation was analogous to having a ruler that could measure the size of a sheet of paper, but not the dimensions of data printed on the paper.

I am happy to announce that I have just completed my vision of the ideal screen measurement system, the Field Precision Universal Scale. With it, you can create custom rulers calibrated to graphical objects displayed on your computer screen by any program. The Universal Scale has other analysis features that extend well beyond simple rulers. The program is available for free download as a service of Field Precision to the science and engineering communities. The official release date is January 1, 2012. You can get a beta copy now at http://www.fieldp.com/fpuniscale.html.

Figure 2. Universal Scale main window and sample ruler.

Figure 2. Universal Scale main window and sample ruler.

Figure 2 shows the main window with a ruler displayed. Note that the program comes in a nice leather case. The push buttons on the left call up the three main functions:

  • Create custom rulers that may be moved around the screen over other applications.
  • Measure points and digitize curves of graphs in publications and reports.
  • Measure dimensions on drawings and diagrams in documents.

Figure 3 shows a screenshot of a drawing analysis. In the remainder of this article, I’ll describe some interesting features of the program.

Figure 3. Set up to analyze dimensions of a diagram in a publication.

Figure 3. Set up to analyze dimensions of a diagram in a publication.

  • My Gerber Variable Scale may lie in a drawer for months between uses. When I take it out, I never have doubts about how it works. I tried to maintain the same user-friendliness in the Universal Scale. The challenge is that the program does a lot more than slide back-and-forth. I limited the program to few well-defined functions with minimal bells-and-whistles. Contextual instructions are displayed at each step, so it’s not necessary for users to memorize procedures.
  • Measurements with physical devices used to be fun in the old days, so I gave the program a retro look.
  • Calibration sheets are the key to program operation. They are translucent windows that act like tracing paper that can be moved over any displayed graphical material on the computer screen. Mouse clicks in the measurement sheet are used to calibrate rulers, graphs and drawings and to measure points.
  • I applied my experience with normal coordinates in finite-element analysis to measurements on graphs. The program uses a generalized trapezoid coordinate system. This means that you can obtain good measurements from badly-scanned graphs (rotations, distortions,…).

Footnotes

[1] Unfortunately, it appears that the Gerber Variable Scale is no longer available for purchase. As a matter of historical interest, here is a link to the original manual: GerberVariableScale.pdf.

[2] Oscillographs were Polaroid photographs of oscilloscope traces, the only way to record fast transient data before digitizers.

Website introduction video

We’ve added a lot of content to our website at www.fieldp.com in 13 years. In fact, there’s so much material that the site might intimidating to first-time visitors looking for software or educational resources. To help, we’ve added a short overview video on the home page. Here it is:

Particle flux plots in Gendist

A recent consulting project involved Xenos simulations of an intense, non-circular electron beam striking a graphite beam stop. A phosphor plate on the downstream face of the target was used as a diagnostic. The researchers wanted to know how the shape of the phosphor response correlated with the shape of the beam. One option was to add the phosphor plate as a region in a GamBet simulation and then to plot dose distribution as a slice plot in GBView3.

For the design of other diagnostics, the researchers wanted the spatial distribution of the X-ray flux emitted from the target. Such plots could be created using the GenDist utility program from information in the GamBet escape file. The escape file is a record of parameters for all particles leaving the solution volume. GenDist is a general-purpose program to create and to analyze large distributions of particles (e.g., electrons, ions, photons, positrons). For the application, the procedure was to load the escape file into GenDist and then to add filters that admit only photons at the exit face (i.e., z coordinate great than or equal to the exit face position). Of the GenDist plot types, the 2D histogram was appropriate for the application. Here, particles are assigned to a 2D matrix of bins according to their position in the x-y plane. The probability function N(x,y) may be weighted by the model particle current, energy or combined current/energy. In this way, the program can generate spatial distributions of the following quantities:

  • Model particle density.
  • Particle flux (weighted by model-particle current or flux).
  • Power flux (weighted by model-particle current and kinetic energy).

The previous version of GenDist had only one available style for 2D histograms —  a projected 3D view showing N(x,y) as height above the x-y plane. Although the style gave attractive plots for presentations, it was not useful for quantitative work. We added the three new styles shown in the figure for better display of spatial particle distributions:

  • The existing 3D bin height plot improved with color coding.
  • A 3D plot with bin height displayed as an interpolated shape.
  • A 2D contour line plot, showing surfaces of equal probability density.
  • A 2D filled contour plot.
  • Plot styles for the 2D histogram type in GenDist
Plot styles for the 2D histogram type in GenDist

b) 3D plot with bin height display as an interpolated shape.
3) 2D contour line plot, showing surfaces of equal probability density.
4) 2D filled contour plot.