The x-rays in a synchrotron are produced by high energy electrons traversing magnetic fields. The main devices that produce the magnetic fields are undulators or wigglers.
To model this process, therefore, first one needs to model the electrons in the ring, and to have a good model of the fields in the ring. This is the purpose of a tracking code. I focus on the code AT, since I have experience, and the elements representing the physics are easily accesible and available, so that one knows where to look if there are problems or questions.
To really know all the fields in the ring that act back on the electron beam, one must do measurements and modelling of the elements. For the insertion devices, there is the Mathematica based code Radia, which allows one to build an insertion device and compute the fields. One can also compute the kick map which will act on the electrons and can reduce the dynamic aperture and lifetime, particularly for narrow pole-width insertion devices.
Next, one needs to compute the radiation that will result from the electrons. For this, the code SRW is quite accurate and state-of the art. Next, one should model how this radiation can progress down the beam-line. For this purpose, the code Shadow is well developed.
In modeling both the electron beam dynamics and the radiation effects from undulators, one needs to have a model for the magnetic field of a given undulator. The field may be computed using a code such as Radia. But there are also representations of the field in terms of harmonics such as the Halbach representation. Here's a description of the symplectic integration routine for an analytical representation from Forest. One may also represent it via a kick map. The latter two representations serve the purpose of the tracking of electrons for the purpose of tracking to determine dynamic aperture. Given the electron orbit, one can compute the radiation emitted. This can be done with e.g. SRW.