Solving 5997 differential equations under Microsoft Windows 95 and NT

Solving 5997 differential equations under Microsoft Windows 95 and NT

Mathematics and Computers in Simulation 47 (1998) 571±582 Solving 5997 differential equations under Microsoft Windows 95 and NT Granino A. Korna,* a ...

1MB Sizes 0 Downloads 64 Views

Mathematics and Computers in Simulation 47 (1998) 571±582

Solving 5997 differential equations under Microsoft Windows 95 and NT Granino A. Korna,* a

ECE Department, The University of Arizona, Tuscon, AZ 85021, USA Received 28 May 1997; accepted 19 June 1998

Abstract New simulation software combines Editor Windows for convenient modeling and file manipulation with a Command Window that automatically switches to full-screen color graphics while a simulation runs. Under Windows 95, the new program preempts the CPU, so that Windows does not compromise solution speed during the time-critical simulation runs. Windows multitasking works at all other times. Extra-fast runtime compilation and Pentium-optimized machine code let you quickly try and compare different models programmed in multiple editor windows. You can also program your own special dialog windows for data entry, model changes, and note keeping. Large problems can include up to 6000 first-order differential equations, plus neural networks and fuzzy logic. As an example, we solve the telegrapher's partial differential equation (delay-line equation) by the method of lines. We solve thousands of simultaneous differential equations first in scalar form and then using DESIRE's compact vector notation. # 1998 IMACS/Elsevier Science B.V. Keywords: Windows 95; Differential equations; DESIRE

1. We combine user-friendly windows and very high computing speed Interactive modeling of dynamic systems requires not only fast solution of differential equations and/ or difference equations but also a facility for convenient editing of simulation models and for the experiment protocols which program successive simulation runs. High speed requires compiled simulation-run code, and we need a very fast compiler to avoid interrupting an experimenter's train of thought with translation delays. Modern graphical user interfaces can be configured to permit very convenient model changes and file manipulation. Microsoft Windows 95TM and Windows NTTM make it especially easy to manipulate simulation programs in multiple windows with toolbars and help menus. Windows multitasking can share the ÐÐÐÐ * Correspondence address: G.A. and T.M. Korn Industrial Consultants, Dynamic System Simulation, RR 1, Box 96C, Chelan, WA 98816, USA. 0378-4754/98/$19.00 # 1998 IMACS/Elsevier Science B.V. All rights reserved PII S 0 3 7 8 - 4 7 5 4 ( 9 8 ) 0 0 1 3 9 - 6

572

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

simulation screen with other useful applications. Such convenient graphical user interfaces, though, normally slow the program execution. This can be a very serious problem for time-critical differentialequation-solving simulation, and especially for large neural networks. But under Windows 95 we can combine user-friendly Windows operations with execution just as fast as under old-fashioned MS-DOS. DESIRE/N96T combines an interactive experiment-protocol interpreter for setting parameters and initial conditions with a fast runtime compiler for the timecritical simulation-run code [1,2]. DESIRE compiles Pentium-optimized machine code into memory and executes this code at once when the experiment protocol calls a simulation run. Quite unlike other simulation systems running under Windows 95, however, DESIRE/N96T preempts the CPU during simulation runs. This suspends all other tasks and produces full-screen color graphics at MS-DOS speed. Our three-dimensional-flight-simulation benchmark is as just fast under Windows 95 as under MS-DOS. Note that Windows multitasking stops only during the simulation run as such. During the rest of the experiment-protocol program, and also while you edit or debug a simulation, all windows (e.g. multiple editors, Explorer shells, graphics screens, and/or other programs) are displayed and can each be manipulated. 2. DESIRE editor and command windows Fig. 1 shows a DESIRE/N96T screen, which displays:  The Command Window. You activate this to accept keyboard input ± mainly function-key commands and mouse clicks. The Command Window can be maximized to display error messages (Fig. 2) and selected runtime output, such as time-history listings.  An Editor Window, with standard Windows 95 menus and convenient toolbar buttons for loading, editing, printing, and saving program files, plus context-sensitive help for these operations.  A Windows Explorer window with source-program icons. DESIRE Editor-window toolbar buttons implement standard Windows commands for file manipulation (New, Open, Save, Print, Print Preview) and for interactive editing (Cut, Copy, Paste, Find, Replace). Toolbar buttons have tooltip labels and status-bar text, and also contextsensitive help. You can thus load, enter, print-preview, print, save, and edit DESIRE program files (and, in fact, any text file) with familiar Windows-standard commands. Programs can be entered, saved, and printed with or without line numbers. However, the very fastest way to load user programs is to open an Explorer (file-manager) window or windows and to drag-and-drop user-program icons into a DESIRE Editor Window (Fig. 1). Also, double-clicking a source file opens it in a new Editor Window. 3. Editing and running a simulation A simulation program (experiment protocol and model description) composed in an Editor Window is transferred to DESIRE's runtime system by a mouse click on the OK or ADD toolbar button. Specifically, the OK Button transfers the editor-window text as a new program, while the ADD Button

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

573

Fig. 1. DESIRE Command and Editor Windows, with two Explorer Windows listing frequently used user programs and help screens. The Command Window accepts runtime commands, mouse clicks, and keyboard input. The Editor Window has menus and a toolbar for conventional File and Edit operations. You can drag source programs into the Editor Window or open them in new Editor Windows by double-clicking source-file icons. Clicking the OK Button on any Editor Window transfers its edited program to the runtime system; a mouse click in the Command Window immediately executes a simulation run. An icon for each window appears on the Windows Taskbar.

adds new text to a previously loaded DESIRE program. The ADD operation lets you combine subprograms and submodels, which can be stored in library files. We now run the simulation in the Command Window. One can activate the Command Window with a mouse click. A much better way is to preload Microsoft's small Xmouse utility.1 This automatically activates the window containing the mouse cursor. A click in the activated Command Window then immediately compiles and runs your simulation program. Simulation graphs begin to display in fullscreen mode (Fig. 3). Note that truly interactive simulation must produce time-history graphs while the simulation runs, since it saves time to terminate runs showing undesirable results. 1

Free from http://www.microsoft.com/windows/software/powertoy.htm.

574

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

Fig. 2. An error message in the maximized Command Window.

Typing any keys pauses and continues the simulation. Typing z terminates a paused simulation run, which can be an important time-saving feature. You can repeat the run by typing a function key, or by clicking the mouse twice. Typing Alt-Return transfers your full-screen graph to a window, so that graphs can also be viewed in a window next to the edited program (Fig. 4). The Print-Screen Key saves the graphs on the Windows Clipboard for editing, filing, and printing. To restore the normal Windows display for editing, click in the full-screen window, or type Return. You can then click again to rerun your program. More often, you will want to modify your program interactively by reactivating the editor window, and then click OK and run again. 4. Multiple editor windows let you compare models Typing Function Key F7 in the DESIRE Command Window opens a new empty Editor Window. You can also open any number of Editor Windows by double-clicking on source-file icons. You can then use their OK buttons to compare different programs, or modified versions of the same by successively transferring and running them from their Editor Windows.

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

575

Fig. 3. Full-screen display of simulation time histories for a fuzzy-logic-control simulation. The original display was in color; the small squares at the bottom of the screen are color keys.

5. Creating custom dialog windows Simulation experiments typically require repeated changes of just a few program lines, say Lines 110±134, 200, and 206. These lines typically assign data values, but they may also redefine functions, procedures, submodels, differential equations, or input and output files. You could easily make such changes in the main Editor Window, but it is nice to avoid repeated scrolling through large programs. For this reason, DESIRE program lines like 1200 edit 110ÿ134; 136ÿ139; 200; 205 produce a special type of editor window (deditor2 Window), which has no File menu and displays just the listed program lines for editing (Fig. 5). Like DESIRE Editor Windows, each deditor2 windows has an OK Button which transfers its edited text to DESIRE. This automatically inserts each numbered program line into its correct place in the program currently in memory. When the edited program runs satisfactorily, you can make the change permanent by typing Function Key F2 (keep) or shift-F2 (keep‡, i.e. keep and display without line numbers). This creates a new

576

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

Fig. 4. Typing Alt-Return displays a runtime graph in a window.

disk file and immediately displays the new program in a new Editor Window. You can then close the old main Editor Window, or else keep it for comparison. It is again possible to open more than one deditor2 Window, for the same or different program lines. You can then run and compare different versions of a simulation program by clicking OK in any Editor Window or deditor2 Window. We typically open a deditor2 Window with a specially labeled program segment label eee edit 110±134, 136±139, 200, 206 STOP

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

577

Fig. 5. Here a user-programmed dialog screen is used to enter and edit control-system parameters.

You can call the routine labeled with eee by typing Function Key F6 (go to eee). Such program segments can include comment lines, help text, and even character graphics. In this way, instructors or industrial users can program custom-made editing screens or dialog boxes for interactive programming (Fig. 5). 6. Software design The main DESIRE program combines an experiment-protocol interpreter, a runtime compiler, and a runtime library comprising integration and graphics routines, much like earlier DOS and UNIX versions [1,2]. We added mouse and function-key operations with a view to good ergonomics. The new Editor Windows, which handle Windows file manipulation as well as interactive editing, were programmed with Microsoft Visual C‡‡ to simplify the design of their graphical user interfaces. The DESIRE Command Window is a ``Command-prompt Window''. Under Windows 95, this window's Property Page was set up to ``use MS-DOS Mode as needed''. This lets the program preempt

578

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

the CPU during simulation runs. DESIRE then runs in the Command Window with the DOS4GW DOS extender supplied with the WATCOM C/C‡‡ compiler. WATCOM C was chosen because of its convenient and fast full-screen graphics library. 7. Obtaining help DESIRE Editor Windows provide standard Windows 95 F1, shift-F1, Help-menu help. In addition, clicking the toolbar Help Button (?) produces context-based help for each item on the editor screen. Other DESIRE help screens are ordinary text files collected in a special \backslash dhelp folder. You can drag-and-drop them into a DESIRE Editor Window, or open them in their own windows by doubleclicking. You can, then, easily add your own user-written help screens as ordinary text files. Perhaps the most important help screen lists the function-key operations. 8. Solving large simulation problems DESIRE/N96T solves up to 8000 differential equations in scalar or matrix form, using fixed- and variable-step Runge±Kutta integration rules; or up to 100 differential equations with variable-step/ variable-order Gear and Adams integration. DESIRE/NEUNET can add multiple neural networks and fuzzy logic controllers to ordinary dynamic-system simulation. DESIRE's compiled Pentium-optimized machine code compares favorably with Fortran-based differential equation solvers like ACSLTM DESIRE is dramatically faster than interpreted block-diagram simulators such as MATLAB/ SIMULINKTM or VisSimTM. As an example, the delay-line circuit of Fig. 6 involves n node voltages V[k] and n branch currents i[k] and i0 which satisfy the 2n‡1 scalar circuit equations: d=dt V‰1Š ˆ …i0 ÿ i‰1Š†=C …input circuit†;

(1)

d=dt i0 ˆ 2…vS ÿ rSi0 ÿ V‰1Š†=L; d=dt V‰kŠ ˆ …i‰k ÿ 1Š ÿ i‰kŠ†=C;

k ˆ 2; 3; :::; n;

d=dt i‰kŠ ˆ …V‰kŠ ÿ V‰k ‡ 1Š†=L;

k ˆ 1; 2; :::; n ÿ 1;

d=dt i‰nŠ ˆ 2…V‰nŠ ÿ rLi‰nŠ†=L …termination† The first two equations represent the source circuit, and the last equation represents the line termination. Fig. 7 illustrates the solution of such a problem in scalar form; for nˆ750, the source program takes 15 pages. With so many differential equations, it is convenient to use DESIRE's vector/matrix notation. Our vector operations are listed in Table 1. Vectors and matrices must be declared as arrays of subscripted variables or subscripted state variables. We declare state vectors representing n voltages V[k] and n currents i[k] with STATE V‰nŠ; i‰nŠ and introduce a ˆ 1=C;

b ˆ ÿ1=L:

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

579

Fig. 6. A delay-line circuit approximating a continuous delay line.

Now thousands of differential equations representing the repeating LC links in the middle of the delay would be neatly represented by just two simple DESIRE vector differential equations: MAT d=dt V ˆ a  …ifÿ1g ÿ i†;

MAT d=dt i ˆ b  …Vf1g ÿ V†;

where the DESIRE index-shift operator {k} shifts the associated vector components by k (Sections 4 and 5). But the equations for V[1] and i[n] would be incorrect. To represent all 2n‡1 scalar circuit Table 1 Examples of DESIRE/NEUNET VECTOR and MATRIX assignments (a, b, alpha are scalars; x, y, u, v vectors; W, A, B rectangular matrices) (a) Vectors yˆau‡bv yˆWx yˆrecip(v) yˆsin(x) yˆtanh(x‡y) yˆtanh(Wx‡alpha) yˆuv yˆv{n} y^ˆvector expression

y[i]ˆau[i]‡bv[i] P y‰iŠ ˆ k W‰i; kŠx‰kŠ y[i]ˆ1/v[i] y[i]ˆsin(x[i]) y[i]ˆtanh(x[i]‡y[i]) P y‰iŠ ˆ tanh… k W‰i; kŠx‰iŠ ‡ alpha† y[i]ˆu[i]v[i] y[i]ˆv[i‡n] y[i]ˆy[i] if y[i] is the largest y[i], else y[i]ˆ0

(b) Matrices WˆaA‡bB Wˆuv Wˆu&v Wˆsin(A) Wˆ(Aÿalpha)

W[i,k]ˆaA[i,k]‡bB[i,k] W[i,k]ˆu[i]v[k] W[i,k]ˆmin(u[i],v[k]) W[i,k]ˆsin(A[i,k]) W[i,k]ˆA[i,k]ÿalpha

(c) CLEARN yˆW(x) Irate, crit PLEARN yˆWx DOT alphaˆxy‡uAv‡  

Implements competitive learning Principal-axes transformation Inner products, bilinear forms

580

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

Fig. 7. Windows display for the delay-line problem showing two of 15 print-preview pages in the Editor Window (a), and a full-screen display (b) which demonstrates a reflection of the input step when the matched line-termination resistance of 50

is replaced by 200 (based on [1]).

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

581

equations correctly, we declare two auxiliary n-dimensional vectors VV, II with ARRAY VV‰nŠ; II‰nŠ: We now program our circuit equations as VV‰1Š ˆ a  i0;

II‰nŠ ˆ b  …2  i‰nŠ  rL ÿ V‰nŠ†;

d=dt i0 ˆ 2  b  …V‰1Š ‡ i0  rS ÿ vS†; MAT d=dt V ˆ a  …ifÿ1g ÿ i† ‡ VV; MAT d=dt i ˆ b  …Vf1g ÿ V† ‡ II: The ARRAY declaration sets all VV[k] and II[k] to 0 until the program specifically modifies them, so that only VV[1] and II[n] will differ from 0. i[ÿ1] and V[n‡1], which would fall outside the declared index range, are also automatically replaced by 0. Our program, therefore, is exactly equivalent to the scalar-differential-equation system (Eq. (1)). We can select values of n as large as, say, 2995 to solve 5991 first-order differential equations. 9. Simulation under different operating systems DESIRE/N96T works, with minor command changes, under Windows NT Versions 3.51 and 4.0 as well as under Windows 95. Unlike Windows 95, NT will not let one program preempt all its resources without special modifications. Since the runtime program in the Command Window is, in fact, an MSDOS program, simple configuration-file changes let it work so under standalone MS-DOS, and under OS/2. The configuration changes mainly replace the Windows editors with appropriate DOS screen editors. Different, but similarly convenient, XWindows versions of DESIRE and DESIRE/NEUNET run on Sum SPARCstations. But DESIRE/N96T lets inexpensive Pentium-Pro-based personal computers, and even ordinary Pentium machines, compete seriously with RISC-based engineering workstations in dynamic-system simulation, because time-critical segments are written in Pentium-optimized machine language rather than C or Fortran. A 133 MHz Pentium PC ran our three-dimensional-flightsimulation benchmark over 10 times faster than the C program on a SPARCstation 10. Newer 64-bit RISC workstations do have faster floating-point operations than a Pentium Pro, but the latter still wins when it uses machine language, which would not be easy to write for multi-pipeline RISC processors. 10. Conclusions A new and different software design produced a very convenient Windows user interface for teaching and learning, as well as for industrial users. Users already familiar with Windows do not need to learn any new file-manipulation or edition operations. Under Windows 95, more over, simulations preempt the CPU and run at full speed by interrupting the multitasking operation temporarily. Splitting the software design into a set of powerful Editor Windows and a full-screen command module also

582

G.A. Korn / Mathematics and Computers in Simulation 47 (1998) 571±582

simplified the software design and reduced the price of this relatively large software package to $675, or $775 with the addition of neural networks and fuzzy logic. References [1] G.A. Korn, Dynamic-system Simulation with Microsoft Windows 95 and NT, G.A. and T.M. Korn Industrial Consultants, RR1, Box 96C, Chelan, WA, 98816, in print. [2] G.A. Korn, Neural Networks and Fuzzy-logic Control on Personal Computers and Workstations, MIT Press, Cambridge, MA, 1995.