  The second-order ($v_2$) and third-order ($v_3$) Fourier coefficients
describing the azimuthal anisotropy of prompt and nonprompt (from b-hadron
decays) J/$\psi$, as well as prompt $\psi$(2S) mesons are measured in lead-lead
collisions at a center-of-mass energy per nucleon pair of
$\sqrt{s_\mathrm{NN}}$ = 5.02 TeV. The analysis uses a data set corresponding
to an integrated luminosity of 1.61 nb$^{-1}$ recorded with the CMS detector.
The J/$\psi$ and $\psi$(2S) mesons are reconstructed using their dimuon decay
channel. The $v_2$ and $v_3$ coefficients are extracted using the scalar
product method and studied as functions of meson transverse momentum and
collision centrality. The measured $v_2$ values for prompt J/$\psi$ mesons are
found to be larger than those for nonprompt J/$\psi$ mesons. The prompt
J/$\psi$ $v_2$ values at high $p_\mathrm{T}$ are found to be underpredicted by
a model incorporating only parton energy loss effects in a quark-gluon plasma
medium. Prompt and nonprompt J/$\psi$ meson $v_3$ and prompt $\psi$(2S) $v_2$
and $v_3$ values are also reported for the first time, providing new
information about heavy quark interactions in the hot and dense medium created
in heavy ion collisions.
