  We address the problem of constructing approximations based on orthogonal
polynomials that preserve an arbitrary set of moments of a given function
without loosing the spectral convergence property. To this aim, we compute the
constrained polynomial of best approximation for a generic basis of orthogonal
polynomials. The construction is entirely general and allows us to derive
structure preserving numerical methods for partial differential equations that
require the conservation of some moments of the solution, typically
representing relevant physical quantities of the problem. These properties are
essential to capture with high accuracy the long-time behavior of the solution.
We illustrate with the aid of several numerical applications to Fokker-Planck
equations the generality and the performances of the present approach.
