Application of variational methods in the fixed and adaptive grid generation