Design of a sub-millimetric electron gun with analysis of thermomechanical effects on beam dynamics