operating a motor with a undersized vfd
It would likely work, but the motor current for 21.6 Hp is likely to be higher than 21.5/40 X the full load current of the 40 Hp motor. That may cause nuisance over-current tripping of the VFD. If that occurs, the maximum speed may need to be further limited. Using the under-sized VFD is certainly a reasonable thing to try. The VFD should protect itself and the motor. The worst that is likely to happen is nuisance tripping.