  While perturbative QCD is sufficient for understanding the color, mass and
energy dependences of parton energy loss and jet quenching at large transverse
momentum in heavy-ion collisions, a simultaneous description of heavy flavor
nuclear modification factor $R_\mathrm{AA}$ and elliptic flow coefficient $v_2$
at low and intermediate $p_\mathrm{T}$ still remains a challenge due to the
effects from non-perturbative interactions. In this work, we extend the linear
Boltzmann transport model by implementing a generalized Cornell-type potential
that incorporates both short-range Yukawa interaction and long-range color
confining interaction between heavy quarks and the QGP medium. Combining our
new approach for heavy-quark-QGP interaction with a (3+1)-dimensional
hydrodynamic model CLVisc for the QGP evolution and a hybrid
fragmentation-coalescence model for heavy quark hadronization, we obtain a
satisfactory description of heavy meson $R_\mathrm{AA}$ and $v_2$ from low to
intermediate to high $p_\mathrm{T}$ observed at both RHIC and the LHC. By
model-data-comparison, we extract for the first time the in-medium heavy quark
potential from open heavy flavor measurements; the result is in agreement with
the lattice QCD calculation. Our study indicates that while jet quenching at
high $p_\mathrm{T}$ is dominated by perturbative QCD interactions,
non-perturbative interactions are indispensible for understanding heavy flavor
quenching and flow at low and intermediate $p_\mathrm{T}$.
