Intellectual Ammunition Department

Ada in Science

ASTROPHYSICAL MODELLING USING ADA:
a new family of spectral line synthesis codes

by G. Koenighofer and M.J. Stift
Wien, 1-Sep-1994

BACKGROUND
As in many other astronomical institutions, scientists at the Institute for Astronomy of the University of Vienna, Austria, run numerical codes that synthesise stellar spectra from appropriate stellar atmospheric models and atomic data. Applications range from the determination of stellar elemental abundances and of macroscopic velocity fields (oscillatory or turbulent) to the diagnosis of full Stokes profiles of selected atomic transitions in magnetic stars in view of unveiling the magnetic geometry.

Since in general the observed stellar spectra cannot be directly inverted to yield the unknown physical quantities such as temperature, elemental abundance or magnetic field strength, they have to be compared with a large variety of synthesised spectra. Obviously, the choice of physical input quantities, numerical techniques, and assumptions concerning the magnetic geometry is crucial for any realistic modelling of the physical world.

These applications are numerically very intensive. The opacity has to be sampled at sufficiently close frequencies to fully resolve the spectral lines and the equation of radiative transfer solved at each of these frequencies. For homogeneous stellar surfaces and in the absence of macroscopic velocity fields one can immediately calculate the emerging flux, but more generally one has to carry out a spatial integration on a 2D grid duly taking into account Doppler shifts and changes in physical quantities over the visible stellar surface.

At the core of all codes in use one therefore finds SUBROUTINES (not PROCEDURES since in the conservative astronomical community FORTRAN dominates everywhere) designed to calculate line shapes and to solve the equation of transfer. These subroutines are embedded in (usually unstructured) codes that provide for the application to the particular problem such as radially and/or nonradially pulsating stars or magnetic stars.

SOFTWARE REQUIREMENTS
In sharp contrast to a l l other relevant codes known to us the spectral line synthesis codes presented here are written in DEC Ada running on VAX and Alpha AXP processors under OpenVMS. The codes work with 2D grids in addition to the above-mentioned core; the different versions represent various degrees of complexity in the modelling of stellar spectral line profiles allowing the inclusion of macroscopic velocity fields (rotation, pulsation, macroturbulence), of magnetic fields and/or overlapping lines (called blends). The software is coupled to graphics libraries written partly in FORTRAN (for historical reasons); these are presently been converted to Ada.

We want to mention 4 points which have led to the choice of Ada:

  1. One crucial part of the software concerns the management of the 2D surface grid. This grid has to adapt itself to the distribution of a number of physical and geometric quantities over the visible stellar surface and will change with rotational and pulsational phase. The main goal is the minimisation of the number of surface elements, hence a minimisation of computing time; at the same time correct numerical integration has to be ensured. In an earlier version of this software written in FORTRAN - no dynamic allocation being possible - oversized one-dimensional arrays and a system of indices pointing into these arrays implemented the adaptive grid. Even worse, in FORTRAN this behaviour had to be made visible to all 'physics' subroutines; tedious and error-prone, it cluttered the 'physics' code.

    In Ada the self-adaptive grid could be designed as an Ada-package, hiding the implementation details, providing well defined services. The 'physics' parts of the software only contain simple calls to these services. The implemention of this package was easy: dynamic allocation of array-slices, passive iterators and recursive invocation reduced the lines of code to a fraction and increased the readability of the code. Experiments to enhance the performance of the surface grid do no longer affect the 'physics' code.

  2. The handling of Stokes vectors - with 4 components which fully describe the polarisation status of light - on the one hand and of coordinate vectors and transformation matrices on the other hand is also made easier thanks to operator-overloading in vector and matrix calculations, leading to increased abstraction, readability and reduction of code size.

  3. The physical models are expected to frequently change due to progress in this area of stellar astrophysics. 'Design for change' is a major programming principle and the concurrent existence of software-variants is a non-negligible fact.

    The definition of Ada-packages representing abstract data types leads to a 'single-point-of-change' design. A simple modification (followed by massive recompilation) and a new variation of the physical model can be examined. The Ada library system allows even more elaborate variant control.

  4. The strict standards, the imminent release of Ada9X, the pledge of the DoD to support Ada for at least another 10 years, the increasing use of Ada in the space community and especially the report "Ada and C++: A Business Case Analysis" have encouraged us to choose Ada as our astrophysical programming language for the decades to come.

THE TRANSITION TO ADA
Most fellow scientists (in particular astronomers) are convinced that the transition from FORTRAN to Ada has to be painful at best, disruptive and counterproductive at worst. Almost 30 years of FORTRAN have narrowed their outlook: "Whatever the future of programming languages is, its name will be FORTRAN!". Productivity, maintainability and reuseability are weak arguments in their ears and lack of software-correctness is an accepted feature.

For the unexperienced who has grown up with FORTRAN IV and who has lived with FORTRAN 77 (Stift) it took a few weeks to completely switch to Ada (possibly previous experience with ALGOL has helped). Students with no programming experience have mastered Ada without any problems (rather better than FORTRAN). The main difficulties arose with the use of generics and exceptions, so these features remained unused in the beginning. Advances were propagated by private communication. No CASE tools were used. On the whole the transition worked out smooth, painless and highly rewarding.

Numerical performance is of utmost importance in most complex astrophysical codes, so the first thing we did was to conduct some performance tests comparing the old FORTRAN with the new Ada versions. Although we had the biased condition of decades of experience in efficient FORTRAN-coding and only some months of Ada experience, the Ada programs had roughly the same speed as their FORTRAN counterparts (at most 15% slower)!

The full advantages of Ada showed up when one of us (Stift) extended the original Ada code to synthesise full spectral regions with dozens of blends in all 4 Stokes parameters for rotating and pulsating magnetic stars. A previous attempt in FORTRAN was only partly successful after weeks of programming because of the limited possibilities of FORTRAN. In Ada the different objects could easily be represented by appropriately defined types, leading to the solution of the problem by an Ada-novice in a mere 2 days! There seems to exist no limit to the complexity of problems that can be effectively dealt with in Ada.

To do things that were not possible before (in an amazingly short time-scale), breaking the complexity barrier, are convincing arguments for a transition! The enhanced readability of the code lead to the statement: "Ada is the real FORmula TRANslator!"

PROPAGATING ADA IN THE ASTRONOMICAL COMMUNITY
Ada training is virtually non-existent among astronomers. We also noted that there seem to exist no appropriate Ada-books dealing with our field of application. An attempt is therefore made in Vienna this autumn to improve the situation with a series of lectures by one of us (Koenighofer) on how to exploit the features of Ada (and Ada9X) for astrophysical modelling purposes.


For further information, please contact:
Univ.Doz. Dr. Martin J. Stift 
Institute for Astronomy, Tuerkenschanzstrasse 17, A-1180 Wien, Austria
Tel.: +43 (1) 470 68 00 91
E-mail: Stift@astro.ast.univie.ac.at

Gerhard Koenighofer
Institute for Astronomy, Tuerkenschanzstrasse 17, A-1180 Wien, Austria
and Swing Entwicklung Betrieblicher Informationssysteme Ges.m.b.H
Glasauerg. 32, A-1130 Wien, Austria
E-mail: Koenighofer@astro.ast.univie.ac.at