  A convenient representation of the structure of the large-scale galactic
magnetic field is required for the interpretation of polarization data in the
sub-mm and radio ranges, in both the Milky Way and external galaxies. We
develop a simple and flexible approach to construct parametrised models of the
large-scale magnetic field of the Milky Way and other disc galaxies, based on
physically justifiable models of magnetic field structure. The resulting models
are designed to be optimised against available observational data.
Representations for the large-scale magnetic fields in the flared disc and
spherical halo of a disc galaxy were obtained in the form of series expansions
whose coefficients can be calculated from observable or theoretically known
galactic properties. The functional basis for the expansions is derived as
eigenfunctions of the mean-field dynamo equation or of the vectorial magnetic
diffusion equation. The solutions presented are axially symmetric but the
approach can be extended straightforwardly to non-axisymmetric cases. The
magnetic fields are solenoidal by construction, can be helical, and are
parametrised in terms of observable properties of the host object, such as the
rotation curve and the shape of the gaseous disc. The magnetic field in the
disc can have a prescribed number of field reversals at any specified radii.
Both the disc and halo magnetic fields can separately have either dipolar or
quadrupolar symmetry. The model is implemented as a publicly available software
package GalMag which allows, in particular, the computation of the synchrotron
emission and Faraday rotation produced by the model's magnetic field. The model
can be used in interpretations of observations of magnetic fields in the Milky
Way and other spiral galaxies, in particular as a prior in Bayesian analyses.
(Abridged.)
