# Varying energy density of photons?

I know photon energy density is proportional to the fourth power of the scale factor, because it dilutes and redshifts.

I want to take into account the added photon energy density from astrophysical sources along the scale factor to the CMB energy density from the beginning of the age of the universe. I know for most of the cases, this one can be disregarded, but I still want to calculate it assuming a certain rate of energy density production proportional to the scale factor.

How can I introduce the creation of photons along the universe scale factor in the Friedmann equations?

To obey stress-energy conservation, we need the photon energy to come from somewhere. For astrophysical sources, it would come out of the matter. In that case you can assume that there is some energy exchange rate $$\Gamma$$ such that $$\frac{d}{dt}\rho_m + 3H\rho_m = -\Gamma\rho_m, \\ \frac{d}{dt}\rho_r + 4H\rho_r = \Gamma\rho_m,$$ where $$\rho_m$$ and $$\rho_r$$ are the energy density of matter and radiation, respectively. $$\Gamma$$ has dimensions of inverse time and can be viewed as the "decay rate" of matter. It can be time dependent, if you like; if it is constant, that just means that a given mass of matter always produces radiation at the same rate.
The above equations, together with the first Friedmann equation, $$H^2 = \frac{8\pi G}{3}(\rho_m+\rho_r)$$ (and you can add dark energy or curvature as needed), are now a coupled system of differential equations that you can solve (probably numerically) to obtain $$\rho_m$$, $$\rho_r$$, and $$H$$ as functions of time.