  We investigate the elliptic and the triangular flow of heavy mesons in
ultrarelativistic heavy-ion collisions at RHIC and the LHC. The dynamics of
heavy quarks is coupled to the locally thermalized and fluid dynamically
evolving quark-gluon plasma. The elliptic flow of $D$ mesons and the centrality
dependence measured at the LHC is well reproduced for purely collisional and
bremsstrahlung interactions. Due to the event-by-event fluctuating initial
conditions from the EPOS2 model, the $D$ meson triangular flow is predicted to
be nonzero at $\sqrt{s}=200$ GeV and $\sqrt{s}=2.76$ TeV. We study the
centrality dependence and quantify the contributions stemming from flow of the
light bulk event and the hadronization process. The flow coefficients as
response to the initial eccentricities behave differently for heavy mesons than
for light hadrons due to their inertia. Higher-order flow coefficients of heavy
flavor become important in order to quantify the degree of thermalization.
