Theory-guided hard constraint projection (HCP): a knowledge-based data-driven scientific machine learning method