A computational method for the Helmholtz equation in unbounded domains based on the minimization of an integral functional