  Cosmic rays (CRs) play a decisive role within our own Galaxy. They provide
partial pressure support against gravity, they trace past energetic events such
as supernovae, and they reveal the underlying structure of the baryonic matter
distribution through their interactions. To study the impact of CRs on galaxy
and cosmic structure formation and evolution, we develop an approximative
framework for treating dynamical and radiative effects of CRs in cosmological
simulations. Our guiding principle is to try to find a balance between
capturing as many physical properties of CR populations as possible while at
the same time requiring as little extra computational resources as possible. We
approximate the CR spectrum of each fluid element by a single power-law, with
spatially and temporally varying normalisation, low-energy cut-off, and
spectral index. Principles of conservation of particle number, energy, and
pressure are then used to derive evolution equations for the basic variables
describing the CR spectrum, both due to adiabatic and non-adiabatic processes.
The processes considered include compression and rarefaction, CR injection via
shocks in supernova remnants, injection in structure formation shock waves,
in-situ re-acceleration of CRs, CR spatial diffusion, CR energy losses due to
Coulomb interactions, ionisation losses, Bremsstrahlung losses, and, finally,
hadronic interactions with the background gas, including the associated
gamma-ray and radio emission due to subsequent pion decay. We show that the
formalism reproduces CR energy densities, pressure, and cooling rates with an
accuracy of ~10% in steady state conditions where CR injection balances
cooling. Our framework is therefore well suited to be included into numerical
simulation schemes of galaxy and structure formation. (abridged)
