A generalization of tensor calculus and its applications to physics