Numerical Model of THz sources and detectors based on Optical Rectification and Electro-Optic Sampling