created subroutine for source term calculation