  We describe techniques for incorporating feedback from star formation and
black hole accretion into simulations of isolated and merging galaxies. At
present, the details of these processes cannot be resolved in simulations on
galactic scales. Our basic approach therefore involves forming coarse-grained
representations of the properties of the interstellar medium and black hole
accretion starting from basic physical assumptions, so that the impact of these
effects can be included on resolved scales. We illustrate our method using a
multiphase description of star-forming gas. Feedback from star formation
pressurises highly overdense gas, altering its effective equation of state. We
show that this allows the construction of stable galaxy models with much larger
gas fractions than possible in earlier numerical work. We extend the model by
including a treatment of gas accretion onto central supermassive black holes in
galaxies. Assuming thermal coupling of a small fraction of the bolometric
luminosity of accreting black holes to the surrounding gas, we show how this
feedback regulates the growth of black holes. In gas-rich mergers of galaxies,
we observe a complex interplay between starbursts and central AGN activity when
the tidal interaction triggers intense nuclear inflows of gas. Once an
accreting supermassive black hole has grown to a critical size, feedback
terminates its further growth, and expels gas from the central region in a
powerful quasar-driven wind. Our simulation methodology is therefore able to
address the coupled processes of gas dynamics, star formation, and black hole
accretion during the formation of galaxies.
