Numerical simulation of sonic logging-while-drilling (LWD) borehole measurements is challenging because of significant wave propagation effects due to the massive drilling collar occupying a large portion of the borehole. In addition, the internal structure of the LWD tool can have a significant impact on the measured dispersions of Stoneley and quadrupole modes. The collar is typically constructed with a set of inner periodic grooves, which act as a mechanical filter to attenuate undesirable collar modes. Reliable numerical simulation and interpretation of LWD sonic waveforms requires that all features and dimensions of the drilling collar be included in the simulation model. Furthermore, the presence of the drilling collar can prompt numerical instabilities due to backward propagating modes in the perfectly matched layer (PML) commonly used to truncate the computational domain. This problem can be circumvented with the implementation of artificial viscoelastic attenuation in the collar whenever the simulations are intended to reproduce only wave propagation within the surrounding rock formations. In addition, reliable modeling of borehole wave propagation in the presence of high contrasts in material properties and the internal structure of the LWD collar requires a numerical method capable of accurately and stably resolving all spectral scales present in the model. We implemented an automatic -adaptive finite-element method in the frequency domain combined with a PML technique to simulate LWD sonic logging measurements. Examples of the application verified the accuracy and reliability of the simulated borehole and formation propagation modes in the presence of casing and internal structures in the LWD collar. The presence of steel casing and quality of casing/formation bond significantly influence the propagation modes excited in a borehole. However, it is still possible to estimate the formation shear slowness using monopole and quadrupole sources regardless of the quality of cement bond in fast formations. Assessment of the formation compressional slowness was significantly impeded by the strong pipe mode. Estimation of formation shear slowness in slow formations is practically impossible due to the presence of casing and a strong annulus mode when the quality of casing bond is poor.