Modelling of the temperature and residual stress fields during 3D printing of polymer composites